com.intellij.ui.GuiUtils Java Examples

The following examples show how to use com.intellij.ui.GuiUtils. 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: FlutterDebugProcess.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Turn off debug-only views (variables and frames).
 */
private static void suppressDebugViews(@Nullable RunnerLayoutUi ui) {
  if (ui == null) {
    return;
  }

  for (Content c : ui.getContents()) {
    if (!Objects.equals(c.getTabName(), "Console")) {
      try {
        GuiUtils.runOrInvokeAndWait(() -> ui.removeContent(c, false /* dispose? */));
      }
      catch (InvocationTargetException | InterruptedException e) {
        FlutterUtils.warn(LOG, e);
      }
    }
  }
}
 
Example #2
Source File: FlutterDebugProcess.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Turn off debug-only views (variables and frames).
 */
private static void suppressDebugViews(@Nullable RunnerLayoutUi ui) {
  if (ui == null) {
    return;
  }

  for (Content c : ui.getContents()) {
    if (!Objects.equals(c.getTabName(), "Console")) {
      try {
        GuiUtils.runOrInvokeAndWait(() -> ui.removeContent(c, false /* dispose? */));
      }
      catch (InvocationTargetException | InterruptedException e) {
        FlutterUtils.warn(LOG, e);
      }
    }
  }
}
 
Example #3
Source File: StartupManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void runWhenProjectIsInitialized(@Nonnull final Runnable action) {
  final Application application = ApplicationManager.getApplication();
  if (application == null) return;

  GuiUtils.invokeLaterIfNeeded(() -> {
    if (myProject.isDisposedOrDisposeInProgress()) return;

    //noinspection SynchronizeOnThis
    synchronized (this) {
      // in tests that simulate project opening, post-startup activities could have been run already
      // then we should act as if the project was initialized
      boolean initialized = myProject.isInitialized() || myProject.isDefault() || (myPostStartupActivitiesPassed && application.isUnitTestMode());
      if (!initialized) {
        registerPostStartupActivity(uiAccess -> action.run());
        return;
      }
    }

    action.run();
  }, ModalityState.defaultModalityState());
}
 
Example #4
Source File: InterruptibleActivity.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected int processTimeoutInEDT() {
  final int[] retcode = new int[1];

  try {
    GuiUtils.runOrInvokeAndWait(new Runnable() {
      public void run() {
        retcode[0] = processTimeout();
      }
    });
  }
  catch (Exception e) {
    throw new RuntimeException(e);
  }

  return retcode[0];
}
 
Example #5
Source File: UsageLimitUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static int runOrInvokeAndWait(@Nonnull final Computable<Integer> f) {
  final int[] answer = new int[1];
  try {
    GuiUtils.runOrInvokeAndWait(new Runnable() {
      @Override
      public void run() {
        answer[0] = f.compute();
      }
    });
  }
  catch (Exception e) {
    answer[0] = 0;
  }

  return answer[0];
}
 
Example #6
Source File: BaseRefactoringProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void prepareSuccessful() {
  if (myPrepareSuccessfulSwingThreadCallback != null) {
    // make sure that dialog is closed in swing thread
    try {
      GuiUtils.runOrInvokeAndWait(myPrepareSuccessfulSwingThreadCallback);
    }
    catch (InterruptedException | InvocationTargetException e) {
      LOG.error(e);
    }
  }
}
 
Example #7
Source File: ProjectViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void setupToolWindow(@Nonnull ToolWindow toolWindow, final boolean loadPaneExtensions) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  myActionGroup = new DefaultActionGroup();

  myAutoScrollFromSourceHandler.install();

  myContentManager = toolWindow.getContentManager();
  if (!ApplicationManager.getApplication().isUnitTestMode()) {
    toolWindow.setDefaultContentUiType(ToolWindowContentUiType.COMBO);
    ((ToolWindowEx)toolWindow).setAdditionalGearActions(myActionGroup);
    toolWindow.getComponent().putClientProperty(ToolWindowContentUI.HIDE_ID_LABEL, "true");
  }

  GuiUtils.replaceJSplitPaneWithIDEASplitter(myPanel);
  SwingUtilities.invokeLater(() -> splitterProportions.restoreSplitterProportions(myPanel));

  if (loadPaneExtensions) {
    ensurePanesLoaded();
  }
  isInitialized = true;
  doAddUninitializedPanes();

  getContentManager().addContentManagerListener(new ContentManagerAdapter() {
    @Override
    public void selectionChanged(ContentManagerEvent event) {
      if (event.getOperation() == ContentManagerEvent.ContentOperation.add) {
        viewSelectionChanged();
      }
    }
  });
  viewSelectionChanged();
}
 
Example #8
Source File: GistManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void invalidateDependentCaches() {
  GuiUtils.invokeLaterIfNeeded(() -> {
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
      PsiManager.getInstance(project).dropPsiCaches();
    }
  }, ModalityState.NON_MODAL);
}
 
Example #9
Source File: ComponentWithBrowseButton.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void setTextFieldPreferredWidth(final int charCount) {
  final Comp comp = getChildComponent();
  Dimension size = GuiUtils.getSizeByChars(charCount, comp);
  comp.setPreferredSize(size);
  final Dimension preferredSize = myBrowseButton.getPreferredSize();
  setPreferredSize(new Dimension(size.width + preferredSize.width + 2, UIUtil.isUnderAquaLookAndFeel() ? preferredSize.height : preferredSize.height + 2));
}
 
Example #10
Source File: ContextItemPanel.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private void contextItemSourceChanged() {
    final boolean editorAsSource = isContextItemFromEditorEnabled();
    if (isContextItemEnabled()) {
        GuiUtils.enableChildren(contextItemEditorContent, editorAsSource);
        GuiUtils.enableChildren(contextItemPathField, ! editorAsSource);
    }
    contextItemEditorContent.invalidate();
    contextItemPathField.invalidate();
}
 
Example #11
Source File: ReviewsPanel.java    From review-board-idea-plugin with Apache License 2.0 5 votes vote down vote up
public void enablePanel(final boolean enable) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        public void run() {
            GuiUtils.enableChildren(ReviewsPanel.this, enable, mainReviewToolbar);
        }
    });
}
 
Example #12
Source File: ReviewsPanel.java    From review-board-idea-plugin with Apache License 2.0 5 votes vote down vote up
public void setReviewsList(final int pageNumber, final List<Review> reviews) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            reviewsTable.setModel(new ReviewTableModel(reviews));
            reviewsTable.getColumnModel().getColumn(ReviewTableModel.Columns.SUMMARY.getIndex()).setPreferredWidth(400);
            reviewsTable.getColumnModel().getColumn(ReviewTableModel.Columns.SUBMITTED_TO.getIndex()).setPreferredWidth(50);
            reviewsTable.getColumnModel().getColumn(ReviewTableModel.Columns.SUBMITTER.getIndex()).setPreferredWidth(50);
            reviewsTable.getColumnModel().getColumn(ReviewTableModel.Columns.LAST_MODIFIED.getIndex()).setPreferredWidth(50);
            page.setText(String.valueOf(pageNumber));
            GuiUtils.enableChildren(true, ReviewsPanel.this);
        }
    });
}
 
Example #13
Source File: AlternativeJREPanel.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
private void enabledChanged() {
    final boolean pathEnabled = isPathEnabled();
    GuiUtils.enableChildren(myPathField, pathEnabled);
    myFieldWithHistory.invalidate(); //need to revalidate inner component
}
 
Example #14
Source File: ProjectManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@RequiredUIAccess
public boolean openProject(@Nonnull final Project project, @Nonnull UIAccess uiAccess) {
  if (isLight(project)) {
    ((ProjectImpl)project).setTemporarilyDisposed(false);
    boolean isInitialized = StartupManagerEx.getInstanceEx(project).startupActivityPassed();
    if (isInitialized) {
      addToOpened(project);
      // events already fired
      return true;
    }
  }

  for (Project p : getOpenProjects()) {
    if (ProjectUtil.isSameProject(project.getProjectFilePath(), p)) {
      GuiUtils.invokeLaterIfNeeded(() -> ProjectUtil.focusProjectWindow(p, false), ModalityState.NON_MODAL);
      return false;
    }
  }

  if (!addToOpened(project)) {
    return false;
  }

  Runnable process = () -> {
    TransactionGuard.getInstance().submitTransactionAndWait(() -> myApplication.getMessageBus().syncPublisher(TOPIC).projectOpened(project, uiAccess));

    final StartupManagerImpl startupManager = (StartupManagerImpl)StartupManager.getInstance(project);
    startupManager.runStartupActivities(uiAccess);
    startupManager.runPostStartupActivitiesFromExtensions(uiAccess);

    GuiUtils.invokeLaterIfNeeded(() -> {
      if (!project.isDisposed()) {
        startupManager.runPostStartupActivities(uiAccess);


        if (!myApplication.isHeadlessEnvironment() && !myApplication.isUnitTestMode()) {
          final TrackingPathMacroSubstitutor macroSubstitutor = ((ProjectEx)project).getStateStore().getStateStorageManager().getMacroSubstitutor();
          if (macroSubstitutor != null) {
            StorageUtil.notifyUnknownMacros(macroSubstitutor, project, null);
          }
        }

        if (myApplication.isActive()) {
          Window projectFrame = TargetAWT.to(WindowManager.getInstance().getWindow(project));
          if (projectFrame != null) {
            IdeFocusManager.getInstance(project).requestFocus(projectFrame, true);
          }
        }
      }
    }, ModalityState.NON_MODAL);
  };

  ProgressIndicator indicator = myProgressManager.getProgressIndicator();
  if (indicator != null) {
    indicator.setText("Preparing workspace...");
    process.run();
    return true;
  }

  boolean ok = myProgressManager.runProcessWithProgressSynchronously(process, "Preparing workspace...", canCancelProjectLoading(), project);
  if (!ok) {
    closeProject(project, false, false, true);
    notifyProjectOpenFailed();
    return false;
  }

  return true;
}
 
Example #15
Source File: ContextItemPanel.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
private void contextItemEnabledChanged() {
    final boolean pathEnabled = isContextItemEnabled();
    GuiUtils.enableChildren(contextItemOptionsPanel, pathEnabled);
    contextItemSourceChanged();
}
 
Example #16
Source File: XMasterBreakpointPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void updateAfterBreakpointHitPanel() {
  boolean enable = myMasterBreakpointChooser.getSelectedBreakpoint() != null;
  GuiUtils.enableChildren(enable, myAfterBreakpointHitPanel);
}
 
Example #17
Source File: CompletionProgressIndicator.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void stop() {
  super.stop();

  myQueue.cancelAllUpdates();
  myFreezeSemaphore.up();
  myFinishSemaphore.up();

  GuiUtils.invokeLaterIfNeeded(() -> {
    final CompletionPhase phase = CompletionServiceImpl.getCompletionPhase();
    if (!(phase instanceof CompletionPhase.BgCalculation) || phase.indicator != this) return;

    LOG.assertTrue(!getProject().isDisposed(), "project disposed");

    if (myEditor.isDisposed()) {
      myLookup.hideLookup(false);
      CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
      return;
    }

    if (myEditor instanceof EditorWindow) {
      LOG.assertTrue(((EditorWindow)myEditor).getInjectedFile().isValid(), "injected file !valid");
      LOG.assertTrue(((DocumentWindow)myEditor.getDocument()).isValid(), "docWindow !valid");
    }
    PsiFile file = myLookup.getPsiFile();
    LOG.assertTrue(file == null || file.isValid(), "file !valid");

    myLookup.setCalculating(false);

    if (myCount == 0) {
      myLookup.hideLookup(false);
      if (!isAutopopupCompletion()) {
        final CompletionProgressIndicator current = CompletionServiceImpl.getCurrentCompletionProgressIndicator();
        LOG.assertTrue(current == null, current + "!=" + this);

        handleEmptyLookup(!((CompletionPhase.BgCalculation)phase).modifiersChanged);
      }
    }
    else {
      updateLookup(myIsUpdateSuppressed);
      if (CompletionServiceImpl.getCompletionPhase() != CompletionPhase.NoCompletion) {
        CompletionServiceImpl.setCompletionPhase(new CompletionPhase.ItemsCalculated(this));
      }
    }
  }, myQueue.getModalityState());
}
 
Example #18
Source File: NewColorAndFontPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
public NewColorAndFontPanel(final SchemesPanel schemesPanel,
                            final OptionsPanel optionsPanel,
                            final PreviewPanel previewPanel,
                            final String category, final Collection<String> optionList, final ColorSettingsPage page) {
  super(new BorderLayout(0, 10));
  mySchemesPanel = schemesPanel;
  myOptionsPanel = optionsPanel;
  myPreviewPanel = previewPanel;
  myCategory = category;
  myOptionList = optionList;
  mySettingsPage = page;

  JPanel top = new JPanel(new BorderLayout());

  top.add(mySchemesPanel, BorderLayout.NORTH);
  top.add(myOptionsPanel.getPanel(), BorderLayout.CENTER);
  if (optionsPanel instanceof ConsoleFontOptions) {
    JPanel wrapper = new JPanel(new FlowLayout(FlowLayout.TRAILING));
    myCopyAction = new AbstractAction(ApplicationBundle.message("action.apply.editor.font.settings")) {
      @Override
      public void actionPerformed(ActionEvent e) {
        EditorColorsScheme scheme = ((ConsoleFontOptions)myOptionsPanel).getCurrentScheme();
        scheme.setConsoleFontName(scheme.getEditorFontName());
        scheme.setConsoleFontPreferences(scheme.getFontPreferences());
        scheme.setConsoleFontSize(scheme.getEditorFontSize());
        scheme.setConsoleLineSpacing(scheme.getLineSpacing());
        myOptionsPanel.updateOptionsList();
        myPreviewPanel.updateView();
      }
    };
    wrapper.add(new JButton(myCopyAction));
    top.add(wrapper, BorderLayout.SOUTH);
  }
  else {
    myCopyAction = null;
  }

  // We don't want to show non-used preview panel (it's considered to be not in use if it doesn't contain text).
  if (myPreviewPanel.getPanel() != null && (page == null || !StringUtil.isEmptyOrSpaces(page.getDemoText()))) {
    @SuppressWarnings("SuspiciousNameCombination")
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, top, myPreviewPanel.getPanel());
    splitPane.setBorder(BorderFactory.createEmptyBorder());
    splitPane.setContinuousLayout(true);
    add(splitPane);
    GuiUtils.replaceJSplitPaneWithIDEASplitter(splitPane);
  }
  else {
    add(top, BorderLayout.CENTER);
  }

  previewPanel.addListener(new ColorAndFontSettingsListener.Abstract() {
    @Override
    public void selectionInPreviewChanged(final String typeToSelect) {
      optionsPanel.selectOption(typeToSelect);
    }
  });

  optionsPanel.addListener(new ColorAndFontSettingsListener.Abstract() {
    @Override
    public void settingsChanged() {
      if (schemesPanel.updateDescription(true)) {
        optionsPanel.applyChangesToScheme();
        previewPanel.updateView();
      }
    }

    @Override
    public void selectedOptionChanged(final Object selected) {
      if (ApplicationManager.getApplication().isDispatchThread()) {
        myPreviewPanel.blinkSelectedHighlightType(selected);
      }
    }

  });
  mySchemesPanel.addListener(new ColorAndFontSettingsListener.Abstract() {
    @Override
    public void schemeChanged(final Object source) {
      myOptionsPanel.updateOptionsList();
      myPreviewPanel.updateView();
      if (optionsPanel instanceof ConsoleFontOptions) {
        ConsoleFontOptions options = (ConsoleFontOptions)optionsPanel;
        boolean readOnly = ColorAndFontOptions.isReadOnly(options.getCurrentScheme());
        myCopyAction.setEnabled(!readOnly);
      }
    }
  });

}
 
Example #19
Source File: VariableUI.java    From CodeGen with MIT License 4 votes vote down vote up
public VariableUI() {
    $$$setupUI$$$();
    GuiUtils.replaceJSplitPaneWithIDEASplitter(splitPanel);
    setVariables(settingManager.getVariables());
}