Search in sources :

Example 66 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class PsiManagerImpl method setAssertOnFileLoadingFilter.

@Override
@TestOnly
public void setAssertOnFileLoadingFilter(@NotNull VirtualFileFilter filter, @NotNull Disposable parentDisposable) {
    // Find something to ensure there's no changed files waiting to be processed in repository indices.
    myAssertOnFileLoadingFilter = filter;
    Disposer.register(parentDisposable, new Disposable() {

        @Override
        public void dispose() {
            myAssertOnFileLoadingFilter = VirtualFileFilter.NONE;
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) TestOnly(org.jetbrains.annotations.TestOnly)

Example 67 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class ExternalSystemFacadeManager method doCreateFacade.

@SuppressWarnings("unchecked")
@NotNull
private RemoteExternalSystemFacade doCreateFacade(@NotNull IntegrationKey key, @NotNull Project project, @NotNull ExternalSystemCommunicationManager communicationManager) throws Exception {
    final RemoteExternalSystemFacade facade = communicationManager.acquire(key.getExternalProjectConfigPath(), key.getExternalSystemId());
    if (facade == null) {
        throw new IllegalStateException("Can't obtain facade to working with external api at the remote process. Project: " + project);
    }
    Disposer.register(project, new Disposable() {

        @Override
        public void dispose() {
            myFacadeWrappers.clear();
            myRemoteFacades.clear();
        }
    });
    final RemoteExternalSystemFacade result = new ExternalSystemFacadeWrapper(facade, myProgressManager);
    ExternalSystemExecutionSettings settings = ExternalSystemApiUtil.getExecutionSettings(project, key.getExternalProjectConfigPath(), key.getExternalSystemId());
    Pair<RemoteExternalSystemFacade, ExternalSystemExecutionSettings> newPair = Pair.create(result, settings);
    myRemoteFacades.put(key, newPair);
    result.applySettings(newPair.second);
    return result;
}
Also used : Disposable(com.intellij.openapi.Disposable) ExternalSystemFacadeWrapper(com.intellij.openapi.externalSystem.service.remote.wrapper.ExternalSystemFacadeWrapper) ExternalSystemExecutionSettings(com.intellij.openapi.externalSystem.model.settings.ExternalSystemExecutionSettings) NotNull(org.jetbrains.annotations.NotNull)

Example 68 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class XWatchesViewImpl method installEditListeners.

private void installEditListeners() {
    final XDebuggerTree watchTree = getTree();
    final Alarm quitePeriod = new Alarm();
    final Alarm editAlarm = new Alarm();
    final ClickListener mouseListener = new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent event, int clickCount) {
            if (!SwingUtilities.isLeftMouseButton(event) || ((event.getModifiers() & (InputEvent.SHIFT_MASK | InputEvent.ALT_MASK | InputEvent.CTRL_MASK | InputEvent.META_MASK)) != 0)) {
                return false;
            }
            boolean sameRow = isAboveSelectedItem(event, watchTree, false);
            if (!sameRow || clickCount > 1) {
                editAlarm.cancelAllRequests();
                return false;
            }
            final AnAction editWatchAction = ActionManager.getInstance().getAction(XDebuggerActions.XEDIT_WATCH);
            Presentation presentation = editWatchAction.getTemplatePresentation().clone();
            DataContext context = DataManager.getInstance().getDataContext(watchTree);
            final AnActionEvent actionEvent = new AnActionEvent(null, context, "WATCH_TREE", presentation, ActionManager.getInstance(), 0);
            Runnable runnable = () -> editWatchAction.actionPerformed(actionEvent);
            if (editAlarm.isEmpty() && quitePeriod.isEmpty()) {
                editAlarm.addRequest(runnable, UIUtil.getMultiClickInterval());
            } else {
                editAlarm.cancelAllRequests();
            }
            return false;
        }
    };
    final ClickListener mouseEmptySpaceListener = new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent event) {
            if (!isAboveSelectedItem(event, watchTree, true)) {
                myRootNode.addNewWatch();
                return true;
            }
            return false;
        }
    };
    ListenerUtil.addClickListener(watchTree, mouseListener);
    ListenerUtil.addClickListener(watchTree, mouseEmptySpaceListener);
    final FocusListener focusListener = new FocusListener() {

        @Override
        public void focusGained(@NotNull FocusEvent e) {
            quitePeriod.addRequest(EmptyRunnable.getInstance(), UIUtil.getMultiClickInterval());
        }

        @Override
        public void focusLost(@NotNull FocusEvent e) {
            editAlarm.cancelAllRequests();
        }
    };
    ListenerUtil.addFocusListener(watchTree, focusListener);
    final TreeSelectionListener selectionListener = new TreeSelectionListener() {

        @Override
        public void valueChanged(@NotNull TreeSelectionEvent e) {
            quitePeriod.addRequest(EmptyRunnable.getInstance(), UIUtil.getMultiClickInterval());
        }
    };
    watchTree.addTreeSelectionListener(selectionListener);
    myDisposables.add(new Disposable() {

        @Override
        public void dispose() {
            ListenerUtil.removeClickListener(watchTree, mouseListener);
            ListenerUtil.removeClickListener(watchTree, mouseEmptySpaceListener);
            ListenerUtil.removeFocusListener(watchTree, focusListener);
            watchTree.removeTreeSelectionListener(selectionListener);
        }
    });
}
Also used : CompositeDisposable(com.intellij.openapi.CompositeDisposable) Disposable(com.intellij.openapi.Disposable) MouseEvent(java.awt.event.MouseEvent) DoubleClickListener(com.intellij.ui.DoubleClickListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener) XDebuggerTree(com.intellij.xdebugger.impl.ui.tree.XDebuggerTree) NotNull(org.jetbrains.annotations.NotNull) FocusEvent(java.awt.event.FocusEvent) Alarm(com.intellij.util.Alarm) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) FocusListener(java.awt.event.FocusListener) DoubleClickListener(com.intellij.ui.DoubleClickListener) ClickListener(com.intellij.ui.ClickListener)

Example 69 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class CvsCheckinHandlerFactory method createVcsHandler.

@NotNull
@Override
protected CheckinHandler createVcsHandler(final CheckinProjectPanel panel) {
    return new CheckinHandler() {

        @Nullable
        public RefreshableOnComponent getAfterCheckinConfigurationPanel(Disposable parentDisposable) {
            final Project project = panel.getProject();
            final CvsVcs2 cvs = CvsVcs2.getInstance(project);
            final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
            final Collection<VirtualFile> roots = panel.getRoots();
            final Collection<FilePath> files = new HashSet<>();
            for (VirtualFile root : roots) {
                final VcsRoot vcsRoot = vcsManager.getVcsRootObjectFor(root);
                if (vcsRoot == null || vcsRoot.getVcs() != cvs) {
                    continue;
                }
                files.add(VcsContextFactory.SERVICE.getInstance().createFilePathOn(root));
            }
            return new AdditionalOptionsPanel(CvsConfiguration.getInstance(project), files, project);
        }
    };
}
Also used : Disposable(com.intellij.openapi.Disposable) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePath(com.intellij.openapi.vcs.FilePath) Project(com.intellij.openapi.project.Project) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler) VcsRoot(com.intellij.openapi.vcs.VcsRoot) AdditionalOptionsPanel(com.intellij.cvsSupport2.checkinProject.AdditionalOptionsPanel) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class KeyedExtensionCollector method addListener.

public void addListener(@NotNull final ExtensionPointListener<T> listener, @NotNull Disposable parent) {
    myListeners.add(listener);
    Disposer.register(parent, new Disposable() {

        @Override
        public void dispose() {
            myListeners.remove(listener);
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable)

Aggregations

Disposable (com.intellij.openapi.Disposable)282 NotNull (org.jetbrains.annotations.NotNull)52 Test (org.junit.Test)25 Project (com.intellij.openapi.project.Project)18 TestOnly (org.jetbrains.annotations.TestOnly)17 ArrayList (java.util.ArrayList)13 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 RelativePoint (com.intellij.ui.awt.RelativePoint)11 Nullable (org.jetbrains.annotations.Nullable)10 Document (com.intellij.openapi.editor.Document)9 File (java.io.File)9 ProcessHandler (com.intellij.execution.process.ProcessHandler)6 Editor (com.intellij.openapi.editor.Editor)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)6 VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)6 Content (com.intellij.ui.content.Content)6 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)5 Alarm (com.intellij.util.Alarm)5 ActionEvent (java.awt.event.ActionEvent)5 ListSelectionEvent (javax.swing.event.ListSelectionEvent)5