public void expandAll(boolean expand) { TreeNode root = (TreeNode) getModel().getRoot(); expandAll(new TreePath(root), expand); }
private void expandSubtree(TreePath path, boolean expand) { if (path == null) { TreePath selectionPath = getSelectionPath(); path = selectionPath == null ? new TreePath(treeModel.getRoot()) : selectionPath; } DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) path.getLastPathComponent(); Enumeration children = currentNode.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); TreePath expandedPath = path.pathByAddingChild(child); expandSubtree(expandedPath, expand); } if (expand) { expandPath(path); } else if (path.getParentPath() != null) { collapsePath(path); } }
nodesCheckingState = new HashMap<TreePath, CheckedNode>(); checkedPaths = new HashSet<TreePath>(); DefaultMutableTreeNode node = (DefaultMutableTreeNode)getModel().getRoot(); if (node == null) { return;
(DefaultMutableTreeNode)tree.getModel().getRoot(); Enumeration e = root.breadthFirstEnumeration(); while(e.hasMoreElements()) {
/** * Constructor. * @param parentComponent the main UI where the Tree resides. */ public Tree(Component parentComponent) { treePopupMenu = new JPopupMenu(); setComponentPopupMenu(treePopupMenu); parent = parentComponent; rootNode = this.getModel().getRoot(); }
/** * Writes a graphical representation of the specified tree model in the given buffer. * * <p>This method should not be defined here, since this class is about optional dependencies. * It should be defined in {@link org.geotools.gui.swing.tree.Trees} instead. However we put it * here (for now) because it is used in some module that don't want to depend on widgets. * * @param tree The tree to format. * @param buffer Where to format the tree. * @param lineSeparator The line separator, or {@code null} for the system default. * @throws IOException if an error occured while writting in the given buffer. * @since 2.5 */ public static void format(final TreeModel tree, final Appendable buffer, String lineSeparator) throws IOException { final Object root = tree.getRoot(); if (root != null) { if (lineSeparator == null) { lineSeparator = System.getProperty("line.separator", "\n"); } format(tree, root, buffer, 0, new boolean[64], lineSeparator); } }
/** * Returns a graphical representation of the specified tree model. This representation can be * printed to the {@linkplain System#out standard output stream} (for example) if it uses a * monospaced font and supports unicode. * * <p>This method should not be defined here, since this class is about optional dependencies. * It should be defined in {@link org.geotools.gui.swing.tree.Trees} instead. However we put it * here (for now) because it is used in some module that don't want to depend on widgets. * * @param tree The tree to format. * @return A string representation of the tree, or {@code null} if it doesn't contain any node. */ public static String toString(final TreeModel tree) { final Object root = tree.getRoot(); if (root == null) { return null; } final StringBuilder buffer = new StringBuilder(); final String lineSeparator = System.getProperty("line.separator", "\n"); try { format(tree, root, buffer, 0, new boolean[64], lineSeparator); } catch (IOException e) { // Should never happen when writting into a StringBuilder. throw new AssertionError(e); } return buffer.toString(); }
TreeModel model = tree.getModel(); DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) model.getRoot(); // Just changing enumeration kind here Enumeration<DefaultMutableTreeNode> en = rootNode.preorderEnumeration(); while (en.hasMoreElements()) { DefaultMutableTreeNode node = en.nextElement(); TreeNode[] path = node.getPath(); System.out.println((node.isLeaf() ? " - " : "+ ") + path[path.length - 1]); }
private Document buildMongoDocument() { JsonTreeNode rootNode = (JsonTreeNode) editTableView.getTree().getModel().getRoot(); return JsonTreeUtils.buildDocumentObject(rootNode); } }
public String getStringifiedResult() { JsonTreeNode rootNode = (JsonTreeNode) resultTreeTableView.getTree().getModel().getRoot(); return stringifyResult(rootNode); }
protected void addRole(ActionEvent evt) { MondrianGuiDef.Schema schema = (MondrianGuiDef.Schema) tree.getModel().getRoot(); MondrianGuiDef.Role role = new MondrianGuiDef.Role(); role.name = ""; role.schemaGrants = new MondrianGuiDef.SchemaGrant[0]; // add cube to schema role.name = getNewName( getResourceConverter().getString( "schemaExplorer.newRole.title", "New Role"), schema.roles); NodeDef[] temp = schema.roles; schema.roles = new MondrianGuiDef.Role[temp.length + 1]; for (int _i = 0; _i < temp.length; _i++) { schema.roles[_i] = (MondrianGuiDef.Role) temp[_i]; } schema.roles[schema.roles.length - 1] = role; tree.setSelectionPath( (new TreePath(model.getRoot())).pathByAddingChild( role)); refreshTree(tree.getSelectionPath()); setTableCellFocus(0); }
protected void addParameter(ActionEvent evt) { MondrianGuiDef.Schema schema = (MondrianGuiDef.Schema) tree.getModel().getRoot(); MondrianGuiDef.Parameter parameter = new MondrianGuiDef.Parameter(); parameter.name = ""; // set the required fields parameter.name = getNewName( getResourceConverter().getString( "schemaExplorer.newParameter.title", "New Parameter"), schema.parameters); // set the default values parameter.type = "String"; parameter.modifiable = Boolean.TRUE; NodeDef[] temp = schema.parameters; schema.parameters = new MondrianGuiDef.Parameter[temp.length + 1]; for (int _i = 0; _i < temp.length; _i++) { schema.parameters[_i] = (MondrianGuiDef.Parameter) temp[_i]; } schema.parameters[schema.parameters.length - 1] = parameter; tree.setSelectionPath( (new TreePath(model.getRoot())).pathByAddingChild( parameter)); refreshTree(tree.getSelectionPath()); setTableCellFocus(0); }
protected void addUserDefinedFunction(ActionEvent evt) { MondrianGuiDef.Schema schema = (MondrianGuiDef.Schema) tree.getModel().getRoot(); MondrianGuiDef.UserDefinedFunction udf = new MondrianGuiDef.UserDefinedFunction(); udf.name = ""; udf.name = getNewName( getResourceConverter().getString( "schemaExplorer.newUserDefinedFunction.title", "New User defined Function"), schema.userDefinedFunctions); NodeDef[] temp = schema.userDefinedFunctions; schema.userDefinedFunctions = new MondrianGuiDef.UserDefinedFunction[temp.length + 1]; for (int _i = 0; _i < temp.length; _i++) { schema.userDefinedFunctions[_i] = (MondrianGuiDef.UserDefinedFunction) temp[_i]; } schema.userDefinedFunctions[schema.userDefinedFunctions.length - 1] = udf; tree.setSelectionPath( new TreePath(model.getRoot()).pathByAddingChild( udf)); refreshTree(tree.getSelectionPath()); setTableCellFocus(0); }
protected void addVirtualCube(ActionEvent evt) { MondrianGuiDef.Schema schema = (MondrianGuiDef.Schema) tree.getModel().getRoot(); MondrianGuiDef.VirtualCube cube = new MondrianGuiDef.VirtualCube(); cube.name = ""; cube.dimensions = new MondrianGuiDef.VirtualCubeDimension[0]; cube.measures = new MondrianGuiDef.VirtualCubeMeasure[0]; cube.calculatedMembers = new MondrianGuiDef.CalculatedMember[0]; cube.enabled = Boolean.TRUE; // add cube to schema cube.name = getNewName( getResourceConverter().getString( "schemaExplorer.newVirtualCube.title", "New Virtual Cube"), schema.virtualCubes); NodeDef[] temp = schema.virtualCubes; schema.virtualCubes = new MondrianGuiDef.VirtualCube[temp.length + 1]; for (int i = 0; i < temp.length; i++) { schema.virtualCubes[i] = (MondrianGuiDef.VirtualCube) temp[i]; } schema.virtualCubes[schema.virtualCubes.length - 1] = cube; tree.setSelectionPath( new TreePath(model.getRoot()).pathByAddingChild( cube)); refreshTree(tree.getSelectionPath()); setTableCellFocus(0); }
protected void addCube(ActionEvent evt) { MondrianGuiDef.Schema schema = (MondrianGuiDef.Schema) tree.getModel().getRoot(); MondrianGuiDef.Cube cube = new MondrianGuiDef.Cube(); cube.name = ""; cube.dimensions = new MondrianGuiDef.Dimension[0]; cube.measures = new MondrianGuiDef.Measure[0]; cube.calculatedMembers = new MondrianGuiDef.CalculatedMember[0]; cube.namedSets = new MondrianGuiDef.NamedSet[0]; cube.name = getNewName( getResourceConverter().getString( "schemaExplorer.newCube.title", "New Cube"), schema.cubes); cube.cache = Boolean.TRUE; cube.enabled = Boolean.TRUE; cube.visible = Boolean.TRUE; NodeDef[] temp = schema.cubes; schema.cubes = new MondrianGuiDef.Cube[temp.length + 1]; for (int _i = 0; _i < temp.length; _i++) { schema.cubes[_i] = (MondrianGuiDef.Cube) temp[_i]; } schema.cubes[schema.cubes.length - 1] = cube; tree.setSelectionPath( (new TreePath(model.getRoot())).pathByAddingChild( cube)); refreshTree(tree.getSelectionPath()); setTableCellFocus(0); }
@Override public T next() { next = false; return cast(treeModel.getRoot()); }
private void copyPressed() { String info = getNodeContents((TreeNode) jtrProviders.getModel().getRoot(), 0); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection copy = new StringSelection(info); clipboard.setContents(copy, copy); }
private void copyPressed() { String properties = getNodeContents((TreeNode) jtrProperties.getModel().getRoot(), 0); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection copy = new StringSelection(properties); clipboard.setContents(copy, copy); }
@Override public String getColumnName(int column) { return (column == 0) ? Visualizer.findNode(tree.getModel().getRoot()).getDisplayName() : nodeTableModel.getColumnName(column - 1); }
/** * Initializes the tree view. * @param node root node */ void init(final ProjectNode node) { ((DefaultMutableTreeNode) getModel().getRoot()).add(node); // expand root and child directories for(int r = 0; r < 2; r++) expandRow(r); setRootVisible(false); setSelectionRow(0); }