private JComponent createTableWithButtons() {
    final boolean isAnalyzeShown = false;

    final ClasspathPanelAction removeAction =
        new ClasspathPanelAction(this) {
          @Override
          public void run() {
            removeSelectedItems(TableUtil.removeSelectedItems(myEntryTable));
          }
        };

    final AnActionButton analyzeButton =
        new AnActionButton(
            ProjectBundle.message("classpath.panel.analyze"), null, IconUtil.getAnalyzeIcon()) {
          @Override
          public void actionPerformed(@NotNull AnActionEvent e) {
            AnalyzeDependenciesDialog.show(getRootModel().getModule());
          }
        };

    // addButton.setShortcut(CustomShortcutSet.fromString("alt A", "INSERT"));
    // removeButton.setShortcut(CustomShortcutSet.fromString("alt DELETE"));
    // upButton.setShortcut(CustomShortcutSet.fromString("alt UP"));
    // downButton.setShortcut(CustomShortcutSet.fromString("alt DOWN"));

    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myEntryTable);
    AnActionButtonUpdater moveUpDownUpdater =
        new AnActionButtonUpdater() {
          @Override
          public boolean isEnabled(AnActionEvent e) {
            for (RowSorter.SortKey key : myEntryTable.getRowSorter().getSortKeys()) {
              if (key.getSortOrder() != SortOrder.UNSORTED) {
                return false;
              }
            }
            return true;
          }
        };
    decorator
        .setAddAction(
            new AnActionButtonRunnable() {
              @Override
              public void run(AnActionButton button) {
                initPopupActions();
                final JBPopup popup =
                    JBPopupFactory.getInstance()
                        .createListPopup(
                            new BaseListPopupStep<AddItemPopupAction<?>>(null, myPopupActions) {
                              @Override
                              public Icon getIconFor(AddItemPopupAction<?> aValue) {
                                return aValue.getIcon();
                              }

                              @Override
                              public boolean hasSubstep(AddItemPopupAction<?> selectedValue) {
                                return selectedValue.hasSubStep();
                              }

                              @Override
                              public boolean isMnemonicsNavigationEnabled() {
                                return true;
                              }

                              @Override
                              public PopupStep onChosen(
                                  final AddItemPopupAction<?> selectedValue,
                                  final boolean finalChoice) {
                                if (selectedValue.hasSubStep()) {
                                  return selectedValue.createSubStep();
                                }
                                return doFinalStep(
                                    new Runnable() {
                                      @Override
                                      public void run() {
                                        selectedValue.execute();
                                      }
                                    });
                              }

                              @Override
                              @NotNull
                              public String getTextFor(AddItemPopupAction<?> value) {
                                return "&" + value.getIndex() + "  " + value.getTitle();
                              }
                            });
                popup.show(button.getPreferredPopupPoint());
              }
            })
        .setRemoveAction(
            new AnActionButtonRunnable() {
              @Override
              public void run(AnActionButton button) {
                removeAction.actionPerformed(null);
              }
            })
        .setRemoveActionUpdater(
            new AnActionButtonUpdater() {
              @Override
              public boolean isEnabled(AnActionEvent e) {
                final int[] selectedRows = myEntryTable.getSelectedRows();
                for (final int selectedRow : selectedRows) {
                  if (!getItemAt(selectedRow).isRemovable()) {
                    return false;
                  }
                }
                return selectedRows.length > 0;
              }
            })
        .setMoveUpAction(
            new AnActionButtonRunnable() {
              @Override
              public void run(AnActionButton button) {
                moveSelectedRows(-1);
              }
            })
        .setMoveUpActionUpdater(moveUpDownUpdater)
        .setMoveUpActionName("Move Up (disabled if items are shown in sorted order)")
        .setMoveDownAction(
            new AnActionButtonRunnable() {
              @Override
              public void run(AnActionButton button) {
                moveSelectedRows(+1);
              }
            })
        .setMoveDownActionUpdater(moveUpDownUpdater)
        .setMoveDownActionName("Move Down (disabled if items are shown in sorted order)")
        .addExtraAction(myEditButton);
    if (isAnalyzeShown) {
      decorator.addExtraAction(analyzeButton);
    }

    final JPanel panel = decorator.createPanel();
    myRemoveButton = ToolbarDecorator.findRemoveButton(panel);
    return panel;
  }
Пример #2
0
  private JComponent createTableWithButtons() {
    final boolean isAnalyzeShown = false;

    final ClasspathPanelAction removeAction =
        new ClasspathPanelAction(this) {
          @Override
          public void run() {
            removeSelectedItems(TableUtil.removeSelectedItems(myEntryTable));
          }
        };

    final AnActionButton analyzeButton =
        new AnActionButton(
            ProjectBundle.message("classpath.panel.analyze"), null, IconUtil.getAnalyzeIcon()) {
          @Override
          public void actionPerformed(AnActionEvent e) {
            AnalyzeDependenciesDialog.show(getRootModel().getModule());
          }
        };

    // addButton.setShortcut(CustomShortcutSet.fromString("alt A", "INSERT"));
    // removeButton.setShortcut(CustomShortcutSet.fromString("alt DELETE"));
    // upButton.setShortcut(CustomShortcutSet.fromString("alt UP"));
    // downButton.setShortcut(CustomShortcutSet.fromString("alt DOWN"));
    myEntryTable.setBorder(new LineBorder(UIUtil.getBorderColor()));

    // we need to register our listener before ToolbarDecorator registers its own. Otherwise
    myEntryTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) {
                  return;
                }
                updateButtons();
              }
            });

    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myEntryTable);
    decorator
        .setAddAction(
            new AnActionButtonRunnable() {
              @Override
              public void run(AnActionButton button) {
                initPopupActions();
                final JBPopup popup =
                    JBPopupFactory.getInstance()
                        .createListPopup(
                            new BaseListPopupStep<AddItemPopupAction<?>>(null, myPopupActions) {
                              @Override
                              public Icon getIconFor(AddItemPopupAction<?> aValue) {
                                return aValue.getIcon();
                              }

                              @Override
                              public boolean hasSubstep(AddItemPopupAction<?> selectedValue) {
                                return selectedValue.hasSubStep();
                              }

                              @Override
                              public boolean isMnemonicsNavigationEnabled() {
                                return true;
                              }

                              @Override
                              public PopupStep onChosen(
                                  final AddItemPopupAction<?> selectedValue,
                                  final boolean finalChoice) {
                                if (selectedValue.hasSubStep()) {
                                  return selectedValue.createSubStep();
                                }
                                return doFinalStep(
                                    new Runnable() {
                                      @Override
                                      public void run() {
                                        selectedValue.execute();
                                      }
                                    });
                              }

                              @Override
                              @NotNull
                              public String getTextFor(AddItemPopupAction<?> value) {
                                return "&" + value.getIndex() + "  " + value.getTitle();
                              }
                            });
                popup.show(button.getPreferredPopupPoint());
              }
            })
        .setRemoveAction(
            new AnActionButtonRunnable() {
              @Override
              public void run(AnActionButton button) {
                removeAction.actionPerformed(null);
              }
            })
        .setMoveUpAction(
            new AnActionButtonRunnable() {
              @Override
              public void run(AnActionButton button) {
                moveSelectedRows(-1);
              }
            })
        .setMoveDownAction(
            new AnActionButtonRunnable() {
              @Override
              public void run(AnActionButton button) {
                moveSelectedRows(+1);
              }
            })
        .addExtraAction(myEditButton);
    if (isAnalyzeShown) {
      decorator.addExtraAction(analyzeButton);
    }

    final JPanel panel = decorator.createPanel();
    myRemoveButton = ToolbarDecorator.findRemoveButton(panel);
    return panel;
  }