Search in sources :

Example 31 with UndoSupport

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

the class VizMapperMediator method openDefaultValueEditor.

@SuppressWarnings("rawtypes")
private void openDefaultValueEditor(final ActionEvent evt, final VisualPropertySheetItem vpSheetItem) {
    final VisualPropertySheetItemModel model = vpSheetItem.getModel();
    final VisualProperty vp = model.getVisualProperty();
    final VisualStyle style = vmProxy.getCurrentVisualStyle();
    final Object oldValue = style.getDefaultValue(vp);
    Object val = null;
    try {
        final EditorManager editorMgr = servicesUtil.get(EditorManager.class);
        val = editorMgr.showVisualPropertyValueEditor(vizMapperMainPanel, vp, oldValue);
    } catch (final Exception ex) {
        logger.error("Error opening Visual Property values editor for: " + vp, ex);
    }
    final Object newValue = val;
    if (newValue != null && !newValue.equals(oldValue)) {
        style.setDefaultValue(vp, newValue);
        // Undo support
        final UndoSupport undo = servicesUtil.get(UndoSupport.class);
        undo.postEdit(new AbstractCyEdit("Set Default Value") {

            @Override
            public void undo() {
                style.setDefaultValue(vp, oldValue);
            }

            @Override
            public void redo() {
                style.setDefaultValue(vp, newValue);
            }
        });
    }
}
Also used : DefaultVisualizableVisualProperty(org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) EditorManager(org.cytoscape.view.vizmap.gui.editor.EditorManager) UndoSupport(org.cytoscape.work.undo.UndoSupport) AbstractCyEdit(org.cytoscape.work.undo.AbstractCyEdit)

Example 32 with UndoSupport

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

the class CellEditorEventHandler method processEvent.

/**
 * Execute commands based on PropertyEditor's local event.
 *
 * In this handler, we should handle the following:
 * <ul>
 * <li>Mapping Type change
 * <li>Attribute Name Change
 * </ul>
 *
 * Other old global events (ex. Cytoscape.NETWORK_LOADED) is replaced by new
 * events.
 *
 * @param e PCE to be processed in this handler.
 */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void processEvent(final PropertyChangeEvent e) {
    final Object newVal = e.getNewValue();
    final Object oldVal = e.getOldValue();
    // Check update is necessary or not.
    if (newVal == null && oldVal == null)
        return;
    // Same value. No change required.
    if (newVal != null && newVal.equals(oldVal))
        return;
    final VisualPropertySheetItem<?> vpSheetItem = vizMapperMediator.getCurrentVisualPropertySheetItem();
    final PropertySheetPanel propSheetPnl = vpSheetItem != null ? vpSheetItem.getPropSheetPnl() : null;
    if (propSheetPnl == null)
        return;
    final VizMapperProperty<?, ?, ?> prop = vizMapperMediator.getCurrentVizMapperProperty();
    if (prop == null)
        return;
    final VisualProperty<?> vp = vpSheetItem.getModel().getVisualProperty();
    final VisualMappingFunction mapping = vpSheetItem.getModel().getVisualMappingFunction();
    if (prop.getCellType() == CellType.DISCRETE && mapping instanceof DiscreteMapping) {
        // Discrete mapping value changed:
        // -------------------------------
        // Create new map entry and register it.
        final DiscreteMapping<Object, Object> discMap = (DiscreteMapping<Object, Object>) mapping;
        setDiscreteMappingEntry(prop.getKey(), oldVal, newVal, discMap);
    } else {
        VisualMappingFunction newMapping = mapping;
        String undoName = null;
        if (prop.getCellType() == CellType.VISUAL_PROPERTY_TYPE) {
            // -----------------------
            if (newVal != null && e.getSource() instanceof AttributeComboBoxPropertyEditor) {
                final AttributeComboBoxPropertyEditor editor = (AttributeComboBoxPropertyEditor) e.getSource();
                final VisualMappingFunctionFactory factory = (VisualMappingFunctionFactory) propSheetPnl.getTable().getValueAt(1, 1);
                newMapping = switchColumn(factory, editor, prop, newVal.toString(), propSheetPnl);
                vpSheetItem.getModel().setVisualMappingFunction(newMapping);
                if (newMapping == null)
                    vpSheetItem.getModel().setMappingColumnName(prop.getValue() != null ? prop.getValue().toString() : null);
                undoName = "Set Mapping Column";
            }
        } else if (prop.getCellType() == CellType.MAPPING_TYPE) {
            // Mapping type changed:
            // -----------------------
            // Parent is always root.
            // TODO: refactor--this class should not have to know the row/column where the value is
            Object controllingAttrName = propSheetPnl.getTable().getValueAt(0, 1);
            if (vp != null && controllingAttrName != null && (newVal == null || newVal instanceof VisualMappingFunctionFactory)) {
                newMapping = switchMappingType(prop, vp, (VisualMappingFunctionFactory) oldVal, (VisualMappingFunctionFactory) newVal, controllingAttrName.toString(), propSheetPnl);
                vpSheetItem.getModel().setVisualMappingFunction(newMapping);
                undoName = "Set Mapping Type";
            }
        }
        if (newMapping != mapping && undoName != null) {
            // Add undo support
            final VisualMappingFunction myNewMapping = newMapping;
            final UndoSupport undo = servicesUtil.get(UndoSupport.class);
            undo.postEdit(new AbstractCyEdit(undoName) {

                @Override
                public void undo() {
                    vpSheetItem.getModel().setVisualMappingFunction(mapping);
                }

                @Override
                public void redo() {
                    vpSheetItem.getModel().setVisualMappingFunction(myNewMapping);
                }
            });
        }
    }
}
Also used : PropertySheetPanel(com.l2fprod.common.propertysheet.PropertySheetPanel) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) UndoSupport(org.cytoscape.work.undo.UndoSupport) AbstractCyEdit(org.cytoscape.work.undo.AbstractCyEdit) AttributeComboBoxPropertyEditor(org.cytoscape.view.vizmap.gui.internal.view.editor.propertyeditor.AttributeComboBoxPropertyEditor)

Example 33 with UndoSupport

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

the class CellEditorEventHandler method setDiscreteMappingEntry.

private void setDiscreteMappingEntry(final Object key, final Object oldVal, final Object newVal, final DiscreteMapping<Object, Object> mapping) {
    final VisualProperty<?> vp = mapping.getVisualProperty();
    if (newVal == null || vp.getRange().getType().isAssignableFrom(newVal.getClass())) {
        mapping.putMapValue(key, newVal);
        // Undo support
        if ((oldVal != null && newVal == null) || (newVal != null && !newVal.equals(oldVal))) {
            final UndoSupport undo = servicesUtil.get(UndoSupport.class);
            undo.postEdit(new AbstractCyEdit("Set Discrete Mapping Value") {

                @Override
                public void undo() {
                    mapping.putMapValue(key, oldVal);
                }

                @Override
                public void redo() {
                    mapping.putMapValue(key, newVal);
                }
            });
        }
    }
}
Also used : UndoSupport(org.cytoscape.work.undo.UndoSupport) AbstractCyEdit(org.cytoscape.work.undo.AbstractCyEdit)

Example 34 with UndoSupport

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

the class RemoveSelectedDiscreteValuesAction method actionPerformed.

// ==[ PUBLIC METHODS ]=============================================================================================
/**
 * Remove all selected values 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 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
                    if (prop.getValue() != null)
                        previousValues.put(prop.getKey(), prop.getValue());
                    // Mapping values to be removed
                    newValues.put(prop.getKey(), null);
                }
            }
        }
        // Save the mapping->old_values for undo
        if (!previousValues.isEmpty())
            previousMappingValues.put(dm, previousValues);
        // Update the visual mapping
        dm.putAll(newValues);
    }
    // Undo support
    if (!previousMappingValues.isEmpty()) {
        final UndoSupport undo = servicesUtil.get(UndoSupport.class);
        undo.postEdit(new RemoveSelectedDiscreteValuesEdit());
    }
}
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)

Example 35 with UndoSupport

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

the class CyActivator method start.

public void start(BundleContext bc) {
    UndoSupport undo = getService(bc, UndoSupport.class);
    JGraphLayoutWrapper jGraphAnnealingLayout = new JGraphLayoutWrapper(JGraphLayoutWrapper.ANNEALING, undo);
    JGraphLayoutWrapper jGraphMoenLayout = new JGraphLayoutWrapper(JGraphLayoutWrapper.MOEN, undo);
    JGraphLayoutWrapper jGraphCircleGraphLayout = new JGraphLayoutWrapper(JGraphLayoutWrapper.CIRCLE_GRAPH, undo);
    JGraphLayoutWrapper jGraphRadialTreeLayout = new JGraphLayoutWrapper(JGraphLayoutWrapper.RADIAL_TREE, undo);
    JGraphLayoutWrapper jGraphGEMLayout = new JGraphLayoutWrapper(JGraphLayoutWrapper.GEM, undo);
    JGraphLayoutWrapper jGraphSpringEmbeddedLayout = new JGraphLayoutWrapper(JGraphLayoutWrapper.SPRING_EMBEDDED, undo);
    JGraphLayoutWrapper jGraphSugiyamaLayout = new JGraphLayoutWrapper(JGraphLayoutWrapper.SUGIYAMA, undo);
    JGraphLayoutWrapper jGraphTreeLayout = new JGraphLayoutWrapper(JGraphLayoutWrapper.TREE, undo);
    Properties jGraphAnnealingLayoutProps = new Properties();
    jGraphAnnealingLayoutProps.setProperty(PREFERRED_MENU, "JGraph Layouts");
    registerService(bc, jGraphAnnealingLayout, CyLayoutAlgorithm.class, jGraphAnnealingLayoutProps);
    Properties jGraphMoenLayoutProps = new Properties();
    jGraphMoenLayoutProps.setProperty(PREFERRED_MENU, "JGraph Layouts");
    registerService(bc, jGraphMoenLayout, CyLayoutAlgorithm.class, jGraphMoenLayoutProps);
    Properties jGraphCircleGraphLayoutProps = new Properties();
    jGraphCircleGraphLayoutProps.setProperty(PREFERRED_MENU, "JGraph Layouts");
    registerService(bc, jGraphCircleGraphLayout, CyLayoutAlgorithm.class, jGraphCircleGraphLayoutProps);
    Properties jGraphRadialTreeLayoutProps = new Properties();
    jGraphRadialTreeLayoutProps.setProperty(PREFERRED_MENU, "JGraph Layouts");
    registerService(bc, jGraphRadialTreeLayout, CyLayoutAlgorithm.class, jGraphRadialTreeLayoutProps);
    Properties jGraphGEMLayoutProps = new Properties();
    jGraphGEMLayoutProps.setProperty(PREFERRED_MENU, "JGraph Layouts");
    registerService(bc, jGraphGEMLayout, CyLayoutAlgorithm.class, jGraphGEMLayoutProps);
    Properties jGraphSpringEmbeddedLayoutProps = new Properties();
    jGraphSpringEmbeddedLayoutProps.setProperty(PREFERRED_MENU, "JGraph Layouts");
    registerService(bc, jGraphSpringEmbeddedLayout, CyLayoutAlgorithm.class, jGraphSpringEmbeddedLayoutProps);
    Properties jGraphSugiyamaLayoutProps = new Properties();
    jGraphSugiyamaLayoutProps.setProperty(PREFERRED_MENU, "JGraph Layouts");
    registerService(bc, jGraphSugiyamaLayout, CyLayoutAlgorithm.class, jGraphSugiyamaLayoutProps);
    Properties jGraphTreeLayoutProps = new Properties();
    jGraphTreeLayoutProps.setProperty(PREFERRED_MENU, "JGraph Layouts");
    registerService(bc, jGraphTreeLayout, CyLayoutAlgorithm.class, jGraphTreeLayoutProps);
}
Also used : Properties(java.util.Properties) ServiceProperties(org.cytoscape.work.ServiceProperties) UndoSupport(org.cytoscape.work.undo.UndoSupport)

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