private static JPanel createTablePanel(final JBTable table) { return ToolbarDecorator.createDecorator(table) .disableUpAction() .disableDownAction() .setAddAction(new AnActionButtonRunnable() { @Override public void run(AnActionButton anActionButton) { final TableCellEditor cellEditor = table.getCellEditor(); if (cellEditor != null) { cellEditor.stopCellEditing(); } final TableModel model = table.getModel(); ((EditableModel)model).addRow(); TableUtil.editCellAt(table, model.getRowCount() - 1, 0); } }) .createPanel(); }
ListToolbarDecorator(JList list, @Nullable EditableModel editableModel) { myList = list; myEditableModel = editableModel; myAddActionEnabled = myRemoveActionEnabled = myUpActionEnabled = myDownActionEnabled = true; createActions(); myList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { updateButtons(); } }); myList.addPropertyChangeListener("enabled", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { updateButtons(); } }); }
@Override public void addRow() { final int count = myModel.getRowCount(); if (myModel instanceof EditableModel) { ((EditableModel)myModel).addRow(); } if (count < myModel.getRowCount()) { fireTableRowsInserted(count, myModel.getRowCount() - 1); } }
@Override public void removeRow(int index) { if (myModel instanceof EditableModel) { ((EditableModel)myModel).removeRow(index); } fireTableRowsDeleted(index, index); }
@Override public boolean canExchangeRows(int oldIndex, int newIndex) { if (myModel instanceof EditableModel) { return ((EditableModel)myModel).canExchangeRows(oldIndex, newIndex); } return false; }
@Override public void exchangeRows(int oldIndex, int newIndex) { if (myModel instanceof EditableModel) { ((EditableModel)myModel).exchangeRows(oldIndex, newIndex); } fireTableRowsUpdated(Math.min(oldIndex, newIndex), Math.max(oldIndex, newIndex)); }
@Override protected boolean isModelEditable() { return myEditableModel != null || myList.getModel() instanceof EditableModel; }
@Override protected void installDnDSupport() { RowsDnDSupport.install(myList, myEditableModel != null ? myEditableModel : (EditableModel)myList.getModel()); }
@Override protected void installDnDSupport() { RowsDnDSupport.install(myTable, (EditableModel)myTable.getModel()); }
@Override protected boolean isModelEditable() { return myTable.getModel() instanceof EditableModel; }
public static void install(@NotNull final JTable table, @NotNull final EditableModel model) { table.setDragEnabled(true); installImpl(table, model); }
public static void install(@NotNull final JList list, @NotNull final EditableModel model) { list.setDragEnabled(true); installImpl(list, model); }
public static void install(@NotNull final JTree tree, @NotNull final EditableModel model) { tree.setDragEnabled(true); installImpl(tree, model); }
public static ToolbarDecorator createDecorator(@NotNull JList list, EditableModel editableModel) { return new ListToolbarDecorator(list, editableModel).initPosition(); }
@Override protected boolean isModelEditable() { return myTree.getModel() instanceof EditableModel; }
@Override protected void installDnDSupport() { RowsDnDSupport.install(myTree, (EditableModel)myTree.getModel()); }
protected boolean isModelEditable() { return myTable.getModel() instanceof EditableModel; }