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; }
@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; }
@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; }
@Override protected void addToolbarButtons(ToolbarDecorator toolbarDecorator) { toolbarDecorator.setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final VirtualFile[] added = doAddItems(); if (added.length > 0) { setModified(true); } requestDefaultFocus(); setSelectedRoots(added); } }); }
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; }
@NotNull protected List<Pair<String, JPanel>> createAdditionalPanels() { // this method is invoked before constructor body myExceptionsModel = new ExceptionsTableModel(myMethod.getMethod().getThrowsList()); myExceptionsModel.setTypeInfos(myMethod.getMethod()); final JBTable table = new JBTable(myExceptionsModel); table.setStriped(true); table.setRowHeight(20); table .getColumnModel() .getColumn(0) .setCellRenderer(new CodeFragmentTableCellRenderer(myProject)); final JavaCodeFragmentTableCellEditor cellEditor = new JavaCodeFragmentTableCellEditor(myProject); cellEditor.addDocumentListener( new DocumentAdapter() { @Override public void documentChanged(DocumentEvent e) { final int row = table.getSelectedRow(); final int col = table.getSelectedColumn(); myExceptionsModel.setValueAt(cellEditor.getCellEditorValue(), row, col); updateSignature(); } }); table.getColumnModel().getColumn(0).setCellEditor(cellEditor); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().setSelectionInterval(0, 0); table.setSurrendersFocusOnKeystroke(true); myPropExceptionsButton = new AnActionButton( RefactoringBundle.message("changeSignature.propagate.exceptions.title"), null, PlatformIcons.NEW_EXCEPTION) { @Override public void actionPerformed(AnActionEvent e) { final Ref<JavaCallerChooser> chooser = new Ref<JavaCallerChooser>(); Consumer<Set<PsiMethod>> callback = new Consumer<Set<PsiMethod>>() { @Override public void consume(Set<PsiMethod> psiMethods) { myMethodsToPropagateExceptions = psiMethods; myExceptionPropagationTree = chooser.get().getTree(); } }; chooser.set( new JavaCallerChooser( myMethod.getMethod(), myProject, RefactoringBundle.message("changeSignature.exception.caller.chooser"), myExceptionPropagationTree, callback)); chooser.get().show(); } }; myPropExceptionsButton.setShortcut(CustomShortcutSet.fromString("alt X")); final JPanel panel = ToolbarDecorator.createDecorator(table) .addExtraAction(myPropExceptionsButton) .createPanel(); panel.setBorder(IdeBorderFactory.createEmptyBorder(0)); myExceptionsModel.addTableModelListener(mySignatureUpdater); final ArrayList<Pair<String, JPanel>> result = new ArrayList<Pair<String, JPanel>>(); final String message = RefactoringBundle.message("changeSignature.exceptions.panel.border.title"); result.add(Pair.create(message, panel)); return result; }
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(); } }); }
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(); } }); }
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; }
public JComponent createComponentImpl() { final DefaultTableModel tableModel = createModel(); myTable = new JBTable(tableModel); myTable.setIntercellSpacing(new Dimension(0, 0)); myTable.setDefaultRenderer(TableItem.class, new MyRenderer()); myTable.setShowGrid(false); myTable.setDragEnabled(false); myTable.setShowHorizontalLines(false); myTable.setShowVerticalLines(false); myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); JPanel tablePanel = ToolbarDecorator.createDecorator(myTable) .setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { FileChooserDescriptor myDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); myDescriptor.setTitle( ProjectBundle.message("add.external.annotations.path.title")); myDescriptor.setDescription( ProjectBundle.message("add.external.annotations.path.description")); VirtualFile[] files = FileChooser.chooseFiles(myDescriptor, myTable, myProject, null); final MyTableModel tableModel = (MyTableModel) myTable.getModel(); boolean changes = false; for (final VirtualFile file : files) { if (file != null) { tableModel.addTableItem(new TableItem(file)); changes = true; } } if (changes) { saveData(); TableUtil.selectRows(myTable, new int[] {tableModel.getRowCount() - 1}); } } }) .setRemoveAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final List removedItems = TableUtil.removeSelectedItems(myTable); if (removedItems.size() > 0) { saveData(); } } }) .createPanel(); final JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(tablePanel, BorderLayout.CENTER); mainPanel.add( new JBLabel( ProjectBundle.message("project.roots.external.annotations.description"), UIUtil.ComponentStyle.SMALL, UIUtil.FontColor.BRIGHTER), BorderLayout.NORTH); return mainPanel; }
private void createActions(ToolbarDecorator decorator) { final Consumer<BaseInjection> consumer = new Consumer<BaseInjection>() { public void consume(final BaseInjection injection) { addInjection(injection); } }; final Factory<BaseInjection> producer = new NullableFactory<BaseInjection>() { public BaseInjection create() { final InjInfo info = getSelectedInjection(); return info == null ? null : info.injection; } }; for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) { ContainerUtil.addAll(myAddActions, support.createAddActions(myProject, consumer)); final AnAction action = support.createEditAction(myProject, producer); myEditActions.put( support.getId(), action == null ? AbstractLanguageInjectionSupport.createDefaultEditAction(myProject, producer) : action); mySupports.put(support.getId(), support); } Collections.sort( myAddActions, new Comparator<AnAction>() { public int compare(final AnAction o1, final AnAction o2) { return Comparing.compare( o1.getTemplatePresentation().getText(), o2.getTemplatePresentation().getText()); } }); decorator.disableUpDownActions(); decorator.setAddActionUpdater( new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { return !myAddActions.isEmpty(); } }); decorator.setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { performAdd(button); } }); decorator.setRemoveActionUpdater( new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { boolean enabled = false; for (InjInfo info : getSelectedInjections()) { if (!info.bundled) { enabled = true; break; } } return enabled; } }); decorator.setRemoveAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { performRemove(); } }); decorator.setEditActionUpdater( new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { AnAction edit = getEditAction(); if (edit != null) edit.update(e); return edit != null && edit.getTemplatePresentation().isEnabled(); } }); decorator.setEditAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { performEditAction(); } }); decorator.addExtraAction( new DumbAwareActionButton("Duplicate", "Duplicate", PlatformIcons.COPY_ICON) { @Override public boolean isEnabled() { return getEditAction() != null; } @Override public void actionPerformed(@NotNull AnActionEvent e) { final InjInfo injection = getSelectedInjection(); if (injection != null) { addInjection(injection.injection.copy()); // performEditAction(e); } } }); decorator.addExtraAction( new DumbAwareActionButton( "Enable Selected Injections", "Enable Selected Injections", PlatformIcons.SELECT_ALL_ICON) { @Override public void actionPerformed(@NotNull final AnActionEvent e) { performSelectedInjectionsEnabled(true); } }); decorator.addExtraAction( new DumbAwareActionButton( "Disable Selected Injections", "Disable Selected Injections", PlatformIcons.UNSELECT_ALL_ICON) { @Override public void actionPerformed(@NotNull final AnActionEvent e) { performSelectedInjectionsEnabled(false); } }); new DumbAwareAction("Toggle") { @Override public void update(@NotNull AnActionEvent e) { SpeedSearchSupply supply = SpeedSearchSupply.getSupply(myInjectionsTable); e.getPresentation().setEnabled(supply == null || !supply.isPopupActive()); } @Override public void actionPerformed(@NotNull final AnActionEvent e) { performToggleAction(); } }.registerCustomShortcutSet( new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)), myInjectionsTable); if (myInfos.length > 1) { AnActionButton shareAction = new DumbAwareActionButton("Move to IDE Scope", null, PlatformIcons.IMPORT_ICON) { { addCustomUpdater( new AnActionButtonUpdater() { @Override public boolean isEnabled(AnActionEvent e) { CfgInfo cfg = getTargetCfgInfo(getSelectedInjections()); e.getPresentation() .setText( cfg == getDefaultCfgInfo() ? "Move to IDE Scope" : "Move to Project Scope"); return cfg != null; } }); } @Override public void actionPerformed(@NotNull final AnActionEvent e) { final List<InjInfo> injections = getSelectedInjections(); final CfgInfo cfg = getTargetCfgInfo(injections); if (cfg == null) return; for (InjInfo info : injections) { if (info.cfgInfo == cfg) continue; if (info.bundled) continue; info.cfgInfo.injectionInfos.remove(info); cfg.addInjection(info.injection); } final int[] selectedRows = myInjectionsTable.getSelectedRows(); myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos)); TableUtil.selectRows(myInjectionsTable, selectedRows); } @Nullable private CfgInfo getTargetCfgInfo(final List<InjInfo> injections) { CfgInfo cfg = null; for (InjInfo info : injections) { if (info.bundled) { continue; } if (cfg == null) cfg = info.cfgInfo; else if (cfg != info.cfgInfo) return info.cfgInfo; } if (cfg == null) return null; for (CfgInfo info : myInfos) { if (info != cfg) return info; } throw new AssertionError(); } }; shareAction.setShortcut( new CustomShortcutSet( KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_DOWN_MASK))); decorator.addExtraAction(shareAction); } decorator.addExtraAction( new DumbAwareActionButton("Import", "Import", AllIcons.Actions.Install) { @Override public void actionPerformed(@NotNull final AnActionEvent e) { doImportAction(e.getDataContext()); updateCountLabel(); } }); decorator.addExtraAction( new DumbAwareActionButton("Export", "Export", AllIcons.Actions.Export) { @Override public void actionPerformed(@NotNull final AnActionEvent e) { final List<BaseInjection> injections = getInjectionList(getSelectedInjections()); final VirtualFileWrapper wrapper = FileChooserFactory.getInstance() .createSaveFileDialog( new FileSaverDescriptor("Export Selected Injections to File...", "", "xml"), myProject) .save(null, null); if (wrapper == null) return; final Configuration configuration = new Configuration(); configuration.setInjections(injections); final Document document = new Document(configuration.getState()); try { JDOMUtil.writeDocument(document, wrapper.getFile(), "\n"); } catch (IOException ex) { final String msg = ex.getLocalizedMessage(); Messages.showErrorDialog( myProject, msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed"); } } @Override public boolean isEnabled() { return !getSelectedInjections().isEmpty(); } }); }
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); }
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; }
private JComponent createChildrenListEditor() { final MyTableModel tableModel = new MyTableModel(); myTable = new JBTable(tableModel); myListChildrenEditor = new DebuggerExpressionTextField(myProject, null, "NamedChildrenConfigurable"); final TableColumn exprColumn = myTable.getColumnModel().getColumn(EXPRESSION_TABLE_COLUMN); exprColumn.setCellEditor( new AbstractTableCellEditor() { public Object getCellEditorValue() { return myListChildrenEditor.getText(); } public Component getTableCellEditorComponent( JTable table, Object value, boolean isSelected, int row, int column) { myListChildrenEditor.setText((TextWithImports) value); return myListChildrenEditor; } }); exprColumn.setCellRenderer( new DefaultTableCellRenderer() { public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final TextWithImports textWithImports = (TextWithImports) value; final String text = (textWithImports != null) ? textWithImports.getText() : ""; return super.getTableCellRendererComponent( table, text, isSelected, hasFocus, row, column); } }); return ToolbarDecorator.createDecorator(myTable) .setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { tableModel.addRow("", DebuggerUtils.getInstance().createExpressionWithImports("")); } }) .setRemoveAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { int selectedRow = myTable.getSelectedRow(); if (selectedRow >= 0 && selectedRow < myTable.getRowCount()) { getTableModel().removeRow(selectedRow); } } }) .setMoveUpAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { TableUtil.moveSelectedItemsUp(myTable); } }) .setMoveDownAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { TableUtil.moveSelectedItemsDown(myTable); } }) .createPanel(); }
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()); }