Search in sources :

Example 16 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class SelectAdjacentEdgesTaskTest method testRun.

@Test
public void testRun() throws Exception {
    UndoSupport undoSupport = mock(UndoSupport.class);
    when(r3.get("selected", Boolean.class)).thenReturn(true);
    when(r4.get("selected", Boolean.class)).thenReturn(false);
    Set<Long> selectedNodes = new HashSet<>();
    selectedNodes.add(r3.get(CyNetwork.SUID, Long.class));
    when(nodeTable.getMatchingKeys(CyNetwork.SELECTED, true, Long.class)).thenReturn(selectedNodes);
    List<CyEdge> el = new ArrayList<CyEdge>();
    el.add(e1);
    when(net.getAdjacentEdgeList(e3, CyEdge.Type.ANY)).thenReturn(el);
    // run the task
    Task t = new SelectAdjacentEdgesTask(undoSupport, net, networkViewManager, eventHelper);
    t.run(tm);
    // check that the expected rows were set
    verify(r1, times(1)).set("selected", true);
}
Also used : Task(org.cytoscape.work.Task) ArrayList(java.util.ArrayList) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyEdge(org.cytoscape.model.CyEdge) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class SelectFirstNeighborsTaskTest method testRun.

@Test
public void testRun() throws Exception {
    UndoSupport undoSupport = mock(UndoSupport.class);
    // more setup
    when(r3.get("selected", Boolean.class)).thenReturn(true);
    when(r4.get("selected", Boolean.class)).thenReturn(false);
    Set<Long> selectedNodes = new HashSet<>();
    selectedNodes.add(r3.get(CyNetwork.SUID, Long.class));
    when(nodeTable.getMatchingKeys(CyNetwork.SELECTED, true, Long.class)).thenReturn(selectedNodes);
    List<CyNode> nl = new ArrayList<CyNode>();
    nl.add(e4);
    when(net.getNeighborList(e3, CyEdge.Type.ANY)).thenReturn(nl);
    // run the task
    Task t = new SelectFirstNeighborsTask(undoSupport, net, networkViewManager, eventHelper, CyEdge.Type.ANY);
    t.run(tm);
    // check that the expected rows were set
    verify(r4, times(1)).set("selected", true);
}
Also used : Task(org.cytoscape.work.Task) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) UndoSupport(org.cytoscape.work.undo.UndoSupport) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class HideFromSelectionTask method run.

@Override
public void run(final TaskMonitor tm) {
    tm.setProgress(0.0);
    final CyNetwork network = view.getModel();
    final List<CyIdentifiable> elements = new ArrayList<>();
    List<CyNode> nodes = null;
    List<CyEdge> edges = null;
    if (hideNodes) {
        nodes = CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, selectionValue);
        elements.addAll(nodes);
    }
    tm.setProgress(0.1);
    if (hideEdges) {
        edges = CyTableUtil.getEdgesInState(network, CyNetwork.SELECTED, selectionValue);
        elements.addAll(edges);
    }
    final UndoSupport undoSupport = serviceRegistrar.getService(UndoSupport.class);
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    undoSupport.postEdit(new HideEdit(description, view, elements, false, eventHelper, vmMgr));
    tm.setProgress(0.4);
    if (nodes != null)
        HideUtils.setVisibleNodes(nodes, false, view);
    tm.setProgress(0.6);
    if (edges != null)
        HideUtils.setVisibleEdges(edges, false, view);
    tm.setProgress(0.8);
    VisualStyle style = vmMgr.getVisualStyle(view);
    for (CyIdentifiable e : elements) {
        View<? extends CyIdentifiable> ev = null;
        if (e instanceof CyNode)
            ev = view.getNodeView((CyNode) e);
        else if (e instanceof CyEdge)
            ev = view.getEdgeView((CyEdge) e);
        if (ev != null)
            style.apply(network.getRow(e), ev);
    }
    view.updateView();
    tm.setProgress(1.0);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 19 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class GenerateDiscreteValuesAction method actionPerformed.

// ==[ PUBLIC METHODS ]=============================================================================================
@Override
public void actionPerformed(final ActionEvent e) {
    final VisualPropertySheet selVpSheet = getVizMapperMainPanel().getSelectedVisualPropertySheet();
    if (selVpSheet == null)
        return;
    final Set<VisualPropertySheetItem<?>> vpSheetItems = selVpSheet.getSelectedItems();
    new Thread() {

        @Override
        public void run() {
            final Map<DiscreteMapping<?, ?>, Map<Object, Object>> previousMappingValues = new HashMap<DiscreteMapping<?, ?>, Map<Object, Object>>();
            final Map<DiscreteMapping<?, ?>, Map<Object, ?>> newMappingValues = new HashMap<DiscreteMapping<?, ?>, Map<Object, ?>>();
            for (final VisualPropertySheetItem<?> vpsItem : vpSheetItems) {
                final VisualPropertySheetItemModel<?> model = vpsItem.getModel();
                final VisualProperty<?> vp = (VisualProperty<?>) model.getVisualProperty();
                final Class<?> vpValueType = vp.getRange().getType();
                final Class<?> generatorType = generator.getDataType();
                final PropertySheetPanel propSheetPnl = vpsItem.getPropSheetPnl();
                final Item value = (Item) propSheetPnl.getTable().getValueAt(0, 0);
                if (value.isProperty()) {
                    final VizMapperProperty<?, ?, ?> prop = (VizMapperProperty<?, ?, ?>) value.getProperty();
                    if (vpValueType.isAssignableFrom(generatorType) || ((generator instanceof NumberSeriesMappingGenerator || generator instanceof RandomNumberMappingGenerator) && Number.class.isAssignableFrom(vpValueType)))
                        generateValues(vpsItem, prop.getValue().toString(), vp, previousMappingValues, newMappingValues);
                }
            }
            // Undo support
            if (!previousMappingValues.isEmpty()) {
                final UndoSupport undo = servicesUtil.get(UndoSupport.class);
                undo.postEdit(new GenerateValuesEdit(previousMappingValues, newMappingValues));
            }
        }
    }.start();
}
Also used : PropertySheetPanel(com.l2fprod.common.propertysheet.PropertySheetPanel) VisualPropertySheet(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheet) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) UndoSupport(org.cytoscape.work.undo.UndoSupport) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) VisualPropertySheetItemModel(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItemModel) Item(com.l2fprod.common.propertysheet.PropertySheetTableModel.Item) VisualPropertySheetItem(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem) NumberSeriesMappingGenerator(org.cytoscape.view.vizmap.gui.internal.util.mapgenerator.NumberSeriesMappingGenerator) VisualProperty(org.cytoscape.view.model.VisualProperty) RandomNumberMappingGenerator(org.cytoscape.view.vizmap.gui.internal.util.mapgenerator.RandomNumberMappingGenerator) HashMap(java.util.HashMap) Map(java.util.Map) VisualPropertySheetItem(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem)

Example 20 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class EditSelectedDiscreteValuesAction method actionPerformed.

// ==[ PUBLIC METHODS ]=============================================================================================
/**
 * Edit all selected cells at once. This is for Discrete Mapping only.
 */
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void actionPerformed(final ActionEvent e) {
    final VizMapperMainPanel vizMapperMainPanel = getVizMapperMainPanel();
    if (vizMapperMainPanel == null)
        return;
    final VisualPropertySheet vpSheet = vizMapperMainPanel.getSelectedVisualPropertySheet();
    if (vpSheet == null)
        return;
    for (final VisualPropertySheetItem<?> vpSheetItem : vpSheet.getSelectedItems()) {
        final VisualPropertySheetItemModel<?> model = vpSheetItem.getModel();
        final PropertySheetTable table = vpSheetItem.getPropSheetPnl().getTable();
        final int[] selected = table.getSelectedRows();
        if (selected == null || selected.length == 0 || !(model.getVisualMappingFunction() instanceof DiscreteMapping))
            continue;
        // Test with the first selected item
        final DiscreteMapping dm = (DiscreteMapping) model.getVisualMappingFunction();
        final VisualProperty vp = dm.getVisualProperty();
        Object newValue = null;
        try {
            // Get new value
            newValue = editorManager.showVisualPropertyValueEditor(vizMapperMainPanel, vp, vp.getDefault());
        } catch (Exception ex) {
            logger.error("Could not edit value.", ex);
        }
        if (newValue == null)
            continue;
        final Map<Object, Object> newValues = new HashMap<Object, Object>();
        final Map<Object, Object> previousValues = new HashMap<Object, Object>();
        for (int i = 0; i < selected.length; i++) {
            final Item item = ((Item) table.getValueAt(selected[i], 0));
            if (item != null && item.getProperty() instanceof VizMapperProperty) {
                final VizMapperProperty<?, ?, ?> prop = (VizMapperProperty<?, ?, ?>) item.getProperty();
                if (prop.getCellType() == CellType.DISCRETE) {
                    // Save the current value for undo
                    previousValues.put(prop.getKey(), prop.getValue());
                    // New value
                    newValues.put(prop.getKey(), newValue);
                }
            }
        }
        // Save the mapping->old_values for undo
        if (!previousValues.isEmpty())
            previousMappingValues.put(dm, previousValues);
        // Save the mapping->new_values for redo
        if (!newValues.isEmpty())
            newMappingValues.put(dm, newValues);
        // Update the visual mapping
        dm.putAll(newValues);
    }
    // Undo support
    if (!previousMappingValues.isEmpty()) {
        final UndoSupport undo = servicesUtil.get(UndoSupport.class);
        undo.postEdit(new EditSelectedDiscreteValuesEdit());
    }
}
Also used : VisualPropertySheet(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheet) HashMap(java.util.HashMap) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) UndoSupport(org.cytoscape.work.undo.UndoSupport) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) VisualPropertySheetItem(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem) Item(com.l2fprod.common.propertysheet.PropertySheetTableModel.Item) PropertySheetTable(com.l2fprod.common.propertysheet.PropertySheetTable) VizMapperMainPanel(org.cytoscape.view.vizmap.gui.internal.view.VizMapperMainPanel) VisualProperty(org.cytoscape.view.model.VisualProperty)

Aggregations

UndoSupport (org.cytoscape.work.undo.UndoSupport)50 Test (org.junit.Test)21 Task (org.cytoscape.work.Task)19 CyEventHelper (org.cytoscape.event.CyEventHelper)15 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)15 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)12 HashSet (java.util.HashSet)10 TaskIterator (org.cytoscape.work.TaskIterator)10 CyNode (org.cytoscape.model.CyNode)9 ArrayList (java.util.ArrayList)8 CyEdge (org.cytoscape.model.CyEdge)7 CyNetwork (org.cytoscape.model.CyNetwork)7 CyNetworkView (org.cytoscape.view.model.CyNetworkView)7 CyRow (org.cytoscape.model.CyRow)6 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)6 Properties (java.util.Properties)5 CyNetworkManager (org.cytoscape.model.CyNetworkManager)5 CyApplicationManager (org.cytoscape.application.CyApplicationManager)4 CyGroupManager (org.cytoscape.group.CyGroupManager)4 CyNetworkFactory (org.cytoscape.model.CyNetworkFactory)4