protected void walk(ItemTreeModel model, Group gr, Object o) { int cc = model.getChildCount(o); for (int i = 0; i < cc; i++) { ActivableMutableTreeNode child = (ActivableMutableTreeNode) model.getChild(o, i); if (child.isActive()) { final Item userObject = (Item) child.getUserObject(); if (userObject instanceof Group) { final Group item = new Group(userObject.getId()); item.setLocalHint(new LayoutHints(userObject.getLocalHint())); gr.add(item); walk(model, item, child); } else { final Item item = new Item(userObject.getId()); item.setLocalHint(new LayoutHints(userObject.getLocalHint())); final SQLTable table = ComptaPropsConfiguration.getInstanceCompta().getRootSociete().getTable(n.getTable()); if (table.contains(userObject.getId())) { SQLField field = table.getField(userObject.getId()); if (!field.isPrimaryKey() && !field.getName().endsWith("ORDRE") && !field.getName().endsWith("ARCHIVE")) { gr.add(item); } } } } } }
public void setMainTable(String table) { n.setTable(table); initGroupFromTable(extension.getAllKnownFieldName(table)); newModel.fillFromGroup(n, this.tableGroup); tree.expandRow(0); }
public Group getFilteredGroup() { // Parcours du Tree Group filteredGroup = new Group(n.getId()); if (n.getTable() == null) { throw new IllegalStateException("Not table defined for " + n); } walk(newModel, filteredGroup, newModel.getRoot()); filteredGroup = (Group) filteredGroup.getItem(0); return filteredGroup; }
protected void addNewGroup() { final DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) (tree.getModel().getRoot())).getFirstChild(); DefaultMutableTreeNode node = root; if (node.getChildCount() > 0) { node = (DefaultMutableTreeNode) node.getFirstChild(); } if (tree.getSelectionPath() != null) { node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); } if (node != root) { DefaultMutableTreeNode newNode = new ActivableMutableTreeNode(new Group("group" + node.getParent().getChildCount() + 1)); final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); parent.insert(newNode, parent.getIndex(node)); newModel.reload(); tree.setSelectionPath(new TreePath(newModel.getPathToRoot(newNode))); } }