consulo.disposer.Disposer Java Examples

The following examples show how to use consulo.disposer.Disposer. 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: TreeInplaceEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void hide() {
  if (!isShown()) {
    return;
  }
  myInplaceEditorComponent = null;
  onHidden();
  for (Runnable action : myRemoveActions) {
    action.run();
  }
  myRemoveActions.clear();

  Disposer.dispose(myDisposable);

  final JTree tree = getTree();
  tree.repaint();
  IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(tree);
}
 
Example #2
Source File: BackgroundTaskUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static <T> T runUnderDisposeAwareIndicator(@Nonnull Disposable parent, @Nonnull Computable<T> task) {
  ProgressIndicator indicator = new EmptyProgressIndicator(ModalityState.defaultModalityState());
  indicator.start();

  Disposable disposable = () -> {
    if (indicator.isRunning()) indicator.cancel();
  };

  if (!registerIfParentNotDisposed(parent, disposable)) {
    indicator.cancel();
    throw new ProcessCanceledException();
  }

  try {
    return ProgressManager.getInstance().runProcess(task, indicator);
  }
  finally {
    Disposer.dispose(disposable);
  }
}
 
Example #3
Source File: CompletionProgressIndicator.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void finishCompletionProcess(boolean disposeOffsetMap) {
  cancel();

  ApplicationManager.getApplication().assertIsDispatchThread();
  Disposer.dispose(myQueue);
  LookupManager.getInstance(getProject()).removePropertyChangeListener(myLookupManagerListener);

  CompletionServiceImpl.assertPhase(CompletionPhase.BgCalculation.class, CompletionPhase.ItemsCalculated.class, CompletionPhase.Synchronous.class, CompletionPhase.CommittingDocuments.class);

  CompletionProgressIndicator currentCompletion = CompletionServiceImpl.getCurrentCompletionProgressIndicator();
  LOG.assertTrue(currentCompletion == this, currentCompletion + "!=" + this);

  CompletionPhase oldPhase = CompletionServiceImpl.getCompletionPhase();
  if (oldPhase instanceof CompletionPhase.CommittingDocuments) {
    LOG.assertTrue(((CompletionPhase.CommittingDocuments)oldPhase).indicator != null, oldPhase);
    ((CompletionPhase.CommittingDocuments)oldPhase).replaced = true;
  }
  CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
  if (disposeOffsetMap) {
    disposeIndicator();
  }
}
 
Example #4
Source File: FrameDiffTool.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean checkNoDifferenceAndNotify(DiffPanel diffPanel, DiffRequest data, final Window window, final boolean showMessage) {
  if (!diffPanel.hasDifferences() && !data.getHints().contains(HINT_ALLOW_NO_DIFFERENCES)) {
    DiffManagerImpl manager = (DiffManagerImpl) DiffManager.getInstance();
    if (!Comparing.equal(manager.getComparisonPolicy(), ComparisonPolicy.DEFAULT)) {
      ComparisonPolicy oldPolicy = manager.getComparisonPolicy();
      manager.setComparisonPolicy(ComparisonPolicy.DEFAULT);
      Disposable parentDisposable = Disposable.newDisposable();
      DiffPanel maybeDiffPanel = DiffManagerImpl.createDiffPanel(data, window, parentDisposable, this);
      manager.setComparisonPolicy(oldPolicy);

      boolean hasDiffs = maybeDiffPanel.hasDifferences();
      Disposer.dispose(parentDisposable);

      if (hasDiffs) return false;
    }

    if (! showMessage) {
      return true;
    }
    return !askForceOpenDiff(data);
  }
  return false;
}
 
Example #5
Source File: GroupTreeNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void addFiles(@Nonnull AbstractTreeNode parentNode,
                      @Nonnull List<File> roots,
                      @Nonnull final Collection<File> files,
                      @Nonnull GroupByPackages groupByPackages,
                      String parentPath) {
  Collections.sort(roots, new Comparator<File>() {
    @Override
    public int compare(File file1, File file2) {
      boolean containsFile1 = files.contains(file1);
      boolean containsFile2 = files.contains(file2);
      if (containsFile1 == containsFile2) {
        return file1.getAbsolutePath().compareToIgnoreCase(file2.getAbsolutePath());
      }
      return containsFile1 ? 1 : -1;
    }
  });

  for (final File root : roots) {
    FileOrDirectoryTreeNode child = files.contains(root)
                                    ? new FileTreeNode(root.getAbsolutePath(), myInvalidAttributes, myProject, parentPath)
                                    : new DirectoryTreeNode(root.getAbsolutePath(), myProject, parentPath);
    Disposer.register((Disposable)parentNode, child);
    parentNode.add(child);
    addFiles(child, groupByPackages.getChildren(root), files, groupByPackages, child.getFilePath());
  }
}
 
Example #6
Source File: ContentImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void dispose() {
  if (myShouldDisposeContent && myComponent instanceof Disposable) {
    Disposer.dispose((Disposable)myComponent);
  }

  myComponent = null;
  myFocusRequest = null;
  myManager = null;

  clearUserData();
  if (myDisposer != null) {
    Disposer.dispose(myDisposer);
    myDisposer = null;
  }
}
 
Example #7
Source File: LazyUiDisposable.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static AsyncResult<Disposable> findDisposable(Disposable defaultValue, final Key<? extends Disposable> key) {
  if (defaultValue == null) {
    if (ApplicationManager.getApplication() != null) {
      final AsyncResult<Disposable> result = AsyncResult.undefined();
      DataManager.getInstance().getDataContextFromFocus().doWhenDone(context -> {
        Disposable disposable = context.getData(key);
        if (disposable == null) {
          disposable = Disposer.get("ui");
        }
        result.setDone(disposable);
      });
      return result;
    }
    else {
      return null;
    }
  }
  else {
    return AsyncResult.done(defaultValue);
  }
}
 
Example #8
Source File: RunContentManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void dispose() {
  if (myContent == null) return;

  final Content content = myContent;
  try {
    RunContentDescriptor descriptor = getRunContentDescriptorByContent(content);
    getSyncPublisher().contentRemoved(descriptor, myExecutor);
    if (descriptor != null) {
      Disposer.dispose(descriptor);
    }
  }
  finally {
    content.getManager().removeContentManagerListener(this);
    ProjectManager.getInstance().removeProjectManagerListener(this);
    myCloseRegisterVetoRemover.dispose();
    content.release(); // don't invoke myContent.release() because myContent becomes null after destroyProcess()
    myContent = null;
  }
}
 
Example #9
Source File: DesktopToolWindowImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
protected void init(boolean canCloseContent, @Nullable Object component) {
  final ContentFactory contentFactory = ContentFactory.getInstance();
  myContentUI = new DesktopToolWindowContentUi(this);
  ContentManager contentManager = myContentManager = contentFactory.createContentManager(myContentUI, canCloseContent, myToolWindowManager.getProject());

  if (component != null) {
    final Content content = contentFactory.createContent((JComponent)component, "", false);
    contentManager.addContent(content);
    contentManager.setSelectedContent(content, false);
  }

  myComponent = contentManager.getComponent();

  DesktopInternalDecorator.installFocusTraversalPolicy(myComponent, new LayoutFocusTraversalPolicy());

  UiNotifyConnector notifyConnector = new UiNotifyConnector(myComponent, new Activatable() {
    @Override
    public void showNotify() {
      myShowing.onReady();
    }
  });
  Disposer.register(contentManager, notifyConnector);
}
 
Example #10
Source File: XDebuggerInlayUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void createInlay(@Nonnull Project project, @Nonnull VirtualFile file, int offset, String inlayText) {
  UIUtil.invokeLaterIfNeeded(() -> {
    FileEditor editor = FileEditorManager.getInstance(project).getSelectedEditor(file);
    if (editor instanceof TextEditor) {
      Editor e = ((TextEditor)editor).getEditor();
      CharSequence text = e.getDocument().getImmutableCharSequence();

      int insertOffset = offset;
      while (insertOffset < text.length() && Character.isJavaIdentifierPart(text.charAt(insertOffset))) insertOffset++;

      List<Inlay> existing = e.getInlayModel().getInlineElementsInRange(insertOffset, insertOffset);
      for (Inlay inlay : existing) {
        if (inlay.getRenderer() instanceof MyRenderer) {
          Disposer.dispose(inlay);
        }
      }

      e.getInlayModel().addInlineElement(insertOffset, new MyRenderer(inlayText));
    }
  });
}
 
Example #11
Source File: DiffManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
static DiffPanel createDiffPanel(DiffRequest data, Window window, @Nonnull Disposable parentDisposable, FrameDiffTool tool) {
  DiffPanel diffPanel = null;
  try {
    diffPanel = DiffManager.getInstance().createDiffPanel(window, data.getProject(), parentDisposable, tool);
    int contentCount = data.getContents().length;
    LOG.assertTrue(contentCount == 2, String.valueOf(contentCount));
    LOG.assertTrue(data.getContentTitles().length == contentCount);
    diffPanel.setDiffRequest(data);
    return diffPanel;
  }
  catch (RuntimeException e) {
    if (diffPanel != null) {
      Disposer.dispose(diffPanel);
    }
    throw e;
  }
}
 
Example #12
Source File: MacUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
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 #13
Source File: ParameterInfoController.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static ParameterInfoController findControllerAtOffset(Editor editor, int offset) {
  List<ParameterInfoController> allControllers = getAllControllers(editor);
  for (int i = 0; i < allControllers.size(); ++i) {
    ParameterInfoController controller = allControllers.get(i);

    int lbraceOffset = controller.myLbraceMarker.getStartOffset();
    if (lbraceOffset == offset) {
      if (controller.myKeepOnHintHidden || controller.myHint.isVisible() || ApplicationManager.getApplication().isHeadlessEnvironment()) return controller;
      Disposer.dispose(controller);
      //noinspection AssignmentToForLoopParameter
      --i;
    }
  }

  return null;
}
 
Example #14
Source File: DesktopTransactionGuardImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void runSyncTransaction(@Nonnull Transaction transaction) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  if (Disposer.isDisposed(transaction.parentDisposable)) return;

  boolean wasWritingAllowed = myWritingAllowed;
  myWritingAllowed = true;
  myCurrentTransaction = new TransactionIdImpl(myCurrentTransaction);

  try {
    transaction.runnable.run();
  }
  finally {
    Queue<Transaction> queue = getQueue(myCurrentTransaction.myParent);
    queue.addAll(myCurrentTransaction.myQueue);
    if (!queue.isEmpty()) {
      pollQueueLater();
    }

    myWritingAllowed = wasWritingAllowed;
    myCurrentTransaction.myFinished = true;
    myCurrentTransaction = myCurrentTransaction.myParent;
  }
}
 
Example #15
Source File: DuplexConsoleView.java    From consulo with Apache License 2.0 6 votes vote down vote up
public DuplexConsoleView(@Nonnull S primaryConsoleView, @Nonnull T secondaryConsoleView, @Nullable String stateStorageKey) {
  super(new CardLayout());
  myPrimaryConsoleView = primaryConsoleView;
  mySecondaryConsoleView = secondaryConsoleView;
  myStateStorageKey = stateStorageKey;

  add(myPrimaryConsoleView.getComponent(), PRIMARY_CONSOLE_PANEL);
  add(mySecondaryConsoleView.getComponent(), SECONDARY_CONSOLE_PANEL);

  mySwitchConsoleAction = new SwitchDuplexConsoleViewAction();

  myPrimary = true;
  enableConsole(getStoredState());

  Disposer.register(this, myPrimaryConsoleView);
  Disposer.register(this, mySecondaryConsoleView);
}
 
Example #16
Source File: DesktopEditorImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
void release() {
  assertIsDispatchThread();
  if (isReleased) {
    throwDisposalError("Double release of editor:");
  }
  myTraceableDisposable.kill(null);

  isReleased = true;
  mySizeAdjustmentStrategy.cancelAllRequests();
  cancelAutoResetForMouseSelectionState();

  myFoldingModel.dispose();
  mySoftWrapModel.release();
  myMarkupModel.dispose();

  myScrollingModel.dispose();
  myGutterComponent.dispose();
  myMousePressedEvent = null;
  myMouseMovedEvent = null;
  Disposer.dispose(myCaretModel);
  Disposer.dispose(mySoftWrapModel);
  Disposer.dispose(myView);
  clearCaretThread();

  myFocusListeners.clear();
  myMouseListeners.clear();
  myMouseMotionListeners.clear();

  myEditorComponent.removeMouseListener(myMouseListener);
  myGutterComponent.removeMouseListener(myMouseListener);
  myEditorComponent.removeMouseMotionListener(myMouseMotionListener);
  myGutterComponent.removeMouseMotionListener(myMouseMotionListener);

  //CodeStyleSettingsManager.removeListener(myProject, this);

  Disposer.dispose(myDisposable);
  myVerticalScrollBar.setUI(null); // clear error panel's cached image
}
 
Example #17
Source File: ExecutionEnvironment.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void setContentToReuse(@Nullable RunContentDescriptor contentToReuse) {
  myContentToReuse = contentToReuse;

  if (contentToReuse != null) {
    Disposer.register(contentToReuse, this);
  }
}
 
Example #18
Source File: FileTypeConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
public TypeEditor(Component parent, T fileType, final String title) {
  super(parent, false);
  myFileType = fileType;
  myEditor = fileType.getEditor();
  setTitle(title);
  init();
  Disposer.register(myDisposable, myEditor);
}
 
Example #19
Source File: ModuleLibraryOrderEntryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ModuleLibraryOrderEntryImpl(Library library, ModuleRootLayerImpl rootLayer, boolean isExported, DependencyScope scope, boolean init) {
  super(ModuleLibraryOrderEntryType.getInstance(), rootLayer, ProjectRootManagerImpl.getInstanceImpl(rootLayer.getProject()));
  myLibrary = library;
  myExported = isExported;
  myScope = scope;
  Disposer.register(this, myLibrary);
  if (init) {
    init();
  }
}
 
Example #20
Source File: WizardPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void disposeChildren() {
  if (myChild != null) {
    myChild.disposeChildren();
    Disposer.dispose(myChild);
    myChild = null;
  }
}
 
Example #21
Source File: XValueHint.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void onHintHidden() {
  super.onHintHidden();
  XValueHint prev = getEditor().getUserData(HINT_KEY);
  if (prev == this) {
    getEditor().putUserData(HINT_KEY, null);
  }
  if (myDisposable != null) {
    Disposer.dispose(myDisposable);
    myDisposable = null;
  }
}
 
Example #22
Source File: TabbedLanguageCodeStylePanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ConfigurableWrapper(@Nonnull Configurable configurable, CodeStyleSettings settings) {
  super(settings);
  myConfigurable = configurable;

  Disposer.register(this, new Disposable() {
    @Override
    public void dispose() {
      myConfigurable.disposeUIResources();
    }
  });
}
 
Example #23
Source File: HierarchyBrowserBaseEx.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void disposeBuilders() {
  final Collection<HierarchyTreeBuilder> builders = new ArrayList<HierarchyTreeBuilder>(myBuilders.values());
  for (final HierarchyTreeBuilder builder : builders) {
    Disposer.dispose(builder);
  }
  myBuilders.clear();
}
 
Example #24
Source File: DockManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void installListeners(Window frame) {
  frame.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosing(WindowEvent e) {
      myContainer.closeAll();
    }
  });

  UiNotifyConnector connector = new UiNotifyConnector(((RootPaneContainer)frame).getContentPane(), myContainer);
  Disposer.register(myContainer, connector);
}
 
Example #25
Source File: RecursionManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@TestOnly
public static void assertOnRecursionPrevention(@Nonnull Disposable parentDisposable) {
  ourAssertOnPrevention = true;
  Disposer.register(parentDisposable, new Disposable() {
    @Override
    public void dispose() {
      //noinspection AssignmentToStaticFieldFromInstanceMethod
      ourAssertOnPrevention = false;
    }
  });
}
 
Example #26
Source File: LocalFileSystemImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
public LocalFileSystemImpl(@Nonnull Application app, @Nonnull ManagingFS managingFS) {
  myManagingFS = managingFS;
  myWatcher = new FileWatcher(myManagingFS);
  if (myWatcher.isOperational()) {
    JobScheduler.getScheduler().scheduleWithFixedDelay(
            () -> { if (!app.isDisposed()) storeRefreshStatusToFiles(); },
            STATUS_UPDATE_PERIOD, STATUS_UPDATE_PERIOD, TimeUnit.MILLISECONDS);
  }

  Disposer.register(app, () -> myWatcher.dispose());
}
 
Example #27
Source File: IdeBackgroundUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void createTemporaryBackgroundTransform(JPanel root, String tmp, Disposable disposable) {
  PaintersHelper paintersHelper = new PaintersHelper(root);
  PaintersHelper.initWallpaperPainter(tmp, paintersHelper);
  Disposer.register(disposable, JBSwingUtilities.addGlobalCGTransform((t, v) -> {
    if (!UIUtil.isAncestor(root, t)) return v;
    return MyGraphics.wrap(v, paintersHelper, t);
  }));
}
 
Example #28
Source File: ScrollingModelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void finish(boolean scrollToTarget) {
  if (scrollToTarget || !myPostRunnables.isEmpty()) {
    _scrollHorizontally(myEndHOffset);
    _scrollVertically(myEndVOffset);
    executePostRunnables();
  }

  Disposer.dispose(myAnimator);
  if (myCurrentAnimationRequest == this) {
    myCurrentAnimationRequest = null;
  }
}
 
Example #29
Source File: AbstractTestProxy.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void dispose() {
  super.dispose();
  for (AbstractTestProxy proxy : getChildren()) {
    Disposer.dispose(proxy);
  }
}
 
Example #30
Source File: ToolWindowsWidget.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void dispose() {
  Disposer.dispose(this);
  KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener("focusOwner", this);
  myStatusBar = null;
  popup = null;
}