svn commit: r14835 - trunk/src/argouml-app/src/org/argouml: i18n notation notation/providers notation/providers/uml uml/diagram/ui

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: mvw
Date: 2008-05-29 11:53:32-0700
New Revision: 14835

Added:
   trunk/src/argouml-app/src/org/argouml/notation/providers/EnumerationLiteralNotation.java   (contents, props changed)
   trunk/src/argouml-app/src/org/argouml/notation/providers/uml/EnumerationLiteralNotationUml.java   (contents, props changed)
Modified:
   trunk/src/argouml-app/src/org/argouml/i18n/parsing.properties
   trunk/src/argouml-app/src/org/argouml/i18n/statusmsg.properties
   trunk/src/argouml-app/src/org/argouml/notation/NotationProviderFactory2.java
   trunk/src/argouml-app/src/org/argouml/notation/providers/uml/InitNotationUml.java
   trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEnumLiteralsCompartment.java

Log:
Fix for issue 5000: Introduced an EnumerationLiteralNotation for UML.

Modified: trunk/src/argouml-app/src/org/argouml/i18n/parsing.properties
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/i18n/parsing.properties?view=diff&rev=14835&p1=trunk/src/argouml-app/src/org/argouml/i18n/parsing.properties&p2=trunk/src/argouml-app/src/org/argouml/i18n/parsing.properties&r1=14834&r2=14835
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/i18n/parsing.properties	(original)
+++ trunk/src/argouml-app/src/org/argouml/i18n/parsing.properties	2008-05-29 11:53:32-0700
@@ -71,6 +71,9 @@
 parsing.help.fig-componentinstance = Enter the name of the \
   componentinstance according: \
   name [ ":" type [ "," type]*]
+parsing.help.fig-enumeration-literal Enter the name of the \
+  enumeration literal according: \
+  [ "<<" stereotype ">>" ] name [ ";" name ]*
 parsing.help.fig-extensionpoint = Enter the Extension Point text according: \
   [ name ":" ] [ location ]
 parsing.help.fig-message = Enter the message definition according: \

Modified: trunk/src/argouml-app/src/org/argouml/i18n/statusmsg.properties
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/i18n/statusmsg.properties?view=diff&rev=14835&p1=trunk/src/argouml-app/src/org/argouml/i18n/statusmsg.properties&p2=trunk/src/argouml-app/src/org/argouml/i18n/statusmsg.properties&r1=14834&r2=14835
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/i18n/statusmsg.properties	(original)
+++ trunk/src/argouml-app/src/org/argouml/i18n/statusmsg.properties	2008-05-29 11:53:32-0700
@@ -1,5 +1,5 @@
 # $Id$
-# Copyright (c) 1996-2007 The Regents of the University of California. All
+# Copyright (c) 1996-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
@@ -49,6 +49,8 @@
 statusmsg.bar.error.parsing.callstate = Error parsing callstate: {0}
 statusmsg.bar.error.parsing.classifierrole = Error parsing classifierrole: {0} \
         at {1}
+statusmsg.bar.error.parsing.enumeration-literal = Error parsing enumeration \
+        literal: {0} at {1}
 statusmsg.bar.error.parsing.message = Error parsing message: {0} at {1}
 statusmsg.bar.error.parsing.node-modelelement = Error parsing modelelement: {0} at {1}
 statusmsg.bar.error.parsing.multiplicity = Error parsing multiplicity: {0}

Modified: trunk/src/argouml-app/src/org/argouml/notation/NotationProviderFactory2.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/notation/NotationProviderFactory2.java?view=diff&rev=14835&p1=trunk/src/argouml-app/src/org/argouml/notation/NotationProviderFactory2.java&p2=trunk/src/argouml-app/src/org/argouml/notation/NotationProviderFactory2.java&r1=14834&r2=14835
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/notation/NotationProviderFactory2.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/notation/NotationProviderFactory2.java	2008-05-29 11:53:32-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2005-2007 The Regents of the University of California. All
+// Copyright (c) 2005-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
@@ -39,7 +39,7 @@
  *  to access the textual representation of modelobjects, 
  *  and since plugin modules can add extra languages.
  *  
- * @author [email protected]
+ * @author Michiel
  */
 public final class NotationProviderFactory2 {
 
@@ -150,6 +150,11 @@
     public static final int TYPE_MULTIPLICITY = 19;
 
     /**
+     * The text shown for an enumeration literal.
+     */
+    public static final int TYPE_ENUMERATION_LITERAL = 20;
+
+    /**
      * defaultLanguage the Notation language used by default, i.e. UML
      */
     private NotationName defaultLanguage;
@@ -199,11 +204,15 @@
 
     /**
      * Get a NotationProvider for the current project.
+     * <p>
+     * If there is any reason for failure, null is returned - no
+     * exception is thrown. 
+     * The caller is supposed to deal with receiving null.
      * 
      * @param type the provider type
      * @param object the constructor parameter
      * @param name the name of the notation language to use
-     * @return the provider
+     * @return the provider, or null if there was any failure
      */
     private NotationProvider getNotationProvider(int type,
             Object object, NotationName name) {

Added: trunk/src/argouml-app/src/org/argouml/notation/providers/EnumerationLiteralNotation.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/notation/providers/EnumerationLiteralNotation.java?view=auto&rev=14835
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/notation/providers/EnumerationLiteralNotation.java	2008-05-29 11:53:32-0700
@@ -0,0 +1,65 @@
+// $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.notation.providers;
+
+import java.beans.PropertyChangeListener;
+import java.util.Collection;
+
+import org.argouml.model.Model;
+import org.argouml.notation.NotationProvider;
+
+/**
+ * This abstract class forms the basis of all Notation providers
+ * for the text shown in the Fig that represents an Enumeration Literal.
+ * Subclass this for all languages.
+ *
+ * @author Michiel
+ */
+public abstract class EnumerationLiteralNotation extends NotationProvider {
+
+    /**
+     * The constructor.
+     *
+     * @param enumLiteral the UML element
+     */
+    public EnumerationLiteralNotation(Object enumLiteral) {
+        if (!Model.getFacade().isAEnumerationLiteral(enumLiteral)) {
+            throw new IllegalArgumentException(
+                    "This is not an Enumeration Literal.");
+        }
+    }
+
+    @Override
+    public void initialiseListener(PropertyChangeListener listener, 
+            Object modelElement) {
+        addElementListener(listener, modelElement, 
+                new String[] {"remove", "stereotype"} );
+        Collection c = Model.getFacade().getStereotypes(modelElement);
+        for (Object st : c) {
+            addElementListener(listener, st, "name");
+        }
+    }
+
+}

Added: trunk/src/argouml-app/src/org/argouml/notation/providers/uml/EnumerationLiteralNotationUml.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/notation/providers/uml/EnumerationLiteralNotationUml.java?view=auto&rev=14835
==============================================================================
--- (empty file)
+++ trunk/src/argouml-app/src/org/argouml/notation/providers/uml/EnumerationLiteralNotationUml.java	2008-05-29 11:53:32-0700
@@ -0,0 +1,251 @@
+// $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.notation.providers.uml;
+
+import java.text.ParseException;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import org.argouml.application.events.ArgoEventPump;
+import org.argouml.application.events.ArgoEventTypes;
+import org.argouml.application.events.ArgoHelpEvent;
+import org.argouml.i18n.Translator;
+import org.argouml.kernel.Project;
+import org.argouml.kernel.ProjectManager;
+import org.argouml.model.Model;
+import org.argouml.notation.providers.EnumerationLiteralNotation;
+import org.argouml.uml.StereotypeUtility;
+import org.argouml.util.MyTokenizer;
+
+/**
+ * The notation for an Enumeration Literal. <p>
+ * 
+ * The supported notation is: <pre>
+ *     [ "<<" stereotype ">>" ] name [ ";" name ]*
+ * </pre>
+ * This means:<ul><li> 
+ * The name is not optional (i.e. leaving it blank 
+ * means deletion of the literal). <li>
+ * Multiple literals may be entered at once 
+ * by separating the names with a semicolon. <li> 
+ * A stereotype may precede the name. </ul><p>
+ * 
+ * As explained in issue 5000, the real implemented BNF is something like: 
+ * <pre>
+ *     ["<<" stereotype ["," stereotype]* ">>"] name [ ";" ["<<" stereotype ["," stereotype]* ">>"] name]*
+ * </pre>
+ * 
+ * @author Michiel
+ */
+public class EnumerationLiteralNotationUml extends EnumerationLiteralNotation {
+
+    /**
+     * The constructor.
+     * 
+     * @param enumLiteral the UML element
+     */
+    public EnumerationLiteralNotationUml(Object enumLiteral) {
+        super(enumLiteral);
+    }
+
+    @Override
+    public String getParsingHelp() {
+        return "parsing.help.fig-enumeration-literal";
+    }
+
+    @Override
+    public void parse(Object modelElement, String text) {
+        try {
+            parseEnumerationLiteralFig(
+                    Model.getFacade().getEnumeration(modelElement),
+                    modelElement, text);
+        } catch (ParseException pe) {
+            String msg = "statusmsg.bar.error.parsing.enumeration-literal";
+            Object[] args = {
+                pe.getLocalizedMessage(),
+                Integer.valueOf(pe.getErrorOffset()),
+            };
+            ArgoEventPump.fireEvent(new ArgoHelpEvent(
+                    ArgoEventTypes.HELP_CHANGED, this,
+                Translator.messageFormat(msg, args)));
+        }
+    }
+    
+    /**
+     * Parse a string representing one or more ";" separated 
+     * enumeration literals.
+     * 
+     * @param enumeration the enumeration that the literal belongs to
+     * @param literal the literal on which the editing will happen
+     * @param text the string to parse
+     * @throws ParseException for invalid input - so that the right 
+     * message may be shown to the user
+     */
+    protected void  parseEnumerationLiteralFig(
+            Object enumeration, Object literal, String text) 
+        throws ParseException {
+        
+        if (enumeration == null || literal == null) {
+            return;
+        }
+        Project project = ProjectManager.getManager().getCurrentProject();
+
+        ParseException pex = null;
+        int start = 0;
+        int end = NotationUtilityUml.indexOfNextCheckedSemicolon(text, start);
+        
+        if (end == -1) {
+            /* No text. We may remove the literal. */
+            project.moveToTrash(literal);
+            return;
+        }
+        String s = text.substring(start, end).trim();
+        if (s.length() == 0) {
+            /* No non-white chars in text? remove literal! */
+            project.moveToTrash(literal);
+            return;
+        }
+        parseEnumerationLiteral(s, literal);
+
+        int i = Model.getFacade().getEnumerationLiterals(enumeration)
+            .indexOf(literal);
+        // check for more literals (';' separated):
+        start = end + 1;
+        end = NotationUtilityUml.indexOfNextCheckedSemicolon(text, start);
+        while (end > start && end <= text.length()) {
+            s = text.substring(start, end).trim();
+            if (s.length() > 0) {
+                // yes, there are more:
+                Object newLiteral = 
+                    Model.getCoreFactory().createEnumerationLiteral();
+                if (newLiteral != null) {
+                    try {
+                        if (i != -1) {
+                            Model.getCoreHelper().addLiteral(
+                                    enumeration, ++i, newLiteral);
+                        } else {
+                            Model.getCoreHelper().addLiteral(
+                                    enumeration, 0, newLiteral);
+                        }
+                        parseEnumerationLiteral(s, newLiteral);
+                    } catch (ParseException ex) {
+                        if (pex == null) {
+                            pex = ex;
+                        }
+                    }
+                }
+            }
+            start = end + 1;
+            end = NotationUtilityUml.indexOfNextCheckedSemicolon(text, start);
+        }
+        if (pex != null) {
+            throw pex;
+        }
+    }
+
+    protected void parseEnumerationLiteral(String text, Object literal) 
+        throws ParseException {
+        text = text.trim();
+        if (text.length() == 0) {
+            return;
+        }
+        // strip any trailing semi-colons
+        if (text.charAt(text.length() - 1) == ';') {
+            text = text.substring(0, text.length() - 2);
+        }
+        MyTokenizer st;
+
+        String name = null;
+        StringBuilder stereotype = null;
+        String token;
+
+        try {
+            st = new MyTokenizer(text, "<<,\u00AB,\u00BB,>>");
+            while (st.hasMoreTokens()) {
+                token = st.nextToken();
+
+                if ("<<".equals(token) || "\u00AB".equals(token)) {
+                    if (stereotype != null) {
+                        String msg = 
+                            "parsing.error.model-element-name.twin-stereotypes";
+                        throw new ParseException(Translator.localize(msg),
+                                st.getTokenIndex());
+                    }
+
+                    stereotype = new StringBuilder();
+                    while (true) {
+                        token = st.nextToken();
+                        if (">>".equals(token) || "\u00BB".equals(token)) {
+                            break;
+                        }
+                        stereotype.append(token);
+                    }
+                } else {
+                    if (name != null) {
+                        String msg = 
+                            "parsing.error.model-element-name.twin-names";
+                        throw new ParseException(Translator.localize(msg), 
+                                st.getTokenIndex());
+                    }
+
+                    name = token;
+                }
+            }
+        } catch (NoSuchElementException nsee) {
+            String msg = 
+                "parsing.error.model-element-name.unexpected-name-element";
+            throw new ParseException(Translator.localize(msg),
+                    text.length());
+        } catch (ParseException pre) {
+            throw pre;
+        }
+
+        if (name != null) {
+            name = name.trim();
+        }
+        if (name != null) {
+            Model.getCoreHelper().setName(literal, name);
+        }
+
+        StereotypeUtility.dealWithStereotypes(literal, stereotype, false);
+
+        return;
+    }
+
+    @Override
+    public String toString(Object modelElement, Map args) {
+        String nameStr = "";
+        /* Heuristic algorithm: do not show stereotypes if there is no name. */
+        if (Model.getFacade().getName(modelElement) != null) {
+            nameStr = NotationUtilityUml.generateStereotype(modelElement, args);
+            if (nameStr.length() > 0) {
+                nameStr += " ";
+            }
+            nameStr += Model.getFacade().getName(modelElement).trim();
+        }
+        return nameStr;
+    }
+
+}

Modified: trunk/src/argouml-app/src/org/argouml/notation/providers/uml/InitNotationUml.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/notation/providers/uml/InitNotationUml.java?view=diff&rev=14835&p1=trunk/src/argouml-app/src/org/argouml/notation/providers/uml/InitNotationUml.java&p2=trunk/src/argouml-app/src/org/argouml/notation/providers/uml/InitNotationUml.java&r1=14834&r2=14835
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/notation/providers/uml/InitNotationUml.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/notation/providers/uml/InitNotationUml.java	2008-05-29 11:53:32-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 2005-2007 The Regents of the University of California. All
+// Copyright (c) 2005-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
@@ -113,6 +113,9 @@
         npf.addNotationProvider(
                 NotationProviderFactory2.TYPE_MULTIPLICITY,
                 name, MultiplicityNotationUml.class);
+        npf.addNotationProvider(
+                NotationProviderFactory2.TYPE_ENUMERATION_LITERAL,
+                name, EnumerationLiteralNotationUml.class);
 
         NotationProviderFactory2.getInstance().setDefaultNotation(name);
 

Modified: trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEnumLiteralsCompartment.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEnumLiteralsCompartment.java?view=diff&rev=14835&p1=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEnumLiteralsCompartment.java&p2=trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEnumLiteralsCompartment.java&r1=14834&r2=14835
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEnumLiteralsCompartment.java	(original)
+++ trunk/src/argouml-app/src/org/argouml/uml/diagram/ui/FigEnumLiteralsCompartment.java	2008-05-29 11:53:32-0700
@@ -1,5 +1,5 @@
 // $Id$
-// Copyright (c) 1996-2007 The Regents of the University of California. All
+// Copyright (c) 1996-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
@@ -35,7 +35,7 @@
 
 /**
  * The Fig for the compartment of an Enumeration 
- * that shows a list of enumerationliterals.
+ * that shows a list of enumeration literals.
  * 
  * @author Tom Morris
  */
@@ -69,10 +69,10 @@
      * @see org.argouml.uml.diagram.ui.FigEditableCompartment#getNotationType()
      */
     protected int getNotationType() {
-        /* TODO: Make a dedicated notation that supports 
-         * parsing "name1;name2" and maybe other notation... 
-         * Also needs to support deleting literal by erasing text. */
-        return NotationProviderFactory2.TYPE_NAME;
+        /* The EnumerationLiteral uses a dedicated notation that supports 
+         * parsing "name1;name2;name3" and stereotypes. 
+         * Also supports deleting a literal by erasing text. */
+        return NotationProviderFactory2.TYPE_ENUMERATION_LITERAL;
     }
 
     /**
@@ -81,7 +81,7 @@
     protected void createModelElement() {
         Object enumeration = getGroup().getOwner();
         Object literal = Model.getCoreFactory().buildEnumerationLiteral(
-                "",  enumeration);
+                "literal",  enumeration);
         TargetManager.getInstance().setTarget(literal);
     }
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.