use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class VizMapperMediator method updateItemsStatus.
private void updateItemsStatus() {
// Children of enabled dependencies must be disabled
final Set<VisualProperty<?>> disabled = new HashSet<>();
final Map<VisualProperty<?>, String> messages = new HashMap<>();
final VisualStyle style = vmProxy.getCurrentVisualStyle();
final String infoMsgTemplate = "<html>To enable this visual property,<br><b>%s</b> the dependency <i><b>%s</b></i></html>";
for (final VisualPropertyDependency<?> dep : style.getAllVisualPropertyDependencies()) {
final VisualProperty<?> parent = dep.getParentVisualProperty();
final Set<VisualProperty<?>> properties = dep.getVisualProperties();
if (dep.isDependencyEnabled()) {
disabled.addAll(properties);
for (final VisualProperty<?> vp : properties) messages.put(vp, String.format(infoMsgTemplate, "uncheck", dep.getDisplayName()));
} else {
disabled.add(parent);
messages.put(parent, String.format(infoMsgTemplate, "check", dep.getDisplayName()));
}
}
for (final VisualPropertySheet vpSheet : vizMapperMainPanel.getVisualPropertySheets()) {
final Set<VisualPropertySheetItem<?>> vpSheetItems = vpSheet.getItems();
for (final VisualPropertySheetItem<?> item : vpSheetItems) {
// First check if this property item must be disabled and show an INFO message
String msg = null;
MessageType msgType = null;
if (msgType == null && item.getModel().getVisualPropertyDependency() == null) {
item.setEnabled(!disabled.contains(item.getModel().getVisualProperty()));
msg = messages.get(item.getModel().getVisualProperty());
msgType = item.isEnabled() ? null : MessageType.INFO;
}
item.setMessage(msg, msgType);
// If item is enabled, check whether or not the mapping is valid for the current network
updateMappingStatus(item);
}
}
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class VizMapperMediator method handleNotification.
@Override
public void handleNotification(final INotification notification) {
final String id = notification.getName();
final Object body = notification.getBody();
if (id.equals(VISUAL_STYLE_SET_CHANGED)) {
updateVisualStyleList((SortedSet<VisualStyle>) body, true);
} else if (id.equals(VISUAL_STYLE_ADDED) || id.equals(VISUAL_STYLE_REMOVED)) {
updateVisualStyleList(vmProxy.getVisualStyles(), false);
} else if (id.equals(CURRENT_VISUAL_STYLE_CHANGED)) {
invokeOnEDTAndWait(() -> {
ignoreVisualStyleSelectedEvents = true;
try {
selectCurrentVisualStyle((VisualStyle) body);
} finally {
ignoreVisualStyleSelectedEvents = false;
}
});
invokeOnEDT(() -> {
updateVisualPropertySheets((VisualStyle) body, false);
});
} else if (id.equals(VISUAL_STYLE_UPDATED) && body != null && body.equals(vmProxy.getCurrentVisualStyle())) {
updateVisualPropertySheets((VisualStyle) body, false);
} else if (id.equals(CURRENT_NETWORK_VIEW_CHANGED)) {
final CyNetworkView view = (CyNetworkView) body;
final String newRendererId = view != null ? view.getRendererId() : null;
if (view != null && newRendererId != null && !newRendererId.equals(curRendererId)) {
updateVisualPropertySheets(vmProxy.getVisualStyle(view), false);
curRendererId = newRendererId;
} else if (view == null || vmProxy.getVisualStyle(view).equals(vizMapperMainPanel.getSelectedVisualStyle())) {
// Ignore it, if the selected style is not the current one,
// because it should change the selection style first and then recreate all the items, anyway.
updateLockedValues((CyNetworkView) body);
if (body instanceof CyNetworkView) {
updateMappings(CyNode.class, view.getModel().getDefaultNodeTable());
updateMappings(CyEdge.class, view.getModel().getDefaultEdgeTable());
}
updateItemsStatus();
}
} else if (id.equals(VISUAL_STYLE_NAME_CHANGED)) {
vizMapperMainPanel.getStylesBtn().repaint();
}
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class VizMapperMediator method openDefaultValueEditor.
@SuppressWarnings("rawtypes")
private void openDefaultValueEditor(final ActionEvent evt, final VisualPropertySheetItem vpSheetItem) {
final VisualPropertySheetItemModel model = vpSheetItem.getModel();
final VisualProperty vp = model.getVisualProperty();
final VisualStyle style = vmProxy.getCurrentVisualStyle();
final Object oldValue = style.getDefaultValue(vp);
Object val = null;
try {
final EditorManager editorMgr = servicesUtil.get(EditorManager.class);
val = editorMgr.showVisualPropertyValueEditor(vizMapperMainPanel, vp, oldValue);
} catch (final Exception ex) {
logger.error("Error opening Visual Property values editor for: " + vp, ex);
}
final Object newValue = val;
if (newValue != null && !newValue.equals(oldValue)) {
style.setDefaultValue(vp, newValue);
// Undo support
final UndoSupport undo = servicesUtil.get(UndoSupport.class);
undo.postEdit(new AbstractCyEdit("Set Default Value") {
@Override
public void undo() {
style.setDefaultValue(vp, oldValue);
}
@Override
public void redo() {
style.setDefaultValue(vp, newValue);
}
});
}
}
use of org.cytoscape.view.vizmap.VisualStyle 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;
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class VisualMappingManagerImpl method handleEvent.
@Override
public void handleEvent(SetCurrentNetworkViewEvent e) {
final CyNetworkView view = e.getNetworkView();
if (view == null)
return;
final VisualStyle newStyle = this.getVisualStyle(view);
if (newStyle != null)
setCurrentVisualStyle(newStyle);
}
Aggregations