Search in sources :

Example 1 with MessageType

use of org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem.MessageType 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);
        }
    }
}
Also used : HashMap(java.util.HashMap) DefaultVisualizableVisualProperty(org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) MessageType(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem.MessageType) HashSet(java.util.HashSet)

Example 2 with MessageType

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

the class VizMapperMediator method updateMappingStatus.

private void updateMappingStatus(final VisualPropertySheetItem<?> item) {
    if (!item.isEnabled())
        return;
    final CyNetwork net = vmProxy.getCurrentNetwork();
    final Class<? extends CyIdentifiable> targetDataType = item.getModel().getTargetDataType();
    if (net != null && targetDataType != CyNetwork.class) {
        final CyTable netTable = targetDataType == CyNode.class ? net.getDefaultNodeTable() : net.getDefaultEdgeTable();
        String msg = null;
        MessageType msgType = null;
        if (netTable != null) {
            final VizMapperProperty<VisualProperty<?>, String, VisualMappingFunctionFactory> columnProp = vizMapPropertyBuilder.getColumnProperty(item.getPropSheetPnl());
            final String colName = (columnProp != null && columnProp.getValue() != null) ? columnProp.getValue().toString() : null;
            if (colName != null) {
                final VisualMappingFunction<?, ?> mapping = item.getModel().getVisualMappingFunction();
                Class<?> mapColType = mapping != null ? mapping.getMappingColumnType() : null;
                final CyColumn column = netTable.getColumn(colName);
                Class<?> colType = column != null ? column.getType() : null;
                // Ignore "List" type
                if (mapColType == List.class)
                    mapColType = String.class;
                if (colType == List.class)
                    colType = String.class;
                if (column == null || (mapColType != null && !mapColType.isAssignableFrom(colType))) {
                    String tableName = netTable != null ? targetDataType.getSimpleName().replace("Cy", "") : null;
                    msg = "<html>Visual Mapping cannot be applied to current network:<br>" + tableName + " table does not have column <b>\"" + colName + "\"</b>" + (mapColType != null ? " (" + mapColType.getSimpleName() + ")" : "") + "</html>";
                    msgType = MessageType.WARNING;
                }
            }
        }
        final String finalMsg = msg;
        final MessageType finalMsgType = msgType;
        invokeOnEDT(() -> item.setMessage(finalMsg, finalMsgType));
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) DefaultVisualizableVisualProperty(org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) CyColumn(org.cytoscape.model.CyColumn) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) MessageType(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem.MessageType)

Aggregations

VisualProperty (org.cytoscape.view.model.VisualProperty)2 DefaultVisualizableVisualProperty (org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty)2 MessageType (org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem.MessageType)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 CyColumn (org.cytoscape.model.CyColumn)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNode (org.cytoscape.model.CyNode)1 CyTable (org.cytoscape.model.CyTable)1 VisualMappingFunctionFactory (org.cytoscape.view.vizmap.VisualMappingFunctionFactory)1 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)1