use of org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty 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;
}
Aggregations