Author: kono
Date: 2010-10-14 13:13:42 -0700 (Thu, 14 Oct 2010)
New Revision: 22236

Modified:
   
core3/vizmap-gui-impl/branches/vp-tree/src/main/java/org/cytoscape/view/vizmap/gui/internal/VizMapPropertySheetMouseAdapter.java
   
core3/vizmap-gui-impl/branches/vp-tree/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/EditorManagerImpl.java
   
core3/vizmap-gui-impl/branches/vp-tree/src/main/java/org/cytoscape/view/vizmap/gui/internal/event/CellEditorEventHandler.java
Log:
Refactoring mapping creation functions.

Modified: 
core3/vizmap-gui-impl/branches/vp-tree/src/main/java/org/cytoscape/view/vizmap/gui/internal/VizMapPropertySheetMouseAdapter.java
===================================================================
--- 
core3/vizmap-gui-impl/branches/vp-tree/src/main/java/org/cytoscape/view/vizmap/gui/internal/VizMapPropertySheetMouseAdapter.java
    2010-10-14 19:53:16 UTC (rev 22235)
+++ 
core3/vizmap-gui-impl/branches/vp-tree/src/main/java/org/cytoscape/view/vizmap/gui/internal/VizMapPropertySheetMouseAdapter.java
    2010-10-14 20:13:42 UTC (rev 22236)
@@ -76,14 +76,11 @@
 
        private VisualStyle selectedStyle;
        
-       private final CyComboBoxPropertyEditor mappingTypeEditor;
        
        private final PropertyEditor nodeAttributeEditor;
        private final PropertyEditor edgeAttributeEditor;
        private final PropertyEditor networkAttributeEditor;
        
-       
-       private static final String[] MAPPING_TYPE = {"Passthrough", 
"Discrete", "Continuous"};
 
        /**
         * Creates a new VizMapPropertySheetMouseAdapter object.
@@ -104,9 +101,6 @@
                this.selectedStyle = selectedStyle;
                this.editorManager = editorManager;
                
-               this.mappingTypeEditor = (CyComboBoxPropertyEditor) 
this.editorManager.getDefaultComboBoxEditor("mappingTypeEditor");
-               this.mappingTypeEditor.setAvailableValues(MAPPING_TYPE);
-               
                this.nodeAttributeEditor = 
editorManager.getDataTableComboBoxEditor(NODE);
                this.edgeAttributeEditor = 
editorManager.getDataTableComboBoxEditor(EDGE);
                this.networkAttributeEditor = 
editorManager.getDataTableComboBoxEditor(NETWORK);
@@ -181,7 +175,7 @@
                                
                                mapProp.setValue("Please select a mapping 
type!");
                                
-                               ((PropertyEditorRegistry) 
propertySheetPanel.getTable().getEditorFactory()).registerEditor(mapProp, 
mappingTypeEditor);
+                               ((PropertyEditorRegistry) 
propertySheetPanel.getTable().getEditorFactory()).registerEditor(mapProp, 
editorManager.getMappingFunctionSelector());
                                
                                newProp.addSubProperty(mapProp);
                                mapProp.setParentProperty(newProp);

Modified: 
core3/vizmap-gui-impl/branches/vp-tree/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/EditorManagerImpl.java
===================================================================
--- 
core3/vizmap-gui-impl/branches/vp-tree/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/EditorManagerImpl.java
   2010-10-14 19:53:16 UTC (rev 22235)
+++ 
core3/vizmap-gui-impl/branches/vp-tree/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/EditorManagerImpl.java
   2010-10-14 20:13:42 UTC (rev 22236)
@@ -34,6 +34,9 @@
  */
 package org.cytoscape.view.vizmap.gui.internal.editor;
 
+import static 
org.cytoscape.view.vizmap.mappings.AbstractVisualMappingFunction.*;
+
+
 import java.awt.Component;
 import java.beans.PropertyEditor;
 import java.util.ArrayList;
@@ -72,6 +75,10 @@
        private final Map<VisualProperty<?>, Component> continuousEditors;
 
        private final Map<Class<?>, ValueEditor<?>> valueEditors;
+       
+       private final PropertyEditor mappingTypeEditor;
+       
+       private static final String[] MAPPING_TYPES = {DISCRETE, PASSTHROUGH, 
CONTINUOUS};
 
        
        /**
@@ -88,6 +95,12 @@
                        
attrComboBoxEditors.put(propEditor.getTargetObjectName(), propEditor);
 
                valueEditors = new HashMap<Class<?>, ValueEditor<?>>();
+               
+               // Create mapping type editor
+               this.mappingTypeEditor = 
getDefaultComboBoxEditor("mappingTypeEditor");
+               
+               
+               
((CyComboBoxPropertyEditor)mappingTypeEditor).setAvailableValues(MAPPING_TYPES);
        }
 
        /*
@@ -292,6 +305,6 @@
 
        
        @Override public PropertyEditor getMappingFunctionSelector() {
-               return getDefaultComboBoxEditor("mappingTypeEditor");
+               return mappingTypeEditor;
        }
 }

Modified: 
core3/vizmap-gui-impl/branches/vp-tree/src/main/java/org/cytoscape/view/vizmap/gui/internal/event/CellEditorEventHandler.java
===================================================================
--- 
core3/vizmap-gui-impl/branches/vp-tree/src/main/java/org/cytoscape/view/vizmap/gui/internal/event/CellEditorEventHandler.java
       2010-10-14 19:53:16 UTC (rev 22235)
+++ 
core3/vizmap-gui-impl/branches/vp-tree/src/main/java/org/cytoscape/view/vizmap/gui/internal/event/CellEditorEventHandler.java
       2010-10-14 20:13:42 UTC (rev 22236)
@@ -57,6 +57,7 @@
 import org.cytoscape.view.vizmap.gui.internal.VizMapperMainPanel;
 import org.cytoscape.view.vizmap.gui.internal.VizMapperProperty;
 import 
org.cytoscape.view.vizmap.gui.internal.editor.propertyeditor.AttributeComboBoxPropertyEditor;
+import org.cytoscape.view.vizmap.mappings.AbstractVisualMappingFunction;
 import org.cytoscape.view.vizmap.mappings.ContinuousMapping;
 import org.cytoscape.view.vizmap.mappings.DiscreteMapping;
 import org.cytoscape.view.vizmap.mappings.PassthroughMapping;
@@ -219,45 +220,31 @@
        }
        
        
-       private void switchMapping(final VisualProperty<?> vp) {
+       private void switchMapping(final VisualProperty<?> vp, final String 
newMapName, final String controllingAttrName) {
                
                 final VisualStyle style = manager.getCurrentVisualStyle();
+                logger.debug("Mapping combo box clicked: " + style.getTitle());
+                
+                
                
-//              final String mappingFunctionName = style.getTitle() + "-" + 
vp.getIdString() + "-" + newMapName;
+                final String mappingFunctionName = style.getTitle() + "-" + 
vp.getIdString() + "-" + newMapName;
+                final VisualMappingFunction<?, ?> currentMapping = 
style.getVisualMappingFunction(vp);
+               
+
+               VisualMappingFunction<?,?> newMapping = null;
+               if(newMapName.equals(AbstractVisualMappingFunction.DISCRETE)) {
+                       newMapping = new DiscreteMapping(controllingAttrName, 
vp.getType(), vp);
+               } else 
if(newMapName.equals(AbstractVisualMappingFunction.PASSTHROUGH)) {
+                       newMapping = new 
PassthroughMapping(controllingAttrName, vp.getType(), vp);
+               } else 
if(newMapName.equals(AbstractVisualMappingFunction.CONTINUOUS)) {
+                       newMapping = new ContinuousMapping(controllingAttrName, 
vp);
+               }
+
+               // TODO: Exception?
+               if(newMapping == null)
+                       return;
 //             
-//              // Extract target calculator
-//              Calculator newCalc = 
vmm.getCalculatorCatalog().getCalculator(type,
-//              newCalcName);
-//             
-//              Calculator oldCalc = null;
-//             
-//              if (type.getObjectType().equals(VisualProperty.NODE))
-//              oldCalc = vmm.getVisualStyle().getNodeAppearanceCalculator()
-//              .getCalculator(type);
-//              else
-//              oldCalc = vmm.getVisualStyle().getEdgeAppearanceCalculator()
-//              .getCalculator(type);
-//             
 //              /*
-//              * If not exist, create new one.
-//              */
-//              if (newCalc == null) {
-//              newCalc = getNewCalculator(type, newMapName, newCalcName);
-//              newCalc.getMapping(0)
-//              .setControllingAttributeName((String) attrName);
-//              vmm.getCalculatorCatalog().addCalculator(newCalc);
-//              }
-//             
-//              newCalc.getMapping(0).setControllingAttributeName((String) 
attrName);
-//             
-//              if (type.getObjectType().equals(VisualProperty.NODE)) {
-//              
vmm.getVisualStyle().getNodeAppearanceCalculator().setCalculator(
-//              newCalc);
-//              } else
-//              
vmm.getVisualStyle().getEdgeAppearanceCalculator().setCalculator(
-//              newCalc);
-//             
-//              /*
 //              * If old calc is not standard name, rename it.
 //              */
 //              if (oldCalc != null) {
@@ -430,11 +417,18 @@
                 if (prop.getHiddenObject() instanceof VisualMappingFunction || 
prop.getDisplayName().equals("Mapping Type")) {
                         logger.debug("Mapping type changed for: " + 
prop.getHiddenObject());
                         logger.debug("Mapping type new = " + e.getNewValue());
+                        
+                        if(e.getNewValue() == e.getOldValue())
+                                return;
+                        
+                        final VizMapperProperty<?> parentProp = 
(VizMapperProperty<?>) prop.getParentProperty();
+                        Object controllingAttrName = parentProp.getValue();
+                        
                         type = (VisualProperty<?>) ((VizMapperProperty<?>) 
prop.getParentProperty()).getHiddenObject();
-                        if(type == null)
+                        if(type == null || controllingAttrName == null)
                                 return;
                         
-                        switchMapping(type);
+                        switchMapping(type, e.getNewValue().toString(), 
controllingAttrName.toString());
                 }
                
 

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to