void update() {
   for (int i = 0; i < getComponentCount(); ++i) {
     Component component = getComponent(i);
     if (component instanceof JButton) {
       final JButton button = (JButton) component;
       button.setEnabled(!isSearchInProgress());
     }
   }
 }
Exemple #2
0
 private void moveMousePointerOnButton(final JButton button) {
   Application application = ApplicationManager.getApplication();
   if (application != null && application.hasComponent(UISettings.class)) {
     if (button != null && UISettings.getInstance().MOVE_MOUSE_ON_DEFAULT_BUTTON) {
       Point p = button.getLocationOnScreen();
       Rectangle r = button.getBounds();
       try {
         Robot robot = new Robot();
         robot.mouseMove(p.x + r.width / 2, p.y + r.height / 2);
       } catch (AWTException e) {
         LOG.warn(e);
       }
     }
   }
 }
 private void updateComponents() {
   boolean archetypesEnabled = myUseArchetypeCheckBox.isSelected();
   myAddArchetypeButton.setEnabled(archetypesEnabled);
   myArchetypesTree.setEnabled(archetypesEnabled);
   myArchetypesTree.setBackground(
       archetypesEnabled ? UIUtil.getListBackground() : UIUtil.getPanelBackground());
 }
  private JComponent createActionsPanel() {
    final JButton include = new JButton(IdeBundle.message("button.include"));
    final JButton includeRec = new JButton(IdeBundle.message("button.include.recursively"));
    final JButton exclude = new JButton(IdeBundle.message("button.exclude"));
    final JButton excludeRec = new JButton(IdeBundle.message("button.exclude.recursively"));
    myPackageTree
        .getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              @Override
              public void valueChanged(TreeSelectionEvent e) {
                final boolean recursiveEnabled = isButtonEnabled(true, e.getPaths(), e);
                includeRec.setEnabled(recursiveEnabled);
                excludeRec.setEnabled(recursiveEnabled);

                final boolean nonRecursiveEnabled = isButtonEnabled(false, e.getPaths(), e);
                include.setEnabled(nonRecursiveEnabled);
                exclude.setEnabled(nonRecursiveEnabled);
              }
            });

    JPanel buttonsPanel = new JPanel(new VerticalFlowLayout());
    buttonsPanel.add(include);
    buttonsPanel.add(includeRec);
    buttonsPanel.add(exclude);
    buttonsPanel.add(excludeRec);

    include.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            includeSelected(false);
          }
        });
    includeRec.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            includeSelected(true);
          }
        });
    exclude.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            excludeSelected(false);
          }
        });
    excludeRec.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            excludeSelected(true);
          }
        });

    return buttonsPanel;
  }
    public void addButtonRunnable(int index, final Runnable runnable, String text) {
      if (getBorder() == null) setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));

      final JButton button = new JButton(UIUtil.replaceMnemonicAmpersand(text));
      DialogUtil.registerMnemonic(button);

      button.setFocusable(false);
      button.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              runnable.run();
            }
          });

      add(button, index);

      invalidate();
      if (getParent() != null) {
        getParent().validate();
      }
    }
  public MavenArchetypesStep(MavenModuleBuilder builder, @Nullable StepAdapter step) {
    myBuilder = builder;
    myStep = step;
    Disposer.register(this, myLoadingIcon);

    myArchetypesTree = new Tree();
    myArchetypesTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode()));
    JScrollPane archetypesScrollPane = ScrollPaneFactory.createScrollPane(myArchetypesTree);

    myArchetypesPanel.add(archetypesScrollPane, "archetypes");

    JPanel loadingPanel = new JPanel(new GridBagLayout());
    JPanel bp = new JPanel(new BorderLayout(10, 10));
    bp.add(new JLabel("Loading archetype list..."), BorderLayout.NORTH);
    bp.add(myLoadingIcon, BorderLayout.CENTER);

    loadingPanel.add(bp, new GridBagConstraints());

    myArchetypesPanel.add(ScrollPaneFactory.createScrollPane(loadingPanel), "loading");
    ((CardLayout) myArchetypesPanel.getLayout()).show(myArchetypesPanel, "archetypes");

    myUseArchetypeCheckBox.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            updateComponents();
            archetypeMayBeChanged();
          }
        });

    myAddArchetypeButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            doAddArchetype();
          }
        });

    myArchetypesTree.setRootVisible(false);
    myArchetypesTree.setShowsRootHandles(true);
    myArchetypesTree.setCellRenderer(new MyRenderer());
    myArchetypesTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    myArchetypesTree
        .getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              public void valueChanged(TreeSelectionEvent e) {
                updateArchetypeDescription();
                archetypeMayBeChanged();
              }
            });

    new TreeSpeedSearch(
            myArchetypesTree,
            new Convertor<TreePath, String>() {
              public String convert(TreePath path) {
                MavenArchetype info =
                    getArchetypeInfoFromPathComponent(path.getLastPathComponent());
                return info.groupId + ":" + info.artifactId + ":" + info.version;
              }
            })
        .setComparator(new SpeedSearchComparator(false));

    myArchetypeDescriptionField.setEditable(false);
    myArchetypeDescriptionField.setBackground(UIUtil.getPanelBackground());

    requestUpdate();
    updateComponents();
  }
Exemple #7
0
  private void initReplaceToolBars() {
    DefaultActionGroup actionGroup1 = new DefaultActionGroup("replace bar 1", false);
    myReplaceActionsToolbar1 =
        (ActionToolbarImpl)
            ActionManager.getInstance()
                .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup1, true);
    myReplaceActionsToolbar1.setForceMinimumSize(true);
    final JButton myReplaceButton = new JButton("Replace");
    myReplaceButton.setFocusable(false);
    myReplaceButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent actionEvent) {
            replaceCurrent();
          }
        });

    final JButton myReplaceAllButton = new JButton("Replace all");
    myReplaceAllButton.setFocusable(false);
    myReplaceAllButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent actionEvent) {
            myLivePreviewController.performReplaceAll();
          }
        });

    final JButton myExcludeButton = new JButton("");
    myExcludeButton.setFocusable(false);
    myExcludeButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent actionEvent) {
            myLivePreviewController.exclude();
            moveCursor(SearchResults.Direction.DOWN);
          }
        });

    if (!UISettings.getInstance().DISABLE_MNEMONICS_IN_CONTROLS) {
      myReplaceButton.setMnemonic('p');
      myReplaceAllButton.setMnemonic('a');
      myExcludeButton.setMnemonic('l');
    }

    actionGroup1.addAction(
        new DefaultCustomComponentAction(myReplaceButton) {
          @Override
          public void update(AnActionEvent e) {
            myReplaceButton.setEnabled(canReplaceCurrent());
          }
        });
    actionGroup1.addAction(
        new DefaultCustomComponentAction(myReplaceAllButton) {
          @Override
          public void update(AnActionEvent e) {
            myReplaceAllButton.setEnabled(mySearchResults != null && mySearchResults.hasMatches());
          }
        });
    actionGroup1.addAction(
        new DefaultCustomComponentAction(myExcludeButton) {
          @Override
          public void update(AnActionEvent e) {
            FindResult cursor = mySearchResults != null ? mySearchResults.getCursor() : null;
            myExcludeButton.setEnabled(cursor != null);
            myExcludeButton.setText(
                cursor != null && mySearchResults.isExcluded(cursor) ? "Include" : "Exclude");
          }
        });

    myReplaceActionsToolbar1.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY);
    myReplaceActionsToolbar1.setBorder(null);
    myReplaceActionsToolbar1.setOpaque(false);
    DefaultActionGroup actionGroup2 = new DefaultActionGroup("replace bar 2", false);
    myReplaceActionsToolbar2 =
        (ActionToolbarImpl)
            ActionManager.getInstance()
                .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup2, true);
    actionGroup2.addAction(new TogglePreserveCaseAction(this));
    actionGroup2.addAction(new ToggleSelectionOnlyAction(this));
    myReplaceActionsToolbar2.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY);
    myReplaceActionsToolbar2.setBorder(null);
    myReplaceActionsToolbar2.setOpaque(false);
    Utils.setSmallerFontForChildren(myReplaceActionsToolbar1);
    Utils.setSmallerFontForChildren(myReplaceActionsToolbar2);
  }
  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());
  }
  @SuppressWarnings("unchecked")
  private void createUIComponents() {
    final JBList projectExistLocalesList = new JBList();
    final MyExistLocalesListModel existLocalesListModel = new MyExistLocalesListModel();
    projectExistLocalesList.setModel(existLocalesListModel);
    projectExistLocalesList.setCellRenderer(getLocaleRenderer());
    myProjectExistLocalesPanel =
        ToolbarDecorator.createDecorator(projectExistLocalesList)
            .disableRemoveAction()
            .disableUpDownActions()
            .createPanel();
    myProjectExistLocalesPanel.setBorder(
        IdeBorderFactory.createTitledBorder("Project locales", false));

    final JBList localesToAddList = new JBList();

    final List<Locale> locales;
    final List<Locale> restrictedLocales;
    if (myResourceBundle == null) {
      locales = Collections.singletonList(PropertiesUtil.DEFAULT_LOCALE);
      restrictedLocales = Collections.emptyList();
    } else {
      locales = Collections.emptyList();
      restrictedLocales =
          ContainerUtil.map(myResourceBundle.getPropertiesFiles(), PropertiesFile::getLocale);
    }
    myLocalesModel =
        new CollectionListModel<Locale>(locales) {
          @Override
          public void add(@NotNull List<? extends Locale> elements) {
            final List<Locale> currentItems = getItems();
            elements =
                ContainerUtil.filter(
                    elements,
                    locale ->
                        !restrictedLocales.contains(locale) && !currentItems.contains(locale));
            super.add(elements);
          }
        };
    localesToAddList.setModel(myLocalesModel);
    localesToAddList.setCellRenderer(getLocaleRenderer());
    localesToAddList.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(FocusEvent e) {
            projectExistLocalesList.clearSelection();
          }
        });
    projectExistLocalesList.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(FocusEvent e) {
            localesToAddList.clearSelection();
          }
        });

    myNewBundleLocalesPanel =
        ToolbarDecorator.createDecorator(localesToAddList)
            .setAddAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    final String rawAddedLocales =
                        Messages.showInputDialog(
                            myProject,
                            PropertiesBundle.message(
                                "create.resource.bundle.dialog.add.locales.validator.message"),
                            PropertiesBundle.message(
                                "create.resource.bundle.dialog.add.locales.validator.title"),
                            null,
                            null,
                            new InputValidatorEx() {
                              @Nullable
                              @Override
                              public String getErrorText(String inputString) {
                                return checkInput(inputString) ? null : "Invalid locales";
                              }

                              @Override
                              public boolean checkInput(String inputString) {
                                return extractLocalesFromString(inputString) != null;
                              }

                              @Override
                              public boolean canClose(String inputString) {
                                return checkInput(inputString);
                              }
                            });
                    if (rawAddedLocales != null) {
                      final List<Locale> locales = extractLocalesFromString(rawAddedLocales);
                      LOG.assertTrue(locales != null);
                      myLocalesModel.add(locales);
                    }
                  }
                })
            .setAddActionName("Add locales by suffix")
            .disableUpDownActions()
            .createPanel();
    myNewBundleLocalesPanel.setBorder(IdeBorderFactory.createTitledBorder("Locales to add", false));

    myAddLocaleFromExistButton = new JButton(AllIcons.Actions.Forward);
    new ClickListener() {
      @Override
      public boolean onClick(@NotNull MouseEvent event, int clickCount) {
        if (clickCount == 1) {
          myLocalesModel.add(
              ContainerUtil.map(projectExistLocalesList.getSelectedValues(), o -> (Locale) o));
          return true;
        }
        return false;
      }
    }.installOn(myAddLocaleFromExistButton);

    projectExistLocalesList.addListSelectionListener(
        new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent e) {
            final List<Locale> currentItems = myLocalesModel.getItems();
            for (Object o : projectExistLocalesList.getSelectedValues()) {
              Locale l = (Locale) o;
              if (!restrictedLocales.contains(l) && !currentItems.contains(l)) {
                myAddLocaleFromExistButton.setEnabled(true);
                return;
              }
            }
            myAddLocaleFromExistButton.setEnabled(false);
          }
        });
    myAddLocaleFromExistButton.setEnabled(false);

    myAddAllButton = new JButton("Add All");
    new ClickListener() {
      @Override
      public boolean onClick(@NotNull MouseEvent event, int clickCount) {
        if (clickCount == 1) {
          myLocalesModel.add(existLocalesListModel.getLocales());
        }
        return false;
      }
    }.installOn(myAddAllButton);
  }