private JTable createAdaptersPanel() { java.util.List<ToolAdapterOperatorDescriptor> toolboxSpis = new ArrayList<>(); toolboxSpis.addAll( ToolAdapterRegistry.INSTANCE .getOperatorMap() .values() .stream() .map(e -> (ToolAdapterOperatorDescriptor) e.getOperatorDescriptor()) .collect(Collectors.toList())); toolboxSpis.sort((o1, o2) -> o1.getAlias().compareTo(o2.getAlias())); OperatorsTableModel model = new OperatorsTableModel(toolboxSpis); operatorsTable = new JTable(model); operatorsTable.getColumnModel().getColumn(0).setMaxWidth(250); operatorsTable.getColumnModel().getColumn(1).setMaxWidth(LABEL_COLUMN_WIDTH); operatorsTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); operatorsTable.addMouseListener( new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() >= 2) { int selectedRow = operatorsTable.getSelectedRow(); // operatorsTable.getModel().setValueAt(true, selectedRow, 0); operatorsTable.repaint(); ToolAdapterOperatorDescriptor operatorDesc = ((OperatorsTableModel) operatorsTable.getModel()).getObjectAt(selectedRow); ToolAdapterEditorDialog dialog = new ToolAdapterEditorDialog(appContext, operatorDesc, false); dialog.show(); refreshContent(); } } @Override public void mousePressed(MouseEvent e) {} @Override public void mouseReleased(MouseEvent e) {} @Override public void mouseEntered(MouseEvent e) {} @Override public void mouseExited(MouseEvent e) {} }); return operatorsTable; }
private JTable createPropertiesPanel() { DefaultTableModel model = new DefaultTableModel(1, 2) { @Override public boolean isCellEditable(int row, int column) { return column == 1; } }; model.setValueAt(Bundle.PathLabel_Text(), 0, 0); model.setValueAt(ToolAdapterIO.getUserAdapterPath(), 0, 1); model.addTableModelListener( l -> { String newPath = model.getValueAt(0, 1).toString(); File path = new File(newPath); if (!path.exists() && SnapDialogs.Answer.YES == SnapDialogs.requestDecision( "Path does not exist", "The path you have entered does not exist.\nDo you want to create it?", true, "Don't ask me in the future")) { if (!path.mkdirs()) { SnapDialogs.showError("Path could not be created!"); } } if (path.exists()) { File oldPath = ToolAdapterIO.getUserAdapterPath(); ToolAdapterOperatorDescriptor[] operatorDescriptors = ToolAdapterActionRegistrar.getActionMap() .values() .toArray( new ToolAdapterOperatorDescriptor [ToolAdapterActionRegistrar.getActionMap().values().size()]); for (ToolAdapterOperatorDescriptor descriptor : operatorDescriptors) { ToolAdapterActionRegistrar.removeOperatorMenu(descriptor); } ToolAdapterIO.setAdaptersPath(Paths.get(newPath)); if (!newPath.equals(oldPath.getAbsolutePath())) { Collection<ToolAdapterOpSpi> toolAdapterOpSpis = ToolAdapterIO.searchAndRegisterAdapters(); for (ToolAdapterOpSpi spi : toolAdapterOpSpis) { ToolAdapterActionRegistrar.registerOperatorMenu( (ToolAdapterOperatorDescriptor) spi.getOperatorDescriptor()); } refreshContent(); } } }); JTable table = new JTable(model); TableColumn labelColumn = table.getColumnModel().getColumn(0); labelColumn.setPreferredWidth((CHECK_COLUMN_WIDTH + LABEL_COLUMN_WIDTH) / 2); TableColumn pathColumn = table.getColumnModel().getColumn(1); pathColumn.setPreferredWidth(COLUMN_WIDTH); pathColumn.setCellEditor(new FileChooserCellEditor()); table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); table.setRowHeight(PATH_ROW_HEIGHT); table.setBorder(BorderFactory.createLineBorder(Color.black)); table.addFocusListener( new FocusListener() { @Override public void focusGained(FocusEvent e) {} @Override public void focusLost(FocusEvent e) { Object source = e.getSource(); if (!table.equals(source)) { table.editingCanceled(new ChangeEvent(source)); table.clearSelection(); } } }); return table; }