Search in sources :

Example 1 with Item

use of com.l2fprod.common.propertysheet.PropertySheetTableModel.Item 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 2 with Item

use of com.l2fprod.common.propertysheet.PropertySheetTableModel.Item 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)

Example 3 with Item

use of com.l2fprod.common.propertysheet.PropertySheetTableModel.Item in project cytoscape-impl by cytoscape.

the class EditSelectedDiscreteValuesAction method updateEnableState.

@Override
public void updateEnableState() {
    boolean enabled = false;
    final VizMapperMainPanel vizMapperMainPanel = getVizMapperMainPanel();
    VisualPropertySheet vpSheet = null;
    if (vizMapperMainPanel != null)
        vpSheet = vizMapperMainPanel.getSelectedVisualPropertySheet();
    if (vpSheet != null) {
        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 && model.getVisualMappingFunction() instanceof DiscreteMapping) {
                // Make sure the selected rows have at least one Discrete Mapping entry
                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) {
                            enabled = true;
                            break;
                        }
                    }
                }
            }
        }
    }
    setEnabled(enabled);
}
Also used : VisualPropertySheetItem(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem) Item(com.l2fprod.common.propertysheet.PropertySheetTableModel.Item) VisualPropertySheet(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheet) PropertySheetTable(com.l2fprod.common.propertysheet.PropertySheetTable) VizMapperMainPanel(org.cytoscape.view.vizmap.gui.internal.view.VizMapperMainPanel) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty)

Example 4 with Item

use of com.l2fprod.common.propertysheet.PropertySheetTableModel.Item in project cytoscape-impl by cytoscape.

the class RemoveSelectedDiscreteValuesAction method updateEnableState.

@Override
public void updateEnableState() {
    boolean enabled = false;
    final VizMapperMainPanel vizMapperMainPanel = getVizMapperMainPanel();
    VisualPropertySheet vpSheet = null;
    if (vizMapperMainPanel != null)
        vpSheet = vizMapperMainPanel.getSelectedVisualPropertySheet();
    if (vpSheet != null) {
        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 && model.getVisualMappingFunction() instanceof DiscreteMapping) {
                // Make sure the selected rows have at least one Discrete Mapping entry with non-null value
                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 && prop.getValue() != null) {
                            enabled = true;
                            break;
                        }
                    }
                }
            }
        }
    }
    setEnabled(enabled);
}
Also used : VisualPropertySheetItem(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem) Item(com.l2fprod.common.propertysheet.PropertySheetTableModel.Item) VisualPropertySheet(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheet) PropertySheetTable(com.l2fprod.common.propertysheet.PropertySheetTable) VizMapperMainPanel(org.cytoscape.view.vizmap.gui.internal.view.VizMapperMainPanel) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty)

Example 5 with Item

use of com.l2fprod.common.propertysheet.PropertySheetTableModel.Item 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

Item (com.l2fprod.common.propertysheet.PropertySheetTableModel.Item)7 VizMapperProperty (org.cytoscape.view.vizmap.gui.internal.VizMapperProperty)5 VisualPropertySheet (org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheet)5 VisualPropertySheetItem (org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem)5 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)5 PropertySheetTable (com.l2fprod.common.propertysheet.PropertySheetTable)4 VizMapperMainPanel (org.cytoscape.view.vizmap.gui.internal.view.VizMapperMainPanel)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 Component (java.awt.Component)1 PropertyEditor (java.beans.PropertyEditor)1 Map (java.util.Map)1 TableCellEditor (javax.swing.table.TableCellEditor)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