Java Code Examples for com.intellij.util.ui.UIUtil#getParentOfType()

The following examples show how to use com.intellij.util.ui.UIUtil#getParentOfType() . 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: FocusManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void toFront(JComponent c) {
  assertDispatchThread();

  if (c == null) return;

  final Window window = UIUtil.getParentOfType(Window.class, c);
  if (window != null && window.isShowing()) {
    doWhenFocusSettlesDown(() -> {
      if (ApplicationManager.getApplication().isActive()) {
        if (window instanceof JFrame && ((JFrame)window).getState() == Frame.ICONIFIED) {
          ((JFrame)window).setState(Frame.NORMAL);
        }
        else {
          window.toFront();
        }
      }
    });
  }
}
 
Example 2
Source File: DialogWrapperPeerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
  e.getPresentation().setEnabled(false);
  if (focusOwner instanceof JComponent && SpeedSearchBase.hasActiveSpeedSearch((JComponent)focusOwner)) {
    return;
  }

  if (StackingPopupDispatcher.getInstance().isPopupFocused()) return;
  JTree tree = UIUtil.getParentOfType(JTree.class, focusOwner);
  JTable table = UIUtil.getParentOfType(JTable.class, focusOwner);

  if (tree != null || table != null) {
    if (hasNoEditingTreesOrTablesUpward(focusOwner)) {
      e.getPresentation().setEnabled(true);
    }
  }
}
 
Example 3
Source File: ComboBoxAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  ComboBoxButton button = (ComboBoxButton)e.getPresentation().getClientProperty(COMPONENT_KEY);
  if (button == null) {
    Component contextComponent = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
    JRootPane rootPane = UIUtil.getParentOfType(JRootPane.class, contextComponent);
    if (rootPane != null) {
      button = (ComboBoxButton)UIUtil.uiTraverser().withRoot(rootPane).bfsTraversal()
              .filter(component -> component instanceof ComboBoxButton && ((ComboBoxButton)component).getComboBoxAction() == ComboBoxAction.this).first();
    }
    if (button == null) return;
  }

  button.showPopup();
}
 
Example 4
Source File: ExpandAll.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  final Component c = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
  if (c != null) {
    final JTree tree = UIUtil.getParentOfType(JTree.class, c);
    if (tree != null) {
      TreeUtil.expandAll(tree);
    }
  }
}
 
Example 5
Source File: DarculaCheckBoxUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("MethodOverridesStaticMethodOfSuperclass")
public static ComponentUI createUI(JComponent c) {
  if (UIUtil.getParentOfType(CellRendererPane.class, c) != null) {
    c.setBorder(null);
  }
  return new DarculaCheckBoxUI();
}
 
Example 6
Source File: ModernCheckBoxUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("MethodOverridesStaticMethodOfSuperclass")
public static ComponentUI createUI(JComponent c) {
  if (UIUtil.getParentOfType(CellRendererPane.class, c) != null) {
    c.setBorder(null);
  }
  return new ModernCheckBoxUI(c);
}
 
Example 7
Source File: TableUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void updateScroller(@Nonnull JTable table) {
  JScrollPane scrollPane = UIUtil.getParentOfType(JScrollPane.class, table);
  if (scrollPane != null) {
    scrollPane.revalidate();
    scrollPane.repaint();
  }
}
 
Example 8
Source File: RunnerContentUi.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void dragOutFinished(MouseEvent event, TabInfo source) {
  final Component component = event.getComponent();
  final IdeFrame window = UIUtil.getParentOfType(IdeFrame.class, component);
  mySession.process(event);
  mySession = null;
}
 
Example 9
Source File: JBListTable.java    From consulo with Apache License 2.0 5 votes vote down vote up
private RowResizeAnimator(JTable table, int row, int height, JBTableRowEditor editor, @Nonnull Ref<Integer> index) {
  super("Row Animator");
  myTable = table;
  myRow = row;
  neededHeight = height;
  myEditor = editor;
  myIndex = index;
  currentHeight = myTable.getRowHeight(myRow);
  myScrollPane = UIUtil.getParentOfType(JScrollPane.class, myTable);
}
 
Example 10
Source File: TableToolbarDecorator.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void updateScroller(JTable table, boolean temporaryHideVerticalScrollBar) {
  JScrollPane scrollPane = UIUtil.getParentOfType(JScrollPane.class, table);
  if (scrollPane != null) {
    if (temporaryHideVerticalScrollBar) {
      final JScrollBar bar = scrollPane.getVerticalScrollBar();
      if (bar == null || !bar.isVisible()) {
        scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
      }
    }
    scrollPane.revalidate();
    scrollPane.repaint();
  }
}
 
Example 11
Source File: EditorTextField.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private Color getBackgroundColor(boolean enabled) {
  if (myEnforcedBgColor != null) return myEnforcedBgColor;
  if (UIUtil.getParentOfType(CellRendererPane.class, this) != null) {
    return getParent().getBackground();
  }
  return enabled ? UIUtil.getTextFieldBackground() : UIUtil.getInactiveTextFieldBackgroundColor();
}
 
Example 12
Source File: FileEditorManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void fireSelectionChanged(EditorComposite newSelectedComposite) {
  final Trinity<VirtualFile, FileEditor, FileEditorProvider> oldData = extract(SoftReference.dereference(myLastSelectedComposite));
  final Trinity<VirtualFile, FileEditor, FileEditorProvider> newData = extract(newSelectedComposite);
  myLastSelectedComposite = newSelectedComposite == null ? null : new WeakReference<>(newSelectedComposite);
  final boolean filesEqual = oldData.first == null ? newData.first == null : oldData.first.equals(newData.first);
  final boolean editorsEqual = oldData.second == null ? newData.second == null : oldData.second.equals(newData.second);
  if (!filesEqual || !editorsEqual) {
    if (oldData.first != null && newData.first != null) {
      for (FileEditorAssociateFinder finder : FileEditorAssociateFinder.EP_NAME.getExtensionList()) {
        VirtualFile associatedFile = finder.getAssociatedFileToOpen(myProject, oldData.first);

        if (Comparing.equal(associatedFile, newData.first)) {
          return;
        }
      }
    }

    final FileEditorManagerEvent event = new FileEditorManagerEvent(this, oldData.first, oldData.second, oldData.third, newData.first, newData.second, newData.third);
    final FileEditorManagerListener publisher = getProject().getMessageBus().syncPublisher(FileEditorManagerListener.FILE_EDITOR_MANAGER);

    if (newData.first != null) {
      final JComponent component = newData.second.getComponent();
      final EditorWindowHolder holder = UIUtil.getParentOfType(EditorWindowHolder.class, component);
      if (holder != null) {
        addSelectionRecord(newData.first, holder.getEditorWindow());
      }
    }
    notifyPublisher(() -> publisher.selectionChanged(event));
  }
}
 
Example 13
Source File: DesktopEditorComposite.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void fireSelectedEditorChanged(final FileEditor oldSelectedEditor, final FileEditor newSelectedEditor) {
  if ((!EventQueue.isDispatchThread() || !myFileEditorManager.isInsideChange()) && !Comparing.equal(oldSelectedEditor, newSelectedEditor)) {
    myFileEditorManager.notifyPublisher(() -> {
      final FileEditorManagerEvent event = new FileEditorManagerEvent(myFileEditorManager, myFile, oldSelectedEditor, myFile, newSelectedEditor);
      final FileEditorManagerListener publisher = myFileEditorManager.getProject().getMessageBus().syncPublisher(FileEditorManagerListener.FILE_EDITOR_MANAGER);
      publisher.selectionChanged(event);
    });
    final JComponent component = newSelectedEditor.getComponent();
    final EditorWindowHolder holder = UIUtil.getParentOfType(EditorWindowHolder.class, component);
    if (holder != null) {
      ((FileEditorManagerImpl)myFileEditorManager).addSelectionRecord(myFile, holder.getEditorWindow());
    }
  }
}
 
Example 14
Source File: ContentChooser.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void rebuildListContent() {
  ArrayList<Item> items = new ArrayList<Item>();
  int i = 0;
  List<Data> contents = new ArrayList<Data>(getContents());
  for (Data content : contents) {
    String fullString = getStringRepresentationFor(content);
    if (fullString != null) {
      String shortString;
      fullString = StringUtil.convertLineSeparators(fullString);
      int newLineIdx = fullString.indexOf('\n');
      if (newLineIdx == -1) {
        shortString = fullString.trim(); 
      }
      else {
        int lastLooked = 0;
        do  {
          int nextLineIdx = fullString.indexOf("\n", lastLooked);
          if (nextLineIdx > lastLooked) {
            shortString = fullString.substring(lastLooked, nextLineIdx).trim() + " ...";
            break;
          }
          else if (nextLineIdx == -1) {
            shortString = " ...";
            break;
          }
          lastLooked = nextLineIdx + 1;
        } while (true);
      }
      items.add(new Item(i ++, shortString, fullString));
    }
  }
  myAllContents = contents;
  FilteringListModel listModel = (FilteringListModel)myList.getModel();
  ((CollectionListModel)listModel.getOriginalModel()).removeAll();
  listModel.addAll(items);
  ListWithFilter listWithFilter = UIUtil.getParentOfType(ListWithFilter.class, myList);
  if (listWithFilter != null) {
    listWithFilter.getSpeedSearch().update();
    if (listModel.getSize() == 0) listWithFilter.resetFilter();
  }
}
 
Example 15
Source File: ActionButton.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected DataContext getDataContext() {
  ActionToolbar actionToolbar = UIUtil.getParentOfType(ActionToolbar.class, this);
  return actionToolbar != null ? actionToolbar.getToolbarDataContext() : DataManager.getInstance().getDataContext();
}
 
Example 16
Source File: ShowNavBarAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean isInsideNavBar(Component c) {
  return c == null
         || c instanceof NavBarPanel
         || UIUtil.getParentOfType(NavBarListWrapper.class, c) != null;
}
 
Example 17
Source File: DarculaUIUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isComboBoxEditor(Component c) {
  return UIUtil.getParentOfType(JComboBox.class, c) != null;
}
 
Example 18
Source File: DetailsPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
DetailsPanel(@Nonnull VcsLogData logData,
             @Nonnull VcsLogColorManager colorManager,
             @Nonnull Disposable parent) {
  myLogData = logData;
  myColorManager = colorManager;

  myScrollPane = new JBScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  myMainContentPanel = new ScrollablePanel() {
    @Override
    public boolean getScrollableTracksViewportWidth() {
      boolean expanded = false;
      for (Component c : getComponents()) {
        if (c instanceof CommitPanel && ((CommitPanel)c).isExpanded()) {
          expanded = true;
          break;
        }
      }
      return !expanded;
    }

    @Override
    public Dimension getPreferredSize() {
      Dimension preferredSize = super.getPreferredSize();
      int height = Math.max(preferredSize.height, myScrollPane.getViewport().getHeight());
      JBScrollPane scrollPane = UIUtil.getParentOfType(JBScrollPane.class, this);
      if (scrollPane == null || getScrollableTracksViewportWidth()) {
        return new Dimension(preferredSize.width, height);
      }
      else {
        return new Dimension(Math.max(preferredSize.width, scrollPane.getViewport().getWidth()), height);
      }
    }

    @Override
    public Color getBackground() {
      return CommitPanel.getCommitDetailsBackground();
    }

    @Override
    protected void paintChildren(Graphics g) {
      if (StringUtil.isNotEmpty(myEmptyText.getText())) {
        myEmptyText.paint(this, g);
      }
      else {
        super.paintChildren(g);
      }
    }
  };
  myEmptyText = new StatusText(myMainContentPanel) {
    @Override
    protected boolean isStatusVisible() {
      return StringUtil.isNotEmpty(getText());
    }
  };
  myMainContentPanel.setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false));

  myMainContentPanel.setOpaque(false);
  myScrollPane.setViewportView(myMainContentPanel);
  myScrollPane.setBorder(IdeBorderFactory.createEmptyBorder());
  myScrollPane.setViewportBorder(IdeBorderFactory.createEmptyBorder());

  myLoadingPanel = new JBLoadingPanel(new BorderLayout(), parent, ProgressWindow.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS) {
    @Override
    public Color getBackground() {
      return CommitPanel.getCommitDetailsBackground();
    }
  };
  myLoadingPanel.add(myScrollPane);

  setLayout(new BorderLayout());
  add(myLoadingPanel, BorderLayout.CENTER);

  myEmptyText.setText("Commit details");
}
 
Example 19
Source File: DarculaCheckBoxBorder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public Insets getBorderInsets(Component c) {
  final int a = SystemInfo.isMac || UIUtil.getParentOfType(CellRendererPane.class, c) != null ? 0 : 2;
  return JBUI.insets(a, a, a, a);
}
 
Example 20
Source File: AnActionButton.java    From consulo with Apache License 2.0 4 votes vote down vote up
private boolean isContextComponentOk() {
  return myContextComponent == null || (myContextComponent.isVisible() && UIUtil.getParentOfType(JLayeredPane.class, myContextComponent) != null);
}