@Override public void run(AnActionButton button) { // 获取选中节点 final DefaultMutableTreeNode selectedNode = getSelectedNode(); if (selectedNode == null) { return; } List<AnAction> actions = getMultipleActions(selectedNode); if (actions == null || actions.isEmpty()) { return; } // 显示新增按钮 final DefaultActionGroup group = new DefaultActionGroup(actions); JBPopupFactory.getInstance() .createActionGroupPopup(null, group, DataManager.getInstance().getDataContext(button.getContextComponent()), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true).show(button.getPreferredPopupPoint()); }
@NotNull public CheckBoxListModelEditor<T> editAction(final @NotNull Function<T, T> consumer) { final Runnable action = new Runnable() { @Override public void run() { T item = getSelectedItem(); if (item != null) { T newItem = consumer.fun(item); if (newItem != null) { list.updateItem(item, newItem, StringUtil.notNullize(toNameConverter.fun(newItem))); } list.requestFocus(); } } }; toolbarDecorator.setEditAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { action.run(); } }); EditSourceOnDoubleClickHandler.install(list, action); return this; }
private AnActionButtonRunnable getEditActionButtonRunnable(Set<String> patterns) { return new AnActionButtonRunnable() { @Override public void run(AnActionButton anActionButton) { String oldValue = (String) patternList.getSelectedValue(); String pattern = Messages.showInputDialog( textEditMessage, textEditTitle, null, oldValue, getRegexInputValidator()); if (pattern != null && !pattern.equals(oldValue)) { patterns.remove(oldValue); patternModels.removeElement(oldValue); if (patterns.add(pattern)) { patternModels.addElementSorted(pattern); } } } }; }
private AnActionButtonRunnable getRemoveAction(final TableView<XQueryRunVariable> variablesTable) { return new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { TableUtil.stopEditing(variablesTable); final int[] selected = variablesTable.getSelectedRows(); if (selected == null || selected.length == 0) return; for (int i = selected.length - 1; i >= 0; i--) { variablesModel.removeRow(selected[i]); } for (int i = selected.length - 1; i >= 0; i--) { int idx = selected[i]; variablesModel.fireTableRowsDeleted(idx, idx); } int selection = selected[0]; if (selection >= variablesModel.getRowCount()) { selection = variablesModel.getRowCount() - 1; } if (selection >= 0) { variablesTable.setRowSelectionInterval(selection, selection); } variablesTable.requestFocus(); } }; }
private AnActionButtonRunnable getAddAction(final TableView<XQueryRunVariable> variablesTable) { return new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { XQueryRunVariable newVariable = new XQueryRunVariable(); if (showEditorDialog(newVariable)) { ArrayList<XQueryRunVariable> newList = new ArrayList<XQueryRunVariable>(variablesModel .getItems()); newList.add(newVariable); variablesModel.setItems(newList); int index = variablesModel.getRowCount() - 1; variablesModel.fireTableRowsInserted(index, index); variablesTable.setRowSelectionInterval(index, index); } } }; }
@Test public void shouldRemoveEntryAfterRemoveButtonClicked() { panel.populateWithConfigurations(asList(defaultDataSource)); final AnActionButton action = getAnActionButton(REMOVE); final AnActionEvent event = new TestActionEvent(action); execute(new GuiTask() { @Override protected void executeInEDT() throws Throwable { action.actionPerformed(event); } }); window.list().requireNoSelection(); assertThat(window.list().contents().length, is(0)); }
private void addWebDeploymentButton(ToolbarDecorator tablePanel) { tablePanel.addExtraAction(new AnActionButton("Remote", WebDeploymentIcons.Download) { @Override public void actionPerformed(AnActionEvent anActionEvent) { UiSettingsUtil.openFileDialogForDefaultWebServerConnection(project, new WebServerFileDialogExtensionCallback("xml") { @Override public void success(@NotNull WebServerConfig server, @NotNull WebServerConfig.RemotePath remotePath) { ContainerSettingsForm.this.tableView.getListTableModel().addRow( new ContainerFile("remote://" + org.apache.commons.lang.StringUtils.stripStart(remotePath.path, "/")) ); ContainerSettingsForm.this.changed = true; } }); } }); }
private void addWebDeploymentButton(ToolbarDecorator tablePanel) { tablePanel.addExtraAction(new AnActionButton("Remote", WebDeploymentIcons.Download) { @Override public void actionPerformed(AnActionEvent anActionEvent) { UiSettingsUtil.openFileDialogForDefaultWebServerConnection(project, new WebServerFileDialogExtensionCallback("php") { @Override public void success(@NotNull WebServerConfig server, @NotNull WebServerConfig.RemotePath remotePath) { RoutingSettingsForm.this.tableView.getListTableModel().addRow( new RoutingFile("remote://" + org.apache.commons.lang.StringUtils.stripStart(remotePath.path, "/")) ); RoutingSettingsForm.this.changed = true; } }); } }); }
public static JPanel createAddRemovePanel(final ListTable table) { return ToolbarDecorator.createDecorator(table) .setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final ListWrappingTableModel tableModel = table.getModel(); tableModel.addRow(); EventQueue.invokeLater(new Runnable() { @Override public void run() { final int lastRowIndex = tableModel.getRowCount() - 1; final Rectangle rectangle = table.getCellRect(lastRowIndex, 0, true); table.scrollRectToVisible(rectangle); table.editCellAt(lastRowIndex, 0); final ListSelectionModel selectionModel = table.getSelectionModel(); selectionModel.setSelectionInterval(lastRowIndex, lastRowIndex); final TableCellEditor editor = table.getCellEditor(); final Component component = editor.getTableCellEditorComponent(table, null, true, lastRowIndex, 0); component.requestFocus(); } }); } }).setRemoveAction(new RemoveAction(table)) .disableUpDownActions().createPanel(); }
@Override public void run(AnActionButton button) { final int selectedRow = myRendererChooser.getSelectedElementRow(); if(selectedRow < 0) { return; } int newRow = selectedRow + (myMoveUp ? -1 : 1); if(newRow < 0) { newRow = myRendererChooser.getElementCount() - 1; } else if(newRow >= myRendererChooser.getElementCount()) { newRow = 0; } myRendererChooser.moveElement(myRendererChooser.getElementAt(selectedRow), newRow); }
@Override public void run(AnActionButton button) { DefaultMutableTreeNode selectedNode = getSelectedNode(); if (selectedNode != null && selectedNode.getParent() != null) { // 删除指定节点 DefaultTreeModel model = (DefaultTreeModel) this.templateTree.getModel(); model.removeNodeFromParent(selectedNode); } }
@Override public void run(AnActionButton button) { final NodeRenderer renderer = (NodeRenderer)NodeRendererSettings.getInstance().createRenderer(CompoundNodeRenderer.UNIQUE_ID); renderer.setEnabled(true); addRenderer(renderer); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { myNameField.requestFocus(); } }); }
@Override public void run(AnActionButton button) { final int selectedRow = myRendererChooser.getSelectedElementRow(); if (selectedRow < 0) { return; } int newRow = selectedRow + (myMoveUp? -1 : 1); if (newRow < 0) { newRow = myRendererChooser.getElementCount() - 1; } else if (newRow >= myRendererChooser.getElementCount()) { newRow = 0; } myRendererChooser.moveElement(myRendererChooser.getElementAt(selectedRow), newRow); }
@Override protected void addToolbarButtons(ToolbarDecorator toolbarDecorator) { AnActionButton reloadButton = new AnActionButton(PyBundle.message("sdk.paths.dialog.reload.paths"), AllIcons.Actions.Refresh) { @Override public void actionPerformed(AnActionEvent e) { onReloadButtonClicked(); } }; toolbarDecorator.addExtraAction(reloadButton); }
/** * Shows the popup-menu. * * @param button The button that was pressed. */ private void showPopupActions(final AnActionButton button) { @Nullable final ActionGroup group = this.addActionPopupGroup; if (group == null) return; JBPopupFactory.getInstance().createActionGroupPopup(null, group, DataManager.getInstance().getDataContext(button.getContextComponent()), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true ).show(button.getPreferredPopupPoint()); }
@NotNull private AnActionButtonRunnable getRemoveActionButtonRunnable(Set<String> patterns) { return new AnActionButtonRunnable() { @Override public void run(AnActionButton anActionButton) { for (Object object : patternList.getSelectedValues()) { String selectedValue = (String) object; patterns.remove(selectedValue); patternModels.removeElement(selectedValue); } } }; }
@NotNull private AnActionButtonRunnable getAddActionButtonRunnable(Set<String> patterns) { return new AnActionButtonRunnable() { @Override public void run(AnActionButton anActionButton) { String pattern = Messages.showInputDialog( textAddMessage, textAddTitle, null, null, getRegexInputValidator()); if (pattern != null) { if (patterns.add(pattern)) { patternModels.addElementSorted(pattern); } } } }; }
private AnActionButtonRunnable getUpdateAction(final TableView<XQueryRunVariable> variablesTable) { return new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final int selectedRow = variablesTable.getSelectedRow(); final XQueryRunVariable selectedVariable = variablesTable.getSelectedObject(); showEditorDialog(selectedVariable); variablesModel.fireTableDataChanged(); variablesTable.setRowSelectionInterval(selectedRow, selectedRow); } }; }
private void clickAdd() { final AnActionButton action = getAnActionButton(ADD); final AnActionEvent event = new TestActionEvent(action); execute(new GuiTask() { @Override protected void executeInEDT() throws Throwable { action.actionPerformed(event); } }); }
@Test public void shouldShowAddPathDialogAfterActioningAddButton() { setUpPanelWithUserLibrary(ENABLED); final AnActionButton action = getAnActionButton(ADD); final AnActionEvent event = new TestActionEvent(action); simulateAction(action, event); assertThat(fileChooserUsedToChooseFiles, is(true)); }
@Test public void shouldRemoveSelectedPositionAfterActioningRemoveButton() { cfg.USER_DEFINED_LIBRARY_PATHS = asList(PATH_JAR); setUpPanelWithUserLibrary(ENABLED); final AnActionButton action = getAnActionButton(REMOVE); final AnActionEvent event = new TestActionEvent(action); panel.getPathList().setSelectedIndex(0); simulateAction(action, event); assertThat(window.list(PATH_LIST_NAME).contents().length, is(0)); }
@Test public void shouldInvokeChangeListenerAfterChangeOfPathListContents() { cfg.USER_DEFINED_LIBRARY_PATHS = asList(PATH_JAR); setUpPanelWithUserLibrary(ENABLED); panel.setUpChangeListeners(aggregatingPanel, listener); final AnActionButton action = getAnActionButton(REMOVE); final AnActionEvent event = new TestActionEvent(action); panel.getPathList().setSelectedIndex(0); simulateAction(action, event); verifyChangeListenerInvokedForCurrentConfigurationState(); }
private void simulateAction(final AnActionButton action, final AnActionEvent event) { execute(new GuiTask() { @Override protected void executeInEDT() throws Throwable { action.actionPerformed(event); } }); }
private void clickButton(CommonActionsPanel.Buttons button) { final AnActionButton action = getAnActionButton(button); final AnActionEvent event = new TestActionEvent(action); execute(new GuiTask() { @Override protected void executeInEDT() throws Throwable { action.actionPerformed(event); } }); }
private void initUI() { myComponent = new JPanel(new BorderLayout()); mySplitter = new Splitter(false, 0.3f); myComponent.add(mySplitter, BorderLayout.CENTER); JPanel leftPanel = new JPanel(new BorderLayout()); leftPanel.setBorder(IdeBorderFactory.createTitledBorder("Project XSLT Files", false, new Insets(0, 0, 0, 0))); myTree = new Tree(); myTree.setRootVisible(false); myTree.setShowsRootHandles(false); leftPanel.add(new JBScrollPane(myTree), BorderLayout.CENTER); mySplitter.setFirstComponent(leftPanel); myList = new JBList(); myList.setCellRenderer(new MyCellRenderer()); myList.setMinimumSize(new Dimension(120, 200)); myList.getEmptyText().setText("No associated files"); JPanel rightPanel = ToolbarDecorator.createDecorator(myList) .addExtraAction(AnActionButton.fromAction(new AddAssociationActionWrapper())) .addExtraAction(AnActionButton.fromAction(new RemoveAssociationAction())) .disableUpDownActions().disableAddAction().disableRemoveAction().createPanel(); UIUtil.addBorder(rightPanel, IdeBorderFactory.createTitledBorder("Associated Files", false, new Insets(0, 0, 0, 0))); mySplitter.setSecondComponent(rightPanel); final float dividerProportion = myProperties.getFloat(DIVIDER_PROPORTION, 0.3f); mySplitter.setProportion(dividerProportion); }
@Override public void run(AnActionButton button) { EventQueue.invokeLater(new Runnable() { @Override public void run() { final TableCellEditor editor = table.getCellEditor(); if (editor != null) { editor.stopCellEditing(); } final ListSelectionModel selectionModel = table.getSelectionModel(); final int minIndex = selectionModel.getMinSelectionIndex(); final int maxIndex = selectionModel.getMaxSelectionIndex(); if (minIndex == -1 || maxIndex == -1) { return; } final ListWrappingTableModel tableModel = table.getModel(); for (int i = minIndex; i <= maxIndex; i++) { if (selectionModel.isSelectedIndex(i)) { tableModel.removeRow(i); } } final int count = tableModel.getRowCount(); if (count <= minIndex) { selectionModel.setSelectionInterval(count - 1, count - 1); } else if (minIndex <= 0) { if (count > 0) { selectionModel.setSelectionInterval(0, 0); } } else { selectionModel.setSelectionInterval(minIndex - 1, minIndex - 1); } } }); }
@Override public void run(AnActionButton button) { final NodeRenderer renderer = (NodeRenderer) NodeRendererSettings.getInstance().createRenderer(CompoundNodeRenderer.UNIQUE_ID); renderer.setEnabled(true); addRenderer(renderer); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { myNameField.requestFocus(); } }); }
@Override public void run(AnActionButton button) { for(NodeRenderer selectedElement : myRendererChooser.getSelectedElements()) { myRendererChooser.removeElement(selectedElement); } }
@NotNull protected AnActionButton[] createExtraActions() { return new AnActionButton[] { new AnActionButton("Re-scan", AllIcons.Actions.ForceRefresh) { protected LuaInterpreter findByPath(String path) { for (LuaInterpreter element : getElements()) if (element.path.equals(path)) return element; return null; } protected void update(LuaInterpreter target, LuaInterpreter source) { target.family = source.family; target.path = source.path; target.version = source.version; } @Override public void actionPerformed(AnActionEvent e) { LuaInterpreterFinder finder = new LuaInterpreterFinder(); List<LuaInterpreter> interpreters = finder.findInterpreters(); for (LuaInterpreter interpreter : interpreters) { LuaInterpreter original = findByPath(interpreter.path); if (original == null) { List<LuaInterpreter> elements = getElements(); if (0 == elements.size()) interpreter.isDefault = Boolean.TRUE; elements.add(interpreter); } else update(original, interpreter); } if (interpreters.size() != 0) { getTableView().getTableViewModel().setItems(getElements()); setModified(); } } } }; }
@Override public void run(AnActionButton button) { for (NodeRenderer selectedElement : myRendererChooser.getSelectedElements()) { myRendererChooser.removeElement(selectedElement); } }
@Override public void run(AnActionButton button) { // todo(elharo): inject a pointer to the parent class, and we can make this class static List<Breakpoint> selectedBreakpoints = getSelectedBreakpoints(); fireDeleteBreakpoints(selectedBreakpoints); }
/** * Adds a language, i.e. shows the popup menu. * * @param button The button that was clicked. */ private void addLanguage(final AnActionButton button) { if (this.controller == null) return; showPopupActions(button); }
private AnActionButton getAnActionButton(CommonActionsPanel.Buttons button) { return panel.getToolbarDecorator() .getActionsPanel() .getAnActionButton(button); }
public PropertiesTab() { myPropertiesTable = new JBTable(); UIPropertyBinding.TableListBinding<BuildFileProperty> tableListBinding = getBinding().bindList(myPropertiesTable, PROPERTY_COLUMNS, AntBuildFileImpl.ANT_PROPERTIES); tableListBinding.setColumnWidths(GlobalAntConfiguration.PROPERTIES_TABLE_LAYOUT); myWholePanel = ToolbarDecorator.createDecorator(myPropertiesTable).setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { if(myPropertiesTable.isEditing() && !myPropertiesTable.getCellEditor().stopCellEditing()) { return; } BuildFileProperty item = new BuildFileProperty(); ListTableModel<BuildFileProperty> model = (ListTableModel<BuildFileProperty>) myPropertiesTable.getModel(); ArrayList<BuildFileProperty> items = new ArrayList<BuildFileProperty>(model.getItems()); items.add(item); model.setItems(items); int newIndex = model.indexOf(item); ListSelectionModel selectionModel = myPropertiesTable.getSelectionModel(); selectionModel.clearSelection(); selectionModel.setSelectionInterval(newIndex, newIndex); ColumnInfo[] columns = model.getColumnInfos(); for(int i = 0; i < columns.length; i++) { ColumnInfo column = columns[i]; if(column.isCellEditable(item)) { myPropertiesTable.requestFocusInWindow(); myPropertiesTable.editCellAt(newIndex, i); break; } } } }).disableUpDownActions().createPanel(); myWholePanel.setBorder(null); }
public static JPanel createAddRemoveTreeClassChooserPanel(final ListTable table, final String chooserTitle, @NonNls String... ancestorClasses) { final ClassFilter filter; if (ancestorClasses.length == 0) { filter = ClassFilter.ALL; } else { filter = new SubclassFilter(ancestorClasses); } return ToolbarDecorator.createDecorator(table) .setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { final DataContext dataContext = DataManager.getInstance().getDataContext(table); final Project project = dataContext.getData(CommonDataKeys.PROJECT); if (project == null) { return; } final TreeClassChooserFactory chooserFactory = TreeClassChooserFactory.getInstance(project); final TreeClassChooser classChooser = chooserFactory.createWithInnerClassesScopeChooser(chooserTitle, GlobalSearchScope.allScope(project), filter, null); classChooser.showDialog(); final PsiClass selectedClass = classChooser.getSelected(); if (selectedClass == null) { return; } final String qualifiedName = selectedClass.getQualifiedName(); final ListWrappingTableModel tableModel = table.getModel(); final int index = tableModel.indexOf(qualifiedName, 0); final int rowIndex; if (index < 0) { tableModel.addRow(qualifiedName); rowIndex = tableModel.getRowCount() - 1; } else { rowIndex = index; } final ListSelectionModel selectionModel = table.getSelectionModel(); selectionModel.setSelectionInterval(rowIndex, rowIndex); EventQueue.invokeLater(new Runnable() { @Override public void run() { final Rectangle rectangle = table.getCellRect(rowIndex, 0, true); table.scrollRectToVisible(rectangle); } }); } }).setRemoveAction(new RemoveAction(table)) .disableUpDownActions().createPanel(); }