Author: bobtarling
Date: 2010-11-06 07:54:07-0700
New Revision: 18838

Modified:
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/MetaDataCache.java
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/PanelData.java
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/metamodel.xml
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/metamodel2.xml
   
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java

Log:
Drive the appearance of the navigate sibling by XML attribtues rather than hard 
coding.
Begin work to allow new child and new sibling buttons on a panel.

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/MetaDataCache.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/MetaDataCache.java?view=diff&pathrev=18838&r1=18837&r2=18838
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/MetaDataCache.java
       (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/MetaDataCache.java
       2010-11-06 07:54:07-0700
@@ -15,7 +15,9 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
 
@@ -121,30 +123,41 @@
         for (int i = 0; i < panelNodes.getLength(); ++i) {
             
             Element panelNode = (Element) panelNodes.item(i);
-            final String name = 
-               panelNode.getAttributes().getNamedItem("name").getNodeValue();
+            final String name = panelNode.getAttribute("name");
+
             Class<?> clazz = metaTypeByName.get(name);
 
             if (clazz == null) {
                 LOG.warn("No class name translation found for panel: " + name);
             } else {
-                PanelData pm = new PanelData(clazz, name);
+                final List<Class<?>> newChildTypes =
+                    stringToMetaTypes(panelNode.getAttribute("new-child"));
+                final List<Class<?>> newSiblingTypes =
+                    stringToMetaTypes(panelNode.getAttribute("new-sibling"));
+                
+                final boolean siblingNavigation =
+                    "true".equals(panelNode.getAttribute("navigate-sibling"));
+                
+                final PanelData pm =
+                    new PanelData(clazz, name, newChildTypes, newSiblingTypes, 
siblingNavigation);
                 map.put(clazz, pm);
                 
-                final NodeList controlNodes = 
panelNode.getElementsByTagName("*");
+                final NodeList controlNodes =
+                    panelNode.getElementsByTagName("*");
                 for (int j = 0; j < controlNodes.getLength(); ++j) {
                     Element controlNode = (Element) controlNodes.item(j);
                     
-                    final String propertyName = 
controlNode.getAttribute("name");
+                    final String propertyName =
+                       controlNode.getAttribute("name");
                     final String label = controlNode.getAttribute("label");
                     
                     final ControlData controlData =
                         new ControlData(controlNode.getTagName(), 
propertyName, label);
                     
-                    final String types = controlNode.getAttribute("type");
-                    StringTokenizer st = new StringTokenizer(types, ",");
-                    while (st.hasMoreTokens()) {
-                        
controlData.addType(metaTypeByName.get(st.nextToken()));
+                    final List<Class<?>> types =
+                       stringToMetaTypes(controlNode.getAttribute("type"));
+                    for (Class<?> metaType : types) {
+                        controlData.addType(metaType);
                     }
                     
                     if (controlNode.getTagName().equals("checkgroup")) {
@@ -158,6 +171,22 @@
         return map;
     }
     
+    /**
+     * Takes as input a string of comma separated metatypes (e.g.
+     * "Class,Interface,Attribute") and converts it to a list of classes of
+     * the appropriate type.
+     * @param typesString
+     * @return 
+     */
+    private List<Class<?>> stringToMetaTypes(String typesString) {
+       List<Class<?>> classes = new ArrayList<Class<?>>();
+        StringTokenizer st = new StringTokenizer(typesString, ",");
+        while (st.hasMoreTokens()) {
+            classes.add(metaTypeByName.get(st.nextToken()));
+        }
+        return classes;
+    }
+    
     private void addCheckboxes(ControlData controlData, Element 
controlElement) {
         final NodeList checkBoxElements =
             controlElement.getElementsByTagName("checkbox");

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/PanelData.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/PanelData.java?view=diff&pathrev=18838&r1=18837&r2=18838
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/PanelData.java
   (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/PanelData.java
   2010-11-06 07:54:07-0700
@@ -13,6 +13,7 @@
 
 package org.argouml.core.propertypanels.model;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
@@ -22,13 +23,29 @@
     private final Class<?> clazz;
     private final List<ControlData> properties;
     private final String name;
-    
-    public PanelData(Class<?> clazz, String name) {
+    private final Collection<Class<?>> newChildElements;
+    private final Collection<Class<?>> newSiblingElements;
+    private final boolean siblingNavigation;
+    
+    public PanelData(
+           final Class<?> clazz,
+           final String name,
+           final Collection<Class<?>> newChildElements,
+           final Collection<Class<?>> newSiblingElements,
+           final boolean siblingNavigation) {
+       
         this.clazz = clazz;
         this.name = name;
         properties = new LinkedList<ControlData>();
+        this.newChildElements = newChildElements;
+        this.newSiblingElements = newSiblingElements;
+        this.siblingNavigation = siblingNavigation;
     }
     
+    public boolean isSiblingNavigation() {
+        return siblingNavigation;
+    }
+
     public void addControlData(ControlData record) {
         properties.add(record);
     }
@@ -44,4 +61,12 @@
     public List<ControlData> getProperties () {
         return Collections.unmodifiableList(properties);
     }
+
+    public Collection<Class<?>> getNewChildElements() {
+        return newChildElements;
+    }
+
+    public Collection<Class<?>> getNewSiblingElements() {
+        return newSiblingElements;
+    }
 }

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/metamodel.xml
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/metamodel.xml?view=diff&pathrev=18838&r1=18837&r2=18838
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/metamodel.xml
    (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/metamodel.xml
    2010-11-06 07:54:07-0700
@@ -339,7 +339,7 @@
     <list name="classifierInState" type="Classifier" 
label="label.classifier-in-state" />
     <list name="objectFlowState" type="Classifier" />
   </panel>
-  <panel name="Class" newchild="Attribute,Operation">
+  <panel name="Class" new-child="Attribute,Operation">
     <text name="name" type="Name" />
     <combo name="namespace" type="Namespace" />    
     <optionbox name="visibility" type="VisibilityKind" />
@@ -498,7 +498,7 @@
     <attribute name="ordering" type="OrderingKind" />
     <attribute name="type" type="Classifier" />
   </panel>
-  <panel name="AssociationEnd">
+  <panel name="AssociationEnd" navigate-sibling="true" >
     <text name="name" type="Name" />
     <combo name="participant" type="Classifier" label="label.type" />
     <combo name="multiplicity" type="Multiplicity" />
@@ -683,7 +683,7 @@
     <attribute name="generalization" type="Generalization" />
     <attribute name="specialization" type="GeneralizableElement" />    
   </panel>
-  <panel name="Attribute" newsibling="Attribute">
+  <panel name="Attribute" new-sibling="Reception,Operation,Attribute" 
navigate-sibling="true" >
     <text name="name" type="Name" />
     <combo name="type" type="Classifier" />
     <combo name="multiplicity" type="Multiplicity" />
@@ -755,7 +755,7 @@
     <separator />
     <list name="raisedSignal" type="Signal" new="true" 
label="label.raisedsignals" />
   </panel>
-  <panel name="Operation" newsibling="Operation">
+  <panel name="Operation" new-sibling="Reception,Operation,Attribute" 
navigate-sibling="true" >
     <text name="name" type="Name" />
     <singlerow name="owner" type="Classifier" />
     <list name="parameter" type="Parameter" new="true" />
@@ -798,7 +798,7 @@
     <attribute name="callAction" type="Operation" />
     <attribute name="occurrence" type="Operation" />
   </panel>
-  <panel name="Parameter">
+  <panel name="Parameter" navigate-sibling="true" >
     <text name="name" type="Name" />
     <singlerow name="behavioralFeature" type="BehavioralFeature" />
     <combo name="type" type="Classifier" />
@@ -2185,7 +2185,7 @@
     <attribute name="value" type="Expression" />
     <attribute name="action" type="Action" />
   </panel>
-  <panel name="Reception" newsibling="Reception">
+  <panel name="Reception" new-sibling="Reception,Operation,Attribute" 
navigate-sibling="true" >
     <text name="name" type="Name" />
     <singlerow name="owner" type="Classifier" />
     <optionbox name="visibility" type="VisibilityKind" />

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/metamodel2.xml
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/metamodel2.xml?view=diff&pathrev=18838&r1=18837&r2=18838
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/metamodel2.xml
   (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/model/metamodel2.xml
   2010-11-06 07:54:07-0700
@@ -587,7 +587,7 @@
     <attribute name="generalization" type="Generalization" />
     <attribute name="specialization" type="GeneralizableElement" />    
   </panel>
-  <panel name="Property">
+  <panel name="Property" navigate-sibling="true" >
     <text name="name" type="Name" />
     <combo name="type" type="Classifier" />
     <combo name="multiplicity" type="Multiplicity" />
@@ -659,7 +659,7 @@
     <separator />
     <list name="raisedSignal" type="Signal" new="true" 
label="label.raisedsignals" />
   </panel>
-  <panel name="Operation">
+  <panel name="Operation" navigate-sibling="true" >
     <text name="name" type="Name" />
     <singlerow name="owner" type="Classifier" />
     <list name="parameter" type="Parameter" new="true" />
@@ -2049,7 +2049,7 @@
     <attribute name="value" type="Expression" />
     <attribute name="action" type="Action" />
   </panel>
-  <panel name="Reception">
+  <panel name="Reception" navigate-sibling="true" >
     <text name="name" type="Name" />
     <singlerow name="owner" type="Classifier" />
     <optionbox name="visibility" type="VisibilityKind" />

Modified: 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java
Url: 
http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java?view=diff&pathrev=18838&r1=18837&r2=18838
==============================================================================
--- 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java
 (original)
+++ 
trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java
 2010-11-06 07:54:07-0700
@@ -54,6 +54,7 @@
 import org.argouml.core.propertypanels.model.CheckBoxData;
 import org.argouml.core.propertypanels.model.ControlData;
 import org.argouml.core.propertypanels.model.GetterSetterManager;
+import org.argouml.core.propertypanels.model.MetaDataCache;
 import org.argouml.core.propertypanels.model.PanelData;
 import org.argouml.i18n.Translator;
 import org.argouml.model.Model;
@@ -81,13 +82,13 @@
     public void createGUI (
             final Object target,
             final JPanel panel) throws Exception {
-        PanelData data = 
+        PanelData panelData = 
             XMLPropPanelFactory.getInstance().getPropertyPanelsData(
                target.getClass());
             
-        createLabel(target, panel);
+        createLabel(target, panelData, panel);
             
-        for (ControlData prop : data.getProperties()) {
+        for (ControlData prop : panelData.getProperties()) {
             try {
                 if ("text".equals(prop.getControlType())) {
                     buildTextboxPanel(panel, target, prop);
@@ -120,7 +121,10 @@
      * @param target
      * @param panel
      */
-    private void createLabel (Object target, JPanel panel) {
+    private void createLabel(
+           final Object target,
+           final PanelData panelData,
+           final JPanel panel) {
         final String metaTypeName = Model.getMetaTypes().getName(target);
         final ToolBarFactory tbf = new ToolBarFactory(new Object[0]);
         tbf.setRollover(true);
@@ -139,12 +143,7 @@
         if (!Model.getModelManagementHelper().isReadOnly(target)) {
             tb.add(new NavigateUpAction(target));
             
-            // TODO: This should not be hard coded but should be driven from 
the panel xml
-            if (Model.getFacade().isAAttribute(target)
-                || Model.getFacade().isAOperation(target)
-                || Model.getFacade().isAReception(target)
-                || Model.getFacade().isAParameter(target)
-                || Model.getFacade().isAAssociationEnd(target)) {
+            if (panelData.isSiblingNavigation()) {
                 tb.add(new NavigatePreviousAction(target));
                 tb.add(new NavigateNextAction(target));
             }
@@ -153,6 +152,15 @@
             // We only have this here until we have stereotypes
             // list on property panel
             tb.add(new ActionNewStereotype());
+            
+            for (Class<?> newChildElement : panelData.getNewChildElements()) {
+               LOG.debug("Child = " + newChildElement);
+               // TODO: Create new child action here
+            }
+            for (Class<?> newSiblingElement : 
panelData.getNewSiblingElements()) {
+               LOG.debug("Sibling = " + newSiblingElement);
+               // TODO: Create new sibling action here
+            }
         }
         panel.add(tb);
     }

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2679536

To unsubscribe from this discussion, e-mail: 
[[email protected]].

Reply via email to