Search in sources :

Example 11 with VizMapperProperty

use of org.cytoscape.view.vizmap.gui.internal.VizMapperProperty 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)

Aggregations

VizMapperProperty (org.cytoscape.view.vizmap.gui.internal.VizMapperProperty)11 VisualProperty (org.cytoscape.view.model.VisualProperty)7 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)7 PropertySheetTable (com.l2fprod.common.propertysheet.PropertySheetTable)6 Item (com.l2fprod.common.propertysheet.PropertySheetTableModel.Item)5 VisualPropertySheet (org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheet)5 VisualPropertySheetItem (org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem)5 PropertyRendererRegistry (com.l2fprod.common.propertysheet.PropertyRendererRegistry)4 HashMap (java.util.HashMap)4 VizMapperMainPanel (org.cytoscape.view.vizmap.gui.internal.view.VizMapperMainPanel)4 PropertyEditorRegistry (com.l2fprod.common.propertysheet.PropertyEditorRegistry)3 CyIdentifiable (org.cytoscape.model.CyIdentifiable)3 VisualMappingFunction (org.cytoscape.view.vizmap.VisualMappingFunction)3 UndoSupport (org.cytoscape.work.undo.UndoSupport)3 Property (com.l2fprod.common.propertysheet.Property)2 PropertySheetPanel (com.l2fprod.common.propertysheet.PropertySheetPanel)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 TreeSet (java.util.TreeSet)2 CyEdge (org.cytoscape.model.CyEdge)2