Search in sources :

Example 46 with Disposable

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

the class FileStatusManagerImpl method addFileStatusListener.

@Override
public void addFileStatusListener(@NotNull final FileStatusListener listener, @NotNull Disposable parentDisposable) {
    addFileStatusListener(listener);
    Disposer.register(parentDisposable, new Disposable() {

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

Example 47 with Disposable

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

the class EditorPlaybackCall method waitDaemonForFinish.

public static AsyncResult<String> waitDaemonForFinish(final PlaybackContext context) {
    final AsyncResult<String> result = new AsyncResult<>();
    final Disposable connection = Disposer.newDisposable();
    result.doWhenProcessed(() -> Disposer.dispose(connection));
    WindowSystemPlaybackCall.findProject().doWhenDone(new Consumer<Project>() {

        @Override
        public void consume(Project project) {
            final MessageBusConnection bus = project.getMessageBus().connect(connection);
            bus.subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonCodeAnalyzer.DaemonListenerAdapter() {

                @Override
                public void daemonFinished() {
                    context.flushAwtAndRunInEdt(result.createSetDoneRunnable());
                }

                @Override
                public void daemonCancelEventOccurred(@NotNull String reason) {
                    result.setDone();
                }
            });
        }
    }).doWhenRejected(() -> result.setRejected("Cannot find project"));
    return result;
}
Also used : Disposable(com.intellij.openapi.Disposable) Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) Consumer(com.intellij.util.Consumer) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) AsyncResult(com.intellij.openapi.util.AsyncResult)

Example 48 with Disposable

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

the class IdeStatusBarImpl method addWidget.

@Override
public void addWidget(@NotNull final StatusBarWidget widget, @NotNull final Disposable parentDisposable) {
    addWidget(widget);
    Disposer.register(parentDisposable, new Disposable() {

        @Override
        public void dispose() {
            removeWidget(widget.ID());
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable)

Example 49 with Disposable

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

the class StatisticsManagerImpl method enableStatistics.

@TestOnly
public void enableStatistics(@NotNull Disposable parentDisposable) {
    myTestingStatistics = true;
    Disposer.register(parentDisposable, new Disposable() {

        @Override
        public void dispose() {
            synchronized (LOCK) {
                Collections.fill(myUnits, null);
            }
            myTestingStatistics = false;
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) TestOnly(org.jetbrains.annotations.TestOnly)

Example 50 with Disposable

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

the class BalloonLayoutImpl method add.

@Override
public void add(@NotNull final Balloon balloon, @Nullable Object layoutData) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    Balloon merge = merge(layoutData);
    if (merge == null) {
        if (getVisibleCount() > 0 && layoutData instanceof BalloonLayoutData && ((BalloonLayoutData) layoutData).groupId != null) {
            int index = -1;
            int count = 0;
            for (int i = 0, size = myBalloons.size(); i < size; i++) {
                BalloonLayoutData ld = myLayoutData.get(myBalloons.get(i));
                if (ld != null && ld.groupId != null) {
                    if (index == -1) {
                        index = i;
                    }
                    count++;
                }
            }
            if (count > 0 && count == getVisibleCount()) {
                remove(myBalloons.get(index));
            }
        }
        myBalloons.add(balloon);
    } else {
        int index = myBalloons.indexOf(merge);
        remove(merge);
        myBalloons.add(index, balloon);
    }
    if (layoutData instanceof BalloonLayoutData) {
        BalloonLayoutData balloonLayoutData = (BalloonLayoutData) layoutData;
        balloonLayoutData.closeAll = myCloseAll;
        balloonLayoutData.doLayout = myLayoutRunnable;
        myLayoutData.put(balloon, balloonLayoutData);
    }
    Disposer.register(balloon, new Disposable() {

        public void dispose() {
            clearNMore(balloon);
            remove(balloon, false);
            queueRelayout();
        }
    });
    if (myLafListener == null && layoutData != null) {
        myLafListener = new LafManagerListener() {

            @Override
            public void lookAndFeelChanged(LafManager source) {
                for (BalloonLayoutData layoutData : myLayoutData.values()) {
                    if (layoutData.lafHandler != null) {
                        layoutData.lafHandler.run();
                    }
                }
            }
        };
        LafManager.getInstance().addLafManagerListener(myLafListener);
    }
    calculateSize();
    relayout();
    if (!balloon.isDisposed()) {
        balloon.show(myLayeredPane);
    }
    fireRelayout();
}
Also used : Disposable(com.intellij.openapi.Disposable) Balloon(com.intellij.openapi.ui.popup.Balloon) LafManager(com.intellij.ide.ui.LafManager) LafManagerListener(com.intellij.ide.ui.LafManagerListener)

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