use of javax.swing.undo.StateEdit in project knetbuilder by Rothamsted.
the class DataSourceFilter method callFilter.
/**
* Calls backend filter.
*/
private void callFilter() throws InvalidPluginArgumentException {
if (targets != null && targets.size() > 0) {
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);
for (DataSource target : targets) {
fa.addOption(Filter.DATASOURCE_ARG, target.getId());
}
filter.setONDEXGraph(graph);
filter.setArguments(fa);
// execute filter
filter.start();
// get results from filter
Set<ONDEXConcept> concepts = BitSetFunctions.andNot(graph.getConcepts(), filter.getVisibleConcepts());
Set<ONDEXRelation> relations = BitSetFunctions.andNot(graph.getRelations(), filter.getVisibleRelations());
// check for visibility selection
if (visibility) {
// first set concepts visible
for (ONDEXConcept c : concepts) {
graph.setVisibility(c, true);
}
// second set relations visible
for (ONDEXRelation r : relations) {
graph.setVisibility(r, true);
}
} else {
// change visibility of relations
for (ONDEXRelation r : relations) {
graph.setVisibility(r, false);
}
// change visibility of concepts
for (ONDEXConcept c : concepts) {
graph.setVisibility(c, false);
}
}
// 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 EvidenceTypeFilter method callFilter.
/**
* Calls backend filter.
*/
private void callFilter() throws InvalidPluginArgumentException {
if (targets != null && targets.size() > 0) {
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);
fa.addOption(Filter.CONCEPTS_ARG, onConcepts);
Iterator<EvidenceType> it = targets.iterator();
while (it.hasNext()) {
fa.addOption(Filter.ET_ARG, it.next().getId());
}
filter.setONDEXGraph(graph);
filter.setArguments(fa);
// execute filter
try {
filter.start();
} catch (Exception e) {
// JOptionPane.showInternalMessageDialog(null, e.getMessage());
ErrorDialog.show(e);
}
// get results from filter
Set<ONDEXConcept> concepts = BitSetFunctions.andNot(graph.getConcepts(), filter.getVisibleConcepts());
Set<ONDEXRelation> relations = BitSetFunctions.andNot(graph.getRelations(), filter.getVisibleRelations());
// check for visibility selection
if (visibility) {
if (onConcepts) {
// change visibility of concepts
for (ONDEXConcept c : concepts) {
graph.setVisibility(c, true);
}
} else {
// change visibility of relations
for (ONDEXRelation r : relations) {
graph.setVisibility(r.getFromConcept(), true);
graph.setVisibility(r.getToConcept(), true);
graph.setVisibility(r, true);
}
}
} else {
if (onConcepts) {
// change visibility of concepts
for (ONDEXConcept c : concepts) {
graph.setVisibility(c, false);
}
} else {
// change visibility of relations
for (ONDEXRelation r : relations) {
graph.setVisibility(r, false);
}
}
}
// 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 TagFilter method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if (cmd.contains(TAG_CC_TYPE)) {
JComboBox typeBox = (JComboBox) e.getSource();
if (typeBox.getSelectedItem() != null) {
table.getCellEditor(table.getModel().getRowCount() - 1, 0).stopCellEditing();
String type = typeBox.getSelectedItem().toString();
updateContext(type, tagBox);
}
} else if (cmd.equals(ADD)) {
// add a new default row to the table
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.addRow(new Object[] { Config.language.getProperty(TAG_FIRST_LINE), operationBox.getItemAt(0) });
} else if (cmd.equals(APPLY)) {
StateEdit edit = new StateEdit(new VisibilityUndo(viewer.getONDEXJUNGGraph()), this.getName());
OVTK2Desktop desktop = OVTK2Desktop.getInstance();
desktop.setRunningProcess(this.getName());
Set<ONDEXConcept> concepts = null;
Set<ONDEXRelation> relations = null;
for (int row = 0; row < table.getModel().getRowCount(); row++) {
// check if tag was selected
if (!table.getModel().getValueAt(row, 0).equals(Config.language.getProperty(TAG_FIRST_LINE))) {
// get value from table
IntegerStringWrapper tag = (IntegerStringWrapper) table.getModel().getValueAt(row, 0);
ONDEXConcept concept = graph.getConcept(tag.getValue());
Filter filter = new Filter();
try {
ONDEXPluginArguments fa = new ONDEXPluginArguments(filter.getArgumentDefinitions());
fa.addOption(ArgumentNames.TAG_ARG, concept.getId());
filter.addONDEXListener(new ONDEXLogger());
filter.setONDEXGraph(graph);
filter.setArguments(fa);
filter.start();
} catch (InvalidPluginArgumentException e1) {
e1.printStackTrace();
}
// store visible relations
if (row == 0) {
concepts = BitSetFunctions.copy(filter.getVisibleConcepts());
relations = BitSetFunctions.copy(filter.getVisibleRelations());
} else {
// operator from previous row more logical
String operation = (String) table.getModel().getValueAt(row - 1, 1);
// and operator
if (operation.equals(AND)) {
concepts.retainAll(filter.getVisibleConcepts());
relations.retainAll(filter.getVisibleRelations());
}
// or operator
if (operation.equals(OR)) {
concepts.addAll(filter.getVisibleConcepts());
relations.addAll(filter.getVisibleRelations());
}
// not operator
if (operation.equals(NOT)) {
concepts.removeAll(filter.getVisibleConcepts());
relations.removeAll(filter.getVisibleRelations());
}
}
} else {
// first row means everything reset
if (row == 0) {
// set entire graph to visible if filter == none
setGraphVisible(true);
// propagate change to viewer
viewer.getVisualizationViewer().getModel().fireStateChanged();
}
}
}
if (concepts != null) {
// set first entire graph to invisible
setGraphVisible(false);
// set only graph returned by filter to visible
setGraphVisible(concepts, relations);
if (showRelations.isSelected()) {
Collection<ONDEXConcept> visible = graph.getVertices();
for (ONDEXRelation r : graph.getRelations()) {
if (visible.contains(r.getToConcept()) && visible.contains(r.getFromConcept())) {
graph.setVisibility(r, true);
}
}
}
// propagate change to viewer
viewer.getVisualizationViewer().getModel().fireStateChanged();
}
edit.end();
viewer.getUndoManager().addEdit(edit);
desktop.getOVTK2Menu().updateUndoRedo(viewer);
desktop.notifyTerminationOfProcess();
used = true;
}
}
Aggregations