Search in sources :

Example 21 with StateEdit

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();
    }
}
Also used : ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) OVTK2Filter(net.sourceforge.ondex.ovtk2.filter.OVTK2Filter) Filter(net.sourceforge.ondex.filter.datasource.Filter) OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) StateEdit(javax.swing.undo.StateEdit) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo) DataSource(net.sourceforge.ondex.core.DataSource)

Example 22 with StateEdit

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();
    }
}
Also used : EvidenceType(net.sourceforge.ondex.core.EvidenceType) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) OVTK2Filter(net.sourceforge.ondex.ovtk2.filter.OVTK2Filter) Filter(net.sourceforge.ondex.filter.evidencetype.Filter) OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) StateEdit(javax.swing.undo.StateEdit) InvalidPluginArgumentException(net.sourceforge.ondex.InvalidPluginArgumentException) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo)

Example 23 with StateEdit

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;
    }
}
Also used : IntegerStringWrapper(net.sourceforge.ondex.ovtk2.util.IntegerStringWrapper) JComboBox(javax.swing.JComboBox) OVTK2Desktop(net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop) DefaultTableModel(javax.swing.table.DefaultTableModel) ONDEXPluginArguments(net.sourceforge.ondex.ONDEXPluginArguments) StateEdit(javax.swing.undo.StateEdit) InvalidPluginArgumentException(net.sourceforge.ondex.InvalidPluginArgumentException) VisibilityUndo(net.sourceforge.ondex.ovtk2.graph.VisibilityUndo) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) OVTK2Filter(net.sourceforge.ondex.ovtk2.filter.OVTK2Filter) Filter(net.sourceforge.ondex.filter.tag.Filter) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) ONDEXLogger(net.sourceforge.ondex.logging.ONDEXLogger)

Aggregations

StateEdit (javax.swing.undo.StateEdit)23 VisibilityUndo (net.sourceforge.ondex.ovtk2.graph.VisibilityUndo)23 ONDEXConcept (net.sourceforge.ondex.core.ONDEXConcept)21 ONDEXRelation (net.sourceforge.ondex.core.ONDEXRelation)20 OVTK2Desktop (net.sourceforge.ondex.ovtk2.ui.OVTK2Desktop)16 ONDEXPluginArguments (net.sourceforge.ondex.ONDEXPluginArguments)13 OVTK2Filter (net.sourceforge.ondex.ovtk2.filter.OVTK2Filter)12 HashSet (java.util.HashSet)7 PropertyVetoException (java.beans.PropertyVetoException)4 ConceptClass (net.sourceforge.ondex.core.ConceptClass)4 ONDEXLogger (net.sourceforge.ondex.logging.ONDEXLogger)4 InvalidPluginArgumentException (net.sourceforge.ondex.InvalidPluginArgumentException)3 RelationType (net.sourceforge.ondex.core.RelationType)3 BitSet (java.util.BitSet)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JComboBox (javax.swing.JComboBox)2 DefaultTableModel (javax.swing.table.DefaultTableModel)2 Attribute (net.sourceforge.ondex.core.Attribute)2 IntegerStringWrapper (net.sourceforge.ondex.ovtk2.util.IntegerStringWrapper)2