Author: penyaskito
Date: 2008-07-31 15:25:51-0700
New Revision: 15430
Added:
branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XmlSinglePanelHandler.java (contents, props changed)
branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/panels.xml (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/XMLPropPanelFactory.java
branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java
Log:
We read a complete xml with the info of all the panels instead of a single xml for each model element panel.
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=15430&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=15429&r2=15430
==============================================================================
--- 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-07-31 15:25:51-0700
@@ -49,8 +49,8 @@
public boolean enable() {
/* Set up the property panels for UML elements: */
- PropPanelFactory elementFactory = new XMLPropPanelFactory();
- PropPanelFactoryManager.addPropPanelFactory(elementFactory);
+// PropPanelFactory elementFactory = new XMLPropPanelFactory();
+// PropPanelFactoryManager.addPropPanelFactory(elementFactory);
return true;
}
Modified: branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XMLPropPanelFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XMLPropPanelFactory.java?view=diff&rev=15430&p1=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XMLPropPanelFactory.java&p2=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XMLPropPanelFactory.java&r1=15429&r2=15430
==============================================================================
--- branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XMLPropPanelFactory.java (original)
+++ branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/panel/XMLPropPanelFactory.java 2008-07-31 15:25:51-0700
@@ -24,9 +24,18 @@
package org.argouml.core.propertypanels.panel;
+import java.io.InputStream;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.argouml.core.propertypanels.xml.XMLPropertyPanelsData;
+import org.argouml.core.propertypanels.xml.XmlSinglePanelHandler;
import org.argouml.model.Model;
import org.argouml.uml.ui.PropPanel;
import org.argouml.uml.ui.PropPanelFactory;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
/**
*
@@ -34,6 +43,23 @@
*/
public class XMLPropPanelFactory implements PropPanelFactory {
+ private final Dictionary<String, XMLPropertyPanelsData> cache;
+
+ private static XMLPropPanelFactory instance;
+
+ public static synchronized XMLPropPanelFactory getInstance()
+ throws Exception {
+ if (instance == null) {
+ instance = new XMLPropPanelFactory();
+ }
+ return instance;
+ }
+
+ private XMLPropPanelFactory() throws Exception {
+ cache = new Hashtable<String, XMLPropertyPanelsData>();
+ parseXML();
+ }
+
public PropPanel createPropPanel(Object target) {
if (Model.getFacade().isAModelElement(target)) {
XmlPropertyPanel panel =
@@ -44,5 +70,22 @@
return null;
}
}
-
+
+ private void parseXML() throws Exception {
+ String file = "org/argouml/core/propertypanels/xml/panels.xml";
+ XMLReader parser = XMLReaderFactory.createXMLReader();
+ parser.setContentHandler(new XmlSinglePanelHandler(cache));
+ InputStream stream = this.getClass().getClassLoader().
+ getResourceAsStream(file);
+ if (stream != null) {
+ InputSource source = new InputSource(stream);
+ parser.parse(source);
+ }
+ }
+
+ public XMLPropertyPanelsData getPropertyPanelsData (String forType) {
+ return cache.get(forType);
+ }
+
+
}
Modified: branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java?view=diff&rev=15430&p1=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java&p2=branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java&r1=15429&r2=15430
==============================================================================
--- branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java (original)
+++ branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/ui/SwingUIFactory.java 2008-07-31 15:25:51-0700
@@ -26,6 +26,7 @@
import java.io.InputStream;
+import javax.sql.rowset.spi.XmlReader;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JComboBox;
import javax.swing.JComponent;
@@ -37,9 +38,11 @@
import org.apache.log4j.Logger;
import org.argouml.core.propertypanels.panel.UIFactory;
+import org.argouml.core.propertypanels.panel.XMLPropPanelFactory;
import org.argouml.core.propertypanels.xml.XMLPropertyPanelsData;
import org.argouml.core.propertypanels.xml.XMLPropertyPanelsDataRecord;
import org.argouml.core.propertypanels.xml.XMLPropertyPanelsHandler;
+import org.argouml.core.propertypanels.xml.XmlSinglePanelHandler;
import org.argouml.i18n.Translator;
import org.argouml.model.Model;
import org.argouml.uml.ui.ScrollList;
@@ -145,9 +148,9 @@
* @see org.argouml.core.propertypanels.panel.UIFactory#createGUI(java.lang.Object)
*/
public JPanel createGUI (Object target) throws Exception {
- String filename = getXMLFileName(target);
- LOG.info("[XMLPP] filename is:" + filename);
- XMLPropertyPanelsData data = parseXML(filename);
+ XMLPropertyPanelsData data =
+ XMLPropPanelFactory.getInstance().getPropertyPanelsData(
+ Model.getMetaTypes().getName(target));
JPanel p = buildPanel(data, target);
return p;
}
@@ -688,29 +691,7 @@
}
- private String getXMLFileName(Object target) {
- return Model.getMetaTypes().getName(target);
- }
-
- private XMLPropertyPanelsData parseXML(String filename)
- throws Exception {
-
- XMLPropertyPanelsData data = new XMLPropertyPanelsData();
-
- XMLReader parser = XMLReaderFactory.createXMLReader();
- parser.setContentHandler(new XMLPropertyPanelsHandler(data));
-
- String file = "org/argouml/core/propertypanels/xml/"
- + filename + ".xml";
- LOG.debug("UIFactory creates PropPanel with file " + file);
- InputStream stream = this.getClass().getClassLoader().
- getResourceAsStream(file);
- if (stream != null) {
- InputSource source = new InputSource(stream);
- parser.parse(source);
- }
- return data;
- }
+
}
Added: branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XmlSinglePanelHandler.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XmlSinglePanelHandler.java?view=auto&rev=15430
==============================================================================
--- (empty file)
+++ branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/XmlSinglePanelHandler.java 2008-07-31 15:25:51-0700
@@ -0,0 +1,112 @@
+// $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 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
+ * the property panels.
+ * @author penyaskito
+ */
+public class XmlSinglePanelHandler extends DefaultHandler {
+
+ /**
+ * The panel that will host the controls.
+ */
+ private final Dictionary<String, XMLPropertyPanelsData> data;
+
+ /**
+ * the panel that we are traversing
+ */
+ private XMLPropertyPanelsData currentPanel = null;
+
+ private XMLPropertyPanelsDataRecord current = null;
+
+ /**
+ * Default constructor.
+ * @param theData The XMLPropertyPanelsData that will
+ * host the info read.
+ */
+ public XmlSinglePanelHandler(
+ Dictionary<String, XMLPropertyPanelsData> theData) {
+ this.data = theData;
+ }
+
+ public void startElement(String namespaceURI, String localName,
+ String qName, Attributes attr) throws SAXException {
+ // ignore the parent node, is only the container
+ if ("panels".equals(localName)) {
+ return;
+ }
+ if ("panel".equals(localName)) {
+ if (this.currentPanel == null) {
+ currentPanel = new XMLPropertyPanelsData();
+ currentPanel.addPanel(
+ new XMLPropertyPanelsDataRecord(localName,
+ attr.getValue("name")));
+ }
+ }
+ else {
+ XMLPropertyPanelsDataRecord record =
+ new XMLPropertyPanelsDataRecord(localName,
+ attr.getValue("name"));
+ if (isChild(localName)) {
+ current.addChild(record);
+ }
+ else if (hasChildren(localName)) {
+ current = record;
+ currentPanel.addProperty(record);
+ }
+ else {
+ currentPanel.addProperty(record);
+ }
+ }
+ }
+
+ @Override
+ public void endElement(String namespaceURI, String localName,
+ String qName) throws SAXException {
+ if ("panel".equals(localName)) {
+ data.put(currentPanel.getTitle(), currentPanel);
+ currentPanel = null;
+ }
+ }
+
+ private boolean isChild(String elementName) {
+ // for now, the only child are checkboxes.
+ return "checkbox".equals(elementName);
+ }
+
+ private boolean hasChildren(String elementName) {
+ // for now, the only element that can have
+ // children are checkgroups.
+ return "checkgroup".equals(elementName);
+ }
+}
Added: branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/panels.xml
Url: http://argouml.tigris.org/source/browse/argouml/branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/panels.xml?view=auto&rev=15430
==============================================================================
--- (empty file)
+++ branches/xmlpropertypanels-penyaskito-soc08/argouml-core-propertypanels-scratch/src/org/argouml/core/propertypanels/xml/panels.xml 2008-07-31 15:25:51-0700
@@ -0,0 +1,276 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<panels>
+ <panel name="Usage">
+ <text name="name" />
+ <combo name="namespace" />
+ <separator />
+ <list name="suppliers" />
+ <list name="clients" />
+ </panel>
+ <panel name="Stereotype">
+ <text name="name" />
+ <combo name="namespace" />
+ <optionbox name="visibility" />
+ <checkgroup name="modifiers">
+ <checkbox name="abstract" />
+ <checkbox name="leaf" />
+ <checkbox name="root" />
+ </checkgroup>
+ <separator />
+ <list name="client_dependency" />
+ <list name="supplier_dependency" />
+ <list name="tag_definitions" />
+ <separator />
+ <list name="base_class" />
+ <list name="extended_elements" />
+ </panel>
+ <panel name="Signal">
+ <text name="name" />
+ <combo name="namespace" />
+ <optionbox name="visibility" />
+ <checkgroup name="modifiers">
+ <checkbox name="abstract" />
+ <checkbox name="leaf" />
+ <checkbox name="root" />
+ <checkbox name="derived" />
+ </checkgroup>
+ <separator />
+ <list name="generalizations" />
+ <list name="specializations" />
+ <separator />
+ <list name="contexts" />
+ <list name="receptions" />
+ </panel>
+ <panel name="Parameter">
+ <text name="name" />
+ <singlerow name="feature" />
+ <separator />
+ <combo name="type" />
+ <textarea name="default_value" />
+ <optionbox name="direction_kind" />
+ </panel>
+ <panel name="Package">
+ <text name="name" />
+ <combo name="namespace" />
+ <optionbox name="visibility" />
+ <checkgroup name="modifiers">
+ <checkbox name="abstract" />
+ <checkbox name="leaf" />
+ <checkbox name="root" />
+ <checkbox name="derived" />
+ </checkgroup>
+ <separator />
+ <list name="generalizations" />
+ <list name="specializations" />
+ <separator />
+ <list name="owned" />
+ <list name="imported_elements" />
+ </panel>
+ <panel name="Operation">
+ <text name="name" />
+ <singlerow name="owner" />
+ <list name="parameters" />
+ <separator />
+ <optionbox name="visibility" />
+ <checkgroup name="modifiers">
+ <checkbox name="abstract" />
+ <checkbox name="leaf" />
+ <checkbox name="root" />
+ <checkbox name="query" />
+ <checkbox name="static" />
+ </checkgroup>
+ <optionbox name="concurrency" />
+ <separator />
+ <list name="raised_signals" />
+ <list name="methods" />
+ <textarea name="specification" />
+ </panel>
+ <panel name="Interface">
+ <text name="name" />
+ <combo name="namespace" />
+ <optionbox name="visibility" />
+ <!-- TODO: NESTED ELEMENTS! WE NEED A TREE STRUCTURE -->
+ <checkgroup name="modifiers">
+ <checkbox name="abstract" />
+ <checkbox name="leaf" />
+ <checkbox name="root" />
+ <checkbox name="derived" />
+ </checkgroup>
+ <separator />
+ <list name="generalizations" />
+ <list name="specializations" />
+ <separator />
+ <list name="association_ends" />
+ <list name="features" />
+ </panel>
+ <panel name="Generalization">
+ <text name="name" />
+ <text name="discriminator" />
+ <combo name="namespace" />
+ <separator />
+ <singlerow name="parent" />
+ <singlerow name="child" />
+ <combo name="powertype" />
+ </panel>
+ <panel name="Exception">
+ <text name="name" />
+ <combo name="namespace" />
+ <optionbox name="visibility" />
+ <checkgroup name="modifiers">
+ <checkbox name="abstract" />
+ <checkbox name="leaf" />
+ <checkbox name="root" />
+ <checkbox name="derived" />
+ </checkgroup>
+ <separator />
+ <list name="generalizations" />
+ <list name="specializations" />
+ <separator />
+ <list name="contexts" />
+ <list name="receptions" />
+ </panel>
+ <panel name="EnumerationLiteral">
+ <text name="name" />
+ <singlerow name="enumeration" />
+ </panel>
+ <panel name="Enumeration">
+ <text name="name" />
+ <combo name="namespace" />
+ <optionbox name="visibility" />
+ <checkgroup name="modifiers">
+ <checkbox name="abstract" />
+ <checkbox name="leaf" />
+ <checkbox name="root" />
+ <checkbox name="derived" />
+ </checkgroup>
+ <separator />
+ <list name="client_dependency" />
+ <list name="supplier_dependency" />
+ <list name="generalizations" />
+ <list name="specializations" />
+ <separator />
+ <list name="operations" />
+ <list name="literals" />
+ </panel>
+ <panel name="Datatype">
+ <text name="name" />
+ <combo name="namespace" />
+ <optionbox name="visibility" />
+ <checkgroup name="modifiers">
+ <checkbox name="abstract" />
+ <checkbox name="leaf" />
+ <checkbox name="root" />
+ <checkbox name="derived" />
+ </checkgroup>
+ <separator />
+ <list name="client_dependency" />
+ <list name="supplier_dependency" />
+ <list name="generalizations" />
+ <list name="specializations" />
+ <separator />
+ <list name="operations" />
+ </panel>
+ <panel name="Comment">
+ <text name="name" />
+ <list name="annotated_elements" />
+ <separator />
+ <textarea name="body" />
+ </panel>
+ <panel name="Class">
+ <text name="name" />
+ <combo name="namespace" />
+ <optionbox name="visibility" />
+ <checkgroup name="modifiers">
+ <checkbox name="abstract" />
+ <checkbox name="leaf" />
+ <checkbox name="root" />
+ <checkbox name="derived" />
+ <checkbox name="active" />
+ </checkgroup>
+ <separator />
+ <list name="client_dependency" />
+ <list name="supplier_dependency" />
+ <list name="generalizations" />
+ <list name="specializations" />
+ <separator />
+ <list name="attributes" />
+ <list name="association_ends" />
+ <list name="operations" />
+ <list name="owned" />
+ </panel>
+ <panel name="Attribute">
+ <text name="name" />
+ <combo name="type" />
+ <combo name="multiplicity" />
+ <singlerow name="owner" />
+ <separator />
+ <optionbox name="visibility" />
+ <optionbox name="changeability" />
+ <checkgroup name="modifiers">
+ <checkbox name="static" />
+ </checkgroup>
+ <textarea name="initial_value" />
+ </panel>
+ <panel name="AssociationEnd">
+ <text name="name" />
+ <singlerow name="association" />
+ <combo name="type" />
+ <combo name="multiplicity" />
+ <separator />
+ <checkgroup name="modifiers">
+ <checkbox name="navigable" />
+ <checkbox name="ordered" />
+ <checkbox name="static" />
+ </checkgroup>
+ <list name="specification" />
+ <list name="qualifiers" />
+ <separator />
+ <optionbox name="aggregation" />
+ <optionbox name="changeability" />
+ <optionbox name="visibility" />
+ </panel>
+ <panel name="AssociationClass">
+ <text name="name" />
+ <combo name="namespace" />
+ <optionbox name="visibility" />
+ <checkgroup name="modifiers">
+ <checkbox name="abstract" />
+ <checkbox name="leaf" />
+ <checkbox name="root" />
+ <checkbox name="derived" />
+ <checkbox name="active" />
+ </checkgroup>
+ <separator />
+ <list name="client_dependency" />
+ <list name="supplier_dependency" />
+ <list name="generalizations" />
+ <list name="specializations" />
+ <list name="connections" />
+ <separator />
+ <list name="attributes" />
+ <list name="association_ends" />
+ <list name="operations" />
+ <list name="owned" />
+ </panel>
+ <panel name="Association">
+ <text name="name" />
+ <combo name="namespace" />
+ <checkgroup name="modifiers">
+ <checkbox name="abstract" />
+ <checkbox name="leaf" />
+ <checkbox name="root" />
+ </checkgroup>
+ <separator />
+ <list name="connections" />
+ <separator />
+ <list name="association_roles" />
+ <list name="links" />
+ </panel>
+ <panel name="Abstraction">
+ <text name="name" />
+ <combo name="namespace" />
+ <separator />
+ <list name="clients" />
+ <list name="suppliers" />
+ </panel>
+</panels>
\ No newline at end of file
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.