public LibraryBundlingEditorComponent(@NotNull Project project) {
    myProject = project;
    GuiUtils.replaceJSplitPaneWithIDEASplitter(myMainPanel);
    ((JBSplitter) myMainPanel.getComponent(0)).setProportion(0.4f);

    myRulesPanel.add(
        ToolbarDecorator.createDecorator(myRulesList)
            .setAddAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    updateCurrentRule();
                    myRulesModel.add(new LibraryBundlificationRule());
                    myRulesList.setSelectedIndex(myRulesModel.getSize() - 1);
                    updateFields();
                  }
                })
            .setRemoveAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    myLastSelected = -1;
                    if (myRulesModel.getSize() == 1) {
                      myRulesModel.setElementAt(new LibraryBundlificationRule(), 0);
                      myRulesList.setSelectedIndex(0);
                    } else {
                      int index = myRulesList.getSelectedIndex();
                      myRulesModel.remove(index);
                      myRulesList.setSelectedIndex(index > 0 ? index - 1 : 0);
                    }
                    updateFields();
                  }
                })
            .setMoveUpAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    updateCurrentRule();
                    myLastSelected = -1;
                    ListUtil.moveSelectedItemsUp(myRulesList);
                    updateFields();
                  }
                })
            .setMoveDownAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    updateCurrentRule();
                    myLastSelected = -1;
                    ListUtil.moveSelectedItemsDown(myRulesList);
                    updateFields();
                  }
                })
            .addExtraAction(
                new AnActionButton("Copy", PlatformIcons.COPY_ICON) {
                  @Override
                  public void actionPerformed(AnActionEvent e) {
                    updateCurrentRule();
                    int index = myRulesList.getSelectedIndex();
                    if (index >= 0) {
                      myRulesModel.add(myRulesModel.getElementAt(index).copy());
                      myRulesList.setSelectedIndex(myRulesModel.getSize() - 1);
                      updateFields();
                    }
                  }

                  @Override
                  public boolean isEnabled() {
                    return myRulesList.getSelectedIndex() >= 0;
                  }
                })
            .createPanel(),
        BorderLayout.CENTER);

    myRulesModel = new CollectionListModel<>();
    //noinspection unchecked
    myRulesList.setModel(myRulesModel);
    myRulesList.addListSelectionListener(
        new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent e) {
            updateCurrentRule();
            updateFields();
          }
        });
  }
Ejemplo n.º 2
0
  protected void reInitWholePanelIfNeeded() {
    if (!myToReInitWholePanel) return;

    myWholePanel =
        new JPanel(new BorderLayout()) {
          public void addNotify() {
            super.addNotify();
            MasterDetailsComponent.this.addNotify();

            TreeModel m = myTree.getModel();
            if (m instanceof DefaultTreeModel) {
              DefaultTreeModel model = (DefaultTreeModel) m;
              for (int eachRow = 0; eachRow < myTree.getRowCount(); eachRow++) {
                TreePath eachPath = myTree.getPathForRow(eachRow);
                Object component = eachPath.getLastPathComponent();
                if (component instanceof TreeNode) {
                  model.nodeChanged((TreeNode) component);
                }
              }
            }
          }
        };
    mySplitter.setHonorComponentsMinimumSize(true);
    myWholePanel.add(mySplitter, BorderLayout.CENTER);

    JPanel left =
        new JPanel(new BorderLayout()) {
          public Dimension getMinimumSize() {
            final Dimension original = super.getMinimumSize();
            return new Dimension(Math.max(original.width, 100), original.height);
          }
        };

    if (isNewProjectSettings()) {
      ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTree);
      DefaultActionGroup group = createToolbarActionGroup();
      if (group != null) {
        decorator.setActionGroup(group);
      }
      // left.add(myNorthPanel, BorderLayout.NORTH);
      myMaster =
          decorator.setAsUsualTopToolbar().setPanelBorder(JBUI.Borders.empty()).createPanel();
      myNorthPanel.setVisible(false);
    } else {
      left.add(myNorthPanel, BorderLayout.NORTH);
      myMaster = ScrollPaneFactory.createScrollPane(myTree);
    }
    left.add(myMaster, BorderLayout.CENTER);
    mySplitter.setFirstComponent(left);

    final JPanel right = new JPanel(new BorderLayout());
    right.add(myDetails.getComponent(), BorderLayout.CENTER);
    if (!isNewProjectSettings()) {
      myWholePanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    }

    mySplitter.setSecondComponent(right);

    GuiUtils.replaceJSplitPaneWithIDEASplitter(myWholePanel);

    myToReInitWholePanel = false;
  }