Author: ruschein
Date: 2010-02-18 14:17:01 -0800 (Thu, 18 Feb 2010)
New Revision: 19372

Modified:
   coreplugins/trunk/browser/src/browser/AttributeModel.java
   coreplugins/trunk/browser/src/browser/ui/ModPanel.java
Log:
Fixed Mantis bug #2183.

Modified: coreplugins/trunk/browser/src/browser/AttributeModel.java
===================================================================
--- coreplugins/trunk/browser/src/browser/AttributeModel.java   2010-02-18 
21:09:48 UTC (rev 19371)
+++ coreplugins/trunk/browser/src/browser/AttributeModel.java   2010-02-18 
22:17:01 UTC (rev 19372)
@@ -41,9 +41,12 @@
 import cytoscape.data.attr.MultiHashMapDefinitionListener;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
 import java.util.Vector;
 
 import javax.swing.ComboBoxModel;
@@ -61,20 +64,35 @@
        private final CyAttributes attributes;
        private List<String> attributeNames;
        private Object selection = null;
+       private Set<Byte> validAttrTypes;
 
        /**
         * Creates a new AttributeModel object.
         *
         * @param data  DOCUMENT ME!
         */
-       public AttributeModel(final CyAttributes data) {
+       public AttributeModel(final CyAttributes data, final Set<Byte> 
validAttrTypes) {
                this.attributes = data;
+               this.validAttrTypes = validAttrTypes;
                
data.getMultiHashMapDefinition().addDataDefinitionListener(this);
                sortAtttributes();
 
                
Cytoscape.getPropertyChangeSupport().addPropertyChangeListener(Cytoscape.ATTRIBUTES_CHANGED,
 this);
        }
 
+       @SuppressWarnings("unchecked") public AttributeModel(final CyAttributes 
data) {
+               this(data,
+                    new TreeSet<Byte>((List<Byte>)(Arrays.asList(new Byte[] {
+                       CyAttributes.TYPE_BOOLEAN,
+                       CyAttributes.TYPE_COMPLEX,
+                       CyAttributes.TYPE_FLOATING,
+                       CyAttributes.TYPE_INTEGER,
+                       CyAttributes.TYPE_SIMPLE_LIST,
+                       CyAttributes.TYPE_SIMPLE_MAP,
+                       CyAttributes.TYPE_STRING
+                       }))));
+       }
+
        public void propertyChange(PropertyChangeEvent e) {
                // This will handle the case for the change of attribute 
userVisibility
                if 
(e.getPropertyName().equalsIgnoreCase(Cytoscape.ATTRIBUTES_CHANGED)){
@@ -87,10 +105,10 @@
         */
        public void sortAtttributes() {
                attributeNames = new ArrayList<String>();
-               for(String attrName: 
CyAttributesUtils.getVisibleAttributeNames(attributes)) {
-                       if(attributes.getUserVisible(attrName)) {
+               for (String attrName: 
CyAttributesUtils.getVisibleAttributeNames(attributes)) {
+                       if (attributes.getUserVisible(attrName)
+                           && 
validAttrTypes.contains(attributes.getType(attrName)))
                                attributeNames.add(attrName);
-                       }
                }
                Collections.sort(attributeNames);
                notifyListeners(new ListDataEvent(this, 
ListDataEvent.CONTENTS_CHANGED, 0,

Modified: coreplugins/trunk/browser/src/browser/ui/ModPanel.java
===================================================================
--- coreplugins/trunk/browser/src/browser/ui/ModPanel.java      2010-02-18 
21:09:48 UTC (rev 19371)
+++ coreplugins/trunk/browser/src/browser/ui/ModPanel.java      2010-02-18 
22:17:01 UTC (rev 19372)
@@ -38,6 +38,10 @@
 import java.awt.GridBagLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.util.Arrays;
+import java.util.List;
+import java.util.TreeSet;
+import java.util.Set;
 
 import javax.swing.JButton;
 import javax.swing.JComboBox;
@@ -63,6 +67,10 @@
        private DataTableModel tableModel;
        private DataObjectType objectType;
 
+       private CyAttributes attrData;
+       private byte currentAttributeCopyToType = CyAttributes.TYPE_UNDEFINED;
+       private final AttributeModel defaultAttrModel;
+
        // Set/Modify
        JComboBox attributeModifyBox;
        JTextField field1;
@@ -74,7 +82,7 @@
 
        // Copy
        JComboBox attributeCopyFromBox;
-       JComboBox attributeCopytoBox;
+       JComboBox attributeCopyToBox;
        JButton copyGo;
 
        // Delete
@@ -89,10 +97,15 @@
         * @param graphObjectType  DOCUMENT ME!
         */
        public ModPanel(final DataTableModel tableModel, final DataObjectType 
graphObjectType) {
+               // get proper Global CytoscapeData object
+               this.attrData = graphObjectType.getAssociatedAttribute();
+
                this.data = graphObjectType.getAssociatedAttribute();
                this.tableModel = tableModel;
                this.objectType = graphObjectType;
 
+               this.defaultAttrModel = new AttributeModel(this.data);
+
                setLayout(new GridBagLayout());
 
                java.awt.GridBagConstraints gridBagConstraints = new 
java.awt.GridBagConstraints();
@@ -208,8 +221,9 @@
                JPanel copy = new JPanel(new java.awt.GridBagLayout());
                tabs.add("Copy", copy);
                attributeCopyFromBox = createAttributeBox();
-               attributeCopytoBox = createAttributeBox();
-               attributeCopytoBox.setEditable(true);
+               attributeCopyFromBox.addActionListener(this);
+               attributeCopyToBox = createAttributeBox();
+               attributeCopyToBox.setEditable(true);
                copyGo = new JButton("GO");
 
                copyGo.addActionListener(this);
@@ -243,7 +257,7 @@
                gridBagConstraints.weightx = 0.5;
                gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
 
-               copy.add(attributeCopytoBox, gridBagConstraints);
+               copy.add(attributeCopyToBox, gridBagConstraints);
 
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 4;
@@ -319,7 +333,7 @@
        }
 
        private JComboBox createAttributeBox() {
-               JComboBox box = new JComboBox(new AttributeModel(data));
+               JComboBox box = new JComboBox(defaultAttrModel);
                Dimension newSize = new Dimension(100, (int) 
box.getPreferredSize().getHeight());
                box.setMaximumSize(newSize);
                box.setPreferredSize(newSize);
@@ -358,11 +372,24 @@
                // 2. Copy operation
                else if (e.getSource() == copyGo) {
                        edit = new MultiDataEditAction(null, ActionName.COPY, 
tableModel.getObjects(),
-                                                      (String) 
attributeCopytoBox.getSelectedItem(),
+                                                      (String) 
attributeCopyToBox.getSelectedItem(),
                                                       (String) 
attributeCopyFromBox.getSelectedItem(), null,
                                                       objectType, tableModel);
                }
-               // 3. Delete (Clear?) operation
+               // 3. The copy source combobox fired an event
+               else if (e.getSource() == attributeCopyFromBox) {
+                       final String selectedItem = 
(String)attributeCopyFromBox.getSelectedItem();
+                       if (selectedItem != null) {
+                               final byte fromType = 
attrData.getType(selectedItem);
+                               if (fromType != currentAttributeCopyToType) {
+                                       final Set<Byte> attrTypes = new 
TreeSet<Byte>();
+                                       attrTypes.add(fromType);
+                                       attributeCopyToBox.setModel(new 
AttributeModel(data, attrTypes));
+                               }
+                       }
+                       return;
+               }       
+               // 4. Delete (Clear?) operation
                else {
                        edit = new MultiDataEditAction(null, ActionName.CLEAR, 
tableModel.getObjects(),
                                                       (String) 
attributeClearBox.getSelectedItem(), null,
@@ -376,3 +403,4 @@
 
        }
 }
+

-- 
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