private void calcMaxIconSize(final ActionGroup actionGroup) {
      AnAction[] actions = actionGroup.getChildren(createActionEvent(actionGroup));
      for (AnAction action : actions) {
        if (action == null) continue;
        if (action instanceof ActionGroup) {
          final ActionGroup group = (ActionGroup) action;
          if (!group.isPopup()) {
            calcMaxIconSize(group);
            continue;
          }
        }

        Icon icon = action.getTemplatePresentation().getIcon();
        if (icon == null && action instanceof Toggleable) icon = PlatformIcons.CHECK_ICON;
        if (icon != null) {
          final int width = icon.getIconWidth();
          final int height = icon.getIconHeight();
          if (myMaxIconWidth < width) {
            myMaxIconWidth = width;
          }
          if (myMaxIconHeight < height) {
            myMaxIconHeight = height;
          }
        }
      }
    }
Example #2
0
 private void mousePressedInIconsArea(MouseEvent e) {
   EditorMessageIconRenderer iconRenderer = getIconRendererUnderMouse(e);
   if (iconRenderer != null) {
     if (e.getButton() == MouseEvent.BUTTON3) {
       JPopupMenu popupMenu = iconRenderer.getPopupMenu();
       if (popupMenu != null && e.getID() == MouseEvent.MOUSE_PRESSED) {
         e.consume();
         Component component = e.getComponent();
         popupMenu.show(component == null ? myEditorComponent : component, e.getX(), e.getY());
       }
       return;
     }
     AnAction action = iconRenderer.getClickAction();
     if (e.getButton() == MouseEvent.BUTTON1 && action != null) {
       if (e.getID() == MouseEvent.MOUSE_CLICKED) {
         AnActionEvent actionEvent =
             new AnActionEvent(
                 e,
                 new LeftEditorHighlighterDataContext(myEditorComponent, iconRenderer.getNode()),
                 ICON_AREA,
                 action.getTemplatePresentation(),
                 ActionManager.getInstance(),
                 e.getModifiers());
         action.update(actionEvent);
         action.actionPerformed(actionEvent);
       }
       e.consume();
     }
   }
 }
 private void registerShortcut(
     @NotNull String actionId, @NotNull ShortcutSet shortcut, @NotNull JComponent component) {
   final AnAction action = ActionManager.getInstance().getAction(actionId);
   if (action != null) {
     action.registerCustomShortcutSet(shortcut, component, this);
   }
 }
  private void registerFileChooserShortcut(
      @NonNls final String baseActionId, @NonNls final String fileChooserActionId) {
    final JTree tree = myFileSystemTree.getTree();
    final AnAction syncAction = ActionManager.getInstance().getAction(fileChooserActionId);

    AnAction original = ActionManager.getInstance().getAction(baseActionId);
    syncAction.registerCustomShortcutSet(original.getShortcutSet(), tree, myDisposable);
  }
 public static void registerActionShortcuts(
     final List<AnAction> actions, final JComponent component) {
   for (AnAction action : actions) {
     if (action.getShortcutSet() != null) {
       action.registerCustomShortcutSet(action.getShortcutSet(), component);
     }
   }
 }
  public boolean processAction(final InputEvent e, ActionProcessor processor) {
    ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
    final Project project = PlatformDataKeys.PROJECT.getData(myContext.getDataContext());
    final boolean dumb = project != null && DumbService.getInstance(project).isDumb();
    List<AnActionEvent> nonDumbAwareAction = new ArrayList<AnActionEvent>();
    for (final AnAction action : myContext.getActions()) {
      final Presentation presentation = myPresentationFactory.getPresentation(action);

      // Mouse modifiers are 0 because they have no any sense when action is invoked via keyboard
      final AnActionEvent actionEvent =
          processor.createEvent(
              e,
              myContext.getDataContext(),
              ActionPlaces.MAIN_MENU,
              presentation,
              ActionManager.getInstance());

      ActionUtil.performDumbAwareUpdate(action, actionEvent, true);

      if (dumb && !action.isDumbAware()) {
        if (Boolean.FALSE.equals(
            presentation.getClientProperty(ActionUtil.WOULD_BE_ENABLED_IF_NOT_DUMB_MODE))) {
          continue;
        }

        nonDumbAwareAction.add(actionEvent);
        continue;
      }

      if (!presentation.isEnabled()) {
        continue;
      }

      processor.onUpdatePassed(e, action, actionEvent);

      ((DataManagerImpl.MyDataContext) myContext.getDataContext())
          .setEventCount(IdeEventQueue.getInstance().getEventCount(), this);
      actionManager.fireBeforeActionPerformed(action, actionEvent.getDataContext(), actionEvent);
      Component component =
          PlatformDataKeys.CONTEXT_COMPONENT.getData(actionEvent.getDataContext());
      if (component != null && !component.isShowing()) {
        return true;
      }

      processor.performAction(e, action, actionEvent);
      actionManager.fireAfterActionPerformed(action, actionEvent.getDataContext(), actionEvent);
      return true;
    }

    if (!nonDumbAwareAction.isEmpty()) {
      showDumbModeWarningLaterIfNobodyConsumesEvent(
          e, nonDumbAwareAction.toArray(new AnActionEvent[nonDumbAwareAction.size()]));
    }

    return false;
  }
 private void registerCustomShortcuts(DirDiffToolbarActions actions, JComponent component) {
   for (AnAction action : actions.getChildren(null)) {
     if (action instanceof ShortcutProvider) {
       final ShortcutSet shortcut = ((ShortcutProvider) action).getShortcut();
       if (shortcut != null) {
         action.registerCustomShortcutSet(shortcut, component);
       }
     }
   }
 }
 public static void invokeNamedAction(final String actionId) {
   final AnAction action = ActionManager.getInstance().getAction(actionId);
   assertNotNull(action);
   final Presentation presentation = new Presentation();
   @SuppressWarnings("deprecation")
   final DataContext context = DataManager.getInstance().getDataContext();
   final AnActionEvent event =
       new AnActionEvent(null, context, "", presentation, ActionManager.getInstance(), 0);
   action.update(event);
   Assert.assertTrue(presentation.isEnabled());
   action.actionPerformed(event);
 }
 public boolean matches(@NotNull final String name, @NotNull final String pattern) {
   final AnAction anAction = myActionManager.getAction(name);
   if (!(anAction instanceof ActionGroup)) {
     final Presentation presentation = anAction.getTemplatePresentation();
     final String text = presentation.getText();
     final String description = presentation.getDescription();
     final Pattern compiledPattern = getPattern(pattern);
     if ((text != null && myMatcher.matches(text, compiledPattern))
         || (description != null && myMatcher.matches(description, compiledPattern))) {
       return true;
     }
   }
   return false;
 }
  private void executeAction(final String watch) {
    AnAction action = ActionManager.getInstance().getAction(watch);
    Presentation presentation = action.getTemplatePresentation().clone();
    DataContext context = DataManager.getInstance().getDataContext(myTreePanel.getTree());

    AnActionEvent actionEvent =
        new AnActionEvent(
            null,
            context,
            ActionPlaces.DEBUGGER_TOOLBAR,
            presentation,
            ActionManager.getInstance(),
            0);
    action.actionPerformed(actionEvent);
  }
    private JComponent createActionPanel() {
      JPanel actions = new NonOpaquePanel();
      actions.setBorder(JBUI.Borders.emptyLeft(10));
      actions.setLayout(new BoxLayout(actions, BoxLayout.Y_AXIS));
      ActionManager actionManager = ActionManager.getInstance();
      ActionGroup quickStart =
          (ActionGroup) actionManager.getAction(IdeActions.GROUP_WELCOME_SCREEN_QUICKSTART);
      DefaultActionGroup group = new DefaultActionGroup();
      collectAllActions(group, quickStart);

      for (AnAction action : group.getChildren(null)) {
        JPanel button = new JPanel(new BorderLayout());
        button.setOpaque(false);
        button.setBorder(JBUI.Borders.empty(8, 20));
        AnActionEvent e =
            AnActionEvent.createFromAnAction(
                action,
                null,
                ActionPlaces.WELCOME_SCREEN,
                DataManager.getInstance().getDataContext(this));
        action.update(e);
        Presentation presentation = e.getPresentation();
        if (presentation.isVisible()) {
          String text = presentation.getText();
          if (text != null && text.endsWith("...")) {
            text = text.substring(0, text.length() - 3);
          }
          Icon icon = presentation.getIcon();
          if (icon.getIconHeight() != JBUI.scale(16) || icon.getIconWidth() != JBUI.scale(16)) {
            icon = JBUI.emptyIcon(16);
          }
          action = wrapGroups(action);
          ActionLink link = new ActionLink(text, icon, action, createUsageTracker(action));
          link.setPaintUnderline(false);
          link.setNormalColor(getLinkNormalColor());
          button.add(link);
          if (action instanceof WelcomePopupAction) {
            button.add(createArrow(link), BorderLayout.EAST);
          }
          installFocusable(button, action, KeyEvent.VK_UP, KeyEvent.VK_DOWN, true);
          actions.add(button);
        }
      }

      WelcomeScreenActionsPanel panel = new WelcomeScreenActionsPanel();
      panel.actions.add(actions);
      return panel.root;
    }
 public static void executeAction(
     @NotNull Editor editor, @NotNull String actionId, boolean assertActionIsEnabled) {
   ActionManager actionManager = ActionManager.getInstance();
   AnAction action = actionManager.getAction(actionId);
   assertNotNull(action);
   DataContext dataContext = createEditorContext(editor);
   AnActionEvent event =
       new AnActionEvent(
           null, dataContext, "", action.getTemplatePresentation(), actionManager, 0);
   action.beforeActionPerformedUpdate(event);
   if (!event.getPresentation().isEnabled()) {
     assertFalse("Action " + actionId + " is disabled", assertActionIsEnabled);
     return;
   }
   action.actionPerformed(event);
 }
      private AnAction patch(final AnAction child) {
        if (child instanceof ActionGroup) {
          return new IconsFreeActionGroup((ActionGroup) child);
        }

        Presentation presentation = child.getTemplatePresentation();
        return new AnAction(presentation.getText(), presentation.getDescription(), null) {
          @Override
          public void actionPerformed(@NotNull AnActionEvent e) {
            child.actionPerformed(e);
            UsageTrigger.trigger("welcome.screen." + e.getActionManager().getId(child));
          }

          @Override
          public void update(@NotNull AnActionEvent e) {
            child.update(e);
            e.getPresentation().setIcon(null);
          }

          @Override
          public boolean isDumbAware() {
            return child.isDumbAware();
          }
        };
      }
 private Presentation getPresentation(@NotNull AnAction action) {
   Presentation presentation = myAction2presentation.get(action);
   if (presentation == null) {
     presentation = action.getTemplatePresentation().clone();
     myAction2presentation.put(action, presentation);
   }
   return presentation;
 }
 private void performEditAction() {
   final AnAction action = getEditAction();
   if (action != null) {
     final int row = myInjectionsTable.getSelectedRow();
     action.actionPerformed(
         new AnActionEvent(
             null,
             DataManager.getInstance().getDataContext(myInjectionsTable),
             ActionPlaces.UNKNOWN,
             new Presentation(""),
             ActionManager.getInstance(),
             0));
     myInjectionsTable.getListTableModel().fireTableDataChanged();
     myInjectionsTable.getSelectionModel().setSelectionInterval(row, row);
     updateCountLabel();
   }
 }
 private ArrayList<Pair<AnAction, KeyStroke>> getSecondKeystrokeActions() {
   ArrayList<Pair<AnAction, KeyStroke>> secondKeyStrokes =
       new ArrayList<Pair<AnAction, KeyStroke>>();
   for (AnAction action : myContext.getActions()) {
     Shortcut[] shortcuts = action.getShortcutSet().getShortcuts();
     for (Shortcut shortcut : shortcuts) {
       if (shortcut instanceof KeyboardShortcut) {
         KeyboardShortcut keyShortcut = (KeyboardShortcut) shortcut;
         if (keyShortcut.getFirstKeyStroke().equals(myFirstKeyStroke)) {
           secondKeyStrokes.add(
               new Pair<AnAction, KeyStroke>(action, keyShortcut.getSecondKeyStroke()));
         }
       }
     }
   }
   return secondKeyStrokes;
 }
    private AnAction wrapGroups(AnAction action) {
      if (action instanceof ActionGroup && ((ActionGroup) action).isPopup()) {
        final Pair<JPanel, JBList> panel =
            createActionGroupPanel(
                (ActionGroup) action,
                mySlidingPanel,
                new Runnable() {
                  @Override
                  public void run() {
                    goBack();
                  }
                });
        final Runnable onDone =
            new Runnable() {
              @Override
              public void run() {
                final JBList list = panel.second;
                ScrollingUtil.ensureSelectionExists(list);
                final ListSelectionListener[] listeners =
                    ((DefaultListSelectionModel) list.getSelectionModel())
                        .getListeners(ListSelectionListener.class);

                // avoid component cashing. This helps in case of LaF change
                for (ListSelectionListener listener : listeners) {
                  listener.valueChanged(
                      new ListSelectionEvent(
                          list, list.getSelectedIndex(), list.getSelectedIndex(), true));
                }
                list.requestFocus();
              }
            };
        final String name = action.getClass().getName();
        mySlidingPanel.add(name, panel.first);
        final Presentation p = action.getTemplatePresentation();
        return new DumbAwareAction(p.getText(), p.getDescription(), p.getIcon()) {
          @Override
          public void actionPerformed(@NotNull AnActionEvent e) {
            mySlidingPanel
                .getLayout()
                .swipe(mySlidingPanel, name, JBCardLayout.SwipeDirection.FORWARD, onDone);
          }
        };
      }
      return action;
    }
    private JComponent createSettingsAndDocs() {
      JPanel panel = new NonOpaquePanel(new BorderLayout());
      NonOpaquePanel toolbar = new NonOpaquePanel();
      AnAction register = ActionManager.getInstance().getAction("Register");
      boolean registeredVisible = false;
      if (register != null) {
        AnActionEvent e =
            AnActionEvent.createFromAnAction(
                register,
                null,
                ActionPlaces.WELCOME_SCREEN,
                DataManager.getInstance().getDataContext(this));
        register.update(e);
        Presentation presentation = e.getPresentation();
        if (presentation.isEnabled()) {
          ActionLink registerLink = new ActionLink("Register", register);
          registerLink.setNormalColor(getLinkNormalColor());
          NonOpaquePanel button = new NonOpaquePanel(new BorderLayout());
          button.setBorder(JBUI.Borders.empty(4, 10));
          button.add(registerLink);
          installFocusable(button, register, KeyEvent.VK_UP, KeyEvent.VK_RIGHT, true);
          NonOpaquePanel wrap = new NonOpaquePanel();
          wrap.setBorder(JBUI.Borders.emptyLeft(10));
          wrap.add(button);
          panel.add(wrap, BorderLayout.WEST);
          registeredVisible = true;
        }
      }

      toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS));
      toolbar.add(
          createActionLink(
              "Configure",
              IdeActions.GROUP_WELCOME_SCREEN_CONFIGURE,
              AllIcons.General.GearPlain,
              !registeredVisible));
      toolbar.add(createActionLink("Get Help", IdeActions.GROUP_WELCOME_SCREEN_DOC, null, false));

      panel.add(toolbar, BorderLayout.EAST);

      panel.setBorder(JBUI.Borders.empty(0, 0, 8, 11));
      return panel;
    }
  private void fillActionsList(
      Component component, MouseShortcut mouseShortcut, boolean isModalContext) {
    myActions.clear();

    // here we try to find "local" shortcuts
    if (component instanceof JComponent) {
      for (AnAction action : ActionUtil.getActions((JComponent) component)) {
        for (Shortcut shortcut : action.getShortcutSet().getShortcuts()) {
          if (mouseShortcut.equals(shortcut) && !myActions.contains(action)) {
            myActions.add(action);
          }
        }
      }
      // once we've found a proper local shortcut(s), we exit
      if (!myActions.isEmpty()) {
        return;
      }
    }

    // search in main keymap
    if (KeymapManagerImpl.ourKeymapManagerInitialized) {
      final KeymapManager keymapManager = KeymapManager.getInstance();
      if (keymapManager != null) {
        final Keymap keymap = keymapManager.getActiveKeymap();
        final String[] actionIds = keymap.getActionIds(mouseShortcut);

        ActionManager actionManager = ActionManager.getInstance();
        for (String actionId : actionIds) {
          AnAction action = actionManager.getAction(actionId);

          if (action == null) continue;

          if (isModalContext && !action.isEnabledInModalContext()) continue;

          if (!myActions.contains(action)) {
            myActions.add(action);
          }
        }
      }
    }
  }
  protected void init() {
    addActionsTo(myToolbarGroup);
    myToolbarGroup.add(new MyCloseAction());
    myToolbarGroup.add(ActionManager.getInstance().getAction(IdeActions.ACTION_CONTEXT_HELP));

    ActionToolbar toolbar =
        ActionManager.getInstance()
            .createActionToolbar(
                ActionPlaces.FILEHISTORY_VIEW_TOOLBAR, myToolbarGroup, !myVerticalToolbar);
    JComponent centerPanel = createCenterPanel();
    toolbar.setTargetComponent(centerPanel);
    for (AnAction action : myToolbarGroup.getChildren(null)) {
      action.registerCustomShortcutSet(action.getShortcutSet(), centerPanel);
    }

    add(centerPanel, BorderLayout.CENTER);
    if (myVerticalToolbar) {
      add(toolbar.getComponent(), BorderLayout.WEST);
    } else {
      add(toolbar.getComponent(), BorderLayout.NORTH);
    }
  }
  private void init() {
    setVisible(myPresentation.isVisible());
    setEnabled(myPresentation.isEnabled());
    setMnemonic(myEnableMnemonics ? myPresentation.getMnemonic() : 0);
    setText(myPresentation.getText());
    final int mnemonicIndex = myEnableMnemonics ? myPresentation.getDisplayedMnemonicIndex() : -1;

    if (getText() != null && mnemonicIndex >= 0 && mnemonicIndex < getText().length()) {
      setDisplayedMnemonicIndex(mnemonicIndex);
    }

    AnAction action = myAction.getAction();
    updateIcon(action);
    String id = ActionManager.getInstance().getId(action);
    if (id != null) {
      setAcceleratorFromShortcuts(KeymapManager.getInstance().getActiveKeymap().getShortcuts(id));
    } else {
      final ShortcutSet shortcutSet = action.getShortcutSet();
      if (shortcutSet != null) {
        setAcceleratorFromShortcuts(shortcutSet.getShortcuts());
      }
    }
  }
Example #22
0
  private List<Button> buildButtons(ActionGroup group, String parentId) {
    AnAction[] actions = group.getChildren(null);

    List<Button> buttons = new ArrayList<Button>();

    for (AnAction action : actions) {
      Presentation presentation = action.getTemplatePresentation();
      if (!USE_ICONS) {
        presentation.setIcon(null);
      }
      if (action instanceof ActionGroup) {
        ActionGroup childGroup = (ActionGroup) action;
        if (childGroup.isPopup()) {
          final String id = String.valueOf(++nCards);
          createCardForGroup(childGroup, id, parentId);

          buttons.add(new Button(new ActivateCard(id), presentation));
        } else {
          buttons.addAll(buildButtons(childGroup, parentId));
        }
      } else {
        action.update(
            new AnActionEvent(
                null,
                DataManager.getInstance().getDataContext(this),
                ActionPlaces.WELCOME_SCREEN,
                presentation,
                ActionManager.getInstance(),
                0));
        if (presentation.isVisible()) {
          buttons.add(new Button(action, presentation));
        }
      }
    }
    return buttons;
  }
  protected void buildToolBar(final DefaultActionGroup toolBarGroup) {
    myDiffAction =
        new DumbAwareAction() {
          public void update(AnActionEvent e) {
            e.getPresentation().setEnabled(canShowDiff());
          }

          public void actionPerformed(AnActionEvent e) {
            showDiff();
          }
        };
    ActionUtil.copyFrom(myDiffAction, "ChangesView.Diff");
    myDiffAction.registerCustomShortcutSet(myViewer, null);
    toolBarGroup.add(myDiffAction);
  }
  private DefaultActionGroup createActionGroup() {
    DefaultActionGroup actionGroup = new DefaultActionGroup();
    if (ApplicationManager.getApplication() == null || Pico.isUnitTest()) return actionGroup;

    addRefreshAction(actionGroup);
    myOpenFileAction = new OpenFileAction(myTree, myIdeFacade);
    myOpenFileAction.registerCustomShortcutSet(
        new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0)), myTree);

    AnAction diffAction =
        new DiffAction(myTree) {
          protected User getUser() {
            return myUser;
          }
        };

    diffAction.registerCustomShortcutSet(CommonShortcuts.getDiff(), myTree);

    actionGroup.add(myOpenFileAction);
    actionGroup.add(diffAction);

    addToggleReadOnlyAction(actionGroup);
    return actionGroup;
  }
 public void performAction(
     final InputEvent e, final AnAction action, final AnActionEvent actionEvent) {
   e.consume();
   action.actionPerformed(actionEvent);
   if (Registry.is("actionSystem.fixLostTyping")) {
     IdeEventQueue.getInstance()
         .doWhenReady(
             new Runnable() {
               @Override
               public void run() {
                 IdeEventQueue.getInstance().getKeyEventDispatcher().resetState();
               }
             });
   }
 }
    private void appendAction(@NotNull AnAction action) {
      Presentation presentation = getPresentation(action);
      AnActionEvent event = createActionEvent(action);

      ActionUtil.performDumbAwareUpdate(action, event, true);
      if ((myShowDisabled || presentation.isEnabled()) && presentation.isVisible()) {
        String text = presentation.getText();
        if (myShowNumbers) {
          if (myCurrentNumber < 9) {
            text = "&" + (myCurrentNumber + 1) + ". " + text;
          } else if (myCurrentNumber == 9) {
            text = "&" + 0 + ". " + text;
          } else if (myUseAlphaAsNumbers) {
            text = "&" + (char) ('A' + myCurrentNumber - 10) + ". " + text;
          }
          myCurrentNumber++;
        } else if (myHonorActionMnemonics) {
          text =
              Presentation.restoreTextWithMnemonic(
                  text, action.getTemplatePresentation().getMnemonic());
        }

        Icon icon = presentation.getIcon();
        if (icon == null) {
          @NonNls final String actionId = ActionManager.getInstance().getId(action);
          if (actionId != null && actionId.startsWith("QuickList.")) {
            icon = AllIcons.Actions.QuickList;
          } else if (action instanceof Toggleable) {
            boolean toggled =
                Boolean.TRUE.equals(presentation.getClientProperty(Toggleable.SELECTED_PROPERTY));
            icon = toggled ? new IconWrapper(PlatformIcons.CHECK_ICON) : myEmptyIcon;
          } else {
            icon = myEmptyIcon;
          }
        } else {
          icon = new IconWrapper(icon);
        }
        boolean prependSeparator =
            (!myListModel.isEmpty() || mySeparatorText != null) && myPrependWithSeparator;
        assert text != null : action + " has no presentation";
        myListModel.add(
            new ActionItem(
                action, text, presentation.isEnabled(), icon, prependSeparator, mySeparatorText));
        myPrependWithSeparator = false;
        mySeparatorText = null;
      }
    }
  /** @return true if action is added and has second stroke */
  private boolean addAction(AnAction action, Shortcut sc) {
    boolean hasSecondStroke = false;

    Shortcut[] shortcuts = action.getShortcutSet().getShortcuts();
    for (Shortcut each : shortcuts) {
      if (!each.isKeyboard()) continue;

      if (each.startsWith(sc)) {
        if (!myContext.getActions().contains(action)) {
          myContext.getActions().add(action);
        }

        if (each instanceof KeyboardShortcut) {
          hasSecondStroke |= ((KeyboardShortcut) each).getSecondKeyStroke() != null;
        }
      }
    }

    return hasSecondStroke;
  }
 private void updateIcon(AnAction action) {
   if (action instanceof Toggleable && myPresentation.getIcon() == null) {
     action.update(myEvent);
     if (Boolean.TRUE.equals(
         myEvent.getPresentation().getClientProperty(Toggleable.SELECTED_PROPERTY))) {
       setIcon(ourCheckedIcon);
       setDisabledIcon(IconLoader.getDisabledIcon(ourCheckedIcon));
     } else {
       setIcon(ourUncheckedIcon);
       setDisabledIcon(IconLoader.getDisabledIcon(ourUncheckedIcon));
     }
   } else {
     if (!SystemInfo.isMac || UISettings.getInstance().SHOW_ICONS_IN_MENUS) {
       Icon icon = myPresentation.getIcon();
       setIcon(icon);
       if (myPresentation.getDisabledIcon() != null) {
         setDisabledIcon(myPresentation.getDisabledIcon());
       } else {
         setDisabledIcon(IconLoader.getDisabledIcon(icon));
       }
     }
   }
 }
 private void updateIcon(AnAction action) {
   if (isToggleable()
       && (myPresentation.getIcon() == null
           || myInsideCheckedGroup
           || !UISettings.getInstance().SHOW_ICONS_IN_MENUS)) {
     action.update(myEvent);
     myToggled =
         Boolean.TRUE.equals(
             myEvent.getPresentation().getClientProperty(Toggleable.SELECTED_PROPERTY));
     if (ActionPlaces.MAIN_MENU.equals(myPlace) && SystemInfo.isMacSystemMenu
         || UIUtil.isUnderNimbusLookAndFeel()
         || UIUtil.isUnderWindowsLookAndFeel() && SystemInfo.isWin7OrNewer) {
       setState(myToggled);
     } else if (!(getUI() instanceof GtkMenuItemUI)) {
       if (myToggled) {
         setIcon(ourCheckedIcon);
         setDisabledIcon(IconLoader.getDisabledIcon(ourCheckedIcon));
       } else {
         setIcon(ourUncheckedIcon);
         setDisabledIcon(IconLoader.getDisabledIcon(ourUncheckedIcon));
       }
     }
   } else {
     if (UISettings.getInstance().SHOW_ICONS_IN_MENUS) {
       Icon icon = myPresentation.getIcon();
       if (action instanceof ToggleAction && ((ToggleAction) action).isSelected(myEvent)) {
         icon = new PoppedIcon(icon, 16, 16);
       }
       setIcon(icon);
       if (myPresentation.getDisabledIcon() != null) {
         setDisabledIcon(myPresentation.getDisabledIcon());
       } else {
         setDisabledIcon(IconLoader.getDisabledIcon(icon));
       }
     }
   }
 }
  public ClasspathPanelImpl(ModuleConfigurationState state) {
    super(new BorderLayout());

    myState = state;
    myModel = new ClasspathTableModel(state, getStructureConfigurableContext());
    myEntryTable =
        new JBTable(myModel) {
          @Override
          protected TableRowSorter<TableModel> createRowSorter(TableModel model) {
            return new DefaultColumnInfoBasedRowSorter(model) {
              @Override
              public void toggleSortOrder(int column) {
                if (isSortable(column)) {
                  SortKey oldKey = ContainerUtil.getFirstItem(getSortKeys());
                  SortOrder oldOrder;
                  if (oldKey == null || oldKey.getColumn() != column) {
                    oldOrder = SortOrder.UNSORTED;
                  } else {
                    oldOrder = oldKey.getSortOrder();
                  }
                  setSortKeys(
                      Collections.singletonList(new SortKey(column, getNextSortOrder(oldOrder))));
                }
              }
            };
          }
        };
    myEntryTable.setShowGrid(false);
    myEntryTable.setDragEnabled(false);
    myEntryTable.setIntercellSpacing(new Dimension(0, 0));

    myEntryTable.setDefaultRenderer(
        ClasspathTableItem.class, new TableItemRenderer(getStructureConfigurableContext()));
    myEntryTable.setDefaultRenderer(
        Boolean.class, new ExportFlagRenderer(myEntryTable.getDefaultRenderer(Boolean.class)));

    JComboBox scopeEditor =
        new ComboBox(new EnumComboBoxModel<DependencyScope>(DependencyScope.class));
    myEntryTable.setDefaultEditor(DependencyScope.class, new DefaultCellEditor(scopeEditor));
    myEntryTable.setDefaultRenderer(
        DependencyScope.class,
        new ComboBoxTableRenderer<DependencyScope>(DependencyScope.values()) {
          @Override
          protected String getTextFor(@NotNull final DependencyScope value) {
            return value.getDisplayName();
          }
        });

    myEntryTable.setTransferHandler(
        new TransferHandler() {
          @Nullable
          @Override
          protected Transferable createTransferable(JComponent c) {
            OrderEntry entry = getSelectedEntry();
            if (entry == null) return null;
            String text = entry.getPresentableName();
            return new TextTransferable(text);
          }

          @Override
          public int getSourceActions(JComponent c) {
            return COPY;
          }
        });

    myEntryTable
        .getSelectionModel()
        .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    new SpeedSearchBase<JBTable>(myEntryTable) {
      @Override
      public int getSelectedIndex() {
        return myEntryTable.getSelectedRow();
      }

      @Override
      protected int convertIndexToModel(int viewIndex) {
        return myEntryTable.convertRowIndexToModel(viewIndex);
      }

      @Override
      public Object[] getAllElements() {
        final int count = myModel.getRowCount();
        Object[] elements = new Object[count];
        for (int idx = 0; idx < count; idx++) {
          elements[idx] = myModel.getItem(idx);
        }
        return elements;
      }

      @Override
      public String getElementText(Object element) {
        return getCellAppearance(
                (ClasspathTableItem<?>) element, getStructureConfigurableContext(), false)
            .getText();
      }

      @Override
      public void selectElement(Object element, String selectedText) {
        final int count = myModel.getRowCount();
        for (int row = 0; row < count; row++) {
          if (element.equals(myModel.getItem(row))) {
            final int viewRow = myEntryTable.convertRowIndexToView(row);
            myEntryTable.getSelectionModel().setSelectionInterval(viewRow, viewRow);
            TableUtil.scrollSelectionToVisible(myEntryTable);
            break;
          }
        }
      }
    };
    setFixedColumnWidth(ClasspathTableModel.EXPORT_COLUMN);
    setFixedColumnWidth(ClasspathTableModel.SCOPE_COLUMN); // leave space for combobox border

    myEntryTable.registerKeyboardAction(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            final int[] selectedRows = myEntryTable.getSelectedRows();
            boolean currentlyMarked = true;
            for (final int selectedRow : selectedRows) {
              final ClasspathTableItem<?> item = getItemAt(selectedRow);
              if (selectedRow < 0 || !item.isExportable()) {
                return;
              }
              currentlyMarked &= item.isExported();
            }
            for (final int selectedRow : selectedRows) {
              getItemAt(selectedRow).setExported(!currentlyMarked);
            }
            myModel.fireTableDataChanged();
            TableUtil.selectRows(myEntryTable, selectedRows);
          }
        },
        KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0),
        WHEN_FOCUSED);

    myEditButton =
        new AnActionButton(
            ProjectBundle.message("module.classpath.button.edit"), null, IconUtil.getEditIcon()) {
          @Override
          public void actionPerformed(@NotNull AnActionEvent e) {
            doEdit();
          }

          @Override
          public boolean isEnabled() {
            ClasspathTableItem<?> selectedItem = getSelectedItem();
            return selectedItem != null && selectedItem.isEditable();
          }

          @Override
          public boolean isDumbAware() {
            return true;
          }
        };
    add(createTableWithButtons(), BorderLayout.CENTER);

    if (myEntryTable.getRowCount() > 0) {
      myEntryTable.getSelectionModel().setSelectionInterval(0, 0);
    }

    new DoubleClickListener() {
      @Override
      protected boolean onDoubleClick(MouseEvent e) {
        navigate(true);
        return true;
      }
    }.installOn(myEntryTable);

    DefaultActionGroup actionGroup = new DefaultActionGroup();
    final AnAction navigateAction =
        new AnAction(ProjectBundle.message("classpath.panel.navigate.action.text")) {
          @Override
          public void actionPerformed(@NotNull AnActionEvent e) {
            navigate(false);
          }

          @Override
          public void update(@NotNull AnActionEvent e) {
            final Presentation presentation = e.getPresentation();
            presentation.setEnabled(false);
            final OrderEntry entry = getSelectedEntry();
            if (entry != null && entry.isValid()) {
              if (!(entry instanceof ModuleSourceOrderEntry)) {
                presentation.setEnabled(true);
              }
            }
          }
        };
    navigateAction.registerCustomShortcutSet(
        ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE).getShortcutSet(),
        myEntryTable);
    actionGroup.add(myEditButton);
    actionGroup.add(myRemoveButton);
    actionGroup.add(navigateAction);
    actionGroup.add(new InlineModuleDependencyAction(this));
    actionGroup.add(new MyFindUsagesAction());
    actionGroup.add(new AnalyzeDependencyAction());
    addChangeLibraryLevelAction(actionGroup, LibraryTablesRegistrar.PROJECT_LEVEL);
    addChangeLibraryLevelAction(actionGroup, LibraryTablesRegistrar.APPLICATION_LEVEL);
    addChangeLibraryLevelAction(actionGroup, LibraryTableImplUtil.MODULE_LEVEL);
    PopupHandler.installPopupHandler(
        myEntryTable, actionGroup, ActionPlaces.UNKNOWN, ActionManager.getInstance());
  }