Search in sources :

Example 6 with VizMapperProperty

use of org.cytoscape.view.vizmap.gui.internal.VizMapperProperty in project cytoscape-impl by cytoscape.

the class VizMapPropertyBuilder method buildProperty.

/**
 * Build the properties for an existing Visual Mapping Function.
 * @param <K> data type of attribute to be mapped.
 * @param <V> data type of Visual Property.
 */
public <K, V> void buildProperty(final VisualMappingFunction<K, V> visualMapping, final PropertySheetPanel propertySheetPanel, final VisualMappingFunctionFactory factory) {
    if (visualMapping == null)
        throw new IllegalArgumentException("'visualMapping' must not be null.");
    if (propertySheetPanel == null)
        throw new IllegalArgumentException("'propertySheetPanel' must not be null.");
    if (factory == null)
        throw new IllegalArgumentException("'factory' must not be null.");
    final VisualProperty<V> vp = visualMapping.getVisualProperty();
    final VizMapperProperty<VisualProperty<V>, String, VisualMappingFunctionFactory> columnProp = new VizMapperProperty<VisualProperty<V>, String, VisualMappingFunctionFactory>(CellType.VISUAL_PROPERTY_TYPE, vp, String.class);
    // Build Property object
    columnProp.setDisplayName(COLUMN);
    columnProp.setValue(visualMapping.getMappingColumnName());
    columnProp.setInternalValue(factory);
    final String attrName = visualMapping.getMappingColumnName();
    final VizMapperProperty<String, VisualMappingFunctionFactory, VisualMappingFunction<K, V>> mapTypeProp = new VizMapperProperty<String, VisualMappingFunctionFactory, VisualMappingFunction<K, V>>(CellType.MAPPING_TYPE, MAPPING_TYPE, VisualMappingFunctionFactory.class);
    if (attrName == null)
        columnProp.setValue(null);
    ((PropertyRendererRegistry) propertySheetPanel.getTable().getRendererFactory()).registerRenderer(columnProp, defaultTableCellRenderer);
    mapTypeProp.setDisplayName(MAPPING_TYPE);
    // Set mapping type as string.
    mapTypeProp.setValue(factory);
    mapTypeProp.setInternalValue(visualMapping);
    ((PropertyRendererRegistry) propertySheetPanel.getTable().getRendererFactory()).registerRenderer(mapTypeProp, defaultTableCellRenderer);
    // TODO: Should refactor factory.
    propertySheetPanel.addProperty(0, columnProp);
    propertySheetPanel.addProperty(1, mapTypeProp);
    final PropertyEditorRegistry propEditorRegistry = (PropertyEditorRegistry) propertySheetPanel.getTable().getEditorFactory();
    propEditorRegistry.registerEditor(columnProp, editorManager.getDataTableComboBoxEditor((Class<? extends CyIdentifiable>) vp.getTargetDataType()));
    propEditorRegistry.registerEditor(mapTypeProp, editorManager.getDefaultComboBoxEditor("mappingTypeEditor"));
    // Mapping Editor
    createMappingProperties(visualMapping, propertySheetPanel, factory);
}
Also used : PropertyRendererRegistry(com.l2fprod.common.propertysheet.PropertyRendererRegistry) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) PropertyEditorRegistry(com.l2fprod.common.propertysheet.PropertyEditorRegistry) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 7 with VizMapperProperty

use of org.cytoscape.view.vizmap.gui.internal.VizMapperProperty in project cytoscape-impl by cytoscape.

the class VizMapPropertyBuilder method buildProperty.

/**
 * Build the properties for a new Visual Mapping Function.
 * @param <V> data type of Visual Property.
 */
public <V> void buildProperty(final VisualProperty<V> visualProperty, final PropertySheetPanel propertySheetPanel) {
    if (visualProperty == null)
        throw new IllegalArgumentException("'visualProperty' must not be null.");
    if (propertySheetPanel == null)
        throw new IllegalArgumentException("'propertySheetPanel' must not be null.");
    // TODO: Refactor--create new view component for mapping editor???
    final VizMapperProperty<VisualProperty<V>, String, VisualMappingFunctionFactory> columnProp = new VizMapperProperty<VisualProperty<V>, String, VisualMappingFunctionFactory>(CellType.VISUAL_PROPERTY_TYPE, visualProperty, String.class);
    // Build Property object
    columnProp.setDisplayName(COLUMN);
    ((PropertyRendererRegistry) propertySheetPanel.getTable().getRendererFactory()).registerRenderer(columnProp, defaultTableCellRenderer);
    final VizMapperProperty<String, VisualMappingFunctionFactory, VisualMappingFunction<?, V>> mapTypeProp = new VizMapperProperty<String, VisualMappingFunctionFactory, VisualMappingFunction<?, V>>(CellType.MAPPING_TYPE, MAPPING_TYPE, VisualMappingFunctionFactory.class);
    mapTypeProp.setDisplayName(MAPPING_TYPE);
    ((PropertyRendererRegistry) propertySheetPanel.getTable().getRendererFactory()).registerRenderer(mapTypeProp, defaultTableCellRenderer);
    propertySheetPanel.addProperty(0, columnProp);
    propertySheetPanel.addProperty(1, mapTypeProp);
    propertySheetPanel.repaint();
    final PropertyEditorRegistry propEditorRegistry = (PropertyEditorRegistry) propertySheetPanel.getTable().getEditorFactory();
    propEditorRegistry.registerEditor(columnProp, editorManager.getDataTableComboBoxEditor((Class<? extends CyIdentifiable>) visualProperty.getTargetDataType()));
    propEditorRegistry.registerEditor(mapTypeProp, editorManager.getDefaultComboBoxEditor("mappingTypeEditor"));
}
Also used : PropertyRendererRegistry(com.l2fprod.common.propertysheet.PropertyRendererRegistry) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) PropertyEditorRegistry(com.l2fprod.common.propertysheet.PropertyEditorRegistry) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 8 with VizMapperProperty

use of org.cytoscape.view.vizmap.gui.internal.VizMapperProperty in project cytoscape-impl by cytoscape.

the class VizMapPropertyBuilder method removeMappingProperties.

protected void removeMappingProperties(final PropertySheetPanel propertySheetPanel) {
    final Property[] properties = propertySheetPanel.getProperties();
    if (properties != null) {
        final PropertySheetTable table = propertySheetPanel.getTable();
        final PropertyRendererRegistry rendReg = (PropertyRendererRegistry) table.getRendererFactory();
        for (final Property p : properties) {
            if (p instanceof VizMapperProperty) {
                final CellType cellType = ((VizMapperProperty<?, ?, ?>) p).getCellType();
                if (cellType == CellType.CONTINUOUS || cellType == CellType.DISCRETE) {
                    if (cellType == CellType.CONTINUOUS) {
                        // TODO: Update range trace?
                        rendReg.unregisterRenderer(p);
                    }
                    propertySheetPanel.removeProperty(p);
                }
            }
        }
        table.repaint();
        propertySheetPanel.repaint();
    }
}
Also used : PropertyRendererRegistry(com.l2fprod.common.propertysheet.PropertyRendererRegistry) CellType(org.cytoscape.view.vizmap.gui.internal.event.CellType) PropertySheetTable(com.l2fprod.common.propertysheet.PropertySheetTable) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) Property(com.l2fprod.common.propertysheet.Property) VisualProperty(org.cytoscape.view.model.VisualProperty) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty)

Example 9 with VizMapperProperty

use of org.cytoscape.view.vizmap.gui.internal.VizMapperProperty in project cytoscape-impl by cytoscape.

the class VizMapperMediator method createVisualPropertySheetItems.

@SuppressWarnings("rawtypes")
private Set<VisualPropertySheetItem<?>> createVisualPropertySheetItems(final Class<? extends CyIdentifiable> type, final VisualLexicon lexicon, final VisualStyle style) {
    final Set<VisualPropertySheetItem<?>> items = new HashSet<>();
    if (lexicon == null || style == null)
        return items;
    final Collection<VisualProperty<?>> vpList = lexicon.getAllDescendants(BasicVisualLexicon.NETWORK);
    final CyNetworkView curNetView = vmProxy.getCurrentNetworkView();
    final Set<View<CyNode>> selectedNodeViews = vmProxy.getSelectedNodeViews(curNetView);
    final Set<View<CyEdge>> selectedEdgeViews = vmProxy.getSelectedEdgeViews(curNetView);
    final Set<View<CyNetwork>> selectedNetViews = curNetView != null ? Collections.singleton((View<CyNetwork>) curNetView) : Collections.EMPTY_SET;
    final RenderingEngine<CyNetwork> engine = vizMapperMainPanel.getRenderingEngine();
    for (final VisualProperty<?> vp : vpList) {
        if (vp.getTargetDataType() != type || vp instanceof DefaultVisualizableVisualProperty)
            continue;
        if (!vmProxy.isSupported(vp))
            continue;
        // Create model
        final VisualPropertySheetItemModel<?> model = new VisualPropertySheetItemModel(vp, style, engine, lexicon);
        final Set values;
        if (vp.getTargetDataType() == CyNode.class) {
            values = getDistinctLockedValues(vp, selectedNodeViews);
            updateVpInfoLockedState(model, values, selectedNodeViews);
        } else if (vp.getTargetDataType() == CyEdge.class) {
            values = getDistinctLockedValues(vp, selectedEdgeViews);
            updateVpInfoLockedState(model, values, selectedEdgeViews);
        } else {
            values = getDistinctLockedValues(vp, selectedNetViews);
            updateVpInfoLockedState(model, values, selectedNetViews);
        }
        // Create View
        final VisualPropertySheetItem<?> sheetItem = new VisualPropertySheetItem(model, vizMapPropertyBuilder, servicesUtil);
        items.add(sheetItem);
        // Add listeners to item and model:
        if (model.isVisualMappingAllowed()) {
            sheetItem.getPropSheetPnl().addPropertySheetChangeListener(evt -> {
                if (evt.getPropertyName().equals("value") && evt.getSource() instanceof VizMapperProperty)
                    updateMappingStatus(sheetItem);
            });
        }
        // Set the updated values to the visual style
        model.addPropertyChangeListener("defaultValue", evt -> {
            final VisualStyle vs = model.getVisualStyle();
            vs.setDefaultValue((VisualProperty) vp, evt.getNewValue());
        });
        model.addPropertyChangeListener("visualMappingFunction", evt -> {
            final VisualStyle vs = model.getVisualStyle();
            if (evt.getNewValue() == null && vs.getVisualMappingFunction(vp) != null)
                vs.removeVisualMappingFunction(vp);
            else if (evt.getNewValue() != null && !evt.getNewValue().equals(vs.getVisualMappingFunction(vp)))
                vs.addVisualMappingFunction((VisualMappingFunction<?, ?>) evt.getNewValue());
            updateMappingStatus(sheetItem);
        });
    }
    // Add dependencies
    final Set<VisualPropertyDependency<?>> dependencies = style.getAllVisualPropertyDependencies();
    for (final VisualPropertyDependency<?> dep : dependencies) {
        if (dep.getParentVisualProperty().getTargetDataType() != type)
            continue;
        if (!vmProxy.isSupported(dep))
            continue;
        final VisualPropertySheetItemModel<?> model = new VisualPropertySheetItemModel(dep, style, engine, lexicon);
        final VisualPropertySheetItem<?> sheetItem = new VisualPropertySheetItem(model, vizMapPropertyBuilder, servicesUtil);
        items.add(sheetItem);
    }
    return items;
}
Also used : Set(java.util.Set) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView) View(org.cytoscape.view.model.View) CyEdge(org.cytoscape.model.CyEdge) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) DefaultVisualizableVisualProperty(org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashSet(java.util.HashSet) DefaultVisualizableVisualProperty(org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty)

Example 10 with VizMapperProperty

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

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