use of gov.sandia.n2a.ui.eq.PanelEquationTree 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.PanelEquationTree 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.PanelEquationTree 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);
}
use of gov.sandia.n2a.ui.eq.PanelEquationTree in project n2a by frothga.
the class ChangeLock method apply.
public static void apply(List<String> path, boolean value) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
NodeBase node = parent.child("lock");
if (node == null)
throw new CannotRedoException();
PanelEquationTree pet = PanelModel.instance.panelEquations;
// Since this function implements both do and undo, we need to toggle the current lock state.
if (// Force entry to be local rather than inherited. Only a local entry causes the lock to take effect.
value)
// Force entry to be local rather than inherited. Only a local entry causes the lock to take effect.
node.source.override();
else
node.source.clearPath();
TreeNode[] nodePath = node.getPath();
pet.updateVisibility(nodePath);
pet.updateLock();
}
use of gov.sandia.n2a.ui.eq.PanelEquationTree in project n2a by frothga.
the class AddAnnotation method create.
public static NodeBase create(List<String> path, int index, String name, MNode createSubtree, boolean nameIsGenerated, boolean multi, boolean selectVariable, boolean touchesPin, boolean touchesCategory) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null) {
int last = path.size() - 1;
if (path.get(last).equals("$metadata"))
parent = NodeBase.locateNode(path.subList(0, last));
}
if (parent == null)
throw new CannotRedoException();
// Update database
MPart mparent = parent.source;
if (parent instanceof NodePart || parent instanceof NodeVariable)
mparent = (MPart) mparent.childOrCreate("$metadata");
else if (parent instanceof NodeAnnotation)
mparent = ((NodeAnnotation) parent).folded;
// else parent is a NodeAnnotations, so mparent is $metadata, which can be used directly.
// For a simple add, name has only one path element. However, if a ChangeAnnotation was
// merged into this, then the name may have several path elements.
String[] names = name.split("\\.");
MPart createdPart = (MPart) mparent.childOrCreate(names);
createdPart.merge(createSubtree);
// Update GUI
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = null;
if (pet != null)
model = (FilteredTreeModel) pet.tree.getModel();
NodeContainer container = (NodeContainer) parent;
if (// If this is a part, then display special block.
parent instanceof NodePart) {
container = (NodeContainer) parent.child("$metadata");
if (container == null) {
container = new NodeAnnotations(mparent);
if (model == null)
FilteredTreeModel.insertNodeIntoUnfilteredStatic(container, parent, index);
else
model.insertNodeIntoUnfiltered(container, parent, index);
// TODO: update order?
index = 0;
}
}
NodeBase createdNode;
if (// pure create, going into edit mode
nameIsGenerated) {
// The given name should be unique, so don't bother checking for an existing node.
createdNode = new NodeAnnotation(createdPart);
// For edit mode. This should only happen on first application of the create action, and should only be possible if visibility is already correct.
createdNode.setUserObject("");
if (model == null)
FilteredTreeModel.insertNodeIntoUnfilteredStatic(createdNode, container, index);
else
model.insertNodeIntoUnfiltered(createdNode, container, index);
} else // create was merged with change name/value
{
List<String> expanded = null;
if (model != null)
expanded = saveExpandedNodes(pet.tree, container);
container.build();
container.filter();
if (model != null && container.visible()) {
model.nodeStructureChanged(container);
restoreExpandedNodes(pet.tree, container, expanded);
}
createdNode = findClosest(container, names);
if (pet != null) {
TreeNode[] parentPath = parent.getPath();
TreeNode[] createdPath = createdNode.getPath();
TreePath createdTreePath = new TreePath(createdPath);
pet.tree.expandPath(createdTreePath);
if (selectVariable)
pet.updateVisibility(parentPath, -2, !multi);
else
pet.updateVisibility(createdPath, -2, !multi);
if (multi) {
if (selectVariable)
pet.tree.addSelectionPath(new TreePath(parentPath));
else
pet.tree.addSelectionPath(createdTreePath);
}
pet.animate();
}
}
update(parent, touchesPin, touchesCategory);
return createdNode;
}
Aggregations