Search in sources :

Example 6 with VisualPropertySheetItem

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

VisualPropertySheet (org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheet)6 VisualPropertySheetItem (org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem)6 Item (com.l2fprod.common.propertysheet.PropertySheetTableModel.Item)5 VizMapperProperty (org.cytoscape.view.vizmap.gui.internal.VizMapperProperty)5 VizMapperMainPanel (org.cytoscape.view.vizmap.gui.internal.view.VizMapperMainPanel)5 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)5 PropertySheetTable (com.l2fprod.common.propertysheet.PropertySheetTable)4 HashMap (java.util.HashMap)3 UndoSupport (org.cytoscape.work.undo.UndoSupport)3 VisualProperty (org.cytoscape.view.model.VisualProperty)2 PropertySheetPanel (com.l2fprod.common.propertysheet.PropertySheetPanel)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 VisualMappingFunction (org.cytoscape.view.vizmap.VisualMappingFunction)1 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)1 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)1 VizMapGUI (org.cytoscape.view.vizmap.gui.VizMapGUI)1 NumberSeriesMappingGenerator (org.cytoscape.view.vizmap.gui.internal.util.mapgenerator.NumberSeriesMappingGenerator)1 RandomNumberMappingGenerator (org.cytoscape.view.vizmap.gui.internal.util.mapgenerator.RandomNumberMappingGenerator)1 VisualPropertySheetItemModel (org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItemModel)1