void update(String group) { myTitleLabel.setText( "<html><body><h2 style=\"text-align:left;\">" + group + "</h2></body></html>"); myContentPanel.removeAll(); List<IdSet> idSets = PluginGroups.getInstance().getSets(group); for (final IdSet set : idSets) { final JCheckBox checkBox = new JCheckBox(set.getTitle(), PluginGroups.getInstance().isIdSetAllEnabled(set)); checkBox.setModel( new JToggleButton.ToggleButtonModel() { @Override public boolean isSelected() { return PluginGroups.getInstance().isIdSetAllEnabled(set); } }); checkBox.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PluginGroups.getInstance().setIdSetEnabled(set, !checkBox.isSelected()); CustomizePluginsStepPanel.this.repaint(); } }); myContentPanel.add(checkBox); } }
private boolean isGroupEnabled(String group) { List<IdSet> sets = PluginGroups.getInstance().getSets(group); for (IdSet idSet : sets) { String[] ids = idSet.getIds(); for (String id : ids) { if (PluginGroups.getInstance().isPluginEnabled(id)) return true; } } return false; }
@Override public void linkSelected(LinkLabel linkLabel, String command) { if (command == null || !command.contains(":")) return; int semicolonPosition = command.indexOf(":"); String group = command.substring(semicolonPosition + 1); command = command.substring(0, semicolonPosition); if (SWITCH_COMMAND.equals(command)) { boolean enabled = isGroupEnabled(group); List<IdSet> sets = PluginGroups.getInstance().getSets(group); for (IdSet idSet : sets) { String[] ids = idSet.getIds(); for (String id : ids) { PluginGroups.getInstance().setPluginEnabledWithDependencies(id, !enabled); } } repaint(); return; } if (CUSTOMIZE_COMMAND.equals(command)) { myCustomizePanel.update(group); myCardLayout.show(this, CUSTOMIZE); } }
public CustomizePluginsStepPanel() { myCardLayout = new JBCardLayout(); setLayout(myCardLayout); JPanel gridPanel = new JPanel(new GridLayout(0, COLS)); myCustomizePanel = new IdSetPanel(); JBScrollPane scrollPane = new JBScrollPane( gridPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.getVerticalScrollBar().setUnitIncrement(10); add(scrollPane, MAIN); add(myCustomizePanel, CUSTOMIZE); // PluginManager.loadDisabledPlugins(new File(PathManager.getConfigPath()).getPath(), // myDisabledPluginIds); // for (IdeaPluginDescriptor pluginDescriptor : myAllPlugins) { // if (pluginDescriptor.getPluginId().getIdString().equals("com.intellij")) { //// skip 'IDEA CORE' plugin // continue; // } // //PluginManager.initClassLoader(PluginGroups.class.getClassLoader(), // (IdeaPluginDescriptorImpl)pluginDescriptor); // } Map<String, List<String>> groups = PluginGroups.getInstance().getTree(); for (Map.Entry<String, List<String>> entry : groups.entrySet()) { final String group = entry.getKey(); if (PluginGroups.CORE.equals(group)) continue; JPanel groupPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 10, 0); gbc.fill = GridBagConstraints.BOTH; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.weightx = 1; JLabel titleLabel = new JLabel( "<html><body><h2 style=\"text-align:left;\">" + group + "</h2></body></html>") { @Override public boolean isEnabled() { return isGroupEnabled(group); } }; groupPanel.add(titleLabel, gbc); JLabel descriptionLabel = new JLabel(PluginGroups.getInstance().getDescription(group)) { @Override public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); size.width = Math.min(size.width, 200); return size; } @Override public boolean isEnabled() { return isGroupEnabled(group); } @Override public Color getForeground() { return ColorUtil.withAlpha(UIManager.getColor("Label.foreground"), .75); } }; groupPanel.add(descriptionLabel, gbc); gbc.weighty = 1; groupPanel.add(Box.createVerticalGlue(), gbc); gbc.weighty = 0; if (PluginGroups.getInstance().getSets(group).size() == 1) { groupPanel.add( createLink(SWITCH_COMMAND + ":" + group, getGroupSwitchTextProvider(group)), gbc); } else { JPanel buttonsPanel = new JPanel(new GridLayout(1, 2, 10, 5)); LinkLabel customizeButton = createLink(CUSTOMIZE_COMMAND + ":" + group, CUSTOMIZE_TEXT_PROVIDER); buttonsPanel.add(customizeButton); LinkLabel disableAllButton = createLink(SWITCH_COMMAND + ":" + group, getGroupSwitchTextProvider(group)); buttonsPanel.add(disableAllButton); groupPanel.add(buttonsPanel, gbc); } gridPanel.add(groupPanel); } int cursor = 0; Component[] components = gridPanel.getComponents(); int rowCount = components.length / COLS; for (Component component : components) { ((JComponent) component) .setBorder( new CompoundBorder( new CustomLineBorder( ColorUtil.withAlpha(JBColor.foreground(), .2), 0, 0, cursor / 3 < rowCount - 1 ? 1 : 0, cursor % COLS != COLS - 1 ? 1 : 0) { @Override protected Color getColor() { return ColorUtil.withAlpha(JBColor.foreground(), .2); } }, BorderFactory.createEmptyBorder(GAP, GAP, GAP, GAP))); cursor++; } }