use of gov.sandia.n2a.ui.eq.FilteredTreeModel in project n2a by frothga.
the class ChangeOrder method apply.
public void apply(int indexBefore, int indexAfter, int indexMetadata, boolean createOrder, boolean destroyOrder) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
NodeBase moveNode = (NodeBase) parent.getChildAt(indexBefore);
model.removeNodeFromParent(moveNode);
NodeAnnotations metadataNode = (NodeAnnotations) parent.child("$metadata");
boolean needBuild = false;
if (createOrder) {
if (metadataNode == null) {
metadataNode = new NodeAnnotations((MPart) parent.source.childOrCreate("$metadata"));
model.insertNodeIntoUnfiltered(metadataNode, parent, indexMetadata);
}
metadataNode.source.childOrCreate("gui", "order");
needBuild = true;
}
if (destroyOrder) {
MNode mparent = metadataNode.source;
mparent.clear("gui", "order");
if (mparent.child("gui").size() == 0)
mparent.clear("gui");
if (mparent.size() == 0) {
parent.source.clear("$metadata");
model.removeNodeFromParent(metadataNode);
} else {
needBuild = true;
}
}
if (needBuild) {
List<String> expanded = AddAnnotation.saveExpandedNodes(pet.tree, metadataNode);
metadataNode.build();
metadataNode.filter();
if (metadataNode.visible()) {
model.nodeStructureChanged(metadataNode);
AddAnnotation.restoreExpandedNodes(pet.tree, metadataNode, expanded);
}
}
model.insertNodeIntoUnfiltered(moveNode, parent, indexAfter);
TreeNode[] movePath = moveNode.getPath();
if (!destroyOrder)
pet.updateOrder(movePath);
pet.updateVisibility(movePath);
}
use of gov.sandia.n2a.ui.eq.FilteredTreeModel in project n2a by frothga.
the class ChangeReference method apply.
public void apply(String nameBefore, String nameAfter, String valueAfter) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
NodeBase nodeBefore = parent.child(nameBefore);
if (nodeBefore == null)
throw new CannotRedoException();
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
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("$reference");
else
mparent = parent.source;
// should directly change destinationNode if it exists
MPart newPart = (MPart) mparent.set(valueAfter, nameAfter);
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 = new NodeReference(newPart);
model.insertNodeIntoUnfiltered(nodeAfter, parent, index);
}
}
}
nodeAfter.setUserObject();
parent.invalidateColumns(null);
TreeNode[] nodePath = nodeAfter.getPath();
pet.updateOrder(nodePath);
pet.updateVisibility(nodePath);
parent.allNodesChanged(model);
pet.animate();
}
use of gov.sandia.n2a.ui.eq.FilteredTreeModel in project n2a by frothga.
the class AddAnnotations method destroy.
public static void destroy(List<String> path, String blockName, boolean setSelected, boolean touchesPin, boolean touchesCategory) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
// The only way to paste a $metadata block is if the tree is visible.
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
NodeContainer node = (NodeContainer) parent.child(blockName);
TreeNode[] nodePath = node.getPath();
int index = parent.getIndexFiltered(node);
MPart mparent = parent.source;
mparent.clear(blockName);
if (mparent.child(blockName) == null) {
model.removeNodeFromParent(node);
} else // Just exposed an overridden node
{
// Necessary to remove all overridden nodes
node.build();
node.filter();
}
pet.updateVisibility(nodePath, index, setSelected);
pet.animate();
if (blockName.equals("$metadata"))
AddAnnotation.update(parent, touchesPin, touchesCategory);
}
use of gov.sandia.n2a.ui.eq.FilteredTreeModel in project n2a by frothga.
the class AddInherit method create.
public static void create(List<String> path, String value) {
NodePart parent = (NodePart) NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
NodePart grandparent = (NodePart) parent.getTrueParent();
PanelEquations pe = PanelModel.instance.panelEquations;
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
PanelEquationGraph peg = pe.panelEquationGraph;
parent.source.set(value, "$inherit");
parent.build();
if (grandparent == null)
parent.findConnections();
else
grandparent.findConnections();
parent.rebuildPins();
parent.filter();
if (parent == pe.part) {
peg.reloadPart();
parent.filter();
}
// Since $inherit is being added, parent will almost certainly become visible, if it's not already.
model.nodeStructureChanged(parent);
TreeNode[] createdPath = parent.child("$inherit").getPath();
pet.updateOrder(createdPath);
pet.updateVisibility(createdPath);
pet.animate();
if (parent != pe.part) {
peg.updatePins();
peg.reconnect();
peg.repaint();
}
if (// root node, so update categories in search list
parent.getTrueParent() == null) {
PanelModel.instance.panelSearch.search();
}
}
use of gov.sandia.n2a.ui.eq.FilteredTreeModel in project n2a by frothga.
the class ChangeAnnotations method apply.
public void apply(MNode add, MNode remove) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = null;
StoredPath sp = null;
if (pet != null) {
model = (FilteredTreeModel) pet.tree.getModel();
sp = new StoredPath(pet.tree);
}
// The immediate container of metadata items in the tree.
NodeContainer metadataNode;
// The $metadata node under which all changes are made.
MNode metadataSource = null;
if (parent instanceof NodeVariable) {
metadataNode = (NodeContainer) parent;
metadataSource = metadataNode.source.child("$metadata");
} else // NodePart is the default case
{
metadataNode = (NodeContainer) parent.child("$metadata");
if (metadataNode != null)
metadataSource = metadataNode.source;
}
boolean needBuild = true;
if (// This is an undo, and $metadata did not exist before, so remove it.
add == null) {
// We can safely assume that metadataSource is non-null, since we only get here during an undo.
metadataSource.parent().clear("$metadata");
if (parent instanceof NodePart) {
if (model == null)
FilteredTreeModel.removeNodeFromParentStatic(metadataNode);
else
model.removeNodeFromParent(metadataNode);
needBuild = false;
}
} else // Update $metadata node. Create if it doesn't exist.
{
if (metadataSource == null)
metadataSource = parent.source.childOrCreate("$metadata");
if (// only happens when parent is NodePart
metadataNode == null) {
metadataNode = new NodeAnnotations((MPart) metadataSource);
if (model == null)
FilteredTreeModel.insertNodeIntoUnfilteredStatic(metadataNode, parent, index);
else
model.insertNodeIntoUnfiltered(metadataNode, parent, index);
}
if (remove != null)
metadataSource.uniqueNodes(remove);
metadataSource.merge(add);
}
if (needBuild) {
List<String> expanded = null;
if (model != null)
expanded = AddAnnotation.saveExpandedNodes(pet.tree, metadataNode);
metadataNode.build();
metadataNode.filter();
if (model != null && metadataNode.visible()) {
model.nodeStructureChanged(metadataNode);
AddAnnotation.restoreExpandedNodes(pet.tree, metadataNode, expanded);
}
}
if (pet != null) {
TreeNode[] path = metadataNode.getPath();
PanelEquationTree.updateVisibility(pet, path, -2, !multi && !graph);
if (// We only care about viewing metadata tree if edit happened in the tree, not graphically.
!graph) {
if (multi)
pet.tree.addSelectionPath(new TreePath(path));
else
// This forces focus back to original location.
sp.restore(pet.tree, true);
}
pet.animate();
}
if (multi && parent instanceof NodePart) {
NodePart np = (NodePart) parent;
if (np.graph != null)
np.graph.setSelected(true);
}
AddAnnotation.update(parent, touchesPin, touchesCategory);
}
Aggregations