📄 workbenchtreeview.java
字号:
//reload(parent); /* Select next project node */ if (newIndex >= 0) selectProject((ProjectTreeNode) root.getChildAt(newIndex)); else setMessage("emptyWorkbench"); return; } /** * This method was created by a SmartGuide. * @param event PropertyChangeEvent */ public void propertyChange(PropertyChangeEvent event) { Object source = event.getSource(); String propertyName = event.getPropertyName(); if ("projectName".equals(propertyName)) { reload(findSelectedProjectNode()); // since it must be the selected one } else if ("tableName".equals(propertyName) || "className".equals(propertyName)) { reload(findSelectedTableNode()); // since it must be the selected one } else if ("selectedProject".equals(propertyName)) { Project project = (Project) event.getNewValue(); selectProject(project); } return; } /** * This method was created by a SmartGuide. * @param node javax.swing.tree.DefaultMutableTreeNode */ public void reload(DefaultMutableTreeNode node) { ((DefaultTreeModel) getModel()).reload(node); return; } /** * This method was created by a SmartGuide. * @param project org.dbgen.Project */ public void selectProject(Project project) { for (int i = 0; i < root.getChildCount(); i++) { ProjectTreeNode curr = (ProjectTreeNode) root.getChildAt(i); org.dbgen.Debug.println("TEST " + curr + " -> " + curr.getProject()); if (curr.getProject() == project) { setSelectionPath(new TreePath(new Object[] { root, curr })); } } throw new RuntimeException("WorkbenchTreeView.selectProject() - Cannot find project " + project); } /** * This method was created by a SmartGuide. * @param index int */ public void selectProject(ProjectTreeNode projectNode) { setSelectionPath(new TreePath(new Object[] { root, projectNode })); return; } /** * This method was created by a SmartGuide. * @param projectNode org.dbgen.view.ProjectTreeNode * @param tableNode org.dbgen.view.TableTreeNode */ public void selectTable(ProjectTreeNode projectNode, TableTreeNode tableNode) { setSelectionPath(new TreePath(new Object[] { root, projectNode, tableNode })); return; } /** * Sets the autoSelectTable property (boolean) value. * @param autoSelectTable The new value for the property. * @see #getAutoSelectTable */ public void setAutoSelectTable(boolean autoSelectTable) { /* Get the old property value for fire property change event. */ boolean oldValue = fieldAutoSelectTable; /* Set the autoSelectTable property (attribute) to the new value. */ fieldAutoSelectTable = autoSelectTable; /* Fire (signal/notify) the autoSelectTable property change event. */ firePropertyChange("autoSelectTable", new Boolean(oldValue), new Boolean(autoSelectTable)); return; } /** * Sets the message property (java.lang.String) value. * @param message The new value for the property. * @see #getMessage */ public void setMessage(String message) { /* Get the old property value for fire property change event. */ String oldValue = fieldMessage; /* Set the message property (attribute) to the new value. */ fieldMessage = message; /* Fire (signal/notify) the message property change event. */ firePropertyChange("message", null, message); return; } /** * Sets the selectedProject property (org.dbgen.Project) value. * @param selectedProject The new value for the property. * @see #getSelectedProject */ public void setSelectedProject(Project selectedProject) { /* Get the old property value for fire property change event. */ Project oldValue = fieldSelectedProject; /* Set the selectedProject property (attribute) to the new value. */ fieldSelectedProject = selectedProject; /* Fire (signal/notify) the selectedProject property change event. */ /* XXX - the following must pass null so that it always make notification */ firePropertyChange("selectedProject", null, selectedProject); return; } /** * Sets the selectedTable property (org.dbgen.Table) value. * @param selectedTable The new value for the property. * @see #getSelectedTable */ public void setSelectedTable(Table selectedTable) { /* Get the old property value for fire property change event. */ Table oldValue = fieldSelectedTable; /* Set the selectedTable property (attribute) to the new value. */ fieldSelectedTable = selectedTable; /* Fire (signal/notify) the selectedTable property change event. */ /* XXX - the following must pass null so that it always make notification */ firePropertyChange("selectedTable", null, selectedTable); return; } /** * Sets the workbench property (org.dbgen.Workbench) value. * @param workbench The new value for the property. * @see #getWorkbench */ public void setWorkbench(Workbench workbench) { /* Get the old property value for fire property change event. */ Workbench oldValue = fieldWorkbench; /* Set the workbench property (attribute) to the new value. */ fieldWorkbench = workbench; /* Fire (signal/notify) the workbench property change event. */ firePropertyChange("workbench", oldValue, workbench); /* Create the tree nodes recursively now */ createTree(); /* Listen to ProjectChange event */ workbench.addProjectChangedListener(this); return; } /** * This method was created by a SmartGuide. * @param event org.dbgen.TableAddedEvent */ public void tableAdded(TableAddedEvent event) { ProjectTreeNode parent = findSelectedProjectNode(); Table newTable = event.getTable(); TableTreeNode tableNode = new TableTreeNode(newTable); /* Find out where to insert the node */ Vector tables = parent.getProject().getTables(); int index = Util.findObjectFromVector(newTable, tables); if (parent != null) { parent.insert(tableNode, index); } DefaultTreeModel tm = (DefaultTreeModel) getModel(); tm.nodesWereInserted(parent, new int[] { index }); //reload(parent); TreePath path = new TreePath(new Object[] { root, parent, tableNode }); if (getAutoSelectTable()) { setSelectionPath(path); } else { makeVisible(path); } /* Listen to property change of the table so we can update representation */ newTable.addPropertyChangeListener(this); return; } /** * This method was created by a SmartGuide. * @param event org.dbgen.TableDeletedEvent */ public void tableDeleted(TableDeletedEvent event) { TableTreeNode tableNode = findSelectedTableNode(); TableTreeNode nextNode = (TableTreeNode) tableNode.getNextSibling(); ProjectTreeNode parent = (ProjectTreeNode) tableNode.getParent(); int index = parent.getIndex(tableNode); int count = parent.getChildCount(); int newIndex = (index == count-1) ? index-1 : index; /* Remove the table node */ parent.remove(tableNode); /* Notify Jtree about the removal */ DefaultTreeModel tm = (DefaultTreeModel) getModel(); tm.nodesWereRemoved(parent, new int[] { index }, new Object[] { event.getTable() }); //reload(parent); /* Select next table node */ if (newIndex >= 0) selectTable(parent, (TableTreeNode) parent.getChildAt(newIndex)); else selectProject(parent); return; } /** * Testing only. * @param args java.lang.String[] */ public static void test(String args[]) { JFrame frame = new JFrame("Workbench Tree View Testing"); WorkbenchTreeView view = new WorkbenchTreeView(); view.setWorkbench(Workbench.getTestWorkbench()); frame.getContentPane().add(view); frame.pack(); frame.setVisible(true); return; } /** * This method was created by a SmartGuide. * @param event javax.swing.event.TreeSelectionEvent */ public void valueChanged(TreeSelectionEvent event) { int level = getSelectionLevel(); switch (level) { case 2: setSelectedProject(findSelectedProjectNode().getProject()); break; case 3: setSelectedProject(findSelectedProjectNode().getProject()); setSelectedTable(findSelectedTableNode().getTable()); break; default: break; //throw new RuntimeException("WorkbenchTreeView.valueChanged() incorrect: level = " + level); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -