@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); } } }; }
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(); }
@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); } }; }
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(); }