use of javax.swing.undo.StateEdit in project knetbuilder by Rothamsted.
the class SubGraphFilter method callFilter.
private void callFilter() throws InvalidPluginArgumentException {
StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
OVTK2Desktop desktop = OVTK2Desktop.getInstance();
desktop.setRunningProcess(this.getName());
// contains results
Set<ONDEXConcept> concepts = null;
Set<ONDEXRelation> relations = null;
// get user choices
PickedState<ONDEXMetaConcept> ccPI = visviewer.getPickedVertexState();
PickedState<ONDEXMetaRelation> rtPI = visviewer.getPickedEdgeState();
// seed nodes from viewer start subgraph at each of them
for (Object o : nodeSelection.getSelectedValuesList()) {
ONDEXConcept root = ((ONDEXNodeWrapper) o).node;
ConceptClass rootCC = root.getOfType();
// execute filter
Filter filter = new Filter();
ONDEXPluginArguments fa = new ONDEXPluginArguments(filter.getArgumentDefinitions());
fa.addOption(ArgumentNames.ROOT_ARG, root.getId());
// graph traversal to identify selected concept classes
for (ONDEXMetaConcept mc : meta.getVertices()) {
// found root, make sure its still picked
if (mc.getMetaData().equals(rootCC) && ccPI.isPicked(mc)) {
seenConcepts = new HashSet<ONDEXMetaConcept>();
seenRelations = new HashSet<ONDEXMetaRelation>();
traverseGraph(fa, ccPI, rtPI, mc);
}
}
filter.setArguments(fa);
filter.setONDEXGraph(graph);
try {
filter.start();
} catch (Exception e) {
e.printStackTrace();
}
// concatenate results
if (concepts == null) {
concepts = filter.getVisibleConcepts();
relations = filter.getVisibleRelations();
} else {
concepts = BitSetFunctions.or(concepts, filter.getVisibleConcepts());
relations = BitSetFunctions.or(relations, filter.getVisibleRelations());
}
}
// show results in graph
if (concepts != null) {
// set all relations to invisible
graph.setVisibility(graph.getRelations(), false);
// set all concepts to invisible
graph.setVisibility(graph.getConcepts(), false);
// first set concepts visible
graph.setVisibility(concepts, true);
// second set relations visible
graph.setVisibility(relations, true);
// propagate change to viewer
viewer.getVisualizationViewer().getModel().fireStateChanged();
}
edit.end();
viewer.getUndoManager().addEdit(edit);
desktop.getOVTK2Menu().updateUndoRedo(viewer);
desktop.notifyTerminationOfProcess();
}
use of javax.swing.undo.StateEdit in project knetbuilder by Rothamsted.
the class DialogEdges method actionPerformed.
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent arg0) {
String cmd = arg0.getActionCommand();
// sync visibility
if (cmd.equals("apply")) {
StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
// this is for edge visibility
Map<ONDEXRelation, Boolean> visible = model.getData();
for (ONDEXRelation relation : visible.keySet()) {
graph.setVisibility(relation, visible.get(relation));
}
viewer.getVisualizationViewer().getModel().fireStateChanged();
edit.end();
viewer.getUndoManager().addEdit(edit);
OVTK2Desktop.getInstance().getOVTK2Menu().updateUndoRedo(viewer);
} else // cancel dialog
if (cmd.equals("cancel")) {
try {
this.setClosed(true);
} catch (PropertyVetoException e) {
ErrorDialog.show(e);
}
} else // load visible flags from Attribute
if (cmd.equals("load")) {
// clear existing visibility list
Map<ONDEXRelation, Boolean> visible = model.getData();
for (ONDEXRelation key : visible.keySet()) {
visible.put(key, false);
}
// fill from Attribute
for (ONDEXRelation relation : graph.getRelationsOfAttributeName(an)) {
Attribute attribute = relation.getAttribute(an);
visible.put(relation, (Boolean) attribute.getValue());
}
// clear existing visibility list
elv.clear();
// fill from Attribute
for (ONDEXRelation relation : graph.getRelationsOfAttributeName(anELV)) {
Attribute attribute = relation.getAttribute(anELV);
elv.put(relation, ((Boolean) attribute.getValue()).booleanValue());
}
model.fireTableDataChanged();
} else // store visible flags to Attribute
if (cmd.equals("store")) {
Map<ONDEXRelation, Boolean> visible = model.getData();
for (ONDEXRelation relation : visible.keySet()) {
Attribute attribute = relation.getAttribute(an);
// set edge visibility
if (attribute == null) {
relation.createAttribute(an, visible.get(relation), false);
} else {
attribute.setValue(visible.get(relation));
}
// set label visibility
attribute = relation.getAttribute(anELV);
if (attribute == null) {
relation.createAttribute(anELV, elv.get(relation), false);
} else {
attribute.setValue(elv.get(relation));
}
}
} else // toggle all visible
if (cmd.equals("visible")) {
if (visibleAll.getText().equals(Config.language.getProperty("Dialog.Edges.SelectAllVisible"))) {
for (int x = 0, y = table.getRowCount(); x < y; x++) {
table.setValueAt(true, x, table.convertColumnIndexToView(3));
}
visibleAll.setText(Config.language.getProperty("Dialog.Edges.DeSelectAllVisible"));
} else if (visibleAll.getText().equals(Config.language.getProperty("Dialog.Edges.DeSelectAllVisible"))) {
for (int x = 0, y = table.getRowCount(); x < y; x++) {
table.setValueAt(false, x, table.convertColumnIndexToView(3));
}
visibleAll.setText(Config.language.getProperty("Dialog.Edges.SelectAllVisible"));
}
visibleAll.repaint();
} else // toggle all labels
if (cmd.equals("labels")) {
if (labelsAll.getText().equals(Config.language.getProperty("Dialog.Edges.SelectAllLabels"))) {
for (int x = 0, y = table.getRowCount(); x < y; x++) {
table.setValueAt(true, x, table.convertColumnIndexToView(4));
}
labelsAll.setText(Config.language.getProperty("Dialog.Edges.DeSelectAllLabels"));
} else if (labelsAll.getText().equals(Config.language.getProperty("Dialog.Edges.DeSelectAllLabels"))) {
for (int x = 0, y = table.getRowCount(); x < y; x++) {
table.setValueAt(false, x, table.convertColumnIndexToView(4));
}
labelsAll.setText(Config.language.getProperty("Dialog.Edges.SelectAllLabels"));
}
labelsAll.repaint();
}
}
use of javax.swing.undo.StateEdit in project knetbuilder by Rothamsted.
the class DialogNodes method actionPerformed.
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent arg0) {
String cmd = arg0.getActionCommand();
// sync visibility
if (cmd.equals("apply")) {
StateEdit edit = new StateEdit(new VisibilityUndo(graph), this.getName());
// this is for node visibility
Map<ONDEXConcept, Boolean> visible = model.getData();
for (ONDEXConcept concept : visible.keySet()) {
graph.setVisibility(concept, visible.get(concept));
}
// backward sync just in case
Set<ONDEXConcept> visibleSet = new HashSet<ONDEXConcept>();
for (ONDEXConcept concept : graph.getConcepts()) {
if (graph.isVisible(concept))
visibleSet.add(concept);
}
// include neighbours of given level
int levelValue = (Integer) level.getValue();
BitSet expanded = new BitSet();
if (levelValue > 0) {
for (ONDEXConcept concept : visibleSet) {
BitSet[] temp = StandardFunctions.getNeighboursAtLevel(concept, graph, levelValue);
expanded.or(temp[0]);
}
for (int i = expanded.nextSetBit(0); i >= 0; i = expanded.nextSetBit(i + 1)) visibleSet.add(graph.getConcept(i));
}
// set neighbours visible too
for (ONDEXConcept concept : visibleSet) graph.setVisibility(concept, true);
// update node labels with new mask
viewer.getVisualizationViewer().getModel().fireStateChanged();
edit.end();
viewer.getUndoManager().addEdit(edit);
OVTK2Desktop.getInstance().getOVTK2Menu().updateUndoRedo(viewer);
} else // cancel dialog
if (cmd.equals("cancel")) {
try {
this.setClosed(true);
} catch (PropertyVetoException e) {
ErrorDialog.show(e);
}
} else // load visible flags from Attribute
if (cmd.equals("load")) {
// clear existing visibility list
Map<ONDEXConcept, Boolean> visible = model.getData();
for (ONDEXConcept concept : visible.keySet()) {
visible.put(concept, false);
}
// fill from Attribute
for (ONDEXConcept concept : graph.getConceptsOfAttributeName(an)) {
Attribute attribute = concept.getAttribute(an);
visible.put(concept, (Boolean) attribute.getValue());
}
// clear existing visibility list
nlv.clear();
// fill from Attribute
for (ONDEXConcept concept : graph.getConceptsOfAttributeName(anNLV)) {
Attribute attribute = concept.getAttribute(anNLV);
nlv.put(concept, ((Boolean) attribute.getValue()).booleanValue());
}
model.fireTableDataChanged();
} else // store visible flags to Attribute
if (cmd.equals("store")) {
Map<ONDEXConcept, Boolean> visible = model.getData();
for (ONDEXConcept concept : visible.keySet()) {
Attribute attribute = concept.getAttribute(an);
// set node visibility
if (attribute == null) {
concept.createAttribute(an, visible.get(concept), false);
} else {
attribute.setValue(visible.get(concept));
}
// set label visibility
attribute = concept.getAttribute(anNLV);
if (attribute == null) {
concept.createAttribute(anNLV, nlv.get(concept), false);
} else {
attribute.setValue(nlv.get(concept));
}
}
} else // toggle all visible
if (cmd.equals("visible")) {
if (visibleAll.getText().equals(Config.language.getProperty("Dialog.Nodes.SelectAllVisible"))) {
for (int x = 0, y = table.getRowCount(); x < y; x++) {
table.setValueAt(true, x, table.convertColumnIndexToView(3));
}
visibleAll.setText(Config.language.getProperty("Dialog.Nodes.DeSelectAllVisible"));
} else if (visibleAll.getText().equals(Config.language.getProperty("Dialog.Nodes.DeSelectAllVisible"))) {
for (int x = 0, y = table.getRowCount(); x < y; x++) {
table.setValueAt(false, x, table.convertColumnIndexToView(3));
}
visibleAll.setText(Config.language.getProperty("Dialog.Nodes.SelectAllVisible"));
}
visibleAll.repaint();
} else // toggle all labels
if (cmd.equals("labels")) {
if (labelsAll.getText().equals(Config.language.getProperty("Dialog.Nodes.SelectAllLabels"))) {
for (int x = 0, y = table.getRowCount(); x < y; x++) {
table.setValueAt(true, x, table.convertColumnIndexToView(4));
}
labelsAll.setText(Config.language.getProperty("Dialog.Nodes.DeSelectAllLabels"));
} else if (labelsAll.getText().equals(Config.language.getProperty("Dialog.Nodes.DeSelectAllLabels"))) {
for (int x = 0, y = table.getRowCount(); x < y; x++) {
table.setValueAt(false, x, table.convertColumnIndexToView(4));
}
labelsAll.setText(Config.language.getProperty("Dialog.Nodes.SelectAllLabels"));
}
labelsAll.repaint();
}
}
use of javax.swing.undo.StateEdit in project knetbuilder by Rothamsted.
the class AttributeValueFilter method actionPerformed.
@Override
public void actionPerformed(ActionEvent ae) {
StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
OVTK2Desktop desktop = OVTK2Desktop.getInstance();
desktop.setRunningProcess(this.getName());
Filter filter = new Filter();
filter.addONDEXListener(this);
try {
ONDEXPluginArguments fa = new ONDEXPluginArguments(filter.getArgumentDefinitions());
fa.addOption(ArgumentNames.ATTRNAME_ARG, target.getId());
for (int index : values.getSelectedIndices()) {
fa.addOption(ArgumentNames.VALUE_ARG, vlm.getObjectAt(index).toString());
}
fa.addOption(ArgumentNames.OPERATOR_ARG, "=");
fa.addOption(ArgumentNames.INCLUDING_ARG, Boolean.FALSE);
fa.addOption(ArgumentNames.MODULUS_ARG, Boolean.FALSE);
filter.setArguments(fa);
filter.setONDEXGraph(graph);
filter.start();
} catch (Exception e) {
ErrorDialog.show(e);
}
for (ONDEXRelation r : filter.getInVisibleRelations()) {
graph.setVisibility(r, visibility);
}
for (ONDEXConcept c : filter.getInVisibleConcepts()) {
graph.setVisibility(c, visibility);
}
viewer.getVisualizationViewer().getModel().fireStateChanged();
edit.end();
viewer.getUndoManager().addEdit(edit);
desktop.getOVTK2Menu().updateUndoRedo(viewer);
desktop.notifyTerminationOfProcess();
used = true;
}
use of javax.swing.undo.StateEdit in project knetbuilder by Rothamsted.
the class ConceptClassFilter method callFilter.
/**
* Calls backend filter.
*/
private void callFilter() throws InvalidPluginArgumentException {
// this is the exit condition just to make sure
if (conceptClassTargets == null || conceptClassTargets.size() == 0)
return;
// now start now undo edit
StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
OVTK2Desktop desktop = OVTK2Desktop.getInstance();
desktop.setRunningProcess(this.getName());
// new instance of filter and set arguments
Filter filter = new Filter();
// construct filter arguments
ONDEXPluginArguments fa = new ONDEXPluginArguments(filter.getArgumentDefinitions());
fa.addOption(Filter.EXCLUDE_ARG, true);
// add all concept class restrictions
Iterator<ConceptClass> it = conceptClassTargets.iterator();
while (it.hasNext()) {
fa.addOption(Filter.TARGETCC_ARG, it.next().getId());
}
// optional data source restriction
if (dataSourceList.getSelectedValue() != null) {
fa.addOption(Filter.FILTER_CV_ARG, dataSourceListModel.getDataSourceAt(dataSourceList.getSelectedIndex()).getId());
}
// set filter arguments
filter.setONDEXGraph(graph);
filter.setArguments(fa);
// execute filter
filter.start();
// get results from filter
Set<ONDEXConcept> concepts = filter.getInVisibleConcepts();
Set<ONDEXRelation> relations = filter.getInVisibleRelations();
// check for visibility selection
if (visibility) {
graph.setVisibility(concepts, true);
graph.setVisibility(relations, true);
} else {
graph.setVisibility(relations, false);
graph.setVisibility(concepts, false);
}
// propagate change to viewer
viewer.getVisualizationViewer().getModel().fireStateChanged();
edit.end();
viewer.getUndoManager().addEdit(edit);
desktop.getOVTK2Menu().updateUndoRedo(viewer);
desktop.notifyTerminationOfProcess();
}
Aggregations