Java Code Examples for com.intellij.openapi.Disposable
The following examples show how to use
com.intellij.openapi.Disposable. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: flutter-intellij Source File: PerfMemoryPanel.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
PerfMemoryPanel(@NotNull FlutterApp app, @NotNull Disposable parentDisposable) { setLayout(new BorderLayout()); setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), MEMORY_TAB_LABEL)); setMinimumSize(new Dimension(0, PerfMemoryPanel.HEIGHT)); setPreferredSize(new Dimension(Short.MAX_VALUE, PerfMemoryPanel.HEIGHT)); final JPanel heapDisplay = HeapDisplay.createJPanelView(parentDisposable, app); add(heapDisplay, BorderLayout.CENTER); if (app.getVMServiceManager() != null) { app.getVMServiceManager().getHeapMonitor().addPollingClient(); } Disposer.register(parentDisposable, () -> { if (app.getVMServiceManager() != null) { app.getVMServiceManager().getHeapMonitor().removePollingClient(); } }); }
Example 2
Source Project: flutter-intellij Source File: WidgetIndentsHighlightingPass.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
private void updatePreviewHighlighter(MarkupModel mm, WidgetIndentsPassData data) { final FlutterSettings settings = FlutterSettings.getInstance(); if (!settings.isEnableHotUiInCodeEditor()) return; if (data.previewsForEditor == null && myEditor instanceof EditorImpl) { // TODO(jacobr): is there a way to get access to a disposable that will // trigger when the editor disposes than casting to EditorImpl? final Disposable parentDisposable = ((EditorImpl)myEditor).getDisposable(); final TextRange range = new TextRange(0, Integer.MAX_VALUE); final RangeHighlighter highlighter = mm.addRangeHighlighter( 0, myDocument.getTextLength(), HighlighterLayer.FIRST, null, HighlighterTargetArea.LINES_IN_RANGE ); data.previewsForEditor = new PreviewsForEditor(context, editorEventService, myEditor, parentDisposable); highlighter.setCustomRenderer(data.previewsForEditor); } if (data.previewsForEditor != null) { data.previewsForEditor.outlinesChanged(data.myDescriptors); } }
Example 3
Source Project: flutter-intellij Source File: StableWidgetTracker.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
public StableWidgetTracker( InspectorService.Location initialLocation, FlutterDartAnalysisServer flutterAnalysisServer, Project project, Disposable parentDisposable ) { Disposer.register(parentDisposable, this); converter = new OutlineOffsetConverter(project, initialLocation.getFile()); currentOutlines = new EventStream<>(ImmutableList.of()); this.flutterAnalysisServer = flutterAnalysisServer; this.initialLocation = initialLocation; final DartAnalysisServerService analysisServerService = DartAnalysisServerService.getInstance(project); currentFilePath = FileUtil.toSystemDependentName(initialLocation.getFile().getPath()); flutterAnalysisServer.addOutlineListener(currentFilePath, outlineListener); }
Example 4
Source Project: flutter-intellij Source File: InspectorTree.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
public InspectorTree(final DefaultMutableTreeNode treemodel, String treeName, boolean detailsSubtree, String parentTreeName, boolean rootVisible, boolean legacyMode, Disposable parentDisposable) { super(treemodel); setUI(new InspectorTreeUI()); final BasicTreeUI ui = (BasicTreeUI)getUI(); this.detailsSubtree = detailsSubtree; setRootVisible(rootVisible); getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); registerShortcuts(parentDisposable); if (detailsSubtree) { // TODO(devoncarew): This empty text is not showing up for the details area, even when there are no detail nodes. getEmptyText().setText(treeName + " subtree of the selected " + parentTreeName); } else { getEmptyText().setText(treeName + " tree for the running app"); } }
Example 5
Source Project: intellij Source File: ServiceHelperCompat.java License: Apache License 2.0 | 6 votes |
public static <T> void registerService( ComponentManager componentManager, Class<T> key, T implementation, Disposable parentDisposable) { @SuppressWarnings({"rawtypes", "unchecked"}) // #api193: wildcard generics added in 2020.1 List<? extends IdeaPluginDescriptor> loadedPlugins = (List) PluginManager.getLoadedPlugins(); Optional<? extends IdeaPluginDescriptor> platformPlugin = loadedPlugins.stream() .filter(descriptor -> descriptor.getName().startsWith("IDEA CORE")) .findAny(); Verify.verify(platformPlugin.isPresent()); ((ComponentManagerImpl) componentManager) .registerServiceInstance(key, implementation, platformPlugin.get()); }
Example 6
Source Project: flutter-intellij Source File: WidgetViewController.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
WidgetViewController(WidgetViewModelData data, Disposable parent) { this.data = data; Disposer.register(parent, this); groupClient = new InspectorGroupManagerService.Client(this) { @Override public void onInspectorAvailabilityChanged() { WidgetViewController.this.onInspectorAvailabilityChanged(); } @Override public void requestRepaint(boolean force) { onFlutterFrame(); } @Override public void onFlutterFrame() { WidgetViewController.this.onFlutterFrame(); } public void onSelectionChanged(DiagnosticsNode selection) { WidgetViewController.this.onSelectionChanged(selection); } }; data.context.inspectorGroupManagerService.addListener(groupClient, parent); }
Example 7
Source Project: intellij Source File: ServiceHelper.java License: Apache License 2.0 | 6 votes |
private static <T> void registerService( ComponentManager componentManager, Class<T> key, T implementation, Disposable parentDisposable) { boolean exists = componentManager.getService(key) != null; if (exists) { // upstream code can do it all for us ServiceContainerUtil.replaceService(componentManager, key, implementation, parentDisposable); return; } // otherwise we should manually unregister on disposal ServiceContainerUtil.registerServiceInstance(componentManager, key, implementation); Disposer.register( parentDisposable, () -> ((MutablePicoContainer) componentManager.getPicoContainer()) .unregisterComponent(key.getName())); }
Example 8
Source Project: flutter-intellij Source File: WidgetIndentsHighlightingPass.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
private void updatePreviewHighlighter(MarkupModel mm, WidgetIndentsPassData data) { final FlutterSettings settings = FlutterSettings.getInstance(); if (!settings.isEnableHotUiInCodeEditor()) return; if (data.previewsForEditor == null && myEditor instanceof EditorImpl) { // TODO(jacobr): is there a way to get access to a disposable that will // trigger when the editor disposes than casting to EditorImpl? final Disposable parentDisposable = ((EditorImpl)myEditor).getDisposable(); final TextRange range = new TextRange(0, Integer.MAX_VALUE); final RangeHighlighter highlighter = mm.addRangeHighlighter( 0, myDocument.getTextLength(), HighlighterLayer.FIRST, null, HighlighterTargetArea.LINES_IN_RANGE ); data.previewsForEditor = new PreviewsForEditor(context, editorEventService, myEditor, parentDisposable); highlighter.setCustomRenderer(data.previewsForEditor); } if (data.previewsForEditor != null) { data.previewsForEditor.outlinesChanged(data.myDescriptors); } }
Example 9
Source Project: flutter-intellij Source File: StableWidgetTracker.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
public StableWidgetTracker( InspectorService.Location initialLocation, FlutterDartAnalysisServer flutterAnalysisServer, Project project, Disposable parentDisposable ) { Disposer.register(parentDisposable, this); converter = new OutlineOffsetConverter(project, initialLocation.getFile()); currentOutlines = new EventStream<>(ImmutableList.of()); this.flutterAnalysisServer = flutterAnalysisServer; this.initialLocation = initialLocation; final DartAnalysisServerService analysisServerService = DartAnalysisServerService.getInstance(project); currentFilePath = FileUtil.toSystemDependentName(initialLocation.getFile().getPath()); flutterAnalysisServer.addOutlineListener(currentFilePath, outlineListener); }
Example 10
Source Project: flutter-intellij Source File: InspectorTree.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
public InspectorTree(final DefaultMutableTreeNode treemodel, String treeName, boolean detailsSubtree, String parentTreeName, boolean rootVisible, boolean legacyMode, Disposable parentDisposable) { super(treemodel); setUI(new InspectorTreeUI()); final BasicTreeUI ui = (BasicTreeUI)getUI(); this.detailsSubtree = detailsSubtree; setRootVisible(rootVisible); getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); registerShortcuts(parentDisposable); if (detailsSubtree) { // TODO(devoncarew): This empty text is not showing up for the details area, even when there are no detail nodes. getEmptyText().setText(treeName + " subtree of the selected " + parentTreeName); } else { getEmptyText().setText(treeName + " tree for the running app"); } }
Example 11
Source Project: flutter-intellij Source File: PropertyEditorPanel.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public static Balloon showPopupHelper( InspectorGroupManagerService inspectorService, Project project, @Nullable DiagnosticsNode node, @NotNull InspectorService.Location location, FlutterDartAnalysisServer service ) { final Color GRAPHITE_COLOR = new JBColor(new Color(236, 236, 236, 215), new Color(60, 63, 65, 215)); final Disposable panelDisposable = Disposer.newDisposable(); final PropertyEditorPanel panel = new PropertyEditorPanel(inspectorService, project, service, true, true, panelDisposable); final StableWidgetTracker tracker = new StableWidgetTracker(location, service, project, panelDisposable); final EventStream<VirtualFile> activeFile = new EventStream<>(location.getFile()); panel.initalize(node, tracker.getCurrentOutlines(), activeFile); panel.setBackground(GRAPHITE_COLOR); panel.setOpaque(false); final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createBalloonBuilder(panel); balloonBuilder.setFadeoutTime(0); balloonBuilder.setFillColor(GRAPHITE_COLOR); balloonBuilder.setAnimationCycle(0); balloonBuilder.setHideOnClickOutside(true); balloonBuilder.setHideOnKeyOutside(false); balloonBuilder.setHideOnAction(false); balloonBuilder.setCloseButtonEnabled(false); balloonBuilder.setBlockClicksThroughBalloon(true); balloonBuilder.setRequestFocus(true); balloonBuilder.setShadow(true); final Balloon balloon = balloonBuilder.createBalloon(); Disposer.register(balloon, panelDisposable); return balloon; }
Example 12
Source Project: intellij Source File: AndroidTestConsoleProvider.java License: Apache License 2.0 | 5 votes |
@Override public ConsoleView createAndAttach(Disposable parent, ProcessHandler handler, Executor executor) throws ExecutionException { switch (configState.getLaunchMethod()) { case BLAZE_TEST: ConsoleView console = createBlazeTestConsole(executor); console.attachToProcess(handler); return console; case NON_BLAZE: case MOBILE_INSTALL: return getStockConsoleProvider().createAndAttach(parent, handler, executor); } throw new AssertionError(); }
Example 13
Source Project: intellij-csv-validator Source File: CsvAnnotatorTest.java License: Apache License 2.0 | 5 votes |
private long collectAndCheckHighlighting(@NotNull ExpectedHighlightingDataWrapper data) { Project project = myFixture.getProject(); EdtTestUtil.runInEdtAndWait(() -> { PsiDocumentManager.getInstance(project).commitAllDocuments(); }); PsiFileImpl file = (PsiFileImpl)this.getHostFile(); FileElement hardRefToFileElement = file.calcTreeElement(); if (!DumbService.isDumb(project)) { ServiceManager.getService(project, CacheManager.class).getFilesWithWord("XXX", (short)2, GlobalSearchScope.allScope(project), true); } long start = System.currentTimeMillis(); Disposable disposable = Disposer.newDisposable(); List<HighlightInfo> infos; try { infos = myFixture.doHighlighting(); this.removeDuplicatedRangesForInjected(infos); } finally { Disposer.dispose(disposable); } long elapsed = System.currentTimeMillis() - start; data.checkResultWrapper(file, infos, file.getText()); hardRefToFileElement.hashCode(); return elapsed; }
Example 14
Source Project: mule-intellij-plugins Source File: MuleDomainMavenModuleBuilder.java License: Apache License 2.0 | 5 votes |
@Nullable @Override public ModuleWizardStep getCustomOptionsStep(WizardContext context, Disposable parentDisposable) { MuleVersionConfiguration step = new MuleVersionConfiguration(this, muleVersion); Disposer.register(parentDisposable, step); return step; }
Example 15
Source Project: mule-intellij-plugins Source File: MuleMavenModuleBuilder.java License: Apache License 2.0 | 5 votes |
@Nullable @Override public ModuleWizardStep getCustomOptionsStep(WizardContext context, Disposable parentDisposable) { MuleVersionConfiguration step = new MuleVersionConfiguration(this, muleVersion); Disposer.register(parentDisposable, step); return step; }
Example 16
Source Project: flutter-intellij Source File: IdeaFrameFixture.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
protected IdeaFrameFixture(@NotNull Robot robot, @NotNull IdeFrameImpl target) { super(IdeaFrameFixture.class, robot, target); Project project = getProject(); myIdeFrameFixture = IdeFrameFixture.find(robot); Disposable disposable = new IdeaFrameFixture.NoOpDisposable(); Disposer.register(project, disposable); GradleBuildState.subscribe(project, myGradleProjectEventListener); }
Example 17
Source Project: flutter-intellij Source File: GradleDependencyFetcherTest.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@BeforeClass public static void setUp() { Disposable disposable = Disposer.newDisposable(); ApplicationManager.setApplication(new MockApplication(disposable), disposable); Extensions.registerAreaClass("IDEA_PROJECT", null); ourProject = new MockProject(ApplicationManager.getApplication().getPicoContainer(), disposable); }
Example 18
Source Project: flutter-intellij Source File: FlutterLog.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public void listenToProcess(@NotNull ProcessHandler processHandler, @NotNull Disposable parent) { processHandler.addProcessListener(new ProcessAdapter() { @Override public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) { onEntry(logEntryParser.parseDaemonEvent(event, outputType)); } }, parent); }
Example 19
Source Project: flutter-intellij Source File: FlutterLogTree.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
private TreeModel(@NotNull ColumnModel columns, @NotNull Disposable parent, @NotNull FlutterLogPreferences logPreferences) { super(new LogRootTreeNode(), columns.getInfos()); this.logPreferences = logPreferences; this.log = columns.app.getFlutterLog(); this.columns = columns; // Scroll to end by default. autoScrollToEnd = true; setShowSequenceNumbers(false); uiThreadAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, parent); updateTimer = new Timer(100, e -> uiExec(this::update, 0)); }
Example 20
Source Project: intellij Source File: ServiceHelper.java License: Apache License 2.0 | 5 votes |
/** Unregister all extensions of the given class, for the given extension point. */ public static <T> void unregisterLanguageExtensionPoint( String extensionPointKey, Class<T> clazz, Disposable parentDisposable) { ExtensionPoint<LanguageExtensionPoint<T>> ep = Extensions.getRootArea().getExtensionPoint(extensionPointKey); LanguageExtensionPoint<T>[] existingExtensions = ep.getExtensions(); for (LanguageExtensionPoint<T> ext : existingExtensions) { if (clazz.getName().equals(ext.implementationClass)) { ep.unregisterExtension(ext); Disposer.register(parentDisposable, () -> ep.registerExtension(ext)); } } }
Example 21
Source Project: flutter-intellij Source File: FlutterModuleBuilder.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@Nullable @Override public ModuleWizardStep getCustomOptionsStep(final WizardContext context, final Disposable parentDisposable) { if (!context.isCreatingNewProject()) { myProject = context.getProject(); } myStep = new FlutterModuleWizardStep(context); mySettingsFields = new FlutterCreateAdditionalSettingsFields(new FlutterCreateAdditionalSettings(), this::getFlutterSdk, myProject); Disposer.register(parentDisposable, myStep); return myStep; }
Example 22
Source Project: flutter-intellij Source File: FlutterPerformanceView.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
private DefaultActionGroup createToolbar(@NotNull ToolWindow toolWindow, @NotNull FlutterApp app, Disposable parentDisposable) { final DefaultActionGroup toolbarGroup = new DefaultActionGroup(); toolbarGroup.add(registerAction(new PerformanceOverlayAction(app))); toolbarGroup.addSeparator(); toolbarGroup.add(registerAction(new DebugPaintAction(app))); toolbarGroup.add(registerAction(new ShowPaintBaselinesAction(app, true))); toolbarGroup.addSeparator(); toolbarGroup.add(registerAction(new TimeDilationAction(app, true))); return toolbarGroup; }
Example 23
Source Project: intellij Source File: TestUtils.java License: Apache License 2.0 | 5 votes |
@NotNull public static MockProject mockProject( @Nullable PicoContainer container, Disposable parentDisposable) { Extensions.registerAreaClass("IDEA_PROJECT", null); container = container != null ? container : new DefaultPicoContainer(); return new MockProject(container, parentDisposable); }
Example 24
Source Project: intellij Source File: ServiceHelper.java License: Apache License 2.0 | 5 votes |
public static <T> void registerProjectComponent( Project project, Class<T> key, T implementation, Disposable parentDisposable) { // #api193 (or #api201?): ComponentManagerImpl moved in 2020.1 dot releases. Check // ComponentManagerImpl directly when earlier releases are no longer supported boolean isComponentManagerImpl = project instanceof ProjectImpl; if (isComponentManagerImpl) { ServiceContainerUtil.registerComponentInstance( project, key, implementation, parentDisposable); } else { registerComponentInstance( (MutablePicoContainer) project.getPicoContainer(), key, implementation, parentDisposable); } }
Example 25
Source Project: flutter-intellij Source File: WidgetPerfTipsPanel.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public WidgetPerfTipsPanel(Disposable parentDisposable, @NotNull FlutterApp app) { setLayout(new VerticalLayout(5)); add(new JSeparator()); perfManager = FlutterWidgetPerfManager.getInstance(app.getProject()); perfTips = new JPanel(); perfTips.setLayout(new VerticalLayout(0)); linkListener = (source, tip) -> handleTipSelection(tip); final Project project = app.getProject(); final MessageBusConnection bus = project.getMessageBus().connect(project); final FileEditorManagerListener listener = new FileEditorManagerListener() { @Override public void selectionChanged(@NotNull FileEditorManagerEvent event) { selectedEditorChanged(); } }; selectedEditorChanged(); bus.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener); // Computing performance tips is somewhat expensive so we don't want to // compute them too frequently. Performance tips are only computed when // new performance stats are available but performance stats are updated // at 60fps so to be conservative we delay computing perf tips. final Timer perfTipComputeDelayTimer = new Timer(PERF_TIP_COMPUTE_DELAY, this::onComputePerfTips); perfTipComputeDelayTimer.start(); Disposer.register(parentDisposable, perfTipComputeDelayTimer::stop); }
Example 26
Source Project: flutter-intellij Source File: HeapDisplay.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public static JPanel createJPanelView(Disposable parentDisposable, FlutterApp app) { final JPanel panel = new JPanel(new BorderLayout()); final JBLabel heapLabel = new JBLabel("", SwingConstants.RIGHT); heapLabel.setAlignmentY(Component.BOTTOM_ALIGNMENT); heapLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL)); heapLabel.setForeground(UIUtil.getLabelDisabledForeground()); heapLabel.setBorder(JBUI.Borders.empty(4)); final HeapState heapState = new HeapState(60 * 1000); final HeapDisplay graph = new HeapDisplay(state -> { heapLabel.setText(heapState.getHeapSummary()); SwingUtilities.invokeLater(heapLabel::repaint); }); graph.setLayout(new BoxLayout(graph, BoxLayout.X_AXIS)); graph.add(Box.createHorizontalGlue()); graph.add(heapLabel); panel.add(graph, BorderLayout.CENTER); final HeapListener listener = memoryUsages -> SwingUtilities.invokeLater(() -> { heapState.handleMemoryUsage(memoryUsages); graph.updateFrom(heapState); panel.repaint(); }); assert app.getVMServiceManager() != null; app.getVMServiceManager().addHeapListener(listener); Disposer.register(parentDisposable, () -> app.getVMServiceManager().removeHeapListener(listener)); return panel; }
Example 27
Source Project: flutter-intellij Source File: InspectorGroupManagerService.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public Client(Disposable parent) { Disposer.register(parent, () -> { if (groupManager != null) { groupManager.clear(false); } }); }
Example 28
Source Project: flutter-intellij Source File: InspectorGroupManagerService.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public void addListener(@NotNull Listener listener, Disposable disposable) { synchronized (listeners) { listeners.add(listener); } // Update the listener with the current active state if any. if (inspectorService != null) { listener.onInspectorAvailable(inspectorService); } if (selection != null) { listener.onSelectionChanged(selection); } Disposer.register(disposable, () -> removeListener(listener)); }
Example 29
Source Project: intellij Source File: ServiceHelperCompat.java License: Apache License 2.0 | 5 votes |
public static <T> void registerService( ComponentManager componentManager, Class<T> key, T implementation, Disposable parentDisposable) { Optional<IdeaPluginDescriptor> platformPlugin = PluginManager.getLoadedPlugins().stream() .filter(descriptor -> descriptor.getName().startsWith("IDEA CORE")) .findAny(); Verify.verify(platformPlugin.isPresent()); ((PlatformComponentManagerImpl) componentManager) .registerServiceInstance(key, implementation, platformPlugin.get()); }
Example 30
Source Project: flutter-intellij Source File: InlinePreviewViewController.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public InlinePreviewViewController(InlineWidgetViewModelData data, boolean drawBackground, Disposable disposable) { super(data, drawBackground, disposable); data.context.editorPositionService.addListener(getEditor(), new EditorPositionService.Listener() { @Override public void updateVisibleArea(Rectangle newRectangle) { InlinePreviewViewController.this.updateVisibleArea(newRectangle); } @Override public void onVisibleChanged() { InlinePreviewViewController.this.onVisibleChanged(); } }, this); }