svn commit: r15026 - branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels: module panel xml

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: penyaskito
Date: 2008-06-22 05:54:51-0700
New Revision: 15026

Added:
   branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/GenericUMLPlainTextDocument.java   (contents, props changed)
   branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XMLPropertyPanelsData.java   (contents, props changed)
Modified:
   branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/module/XmlPropertyPanelsModule.java
   branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/UIFactory.java
   branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java
   branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XMLPropertyPanelsHandler.java

Log:
Removed the dependency between the XML handler and the UI. Added a GenericUMLPlainTextDocument that handles the changes. Now we can have a name textbox that updates/updated itself from the model.

Modified: branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/module/XmlPropertyPanelsModule.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/module/XmlPropertyPanelsModule.java?view=diff&rev=15026&p1=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/module/XmlPropertyPanelsModule.java&p2=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/module/XmlPropertyPanelsModule.java&r1=15025&r2=15026
==============================================================================
--- branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/module/XmlPropertyPanelsModule.java	(original)
+++ branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/module/XmlPropertyPanelsModule.java	2008-06-22 05:54:51-0700
@@ -32,8 +32,13 @@
 import org.argouml.moduleloader.DetailsTabProvider;
 import org.argouml.moduleloader.ModuleInterface;
 
-
-public class XmlPropertyPanelsModule implements ModuleInterface, DetailsTabProvider {
+/**
+ * Defines the XMLPropertyPanels module
+ *
+ * @author penyaskito
+ */
+public class XmlPropertyPanelsModule 
+        implements ModuleInterface, DetailsTabProvider {
 
     public boolean disable() {
         return true;
@@ -50,7 +55,7 @@
     }
 
     public String getInfo(int type) {
-        switch (type){
+        switch (type) {
         case AUTHOR:
             return "Christian Lopez Espinola";
         case DESCRIPTION:

Added: branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/GenericUMLPlainTextDocument.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/GenericUMLPlainTextDocument.java?view=auto&rev=15026
==============================================================================
--- (empty file)
+++ branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/GenericUMLPlainTextDocument.java	2008-06-22 05:54:51-0700
@@ -0,0 +1,64 @@
+// $Id$
+// Copyright (c) 2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.core.propertypanels.panel;
+
+import org.argouml.model.Model;
+import org.argouml.uml.ui.UMLPlainTextDocument;
+
+/**
+ * Generic document for the plain text properties of the
+ * UML elements.
+ *
+ * @author penyaskito
+ */
+public class GenericUMLPlainTextDocument extends UMLPlainTextDocument {
+
+    private String fieldName = null;
+    
+    public GenericUMLPlainTextDocument(String theFieldName) {
+        super(theFieldName);
+        this.fieldName = theFieldName;
+    }
+    
+    @Override
+    protected String getProperty() {
+        Object target = getTarget();
+        // TODO: This can be a mess... There are any better solution?
+        if ("name".equals(fieldName)) {
+            return Model.getFacade().getName(target);
+        }
+        return null;
+    }
+
+    @Override
+    protected void setProperty(String text) {
+        Object target = getTarget();
+        // TODO: This can be a mess... There are any better solution?        
+        if ("name".equals(fieldName)) {
+            Model.getCoreHelper().setName(target, text);
+        }
+    }
+
+}

Modified: branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/UIFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/UIFactory.java?view=diff&rev=15026&p1=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/UIFactory.java&p2=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/UIFactory.java&r1=15025&r2=15026
==============================================================================
--- branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/UIFactory.java	(original)
+++ branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/UIFactory.java	2008-06-22 05:54:51-0700
@@ -26,16 +26,25 @@
 
 import java.io.InputStream;
 
+import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import javax.swing.JTextField;
 
 import org.apache.log4j.Logger;
+import org.argouml.core.propertypanels.xml.XMLPropertyPanelsData;
 import org.argouml.core.propertypanels.xml.XMLPropertyPanelsHandler;
+import org.argouml.uml.ui.UMLTextField2;
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.XMLReaderFactory;
 
 // TODO: This class will be an interface or abstract class
 // and will be implemented by SwingUIFactory and SwtUIFactory.
+/**
+ * Creates the XML Property panels
+ * <<factory>><<singleton>>
+ */
 public class UIFactory {
     
     /**
@@ -43,55 +52,86 @@
      */
     private static final Logger LOG = Logger.getLogger(UIFactory.class);
     
-    private static UIFactory INSTANCE = new UIFactory();
+    private static UIFactory instance = new UIFactory();
     
     public UIFactory() {
         
     }
     
     public static UIFactory getInstance() {        
-        return INSTANCE;
+        return instance;
     }
     
     // TODO: This will be a template method, where there will be two
     // implementations, for Swing and for SWT.
+    // TODO: This should take care of diagrams? or only model
+    // elements?
+    /**
+     * Creates a panel based on the target, using a XML that
+     * describes the UI of the panel.     * 
+     * @param target The model element selected
+     * @return A Panel to be added to the main panel
+     * @throws Exception If something goes wrong
+     */
     public JPanel createGUI (Object target) throws Exception {
         String filename = getXMLFileName(target);
         LOG.info("[XMLPP] filename is:" + filename);
-        JPanel panel = parseXML(filename);
+        XMLPropertyPanelsData data = parseXML(filename);
+        JPanel panel = buildPanel(data, target);
         return panel;       
     }
     
+    private JPanel buildPanel(XMLPropertyPanelsData data, Object target) {
+        
+        JPanel panel = new JPanel();
+               
+        for (String prop : data.getProperties()) {
+            JLabel label = new JLabel(prop);
+            GenericUMLPlainTextDocument document = 
+                new GenericUMLPlainTextDocument(prop);
+            document.setTarget(target);
+            JTextField tfield = 
+                new UMLTextField2(document);
+            tfield.setColumns(80);
+            panel.add(label);
+            panel.add(tfield);
+            panel.add(new JSeparator());
+        }
+        
+        return panel;
+    }
+
     private String getXMLFileName(Object target) {
         String classname = target.getClass().getSimpleName();
         // TODO: I don't like this hack, it may exist a better way.
         return classname.replace("$Impl", "");
     }
 
-    public JPanel parseXML(String filename) 
+    private XMLPropertyPanelsData parseXML(String filename) 
         throws Exception {
-        JPanel panel = new JPanel();
+        
+        XMLPropertyPanelsData data = new XMLPropertyPanelsData();
         
         // TODO: I have to investigate how to read the XML.
         // There are some different APIs available, but
         // I'll choose SAX because it's the one API used in
         // PGML, so we don't have different APIs in Argo.
         XMLReader parser = XMLReaderFactory.createXMLReader(
-                "org.apache.xerces.parsers.SAXParser"
-              );
-        parser.setContentHandler(new XMLPropertyPanelsHandler(panel));
+                "org.apache.xerces.parsers.SAXParser"              
+        );
+        parser.setContentHandler(new XMLPropertyPanelsHandler(data));
 
         String file = "org/argouml/core/propertypanels/xml/"
             + filename + ".xml";
-        LOG.info("File = "+ file);
-        LOG.info("URL="+this.getClass().getClassLoader().
-                getResource(file));
+        LOG.info("File = " + file);
         InputStream stream = this.getClass().getClassLoader().
             getResourceAsStream(file);
-        LOG.info("INPUT = " + stream);
-        InputSource source = new InputSource(stream);
-        parser.parse(source);        
-        
-        return panel; 
+        if (stream != null) {
+            InputSource source = new InputSource(stream);
+            parser.parse(source);        
+        }
+        return data;
     }
+    
+
 }

Modified: branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java?view=diff&rev=15026&p1=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java&p2=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java&r1=15025&r2=15026
==============================================================================
--- branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java	(original)
+++ branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XmlPropertyPanel.java	2008-06-22 05:54:51-0700
@@ -31,6 +31,11 @@
 import org.argouml.ui.TabFigTarget;
 import org.argouml.uml.ui.PropPanel;
 
+/**
+ * This class is the main property panel, based on XML
+ *
+ * @author penyaskito
+ */
 public class XmlPropertyPanel extends PropPanel 
     implements TabFigTarget {
     
@@ -39,6 +44,8 @@
      */
     private static final Logger LOG = Logger.getLogger(XmlPropertyPanel.class);
     
+    private JPanel currentPanel = null;
+    
     public XmlPropertyPanel(String label, ImageIcon icon) {
         super(label, icon);
     }
@@ -59,6 +66,7 @@
     @Override
     public void setTarget(Object t) {
         super.setTarget(t);
+        setTitle(t.toString());
         // TODO: Here will have to do something based on the 
         // type of the target received. For
         // commodity, we could use just the name:
@@ -67,11 +75,12 @@
         // UI and the model info, Class.ui.xml and Class.model.xml
         LOG.info("[XMLPP] t is type:" + t.getClass());
         
-        JPanel panel;
+        if (currentPanel != null) {
+            this.remove(currentPanel);
+        }
         try {
-            this.removeAll();
-            panel = UIFactory.getInstance().createGUI(t);
-            this.add(panel);
+            currentPanel = UIFactory.getInstance().createGUI(t);
+            this.add(currentPanel);
         } catch (Exception e) {
             // TODO: Auto-generated catch block
             LOG.error("Exception", e);

Added: branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XMLPropertyPanelsData.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XMLPropertyPanelsData.java?view=auto&rev=15026
==============================================================================
--- (empty file)
+++ branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XMLPropertyPanelsData.java	2008-06-22 05:54:51-0700
@@ -0,0 +1,111 @@
+// $Id$
+// Copyright (c) 2008 The Regents of the University of California. All
+// Rights Reserved. Permission to use, copy, modify, and distribute this
+// software and its documentation without fee, and without a written
+// agreement is hereby granted, provided that the above copyright notice
+// and this paragraph appear in all copies. This software program and
+// documentation are copyrighted by The Regents of the University of
+// California. The software program and documentation are supplied "AS
+// IS", without any accompanying services from The Regents. The Regents
+// does not warrant that the operation of the program will be
+// uninterrupted or error-free. The end-user understands that the program
+// was developed for research purposes and is advised not to rely
+// exclusively on the program for any reason. IN NO EVENT SHALL THE
+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+
+package org.argouml.core.propertypanels.xml;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Contains the data read on the XML file.
+ *
+ * @author penyaskito
+ */
+public class XMLPropertyPanelsData  {
+    
+    /**
+     * Logger.
+     */
+    private static final Logger LOG = 
+        Logger.getLogger(XMLPropertyPanelsData.class);
+        
+    /**
+     * The info of the properties in the XML.
+     */
+    private Dictionary<String, XMLPropertyPanelsDataRecord> properties;
+    
+    /**
+     * The info of the panels in the XML.
+     */
+    private XMLPropertyPanelsDataRecord panel;
+
+    
+    public XMLPropertyPanelsData() {
+        properties = new Hashtable<String, XMLPropertyPanelsDataRecord>();
+    }
+    
+    public void addProperty(String type, String name) {
+        XMLPropertyPanelsDataRecord record = new 
+            XMLPropertyPanelsDataRecord(type, name);
+        properties.put(name, record);
+    }
+    
+    public void addPanel(String title) {
+        if (panel != null) {
+            LOG.error("You tried to add a panel "
+            		+ "when a previous one exist.");            
+        }
+        panel = new XMLPropertyPanelsDataRecord("panel", title);
+    }
+    
+    public String getTitle() {
+        return panel.getName();
+    }
+    
+    public List<String> getProperties() {
+        List<String> props = new LinkedList<String>();
+        Enumeration<XMLPropertyPanelsDataRecord> elements =
+            properties.elements();
+        while (elements.hasMoreElements()) {
+            props.add(elements.nextElement().getName());
+        }
+        return props;
+    }
+    
+    class XMLPropertyPanelsDataRecord {
+        
+        private String type;
+        private String name;
+        
+        XMLPropertyPanelsDataRecord (String theType, String theName) {
+            this.type = theType;
+            this.name = theName;
+        }
+        
+        String getType() {
+            return type;
+        }
+
+        String getName() {
+            return name;
+        }
+    }
+}
+
+

Modified: branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XMLPropertyPanelsHandler.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XMLPropertyPanelsHandler.java?view=diff&rev=15026&p1=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XMLPropertyPanelsHandler.java&p2=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XMLPropertyPanelsHandler.java&r1=15025&r2=15026
==============================================================================
--- branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XMLPropertyPanelsHandler.java	(original)
+++ branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XMLPropertyPanelsHandler.java	2008-06-22 05:54:51-0700
@@ -24,14 +24,9 @@
 
 package org.argouml.core.propertypanels.xml;
 
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JSeparator;
-import javax.swing.JTextField;
-
-import org.xml.sax.helpers.DefaultHandler;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
 
 /**
  * This handles the XML events by SAX Api for building 
@@ -43,30 +38,26 @@
     /**
      * The panel that will host the controls. 
      */
-    private final JPanel panel;    
-    
+    private final XMLPropertyPanelsData data;       
     
     /**
-     * 
+     * Default constructor.
+     * @param theData The XMLPropertyPanelsData that will 
+     * host the info read.
      */
-    public XMLPropertyPanelsHandler(JPanel panel) {
-        this.panel = panel;
+    public XMLPropertyPanelsHandler(XMLPropertyPanelsData theData) {
+        this.data = theData;
     }
 
     public void startElement(String namespaceURI, String localName, 
             String qName, Attributes attr) throws SAXException { 
-        if (localName.equals("panel")){
+        if (localName.equals("panel")) {
             String title = attr.getValue("title");
-            panel.add(new JLabel(title));
-            panel.add(new JSeparator() );
+            data.addPanel(title);
         }
-        if (localName.equals("property")){
+        if (localName.equals("property")) {
             String name = attr.getValue("name");
-            String value = attr.getValue("value");
-            panel.add(new JLabel(name));
-            panel.add(new JTextField(value, 60));
-            panel.add(new JSeparator() );
+            data.addProperty("property", name);
         }
     }
-
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.