use of gov.sandia.n2a.ui.eq.PanelEquationTree in project n2a by frothga.
the class AddAnnotation method destroy.
public static void destroy(List<String> path, boolean canceled, String name, String prefix, boolean multi, boolean multiLast, boolean selectVariable, boolean touchesPin, boolean touchesCategory) {
// Retrieve created node
NodeContainer parent = (NodeContainer) NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
NodeBase createdNode = findClosest(parent, name.split("\\."));
if (createdNode == parent)
throw new CannotUndoException();
// Update database
MPart mparent = parent.source;
if (parent instanceof NodeVariable)
mparent = (MPart) mparent.child("$metadata");
else if (parent instanceof NodeAnnotation)
mparent = ((NodeAnnotation) parent).folded;
// else parent is a NodeAnnotations, so mparent is $metadata, which should be used directly.
boolean killBlock = false;
if (!prefix.isEmpty()) {
String[] names = prefix.split("\\.");
mparent.clear(names);
if (mparent.key().equals("$metadata") && mparent.size() == 0) {
mparent.parent().clear("$metadata");
killBlock = true;
}
}
// Update GUI
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = null;
if (pet != null)
model = (FilteredTreeModel) pet.tree.getModel();
TreeNode[] createdPath = createdNode.getPath();
int index = parent.getIndexFiltered(createdNode);
if (canceled)
index--;
if (// We just emptied $metadata, so remove the node.
killBlock && parent instanceof NodeAnnotations) {
if (model == null)
FilteredTreeModel.removeNodeFromParentStatic(parent);
else
model.removeNodeFromParent(parent);
// No need to update order, because we just destroyed $metadata, where order is stored.
// No need to update tab stops in grandparent, because block nodes don't offer any tab stops.
} else // Rebuild container (variable, metadata block, or annotation)
{
List<String> expanded = null;
if (model != null)
expanded = saveExpandedNodes(pet.tree, parent);
parent.build();
parent.filter();
if (model != null && parent.visible()) {
model.nodeStructureChanged(parent);
restoreExpandedNodes(pet.tree, parent, expanded);
}
}
if (pet != null) {
TreeNode[] parentPath = parent.getPath();
if (selectVariable)
pet.updateVisibility(parentPath, index, !multi);
else
pet.updateVisibility(createdPath, index, !multi || multiLast);
// Assumes nodeAfter is directly under a NodeVariable. Note that effect will be redundant with above when multiLast is true.
if (multi && selectVariable)
pet.tree.addSelectionPath(new TreePath(parentPath));
pet.animate();
}
update(parent, touchesPin, touchesCategory);
}
use of gov.sandia.n2a.ui.eq.PanelEquationTree in project n2a by frothga.
the class AddEquation method create.
public static NodeBase create(List<String> path, int equationCount, int index, String name, String combinerAfter, String value, boolean multi) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
// Update the database
String parentValueBefore = parent.source.get();
Variable.ParsedValue parentPiecesBefore = new Variable.ParsedValue(parentValueBefore);
// The minimum number of equations is 2. There should never be exactly 1 equation, because that is single-line form, which should have no child equations at all.
if (// We are about to switch from single-line form to multi-conditional, so make a tree node for the existing equation.
equationCount == 0) {
MPart equation = (MPart) parent.source.set(parentPiecesBefore.expression, "@" + parentPiecesBefore.condition);
model.insertNodeIntoUnfiltered(new NodeEquation(equation), parent, 0);
}
MPart createdPart = (MPart) parent.source.set(value == null ? "0" : value, name);
boolean parentChanged = false;
if (!combinerAfter.equals(parentValueBefore)) {
parent.source.set(combinerAfter);
parentChanged = true;
}
// Update the GUI
NodeBase createdNode = parent.child(name);
boolean alreadyExists = createdNode != null;
if (!alreadyExists)
createdNode = new NodeEquation(createdPart);
if (value == null)
createdNode.setUserObject("");
if (!alreadyExists)
model.insertNodeIntoUnfiltered(createdNode, parent, index);
if (parentChanged) {
parent.setUserObject();
NodeBase grandparent = (NodeBase) parent.getParent();
grandparent.invalidateColumns(model);
}
if (// create was merged with change name/value
value != null) {
parent.invalidateColumns(null);
TreeNode[] createdPath = createdNode.getPath();
pet.updateVisibility(createdPath, -2, !multi);
if (multi)
pet.tree.addSelectionPath(new TreePath(createdPath));
parent.allNodesChanged(model);
pet.animate();
}
return createdNode;
}
use of gov.sandia.n2a.ui.eq.PanelEquationTree in project n2a by frothga.
the class AddAnnotations method create.
public static NodeBase create(List<String> path, int index, MNode saved, NodeFactory factory, boolean multi, boolean touchesPin, boolean touchesCategory) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
String blockName = saved.key();
NodeBase n = parent.child(blockName);
if (n != null && !(n instanceof NodeContainer))
throw new CannotRedoException();
NodeContainer node = (NodeContainer) n;
MPart block = (MPart) parent.source.childOrCreate(blockName);
block.merge(saved);
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
if (node == null) {
node = (NodeContainer) factory.create(block);
model.insertNodeIntoUnfiltered(node, parent, index);
}
// Replaces all nodes, so they are set to require tab initialization.
node.build();
node.filter();
TreeNode[] nodePath = node.getPath();
pet.updateVisibility(nodePath, -2, !multi);
if (multi)
pet.tree.addSelectionPath(new TreePath(nodePath));
pet.animate();
if (blockName.equals("$metadata"))
AddAnnotation.update(parent, touchesPin, touchesCategory);
return node;
}
use of gov.sandia.n2a.ui.eq.PanelEquationTree in project n2a by frothga.
the class AddInherit method destroy.
public static void destroy(List<String> path, boolean canceled) {
NodePart parent = (NodePart) NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
NodePart grandparent = (NodePart) parent.getTrueParent();
NodeBase node = parent.child("$inherit");
TreeNode[] nodePath = node.getPath();
int index = parent.getIndexFiltered(node);
if (canceled)
index--;
PanelEquations pe = PanelModel.instance.panelEquations;
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
PanelEquationGraph peg = pe.panelEquationGraph;
MPart mparent = parent.source;
// Complex restructuring happens here.
mparent.clear("$inherit");
// Handles all cases (complete deletion or exposed hidden node)
parent.build();
if (grandparent == null)
parent.findConnections();
else
grandparent.findConnections();
parent.rebuildPins();
parent.filter();
if (parent == pe.part) {
// safely disconnects old nodes, even though parent has been rebuilt with new nodes
peg.reloadPart();
// Ensure that parts are not visible in parent panel.
parent.filter();
}
// Presumably, part node is still visible. Is there any harm in doing this if it is not?
model.nodeStructureChanged(parent);
pet.updateOrder(nodePath);
pet.updateVisibility(nodePath, index);
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 AddReference method create.
public static NodeBase create(List<String> path, int index, String name, String value, boolean multi) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotRedoException();
MPart block = (MPart) parent.source.childOrCreate("$reference");
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = (FilteredTreeModel) pet.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 = new NodeReferences(block);
model.insertNodeIntoUnfiltered(container, parent, index);
index = 0;
} else // the node is present, so retrieve it
{
container = parent.child("$reference");
}
}
NodeBase createdNode = container.child(name);
boolean alreadyExists = createdNode != null;
MPart createdPart = (MPart) block.set(value, name);
if (!alreadyExists)
createdNode = new NodeReference(createdPart);
// 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("");
if (!alreadyExists)
model.insertNodeIntoUnfiltered(createdNode, container, index);
if (// create was merged with change name/value
value != null) {
container.invalidateColumns(null);
TreeNode[] createdPath = createdNode.getPath();
pet.updateOrder(createdPath);
pet.updateVisibility(createdPath, -2, !multi);
if (multi)
pet.tree.addSelectionPath(new TreePath(createdPath));
container.allNodesChanged(model);
pet.animate();
}
return createdNode;
}
Aggregations