Search in sources :

Example 6 with PropertySheetTable

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

the class VizMapPropertyBuilder method setDiscreteProps.

/**
 * Set value, title, and renderer for each property in the category. This
 * list should be created against all available attribute values.
 */
private <K, V> void setDiscreteProps(VisualProperty<V> vp, VisualMappingFunction<K, V> mapping, SortedSet<Object> attrSet, VisualPropertyEditor<V> vpEditor, PropertySheetPanel propertySheetPanel) {
    if (attrSet == null)
        return;
    final Map<K, V> discMapping = ((DiscreteMapping<K, V>) mapping).getAll();
    V val = null;
    VizMapperProperty<K, V, VisualMappingFunction<K, V>> valProp;
    String strVal;
    final PropertySheetTable table = propertySheetPanel.getTable();
    final PropertyRendererRegistry cellRendererFactory = (PropertyRendererRegistry) table.getRendererFactory();
    final PropertyEditorRegistry cellEditorFactory = (PropertyEditorRegistry) table.getEditorFactory();
    for (final Object key : attrSet) {
        valProp = new VizMapperProperty<K, V, VisualMappingFunction<K, V>>(CellType.DISCRETE, (K) key, mapping.getVisualProperty().getRange().getType());
        strVal = key.toString();
        valProp.setDisplayName(strVal);
        // but we don't know the type of the list items.
        if (mapping.getMappingColumnType() == String.class && !(key instanceof String))
            val = discMapping.get(key.toString());
        else
            val = discMapping.get(key);
        if (val != null)
            valProp.setType(val.getClass());
        propertySheetPanel.addProperty(valProp);
        if (vpEditor != null) {
            final TableCellRenderer renderer = vpEditor.getDiscreteTableCellRenderer();
            if (renderer != null)
                cellRendererFactory.registerRenderer(valProp, renderer);
            PropertyEditor cellEditor = null;
            if (vpEditor instanceof VisualPropertyEditor2) {
                cellEditor = ((VisualPropertyEditor2) vpEditor).getPropertyEditor(vp);
            } else {
                cellEditor = vpEditor.getPropertyEditor();
            }
            if (cellEditor != null)
                cellEditorFactory.registerEditor(valProp, cellEditor);
        }
        valProp.setValue(val);
        valProp.setInternalValue(mapping);
    }
}
Also used : PropertyRendererRegistry(com.l2fprod.common.propertysheet.PropertyRendererRegistry) TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) PropertyEditorRegistry(com.l2fprod.common.propertysheet.PropertyEditorRegistry) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) PropertySheetTable(com.l2fprod.common.propertysheet.PropertySheetTable) VisualPropertyEditor(org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor) PropertyEditor(java.beans.PropertyEditor) VisualPropertyEditor2(org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor2)

Example 7 with PropertySheetTable

use of com.l2fprod.common.propertysheet.PropertySheetTable 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 8 with PropertySheetTable

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

PropertySheetTable (com.l2fprod.common.propertysheet.PropertySheetTable)8 VizMapperProperty (org.cytoscape.view.vizmap.gui.internal.VizMapperProperty)6 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)6 Item (com.l2fprod.common.propertysheet.PropertySheetTableModel.Item)4 VisualPropertySheet (org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheet)4 VisualPropertySheetItem (org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem)4 VizMapperMainPanel (org.cytoscape.view.vizmap.gui.internal.view.VizMapperMainPanel)4 PropertyRendererRegistry (com.l2fprod.common.propertysheet.PropertyRendererRegistry)3 PropertyEditorRegistry (com.l2fprod.common.propertysheet.PropertyEditorRegistry)2 PropertyEditor (java.beans.PropertyEditor)2 HashMap (java.util.HashMap)2 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)2 TableCellRenderer (javax.swing.table.TableCellRenderer)2 VisualProperty (org.cytoscape.view.model.VisualProperty)2 VisualMappingFunction (org.cytoscape.view.vizmap.VisualMappingFunction)2 VisualPropertyEditor (org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor)2 UndoSupport (org.cytoscape.work.undo.UndoSupport)2 Property (com.l2fprod.common.propertysheet.Property)1 Dimension (java.awt.Dimension)1 GradientPaint (java.awt.GradientPaint)1