@Override protected void init() { super.init(); myPanel.setLayout(new GridBagLayout()); initTables(); myTreeTable = createOptionsTree(getSettings()); myTreeTable.setBackground(UIUtil.getPanelBackground()); myTreeTable.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); JBScrollPane scrollPane = new JBScrollPane(myTreeTable) { @Override public Dimension getMinimumSize() { return super.getPreferredSize(); } }; myPanel.add( scrollPane, new GridBagConstraints( 0, 0, 1, 1, 0, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); final JPanel previewPanel = createPreviewPanel(); myPanel.add( previewPanel, new GridBagConstraints( 1, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); installPreviewPanel(previewPanel); addPanelToWatch(myPanel); isFirstUpdate = false; customizeSettings(); }
@Override public boolean isModified(CodeStyleSettings settings) { TreeModel treeModel = myTreeTable.getTree().getModel(); TreeNode root = (TreeNode) treeModel.getRoot(); if (isModified(root, settings)) { return true; } return false; }
@Override protected void resetImpl(final CodeStyleSettings settings) { TreeModel treeModel = myTreeTable.getTree().getModel(); TreeNode root = (TreeNode) treeModel.getRoot(); resetNode(root, settings); }
@Override public void apply(CodeStyleSettings settings) { TreeModel treeModel = myTreeTable.getTree().getModel(); TreeNode root = (TreeNode) treeModel.getRoot(); applyNode(root, settings); }
protected TreeTable createOptionsTree(CodeStyleSettings settings) { DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(); Map<String, DefaultMutableTreeNode> groupsMap = new THashMap<String, DefaultMutableTreeNode>(); List<Option> sorted = sortOptions(ContainerUtil.concat(myOptions, myCustomOptions)); for (Option each : sorted) { if (!(myCustomOptions.contains(each) || myAllowedOptions.contains(each.field.getName()) || myShowAllStandardOptions)) continue; String group = each.groupName; MyTreeNode newNode = new MyTreeNode(each, each.title, settings); DefaultMutableTreeNode groupNode = groupsMap.get(group); if (groupNode != null) { groupNode.add(newNode); } else { String groupName; if (group == null) { groupName = each.title; groupNode = newNode; } else { groupName = group; groupNode = new DefaultMutableTreeNode(groupName); groupNode.add(newNode); } groupsMap.put(groupName, groupNode); rootNode.add(groupNode); } } ListTreeTableModel model = new ListTreeTableModel(rootNode, COLUMNS); TreeTable treeTable = new TreeTable(model) { @Override public TreeTableCellRenderer createTableRenderer(TreeTableModel treeTableModel) { TreeTableCellRenderer tableRenderer = super.createTableRenderer(treeTableModel); UIUtil.setLineStyleAngled(tableRenderer); tableRenderer.setRootVisible(false); tableRenderer.setShowsRootHandles(true); return tableRenderer; } @Override public TableCellRenderer getCellRenderer(int row, int column) { TreePath treePath = getTree().getPathForRow(row); if (treePath == null) return super.getCellRenderer(row, column); Object node = treePath.getLastPathComponent(); @SuppressWarnings("unchecked") TableCellRenderer renderer = COLUMNS[column].getRenderer(node); return renderer == null ? super.getCellRenderer(row, column) : renderer; } @Override public TableCellEditor getCellEditor(int row, int column) { TreePath treePath = getTree().getPathForRow(row); if (treePath == null) return super.getCellEditor(row, column); Object node = treePath.getLastPathComponent(); @SuppressWarnings("unchecked") TableCellEditor editor = COLUMNS[column].getEditor(node); return editor == null ? super.getCellEditor(row, column) : editor; } }; new TreeTableSpeedSearch(treeTable).setComparator(new SpeedSearchComparator(false)); treeTable.setRootVisible(false); final JTree tree = treeTable.getTree(); tree.setCellRenderer(myTitleRenderer); tree.setShowsRootHandles(true); // myTreeTable.setRowHeight(new JComboBox(new String[]{"Sample // Text"}).getPreferredSize().height); treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); treeTable.setTableHeader(null); expandTree(tree); treeTable.getColumnModel().getSelectionModel().setAnchorSelectionIndex(1); treeTable.getColumnModel().getSelectionModel().setLeadSelectionIndex(1); int maxWidth = tree.getPreferredScrollableViewportSize().width + 10; final TableColumn titleColumn = treeTable.getColumnModel().getColumn(0); titleColumn.setPreferredWidth(maxWidth); titleColumn.setMinWidth(maxWidth); titleColumn.setMaxWidth(maxWidth); titleColumn.setResizable(false); // final TableColumn levelColumn = treeTable.getColumnModel().getColumn(1); // TODO[max]: better preffered size... // TODO[kb]: Did I fixed it by making the last column floating? // levelColumn.setPreferredWidth(valueSize.width); // levelColumn.setMaxWidth(valueSize.width); // levelColumn.setMinWidth(valueSize.width); // levelColumn.setResizable(false); final Dimension valueSize = new JLabel(ApplicationBundle.message("option.table.sizing.text")).getPreferredSize(); treeTable.setPreferredScrollableViewportSize( new Dimension(maxWidth + valueSize.width + 10, 20)); return treeTable; }
public void setTableModel(TreeTableModel treeTableModel) { super.setTableModel(treeTableModel); LOG.assertTrue(treeTableModel instanceof SortableColumnModel); }