Search in sources :

Example 1 with AttributeSet

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

the class AttributeComboBoxPropertyEditor method updateComboBox.

private void updateComboBox(final CyNetwork currentNetwork) {
    final JComboBox box = (JComboBox) editor;
    final Object selected = box.getSelectedItem();
    box.removeAllItems();
    if (currentNetwork == null)
        return;
    final AttributeSet compatibleColumns = attrProxy.getAttributeSet(currentNetwork, graphObjectType);
    currentColumnMap = compatibleColumns.getAttrMap();
    final AttributeSet targetSet = attrProxy.getAttributeSet(currentNetwork, graphObjectType);
    if (targetSet == null)
        return;
    // For locale-specific sorting
    final Collator collator = Collator.getInstance(Locale.getDefault());
    final SortedSet<String> sortedName = new TreeSet<String>(collator);
    final Set<CyNetwork> networks = networkManager.getNetworkSet();
    for (final CyNetwork net : networks) {
        final AttributeSet currentSet = attrProxy.getAttributeSet(net, graphObjectType);
        for (Entry<String, Class<?>> entry : currentSet.getAttrMap().entrySet()) {
            if (columnIsAllowed(entry.getKey(), entry.getValue()))
                sortedName.add(entry.getKey());
        }
    }
    for (final String attrName : sortedName) box.addItem(attrName);
    // Add new name if not in the list.
    box.setSelectedItem(selected);
}
Also used : JComboBox(javax.swing.JComboBox) AttributeSet(org.cytoscape.view.vizmap.gui.internal.model.AttributeSet) TreeSet(java.util.TreeSet) CyNetwork(org.cytoscape.model.CyNetwork) Collator(java.text.Collator)

Example 2 with AttributeSet

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

the class CellEditorEventHandler method switchMappingType.

private VisualMappingFunction<?, ?> switchMappingType(final VizMapperProperty<?, ?, ?> prop, final VisualProperty<?> vp, final VisualMappingFunctionFactory oldFactory, final VisualMappingFunctionFactory newFactory, final String controllingAttrName, final PropertySheetPanel propertySheetPanel) {
    // This is the currently selected Visual Style.
    final VisualStyle style = servicesUtil.get(VisualMappingManager.class).getCurrentVisualStyle();
    final VisualMappingFunction<?, ?> mapping = style.getVisualMappingFunction(vp);
    VisualMappingFunction<?, ?> newMapping = mapping;
    final Class<?> newMappingType = newFactory.getMappingFunctionType();
    if (mapping == null || mapping.getClass() != newMappingType || !mapping.getMappingColumnName().equals(controllingAttrName)) {
        final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
        final CyNetwork currentNet = appMgr.getCurrentNetwork();
        if (currentNet == null)
            return newMapping;
        // Mapping does not exist. Need to create new one.
        final AttributeSet attrSet = attrProxy.getAttributeSet(currentNet, vp.getTargetDataType());
        Class<?> attributeDataType = attrSet.getAttrMap().get(controllingAttrName);
        if (attributeDataType == null) {
            JOptionPane.showMessageDialog(null, "The current table does not have the selected column (\"" + controllingAttrName + "\").\nPlease select another column.", "Invalid Column.", JOptionPane.WARNING_MESSAGE);
            prop.setValue(oldFactory);
            return newMapping;
        }
        if (newMappingType == ContinuousMapping.class) {
            if (!Number.class.isAssignableFrom(attributeDataType)) {
                JOptionPane.showMessageDialog(null, "Selected column data type is not Number.\nPlease select a numerical column type.", "Incompatible Column Type.", JOptionPane.WARNING_MESSAGE);
                prop.setValue(oldFactory);
                return newMapping;
            }
        } else if (newMappingType == DiscreteMapping.class) {
            if (attributeDataType == List.class)
                attributeDataType = String.class;
        }
        // Create new mapping
        newMapping = newFactory.createVisualMappingFunction(controllingAttrName, attributeDataType, vp);
        // Keep old mapping values if the new mapping has the same type
        if (oldFactory != null && oldFactory.getMappingFunctionType() == newMappingType)
            copyMappingValues(mapping, newMapping);
    }
    // Disable listeners to avoid unnecessary updates
    final PropertySheetTableModel model = (PropertySheetTableModel) propertySheetPanel.getTable().getModel();
    final TableModelListener[] modelListeners = model.getTableModelListeners();
    for (final TableModelListener tm : modelListeners) model.removeTableModelListener(tm);
    vizMapPropertyBuilder.createMappingProperties(newMapping, propertySheetPanel, newFactory);
    // Restore listeners
    for (final TableModelListener tm : modelListeners) model.addTableModelListener(tm);
    return newMapping;
}
Also used : DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) CyNetwork(org.cytoscape.model.CyNetwork) CyApplicationManager(org.cytoscape.application.CyApplicationManager) AttributeSet(org.cytoscape.view.vizmap.gui.internal.model.AttributeSet) PropertySheetTableModel(com.l2fprod.common.propertysheet.PropertySheetTableModel) TableModelListener(javax.swing.event.TableModelListener) List(java.util.List) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager)

Aggregations

CyNetwork (org.cytoscape.model.CyNetwork)2 AttributeSet (org.cytoscape.view.vizmap.gui.internal.model.AttributeSet)2 PropertySheetTableModel (com.l2fprod.common.propertysheet.PropertySheetTableModel)1 Collator (java.text.Collator)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 JComboBox (javax.swing.JComboBox)1 TableModelListener (javax.swing.event.TableModelListener)1 CyApplicationManager (org.cytoscape.application.CyApplicationManager)1 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)1 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)1 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)1