consulo.disposer.Disposable Java Examples
The following examples show how to use
consulo.disposer.Disposable.
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 File: EditorUtil.java From consulo with Apache License 2.0 | 6 votes |
public static void disposeWithEditor(@Nonnull Editor editor, @Nonnull Disposable disposable) { ApplicationManager.getApplication().assertIsDispatchThread(); if (Disposer.isDisposed(disposable)) return; if (editor.isDisposed()) { Disposer.dispose(disposable); return; } // for injected editors disposal will happen only when host editor is disposed, // but this seems to be the best we can do (there are no notifications on disposal of injected editor) Editor hostEditor = editor instanceof EditorWindow ? ((EditorWindow)editor).getDelegate() : editor; EditorFactory.getInstance().addEditorFactoryListener(new EditorFactoryAdapter() { @Override public void editorReleased(@Nonnull EditorFactoryEvent event) { if (event.getEditor() == hostEditor) { Disposer.dispose(disposable); } } }, disposable); }
Example #2
Source File: MacUtil.java From consulo with Apache License 2.0 | 6 votes |
public static void adjustFocusTraversal(@Nonnull Disposable disposable) { if (!SystemInfo.isMacOSSnowLeopard) return; final AWTEventListener listener = new AWTEventListener() { @Override public void eventDispatched(AWTEvent event) { if (event instanceof KeyEvent && ((KeyEvent)event).getKeyCode() == KeyEvent.VK_TAB && (!(event.getSource() instanceof JTextComponent)) && (!(event.getSource() instanceof JList)) && !isFullKeyboardAccessEnabled()) ((KeyEvent)event).consume(); } }; Disposer.register(disposable, new Disposable() { @Override public void dispose() { Toolkit.getDefaultToolkit().removeAWTEventListener(listener); } }); Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.KEY_EVENT_MASK); }
Example #3
Source File: RecentStringInterner.java From consulo with Apache License 2.0 | 6 votes |
public RecentStringInterner(@Nonnull Disposable parentDisposable) { final int stripes = 16; //noinspection unchecked myInterns = new SLRUCache[stripes]; myStripeLocks = new Lock[myInterns.length]; int capacity = 8192; for (int i = 0; i < myInterns.length; ++i) { myInterns[i] = new SLRUCache<String, String>(capacity / stripes, capacity / stripes) { @Nonnull @Override public String createValue(String key) { return key; } @Override protected void putToProtectedQueue(String key, @Nonnull String value) { super.putToProtectedQueue(value, value); } }; myStripeLocks[i] = new ReentrantLock(); } assert Integer.highestOneBit(stripes) == stripes; myStripeMask = stripes - 1; LowMemoryWatcher.register(this::clear, parentDisposable); }
Example #4
Source File: DiffSideView.java From consulo with Apache License 2.0 | 6 votes |
public static void install(DiffContent content, EditorSource source, DiffSidesContainer container) { final Editor editor = source.getEditor(); Project project = container.getProject(); if (project == null || editor == null) { return; } final MouseLineNumberListener listener = new MouseLineNumberListener(content, editor, container, project); editor.addEditorMouseListener(listener.myMouseListener); editor.addEditorMouseMotionListener(listener.myMouseMotionListener); source.addDisposable(new Disposable() { public void dispose() { editor.removeEditorMouseListener(listener.myMouseListener); editor.removeEditorMouseMotionListener(listener.myMouseMotionListener); } }); }
Example #5
Source File: TestFrameworkActions.java From consulo with Apache License 2.0 | 6 votes |
public static void addPropertyListener(final AbstractProperty<Boolean> property, final TestFrameworkPropertyListener<Boolean> propertyListener, final TestFrameworkRunningModel model, final boolean sendValue) { final TestConsoleProperties properties = model.getProperties(); if (sendValue) { properties.addListenerAndSendValue(property, propertyListener); } else { properties.addListener(property, propertyListener); } Disposer.register(model, new Disposable() { public void dispose() { properties.removeListener(property, propertyListener); } }); }
Example #6
Source File: AsyncPopupImpl.java From consulo with Apache License 2.0 | 6 votes |
public AsyncPopupImpl(@Nullable Project project, @Nullable WizardPopup parent, @Nonnull AsyncPopupStep<Object> step, @Nullable Object parentValue) { super(project, parent, step); if (!(parent instanceof NextStepHandler)) throw new IllegalArgumentException("parent must be NextStepHandler"); myCallBackParent = (NextStepHandler)parent; myParentValue = parentValue; myFuture = ApplicationManager.getApplication().executeOnPooledThread(step); myAlarm = new Alarm(this); myAlarm.addRequest(this, 200); Disposer.register(this, new Disposable() { @Override public void dispose() { if (!myFuture.isCancelled() && !myFuture.isDone()) { myFuture.cancel(false); } } }); }
Example #7
Source File: ChangesViewManager.java From consulo with Apache License 2.0 | 5 votes |
public void projectOpened() { final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject); changeListManager.addChangeListListener(myListener); Disposer.register(myProject, new Disposable() { public void dispose() { changeListManager.removeChangeListListener(myListener); } }); if (ApplicationManager.getApplication().isHeadlessEnvironment()) return; myContent = new MyChangeViewContent(createChangeViewComponent(), ChangesViewContentManager.LOCAL_CHANGES, false); myContent.setCloseable(false); myContentManager.addContent(myContent); scheduleRefresh(); myProject.getMessageBus().connect().subscribe(RemoteRevisionsCache.REMOTE_VERSION_CHANGED, new Runnable() { public void run() { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { refreshView(); } }, ModalityState.NON_MODAL, myProject.getDisposed()); } }); myDetailsOn = VcsConfiguration.getInstance(myProject).LOCAL_CHANGES_DETAILS_PREVIEW_SHOWN; changeDetails(); }
Example #8
Source File: CoreProjectEnvironment.java From consulo with Apache License 2.0 | 5 votes |
public CoreProjectEnvironment(Disposable parentDisposable, CoreApplicationEnvironment applicationEnvironment) { myParentDisposable = parentDisposable; myEnvironment = applicationEnvironment; myProject = new MockProject(myEnvironment.getApplication(), myParentDisposable); preregisterServices(); myFileIndexFacade = createFileIndexFacade(); myMessageBus = (MessageBusImpl)myProject.getMessageBus(); PsiModificationTrackerImpl modificationTracker = new PsiModificationTrackerImpl(applicationEnvironment.getApplication(), myProject); myProject.registerService(PsiModificationTracker.class, modificationTracker); myProject.registerService(FileIndexFacade.class, myFileIndexFacade); myProject.registerService(ResolveCache.class, new ResolveCache(myProject)); registerProjectExtensionPoint(PsiTreeChangePreprocessor.EP_NAME, PsiTreeChangePreprocessor.class); myPsiManager = new PsiManagerImpl(myProject, () -> myFileIndexFacade, modificationTracker); ((FileManagerImpl)myPsiManager.getFileManager()).markInitialized(); registerProjectComponent(PsiManager.class, myPsiManager); registerProjectComponent(PsiDocumentManager.class, new CorePsiDocumentManager(myProject, new MockDocumentCommitProcessor())); myProject.registerService(ResolveScopeManager.class, createResolveScopeManager(myPsiManager)); myProject.registerService(PsiFileFactory.class, new PsiFileFactoryImpl(myPsiManager)); myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myPsiManager))); myProject.registerService(ProjectScopeBuilder.class, createProjectScopeBuilder()); myProject.registerService(DumbService.class, new MockDumbService(myProject)); }
Example #9
Source File: RegExHelpPopup.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static LinkLabel createRegExLink(@Nonnull String title, @Nullable final Component owner, @Nullable final Logger logger) { return new LinkLabel(title, null, new LinkListener() { JBPopup helpPopup; @Override public void linkSelected(LinkLabel aSource, Object aLinkData) { try { if (helpPopup != null && !helpPopup.isDisposed() && helpPopup.isVisible()) { return; } helpPopup = createRegExHelpPopup(); Disposer.register(helpPopup, new Disposable() { @Override public void dispose() { destroyPopup(); } }); helpPopup.showInCenterOf(owner); } catch (BadLocationException e) { if (logger != null) logger.info(e); } } private void destroyPopup() { helpPopup = null; } }); }
Example #10
Source File: DiffPanelState.java From consulo with Apache License 2.0 | 5 votes |
public DiffPanelState(ContentChangeListener changeListener, Project project, int diffDividerPolygonsOffset, @Nonnull Disposable parentDisposable) { super(project, changeListener, parentDisposable); myDiffDividerPolygonsOffset = diffDividerPolygonsOffset; }
Example #11
Source File: ChangeListTodosPanel.java From consulo with Apache License 2.0 | 5 votes |
public ChangeListTodosPanel(Project project,TodoPanelSettings settings, Content content){ super(project,settings,false,content); ChangeListManager changeListManager = ChangeListManager.getInstance(project); final MyChangeListManagerListener myChangeListManagerListener = new MyChangeListManagerListener(); changeListManager.addChangeListListener(myChangeListManagerListener); Disposer.register(this, new Disposable() { @Override public void dispose() { ChangeListManager.getInstance(myProject).removeChangeListListener(myChangeListManagerListener); } }); myAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, this); }
Example #12
Source File: ProjectLibraryTabFactory.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public AddModuleDependencyTabContext createTabContext(@Nonnull Disposable parent, @Nonnull ClasspathPanel panel, @Nonnull StructureConfigurableContext context) { return new ProjectLibraryTabContext(panel, context); }
Example #13
Source File: DesktopEditorMarkupModelImpl.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public void setErrorStripeRenderer(ErrorStripeRenderer renderer) { assertIsDispatchThread(); if (myErrorStripeRenderer instanceof Disposable) { Disposer.dispose((Disposable)myErrorStripeRenderer); } myErrorStripeRenderer = renderer; //try to not cancel tooltips here, since it is being called after every writeAction, even to the console //HintManager.getInstance().getTooltipController().cancelTooltips(); }
Example #14
Source File: ObjectTree.java From consulo with Apache License 2.0 | 5 votes |
public final void register(@Nonnull Disposable parent, @Nonnull Disposable child) { if (parent == child) throw new IllegalArgumentException("Cannot register to itself: " + parent); synchronized (treeLock) { Object wasDisposed = getDisposalInfo(parent); if (wasDisposed != null) { throw new IncorrectOperationException("Sorry but parent: " + parent + " has already been disposed " + "(see the cause for stacktrace) so the child: " + child + " will never be disposed", wasDisposed instanceof Throwable ? (Throwable)wasDisposed : null); } if (isDisposing(parent)) { throw new IncorrectOperationException("Sorry but parent: " + parent + " is being disposed so the child: " + child + " will never be disposed"); } myDisposedObjects.remove(child); // if we dispose thing and then register it back it means it's not disposed anymore ObjectNode parentNode = getNode(parent); if (parentNode == null) parentNode = createNodeFor(parent, null); ObjectNode childNode = getNode(child); if (childNode == null) { childNode = createNodeFor(child, parentNode); } else { ObjectNode oldParent = childNode.getParent(); if (oldParent != null) { oldParent.removeChild(childNode); } } myRootObjects.remove(child); checkWasNotAddedAlready(parentNode, childNode); parentNode.addChild(childNode); } }
Example #15
Source File: ProgressIndicatorUtils.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static ProgressIndicator forceWriteActionPriority(@Nonnull ProgressIndicator progress, @Nonnull Disposable parentDisposable) { ApplicationManager.getApplication().addApplicationListener(new ApplicationListener() { @Override public void beforeWriteActionStart(@Nonnull Object action) { if (progress.isRunning()) { progress.cancel(); } } }, parentDisposable); return progress; }
Example #16
Source File: ExpirationUtil.java From consulo with Apache License 2.0 | 5 votes |
public static AutoCloseable cancelJobOnDisposal(Disposable thisDisposable, Job job, boolean weaklyReferencedJob) { ExpirableConstrainedExecution.RunOnce runOnce = new ExpirableConstrainedExecution.RunOnce(); Disposable child = () -> { runOnce.invoke(() -> { job.cancel(); }); }; Disposable childRef = !weaklyReferencedJob ? child : new WeakReferenceDisposableWrapper(child); if (!tryRegisterDisposable(thisDisposable, childRef)) { Disposer.dispose(childRef); // runs disposableBlock() return () -> { }; } else { Consumer<Throwable> completionHandler = new Consumer<Throwable>() { @SuppressWarnings("unused") Disposable hardRefToChild = child; // transitive: job -> completionHandler -> child @Override public void accept(Throwable t) { runOnce.invoke(() -> { Disposer.dispose(childRef); }); } }; Disposable jobCompletionUnregisteringHandle = job.invokeOnCompletion(completionHandler); return () -> { jobCompletionUnregisteringHandle.dispose(); completionHandler.accept(null); }; } }
Example #17
Source File: VcsLogPersistentIndex.java From consulo with Apache License 2.0 | 5 votes |
public VcsLogPersistentIndex(@Nonnull Project project, @Nonnull VcsLogStorage hashMap, @Nonnull VcsLogProgress progress, @Nonnull Map<VirtualFile, VcsLogProvider> providers, @Nonnull FatalErrorHandler fatalErrorsConsumer, @Nonnull Disposable disposableParent) { myHashMap = hashMap; myProject = project; myProgress = progress; myProviders = providers; myFatalErrorsConsumer = fatalErrorsConsumer; myRoots = ContainerUtil.newLinkedHashSet(); for (Map.Entry<VirtualFile, VcsLogProvider> entry : providers.entrySet()) { if (VcsLogProperties.get(entry.getValue(), VcsLogProperties.SUPPORTS_INDEXING)) { myRoots.add(entry.getKey()); } } myUserRegistry = (VcsUserRegistryImpl)ServiceManager.getService(myProject, VcsUserRegistry.class); myIndexStorage = createIndexStorage(fatalErrorsConsumer, calcLogId(myProject, providers)); for (VirtualFile root : myRoots) { myNumberOfTasks.put(root, new AtomicInteger()); } Disposer.register(disposableParent, this); }
Example #18
Source File: CompilerCacheManager.java From consulo with Apache License 2.0 | 5 votes |
public synchronized void flushCaches() { for (Disposable disposable : myCacheDisposables) { try { disposable.dispose(); } catch (Throwable e) { LOG.info(e); } } myCacheDisposables.clear(); myGenericCachesMap.clear(); myCompilerToCacheMap.clear(); }
Example #19
Source File: VirtualFilePointerManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
private static void registerDisposable(@Nonnull Disposable parentDisposable, @Nonnull VirtualFilePointerImpl pointer) { DelegatingDisposable result = ourInstances.get(parentDisposable); if (result == null) { DelegatingDisposable newDisposable = new DelegatingDisposable(parentDisposable, pointer); result = ConcurrencyUtil.cacheOrGet(ourInstances, parentDisposable, newDisposable); if (result == newDisposable) { Disposer.register(parentDisposable, result); return; } } result.increment(pointer); }
Example #20
Source File: RunnerContentUi.java From consulo with Apache License 2.0 | 5 votes |
@Override public void addListener(final Listener listener, Disposable parent) { myDockingListeners.add(listener); Disposer.register(parent, new Disposable() { @Override public void dispose() { myDockingListeners.remove(listener); } }); }
Example #21
Source File: LazyUiDisposable.java From consulo with Apache License 2.0 | 5 votes |
public LazyUiDisposable(@Nullable Disposable parent, @Nonnull JComponent ui, @Nonnull T child) { if (ApplicationProperties.isInSandbox()) { myAllocation = new Exception(); } myParent = parent; myChild = child; new UiNotifyConnector.Once(ui, this); }
Example #22
Source File: ModulePointerTest.java From consulo with Apache License 2.0 | 5 votes |
private Module addModule(final String name) { final ModifiableModuleModel model = getModuleManager().getModifiableModel(); final Module module = model.newModule(name, myProject.getBaseDir().getPath()); commitModel(model); disposeOnTearDown(new Disposable() { @Override public void dispose() { if (!module.isDisposed()) { getModuleManager().disposeModule(module); } } }); return module; }
Example #23
Source File: NewProjectPanel.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess public NewProjectPanel(@Nonnull Disposable parentDisposable, @Nullable Project project, @Nullable VirtualFile moduleHome) { super(parentDisposable); myModuleHome = moduleHome; setOKActionText(IdeBundle.message("button.create")); setCancelText(CommonBundle.message("button.cancel")); }
Example #24
Source File: ToolWindowHeadlessManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
private ToolWindow doRegisterToolWindow(final String id, @Nullable Disposable parentDisposable) { MockToolWindow tw = new MockToolWindow(myProject); myToolWindows.put(id, tw); if (parentDisposable != null) { Disposer.register(parentDisposable, () -> unregisterToolWindow(id)); } return tw; }
Example #25
Source File: BaseTestsOutputConsoleView.java From consulo with Apache License 2.0 | 5 votes |
public void addChangeListener(@Nonnull final ChangeListener listener, @Nonnull final Disposable parent) { if (myConsole instanceof ObservableConsoleView) { ((ObservableConsoleView)myConsole).addChangeListener(listener, parent); } else { throw new UnsupportedOperationException(myConsole.getClass().getName()); } }
Example #26
Source File: DiffPanelImpl.java From consulo with Apache License 2.0 | 5 votes |
public void dispose() { myDisposed = true; myDiffUpdater.dispose(); Disposer.dispose(myScrollSupport); Disposer.dispose(myData); myPanel.cancelScrollEditors(); JComponent component = myPanel.getBottomComponent(); if (component instanceof Disposable) { Disposer.dispose((Disposable)component); } myPanel.setBottomComponent(null); myPanel.setDataProvider(null); myPanel.setScrollingPanel(null); }
Example #27
Source File: IdeGlassPaneImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public void addPainter(final Component component, final Painter painter, final Disposable parent) { getPainters().addPainter(painter, component); activateIfNeeded(); Disposer.register(parent, new Disposable() { @Override public void dispose() { SwingUtilities.invokeLater(() -> removePainter(painter)); } }); }
Example #28
Source File: DesktopFileChooserFactoryImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public void installFileCompletion(@Nonnull TextBox textBox, @Nonnull FileChooserDescriptor descriptor, boolean showHidden, @Nullable consulo.disposer.Disposable parent) { if(!(textBox instanceof TextBoxWithTextField)) { throw new UnsupportedOperationException(textBox + " is not TextBoxWithTextField"); } JTextField textField = ((TextBoxWithTextField)textBox).getTextField(); new FileTextFieldImpl.Vfs(textField, getMacroMap(), parent, new LocalFsFinder.FileChooserFilter(descriptor, showHidden)); }
Example #29
Source File: TrackCoverageAction.java From consulo with Apache License 2.0 | 5 votes |
public void setModel(final TestFrameworkRunningModel model) { if (myModel != null) myModel.getTreeView().removeTreeSelectionListener(myTreeSelectionListener); myModel = model; if (model != null) { myTreeSelectionListener = new MyTreeSelectionListener(); model.getTreeView().addTreeSelectionListener(myTreeSelectionListener); Disposer.register(model, new Disposable() { public void dispose() { restoreMergedCoverage(); } }); } }
Example #30
Source File: ExtensibleQueryFactory.java From consulo with Apache License 2.0 | 5 votes |
public void registerExecutor(final QueryExecutor<Result, Parameters> queryExecutor, Disposable parentDisposable) { registerExecutor(queryExecutor); Disposer.register(parentDisposable, new Disposable() { @Override public void dispose() { unregisterExecutor(queryExecutor); } }); }