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;
  }
  ToolsPanel() {

    myTree =
        new CheckboxTree(
            new CheckboxTree.CheckboxTreeCellRenderer() {
              public void customizeRenderer(
                  final JTree tree,
                  final Object value,
                  final boolean selected,
                  final boolean expanded,
                  final boolean leaf,
                  final int row,
                  final boolean hasFocus) {
                if (!(value instanceof CheckedTreeNode)) return;
                Object object = ((CheckedTreeNode) value).getUserObject();

                if (object instanceof ToolsGroup) {
                  final String groupName = ((ToolsGroup) object).getName();
                  if (groupName != null) {
                    getTextRenderer()
                        .append(groupName, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
                  } else {
                    getTextRenderer()
                        .append("[unnamed group]", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
                  }
                } else if (object instanceof Tool) {
                  getTextRenderer()
                      .append(
                          ((Tool) object).getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
                }
              }
            },
            new CheckedTreeNode(null)) {
          @Override
          protected void onDoubleClick(final CheckedTreeNode node) {
            editSelected();
          }

          @Override
          protected void onNodeStateChanged(final CheckedTreeNode node) {
            myIsModified = true;
          }
        };

    myTree.setRootVisible(false);
    myTree.getEmptyText().setText(ToolsBundle.message("tools.not.configured"));
    myTree.setSelectionModel(new DefaultTreeSelectionModel());
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);

    setLayout(new BorderLayout());
    add(
        ToolbarDecorator.createDecorator(myTree)
            .setAddAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    ToolEditorDialog dlg = new ToolEditorDialog(ToolsPanel.this);
                    Tool tool = new Tool();
                    tool.setUseConsole(true);
                    tool.setFilesSynchronizedAfterRun(true);
                    tool.setShownInMainMenu(true);
                    tool.setShownInEditor(true);
                    tool.setShownInProjectViews(true);
                    tool.setShownInSearchResultsPopup(true);
                    tool.setEnabled(true);
                    dlg.setData(tool, getGroups());
                    dlg.show();
                    if (dlg.isOK()) {
                      insertNewTool(dlg.getData(), true);
                    }
                    myTree.requestFocus();
                  }
                })
            .setRemoveAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    removeSelected();
                  }
                })
            .setEditAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    editSelected();
                    myTree.requestFocus();
                  }
                })
            .setMoveUpAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    moveNode(Direction.UP);
                    myIsModified = true;
                  }
                })
            .setMoveDownAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    moveNode(Direction.DOWN);
                    myIsModified = true;
                  }
                })
            .addExtraAction(
                myCopyButton =
                    new AnActionButton(
                        ToolsBundle.message("tools.copy.button"), PlatformIcons.COPY_ICON) {
                      @Override
                      public void actionPerformed(AnActionEvent e) {
                        Tool originalTool = getSelectedTool();

                        if (originalTool != null) {
                          ToolEditorDialog dlg = new ToolEditorDialog(ToolsPanel.this);
                          Tool toolCopy = new Tool();
                          toolCopy.copyFrom(originalTool);
                          dlg.setData(toolCopy, getGroups());
                          dlg.show();
                          if (dlg.isOK()) {
                            insertNewTool(dlg.getData(), true);
                          }
                          myTree.requestFocus();
                        }
                      }
                    })
            .setButtonComparator("Add", "Copy", "Edit", "Remove", "Up", "Down")
            .createPanel(),
        BorderLayout.CENTER);

    myAddButton = ToolbarDecorator.findAddButton(this);
    myEditButton = ToolbarDecorator.findEditButton(this);
    myRemoveButton = ToolbarDecorator.findRemoveButton(this);
    myMoveUpButton = ToolbarDecorator.findUpButton(this);
    myMoveDownButton = ToolbarDecorator.findDownButton(this);

    // TODO check edit and delete

    myTree
        .getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              public void valueChanged(TreeSelectionEvent e) {
                update();
              }
            });
  }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
0
  public SeverityEditorDialog(
      final JComponent parent,
      final HighlightSeverity severity,
      final SeverityRegistrar severityRegistrar) {
    super(parent, true);
    mySeverityRegistrar = severityRegistrar;
    myOptionsList.setCellRenderer(
        new DefaultListCellRenderer() {
          @Override
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            final Component rendererComponent =
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value instanceof SeverityBasedTextAttributes) {
              setText(((SeverityBasedTextAttributes) value).getSeverity().toString());
            }
            return rendererComponent;
          }
        });
    myOptionsList.addListSelectionListener(
        new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent e) {
            if (myCurrentSelection != null) {
              apply(myCurrentSelection);
            }
            myCurrentSelection = (SeverityBasedTextAttributes) myOptionsList.getSelectedValue();
            if (myCurrentSelection != null) {
              reset(myCurrentSelection);
              myCard.show(
                  myRightPanel,
                  mySeverityRegistrar.isDefaultSeverity(myCurrentSelection.getSeverity())
                      ? DEFAULT
                      : EDITABLE);
            }
          }
        });
    myOptionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JPanel leftPanel =
        ToolbarDecorator.createDecorator(myOptionsList)
            .setAddAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    final String name =
                        Messages.showInputDialog(
                            myPanel,
                            InspectionsBundle.message(
                                "highlight.severity.create.dialog.name.label"),
                            InspectionsBundle.message("highlight.severity.create.dialog.title"),
                            Messages.getQuestionIcon(),
                            "",
                            new InputValidator() {
                              @Override
                              public boolean checkInput(final String inputString) {
                                final ListModel listModel = myOptionsList.getModel();
                                for (int i = 0; i < listModel.getSize(); i++) {
                                  final String severityName =
                                      ((SeverityBasedTextAttributes) listModel.getElementAt(i))
                                          .getSeverity()
                                          .myName;
                                  if (Comparing.strEqual(severityName, inputString)) return false;
                                }
                                return true;
                              }

                              @Override
                              public boolean canClose(final String inputString) {
                                return checkInput(inputString);
                              }
                            });
                    if (name == null) return;
                    final TextAttributes textAttributes =
                        CodeInsightColors.WARNINGS_ATTRIBUTES.getDefaultAttributes();
                    HighlightInfoType.HighlightInfoTypeImpl info =
                        new HighlightInfoType.HighlightInfoTypeImpl(
                            new HighlightSeverity(name, 50),
                            TextAttributesKey.createTextAttributesKey(name));

                    SeverityBasedTextAttributes newSeverityBasedTextAttributes =
                        new SeverityBasedTextAttributes(textAttributes.clone(), info);
                    ((DefaultListModel) myOptionsList.getModel())
                        .addElement(newSeverityBasedTextAttributes);

                    myOptionsList.clearSelection();
                    ListScrollingUtil.selectItem(myOptionsList, newSeverityBasedTextAttributes);
                  }
                })
            .setMoveUpAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    apply(myCurrentSelection);
                    ListUtil.moveSelectedItemsUp(myOptionsList);
                  }
                })
            .setMoveDownAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    apply(myCurrentSelection);
                    ListUtil.moveSelectedItemsDown(myOptionsList);
                  }
                })
            .createPanel();
    ToolbarDecorator.findRemoveButton(leftPanel)
        .addCustomUpdater(
            new AnActionButtonUpdater() {
              @Override
              public boolean isEnabled(AnActionEvent e) {
                return !mySeverityRegistrar.isDefaultSeverity(
                    ((SeverityBasedTextAttributes) myOptionsList.getSelectedValue()).getSeverity());
              }
            });
    ToolbarDecorator.findUpButton(leftPanel)
        .addCustomUpdater(
            new AnActionButtonUpdater() {
              @Override
              public boolean isEnabled(AnActionEvent e) {
                boolean canMove = ListUtil.canMoveSelectedItemsUp(myOptionsList);
                if (canMove) {
                  SeverityBasedTextAttributes pair =
                      (SeverityBasedTextAttributes) myOptionsList.getSelectedValue();
                  if (pair != null && mySeverityRegistrar.isDefaultSeverity(pair.getSeverity())) {
                    final int newPosition = myOptionsList.getSelectedIndex() - 1;
                    pair =
                        (SeverityBasedTextAttributes)
                            myOptionsList.getModel().getElementAt(newPosition);
                    if (mySeverityRegistrar.isDefaultSeverity(pair.getSeverity())) {
                      canMove = false;
                    }
                  }
                }

                return canMove;
              }
            });
    ToolbarDecorator.findDownButton(leftPanel)
        .addCustomUpdater(
            new AnActionButtonUpdater() {
              @Override
              public boolean isEnabled(AnActionEvent e) {
                boolean canMove = ListUtil.canMoveSelectedItemsDown(myOptionsList);
                if (canMove) {
                  SeverityBasedTextAttributes pair =
                      (SeverityBasedTextAttributes) myOptionsList.getSelectedValue();
                  if (pair != null && mySeverityRegistrar.isDefaultSeverity(pair.getSeverity())) {
                    final int newPosition = myOptionsList.getSelectedIndex() + 1;
                    pair =
                        (SeverityBasedTextAttributes)
                            myOptionsList.getModel().getElementAt(newPosition);
                    if (mySeverityRegistrar.isDefaultSeverity(pair.getSeverity())) {
                      canMove = false;
                    }
                  }
                }

                return canMove;
              }
            });

    myPanel = new JPanel(new BorderLayout());
    myPanel.add(leftPanel, BorderLayout.CENTER);
    myCard = new CardLayout();
    myRightPanel = new JPanel(myCard);
    final JPanel disabled = new JPanel(new GridBagLayout());
    final JButton button =
        new JButton(InspectionsBundle.message("severities.default.settings.message"));
    button.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            editColorsAndFonts();
          }
        });
    disabled.add(
        button,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));
    myRightPanel.add(DEFAULT, disabled);
    myRightPanel.add(EDITABLE, myOptionsPanel);
    myCard.show(myRightPanel, EDITABLE);
    myPanel.add(myRightPanel, BorderLayout.EAST);
    fillList(severity);
    init();
    setTitle(InspectionsBundle.message("severities.editor.dialog.title"));
    reset((SeverityBasedTextAttributes) myOptionsList.getSelectedValue());
  }