use of javax.swing.tree.TreeNode in project processdash by dtuma.
the class TreeListSelector method expandAll.
private void expandAll(TreePath parentPath, boolean expand) {
TreeNode node = (TreeNode) parentPath.getLastPathComponent();
for (Enumeration e = node.children(); e.hasMoreElements(); ) {
TreeNode child = (TreeNode) e.nextElement();
TreePath childPath = parentPath.pathByAddingChild(child);
expandAll(childPath, expand);
}
if (expand)
treeComponent.expandPath(parentPath);
else
treeComponent.collapsePath(parentPath);
}
use of javax.swing.tree.TreeNode in project processdash by dtuma.
the class TreeListSelector method setSelectedList.
public void setSelectedList(List selectedList) {
// reset tree expansion to only show first level
TreeNode root = (TreeNode) treeModel.getRoot();
TreePath rootPath = new TreePath(root);
for (Enumeration e = root.children(); e.hasMoreElements(); ) expandAll(rootPath.pathByAddingChild(e.nextElement()), false);
treeComponent.getSelectionModel().clearSelection();
listModel.clear();
for (Iterator iter = selectedList.iterator(); iter.hasNext(); ) {
listModel.addElement(iter.next());
}
}
use of javax.swing.tree.TreeNode in project n2a by frothga.
the class NodeBase method getKeyPath.
// Structure maintenance -------------------------------------------------
public List<String> getKeyPath() {
TreeNode[] path = getPath();
List<String> result = new ArrayList<String>(path.length);
for (TreeNode n : path) result.add(((NodeBase) n).source.key());
return result;
}
use of javax.swing.tree.TreeNode in project n2a by frothga.
the class AddAnnotation method create.
public static NodeBase create(List<String> path, int index, String name, String value, String blockName, NodeFactory factory, NodeFactory factoryBlock) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
MPart block = (MPart) parent.source.childOrCreate(blockName);
PanelEquationTree pet = PanelModel.instance.panelEquations;
JTree tree = pet.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
// If this is a variable, then mix metadata with equations and references
NodeBase container = parent;
if (// If this is a part, then display special block
parent instanceof NodePart) {
if (// empty implies the node is absent
block.size() == 0) {
container = factoryBlock.create(block);
model.insertNodeIntoUnfiltered(container, parent, index);
index = 0;
} else // the node is present, so retrieve it
{
container = parent.child(blockName);
}
}
NodeBase createdNode = container.child(name);
boolean alreadyExists = createdNode != null;
MPart createdPart = (MPart) block.set(name, value);
if (!alreadyExists)
createdNode = factory.create(createdPart);
FontMetrics fm = createdNode.getFontMetrics(tree);
if (container.getChildCount() > 0) {
NodeBase firstChild = (NodeBase) container.getChildAt(0);
if (firstChild.needsInitTabs())
firstChild.initTabs(fm);
}
// pure create, so about to go into edit mode. This should only happen on first application of the create action, and should only be possible if visibility is already correct.
if (value == null)
createdNode.setUserObject("");
// preempt initialization; uses actual name, not user value
createdNode.updateColumnWidths(fm);
if (!alreadyExists)
model.insertNodeIntoUnfiltered(createdNode, container, index);
if (// create was merged with change name/value
value != null) {
container.updateTabStops(fm);
container.allNodesChanged(model);
TreeNode[] createdPath = createdNode.getPath();
pet.updateOrder(createdPath);
pet.updateVisibility(createdPath);
if (path.size() == 1 && name.equals("lock"))
pet.updateLock();
}
return createdNode;
}
use of javax.swing.tree.TreeNode in project n2a by frothga.
the class ChangeAnnotation method apply.
public static void apply(List<String> path, String nameBefore, String nameAfter, String valueAfter, String blockName, NodeFactory factory) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
NodeBase nodeBefore = parent.child(nameBefore);
if (nodeBefore == null)
throw new CannotRedoException();
PanelEquationTree pet = PanelModel.instance.panelEquations;
JTree tree = pet.tree;
FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
FontMetrics fm = nodeBefore.getFontMetrics(tree);
NodeBase nodeAfter;
if (nameBefore.equals(nameAfter)) {
nodeAfter = nodeBefore;
nodeAfter.source.set(valueAfter);
} else {
// Update database
MPart mparent;
if (parent instanceof NodeVariable)
mparent = (MPart) parent.source.child(blockName);
else
mparent = parent.source;
// should directly change destinationNode if it exists
MPart newPart = (MPart) mparent.set(nameAfter, valueAfter);
mparent.clear(nameBefore);
MPart oldPart = (MPart) mparent.child(nameBefore);
// Update GUI
nodeAfter = parent.child(nameAfter);
if (oldPart == null) {
if (nodeAfter == null) {
nodeAfter = nodeBefore;
nodeAfter.source = newPart;
} else {
model.removeNodeFromParent(nodeBefore);
}
} else {
if (nodeAfter == null) {
int index = parent.getIndex(nodeBefore);
nodeAfter = factory.create(newPart);
model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
}
}
}
nodeAfter.updateColumnWidths(fm);
parent.updateTabStops(fm);
parent.allNodesChanged(model);
TreeNode[] nodePath = nodeAfter.getPath();
pet.updateOrder(nodePath);
pet.updateVisibility(nodePath);
// Only an inherited lock node can be touched by editing. It is possible to activate (make local) if the user assigns a specific value to it.
if (path.size() == 2 && path.get(1).equals("$metadata") && (nameBefore.equals("lock") || nameAfter.equals("lock")))
pet.updateLock();
}
Aggregations