use of gov.sandia.n2a.ui.eq.undo.DeleteAnnotation in project n2a by frothga.
the class PanelEquationTree method watchSelected.
public void watchSelected(boolean clearOthers) {
if (container.locked)
return;
TreePath[] paths = tree.getSelectionPaths();
if (paths == null)
return;
TreePath leadPath = tree.getLeadSelectionPath();
NodeVariable leadVariable = null;
List<NodeVariable> variables = new ArrayList<NodeVariable>(paths.length);
for (TreePath path : paths) {
NodeBase n = (NodeBase) path.getLastPathComponent();
// Make one attempt to walk up tree, in case an equation or metadata item is selected under a variable.
if (!(n instanceof NodeVariable))
n = (NodeBase) n.getParent();
if (!(n instanceof NodeVariable))
continue;
NodeVariable v = (NodeVariable) n;
if (v.isBinding)
continue;
variables.add(v);
if (path.equals(leadPath))
leadVariable = v;
}
if (clearOthers)
findExistingWatches(container.root, variables);
UndoManager um = MainFrame.instance.undoManager;
CompoundEditView compound = null;
boolean multi = variables.size() > 1;
if (multi)
um.addEdit(compound = new CompoundEditView(CompoundEditView.CLEAR_TREE));
for (NodeVariable v : variables) {
// Toggle watch on the selected variable
boolean selectVariable = multi || tree.isCollapsed(new TreePath(v.getPath()));
MPart watch = (MPart) v.source.child("$metadata", "watch");
if (watch != null) {
NodeAnnotation watchNode = (NodeAnnotation) v.child("watch");
if (// currently on, so turn it off
watch.isFromTopDocument()) {
DeleteAnnotation d = new DeleteAnnotation(watchNode, false);
d.selectVariable = selectVariable;
if (multi)
compound.addEdit(d);
else
um.apply(d);
} else // Currently off, because it is not explicitly set in this document. Turn it on by overriding it locally.
{
ChangeAnnotation c = new ChangeAnnotation(watchNode, "watch", "");
c.selectVariable = selectVariable;
if (multi)
compound.addEdit(c);
else
um.apply(c);
}
} else // currently off, so turn it on
{
AddAnnotation a = new AddAnnotation(v, v.getChildCount(), new MVolatile("", "watch"));
a.selectVariable = selectVariable;
if (multi)
compound.addEdit(a);
else
um.apply(a);
}
}
if (multi) {
um.endCompoundEdit();
if (leadVariable != null)
compound.leadPath = leadVariable.getKeyPath();
compound.redo();
}
}
Aggregations