@Override
 protected JComponent createTreePanel(final WatchDebuggerTree tree) {
   final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(tree);
   decorator.setAddAction(
       new AnActionButtonRunnable() {
         @Override
         public void run(AnActionButton button) {
           executeAction(DebuggerActions.NEW_WATCH, tree);
         }
       });
   // TODO[den]: add "Add to watches action" on Mac
   if (!SystemInfo.isMac) {
     decorator.addExtraAction(
         AnActionButton.fromAction(
             ActionManager.getInstance().getAction(XDebuggerActions.ADD_TO_WATCH)));
   }
   decorator.setRemoveAction(
       new AnActionButtonRunnable() {
         @Override
         public void run(AnActionButton button) {
           executeAction(DebuggerActions.REMOVE_WATCH, tree);
         }
       });
   CustomLineBorder border =
       new CustomLineBorder(
           CaptionPanel.CNT_ACTIVE_BORDER_COLOR,
           SystemInfo.isMac ? 1 : 0,
           0,
           SystemInfo.isMac ? 0 : 1,
           0);
   decorator.setToolbarBorder(border);
   final JPanel panel = decorator.createPanel();
   panel.setBorder(null);
   return panel;
 }
  public InjectionsSettingsUI(final Project project, final Configuration configuration) {
    myProject = project;
    myConfiguration = configuration;

    final CfgInfo currentInfo = new CfgInfo(configuration, "Project");
    myInfos =
        configuration instanceof Configuration.Prj
            ? new CfgInfo[] {
              new CfgInfo(((Configuration.Prj) configuration).getParentConfiguration(), "IDE"),
              currentInfo
            }
            : new CfgInfo[] {currentInfo};

    myRoot = new JPanel(new BorderLayout());

    myInjectionsTable = new InjectionsTable(getInjInfoList(myInfos));
    myInjectionsTable.getEmptyText().setText("No injections configured");

    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myInjectionsTable);
    createActions(decorator);

    // myRoot.add(new TitledSeparator("Languages injection places"), BorderLayout.NORTH);
    myRoot.add(decorator.createPanel(), BorderLayout.CENTER);
    myCountLabel = new JLabel();
    myCountLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    myCountLabel.setForeground(SimpleTextAttributes.GRAY_ITALIC_ATTRIBUTES.getFgColor());
    myRoot.add(myCountLabel, BorderLayout.SOUTH);
    updateCountLabel();
  }
  public JComponent createComponent() {
    myList = new JBList(getListModel());
    myList.setCellRenderer(createListCellRenderer(myList));

    ToolbarDecorator toolbarDecorator =
        ToolbarDecorator.createDecorator(myList)
            .disableUpDownActions()
            .setAddAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    final VirtualFile[] added = doAdd();
                    if (added.length > 0) {
                      setModified(true);
                    }
                    requestDefaultFocus();
                    setSelectedRoots(added);
                  }
                })
            .setRemoveAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    int[] idxs = myList.getSelectedIndices();
                    doRemoveItems(idxs, myList);
                  }
                })
            .setAddActionUpdater(
                new AnActionButtonUpdater() {
                  @Override
                  public boolean isEnabled(AnActionEvent e) {
                    return myEnabled;
                  }
                })
            .setRemoveActionUpdater(
                new AnActionButtonUpdater() {
                  @Override
                  public boolean isEnabled(AnActionEvent e) {
                    Object[] values = getSelectedRoots();
                    return values.length > 0 && myEnabled;
                  }
                });

    addToolbarButtons(toolbarDecorator);

    myPanel = toolbarDecorator.createPanel();
    myPanel.setBorder(null);

    return myPanel;
  }
  @Nullable
  @Override
  protected JComponent createCenterPanel() {
    mySdkList = new JBList();
    //noinspection unchecked
    mySdkList.setCellRenderer(new PySdkListCellRenderer("", myModificators));
    mySdkList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    ToolbarDecorator decorator =
        ToolbarDecorator.createDecorator(mySdkList)
            .disableUpDownActions()
            .setAddAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    addSdk(button);
                    updateOkButton();
                  }
                })
            .setEditAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    editSdk();
                    updateOkButton();
                  }
                })
            .setRemoveAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    removeSdk();
                    updateOkButton();
                  }
                })
            .addExtraAction(new ToggleVirtualEnvFilterButton())
            .addExtraAction(new ShowPathButton());

    decorator.setPreferredSize(new Dimension(600, 500));
    myMainPanel = decorator.createPanel();
    refreshSdkList();
    addListeners();
    return myMainPanel;
  }
  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;
  }
  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;
  }
  BeforeRunStepsPanel(StepsBeforeRunListener listener) {
    myListener = listener;
    myModel = new CollectionListModel<BeforeRunTask>();
    myList = new JBList(myModel);
    myList.getEmptyText().setText(ExecutionBundle.message("before.launch.panel.empty"));
    myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myList.setCellRenderer(new MyListCellRenderer());

    myModel.addListDataListener(
        new ListDataListener() {
          @Override
          public void intervalAdded(ListDataEvent e) {
            adjustVisibleRowCount();
            updateText();
          }

          @Override
          public void intervalRemoved(ListDataEvent e) {
            adjustVisibleRowCount();
            updateText();
          }

          @Override
          public void contentsChanged(ListDataEvent e) {}

          private void adjustVisibleRowCount() {
            myList.setVisibleRowCount(Math.max(4, Math.min(8, myModel.getSize())));
          }
        });

    ToolbarDecorator myDecorator = ToolbarDecorator.createDecorator(myList);
    if (!SystemInfo.isMac) {
      myDecorator.setAsUsualTopToolbar();
    }
    myDecorator.setEditAction(
        new AnActionButtonRunnable() {
          @Override
          public void run(AnActionButton button) {
            int index = myList.getSelectedIndex();
            if (index == -1) return;
            Pair<BeforeRunTask, BeforeRunTaskProvider<BeforeRunTask>> selection = getSelection();
            if (selection == null) return;
            BeforeRunTask task = selection.getFirst();
            BeforeRunTaskProvider<BeforeRunTask> provider = selection.getSecond();
            if (provider.configureTask(myRunConfiguration, task)) {
              myModel.setElementAt(task, index);
            }
          }
        });
    myDecorator.setEditActionUpdater(
        new AnActionButtonUpdater() {
          @Override
          public boolean isEnabled(AnActionEvent e) {
            Pair<BeforeRunTask, BeforeRunTaskProvider<BeforeRunTask>> selection = getSelection();
            return selection != null && selection.getSecond().isConfigurable();
          }
        });
    myDecorator.setAddAction(
        new AnActionButtonRunnable() {
          @Override
          public void run(AnActionButton button) {
            doAddAction(button);
          }
        });
    myDecorator.setAddActionUpdater(
        new AnActionButtonUpdater() {
          @Override
          public boolean isEnabled(AnActionEvent e) {
            return checkBeforeRunTasksAbility(true);
          }
        });

    myShowSettingsBeforeRunCheckBox =
        new JCheckBox(ExecutionBundle.message("configuration.edit.before.run"));
    myShowSettingsBeforeRunCheckBox.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            updateText();
          }
        });

    myPanel = myDecorator.createPanel();

    setLayout(new BorderLayout());
    add(myPanel, BorderLayout.CENTER);
    add(myShowSettingsBeforeRunCheckBox, BorderLayout.SOUTH);
  }
  public CreateXmlResourceDialog(
      @NotNull Module module,
      @NotNull ResourceType resourceType,
      @Nullable String predefinedName,
      @Nullable String predefinedValue,
      boolean chooseName,
      @Nullable VirtualFile defaultFile) {
    super(module.getProject());
    myResourceType = resourceType;

    if (predefinedName != null && predefinedName.length() > 0) {
      if (!chooseName) {
        myNameLabel.setVisible(false);
        myNameField.setVisible(false);
      }
      myNameField.setText(predefinedName);
    }

    if (predefinedValue != null && predefinedValue.length() > 0) {
      myValueLabel.setVisible(false);
      myValueField.setVisible(false);
      myValueField.setText(predefinedValue);
    }
    final Set<Module> modulesSet = new HashSet<Module>();
    modulesSet.add(module);

    for (AndroidFacet depFacet : AndroidUtils.getAllAndroidDependencies(module, true)) {
      modulesSet.add(depFacet.getModule());
    }

    assert modulesSet.size() > 0;

    if (modulesSet.size() == 1) {
      myModule = module;
      myModuleLabel.setVisible(false);
      myModuleCombo.setVisible(false);
    } else {
      myModule = null;

      final Module[] modules = modulesSet.toArray(new Module[modulesSet.size()]);
      Arrays.sort(
          modules,
          new Comparator<Module>() {
            @Override
            public int compare(Module m1, Module m2) {
              return m1.getName().compareTo(m2.getName());
            }
          });

      myModuleCombo.setModel(new DefaultComboBoxModel(modules));
      myModuleCombo.setSelectedItem(module);
      myModuleCombo.setRenderer(new ModuleListCellRendererWrapper(myModuleCombo.getRenderer()));
    }

    if (defaultFile == null) {
      final String defaultFileName = AndroidResourceUtil.getDefaultResourceFileName(resourceType);

      if (defaultFileName != null) {
        myFileNameCombo.getEditor().setItem(defaultFileName);
      }
    }
    myDirectoriesList = new CheckBoxList();
    myDirectoriesLabel.setLabelFor(myDirectoriesList);
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myDirectoriesList);

    decorator.setEditAction(null);
    decorator.disableUpDownActions();

    decorator.setAddAction(
        new AnActionButtonRunnable() {
          @Override
          public void run(AnActionButton button) {
            doAddNewDirectory();
          }
        });

    decorator.setRemoveAction(
        new AnActionButtonRunnable() {
          @Override
          public void run(AnActionButton button) {
            doDeleteDirectory();
          }
        });

    final AnActionButton selectAll =
        new AnActionButton("Select All", null, PlatformIcons.SELECT_ALL_ICON) {
          @Override
          public void actionPerformed(AnActionEvent e) {
            doSelectAllDirs();
          }
        };
    decorator.addExtraAction(selectAll);

    final AnActionButton unselectAll =
        new AnActionButton("Unselect All", null, PlatformIcons.UNSELECT_ALL_ICON) {
          @Override
          public void actionPerformed(AnActionEvent e) {
            doUnselectAllDirs();
          }
        };
    decorator.addExtraAction(unselectAll);

    myDirectoriesPanel.add(decorator.createPanel());

    updateDirectories(true);

    myModuleCombo.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            updateDirectories(true);
          }
        });
    final JCheckBox valuesCheckBox = myCheckBoxes.get(SdkConstants.FD_RES_VALUES);
    if (valuesCheckBox != null) {
      valuesCheckBox.setSelected(true);
    }

    if (defaultFile != null) {
      resetFromFile(defaultFile, module.getProject());
    }
    init();
  }
  private JComponent createMasterView() {
    myTreeController = new BreakpointItemsTreeController(myRulesEnabled);
    JTree tree = new BreakpointsCheckboxTree(myProject, myTreeController);

    new AnAction("BreakpointDialog.GoToSource") {
      @Override
      public void actionPerformed(AnActionEvent e) {
        navigate();
        close(OK_EXIT_CODE);
      }
    }.registerCustomShortcutSet(
        new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)), tree);

    new AnAction("BreakpointDialog.ShowSource") {
      @Override
      public void actionPerformed(AnActionEvent e) {
        navigate();
      }
    }.registerCustomShortcutSet(
        ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE).getShortcutSet(),
        tree);

    tree.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent event) {
            if (event.getClickCount() == 2
                && UIUtil.isActionClick(event, MouseEvent.MOUSE_CLICKED)
                && !UIUtil.isSelectionButtonDown(event)
                && !event.isConsumed()) {
              navigate();
              close(OK_EXIT_CODE);
            }
          }
        });

    final DefaultActionGroup breakpointTypes = new DefaultActionGroup();
    for (BreakpointPanelProvider provider : myBreakpointsPanelProviders) {
      breakpointTypes.addAll(provider.getAddBreakpointActions(myProject));
    }

    ToolbarDecorator decorator =
        ToolbarDecorator.createDecorator(tree)
            .setAddAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    JBPopupFactory.getInstance()
                        .createActionGroupPopup(
                            null,
                            breakpointTypes,
                            DataManager.getInstance().getDataContext(button.getContextComponent()),
                            JBPopupFactory.ActionSelectionAid.NUMBERING,
                            false)
                        .show(button.getPreferredPopupPoint());
                  }
                })
            .setRemoveAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    myTreeController.removeSelectedBreakpoints(myProject);
                  }
                })
            .setRemoveActionUpdater(
                new AnActionButtonUpdater() {
                  @Override
                  public boolean isEnabled(AnActionEvent e) {
                    boolean enabled = false;
                    final ItemWrapper[] items = myMasterController.getSelectedItems();
                    for (ItemWrapper item : items) {
                      if (item.allowedToRemove()) {
                        enabled = true;
                      }
                    }
                    return enabled;
                  }
                });

    for (ToggleActionButton action : myToggleRuleActions) {
      decorator.addExtraAction(action);
    }

    JPanel decoratedTree = decorator.createPanel();
    myTreeController.setTreeView(tree);

    myDetailController.setTree(tree);

    myTreeController.buildTree(myBreakpointItems);

    initSelection(myBreakpointItems);

    final BreakpointPanelProvider.BreakpointsListener listener =
        new BreakpointPanelProvider.BreakpointsListener() {
          @Override
          public void breakpointsChanged() {
            collectItems();
            myTreeController.rebuildTree(myBreakpointItems);
          }
        };

    for (BreakpointPanelProvider provider : myBreakpointsPanelProviders) {
      provider.addListener(listener, myProject, myListenerDisposable);
    }

    return decoratedTree;
  }