svn commit: r19145 - trunk/src: argouml-core-model-euml/src/org/argouml/model/euml argouml-core-model-mdr/src/org/argouml/model/mdr argouml-core-model/src/org/argouml/model

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2011-03-30 09:15:11-0700
New Revision: 19145

Added:
   trunk/src/argouml-core-model/src/org/argouml/model/UmlFactoryDefaults.java
Modified:
   trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java
   trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java
   trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreHelperMDRImpl.java
   trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java
   trunk/src/argouml-core-model/src/org/argouml/model/UmlFactory.java

Log:
Allow uml factory to set a default type for certain newly created model elements

Modified: trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java?view=diff&pathrev=19145&r1=19144&r2=19145
==============================================================================
--- trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java	(original)
+++ trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/CoreHelperEUMLImpl.java	2011-03-30 09:15:11-0700
@@ -1,6 +1,6 @@
 // $Id$
 /*******************************************************************************
- * Copyright (c) 2007,2010 Tom Morris and other contributors
+ * Copyright (c) 2007-2011 Tom Morris and other contributors
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -11,6 +11,7 @@
  *    Bogdan Pistol - initial implementation
  *    Thomas Neustupny
  *    Michiel van der Wulp
+ *    Bob Tarling
  *****************************************************************************/
 
 package org.argouml.model.euml;
@@ -1902,20 +1903,23 @@
     }
 
     public void setType(final Object handle, final Object type) {
-        if (!(handle instanceof TypedElement)) {
+        if (!(handle instanceof TypedElement) && !(handle instanceof Operation)) {
             throw new IllegalArgumentException(
                     "handle must be instance of TypedElement"); //$NON-NLS-1$
         }
         if (type != null && !(type instanceof Type)) {
             throw new IllegalArgumentException("type must be instance of Type"); //$NON-NLS-1$
         }
+        final TypedElement typedElement;
+        if (handle instanceof Operation) {
+            typedElement = (TypedElement) getReturnParameters(handle).get(0);
+        } else {
+            typedElement = (TypedElement) handle;
+        }
+
         RunnableClass run = new RunnableClass() {
             public void run() {
-                if (type != null) {
-                    ((TypedElement) handle).setType((Type) type);
-                } else {
-                    ((TypedElement) handle).setType(null);
-                }
+                typedElement.setType((Type) type);
             }
         };
         editingDomain.getCommandStack().execute(

Modified: trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java?view=diff&pathrev=19145&r1=19144&r2=19145
==============================================================================
--- trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java	(original)
+++ trunk/src/argouml-core-model-euml/src/org/argouml/model/euml/UmlFactoryEUMLImpl.java	2011-03-30 09:15:11-0700
@@ -1,6 +1,6 @@
 /* $Id$
  *******************************************************************************
- * Copyright (c) 2007,2010 Tom Morris and other contributors
+ * Copyright (c) 2007-2011 Tom Morris and other contributors
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -28,6 +28,7 @@
 import org.argouml.model.InvalidElementException;
 import org.argouml.model.MetaTypes;
 import org.argouml.model.UmlFactory;
+import org.argouml.model.UmlFactoryDefaults;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.resource.Resource;
@@ -282,7 +283,16 @@
     }
 
     public Object buildNode(Object elementType, Object container) {
-        return buildNode(elementType, container, null);
+        return buildNode(elementType, container, (String) null);
+    }
+    
+    public Object buildNode(Object elementType, Object container, String property, UmlFactoryDefaults defaults) {
+        Object element = buildNode(elementType, container, property);
+        if (defaults != null && defaults.getDefaultType(elementType) != null) {
+            Object type = defaults.getDefaultType(elementType);
+            modelImpl.getCoreHelper().setType(element, type);
+        }
+        return element;
     }
 
     public Object buildNode(Object elementType) {

Modified: trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreHelperMDRImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreHelperMDRImpl.java?view=diff&pathrev=19145&r1=19144&r2=19145
==============================================================================
--- trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreHelperMDRImpl.java	(original)
+++ trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/CoreHelperMDRImpl.java	2011-03-30 09:15:11-0700
@@ -1,6 +1,6 @@
 /* $Id$
  *****************************************************************************
- * Copyright (c) 2009-2010 Contributors - see below
+ * Copyright (c) 2009-2011 Contributors - see below
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -10,6 +10,7 @@
  *    Thomas Neustupny
  *    Michiel van der Wulp
  *    Tom Morris
+ *    Bob Tarling
  *****************************************************************************
  *
  * Some portions of this file was previously release using the BSD License:
@@ -3394,6 +3395,13 @@
                 ((StructuralFeature) handle).setType((Classifier) type);
                 return;
             }
+            if (handle instanceof Operation) {
+                if (!getReturnParameters(handle).isEmpty()) {
+                    Parameter p = getReturnParameters(handle).get(0);
+                    p.setType((Classifier) type);
+                }
+                return;
+            }
         }
         throw new IllegalArgumentException("handle: " + handle + " or type: "
                 + type);

Modified: trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java?view=diff&pathrev=19145&r1=19144&r2=19145
==============================================================================
--- trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java	(original)
+++ trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/UmlFactoryMDRImpl.java	2011-03-30 09:15:11-0700
@@ -1,6 +1,6 @@
 /* $Id$
  *****************************************************************************
- * Copyright (c) 2009-2010 Contributors - see below
+ * Copyright (c) 2009-2011 Contributors - see below
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -57,6 +57,7 @@
 import org.argouml.model.MetaTypes;
 import org.argouml.model.Model;
 import org.argouml.model.UmlFactory;
+import org.argouml.model.UmlFactoryDefaults;
 import org.omg.uml.behavioralelements.activitygraphs.ActionState;
 import org.omg.uml.behavioralelements.activitygraphs.ActivityGraph;
 import org.omg.uml.behavioralelements.activitygraphs.CallState;
@@ -792,6 +793,16 @@
                 "Attempted to create unsupported model element type: " 
                 + elementType);
     }
+    
+    public Object buildNode(Object elementType, Object container, String property, UmlFactoryDefaults defaults) {
+        Object element = buildNode(elementType, container, property);
+        if (defaults != null && defaults.getDefaultType(elementType) != null) {
+            Object type = defaults.getDefaultType(elementType);
+            modelImpl.getCoreHelper().setType(element, type);
+        }
+        return element;
+    }
+    
 
     public Object buildNode(Object elementType, Object container, String properyName) {
         
@@ -958,7 +969,7 @@
     }
 
     public Object buildNode(Object elementType, Object container) {
-        return buildNode(elementType, container, null);
+        return buildNode(elementType, container, (String) null);
     }
     
     

Modified: trunk/src/argouml-core-model/src/org/argouml/model/UmlFactory.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model/src/org/argouml/model/UmlFactory.java?view=diff&pathrev=19145&r1=19144&r2=19145
==============================================================================
--- trunk/src/argouml-core-model/src/org/argouml/model/UmlFactory.java	(original)
+++ trunk/src/argouml-core-model/src/org/argouml/model/UmlFactory.java	2011-03-30 09:15:11-0700
@@ -1,13 +1,14 @@
 /* $Id$
  *******************************************************************************
- * Copyright (c) 2009 Contributors - see below
+ * Copyright (c) 2009-2011 Contributors - see below
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
  *
  * Contributors:
- *    tfmorris
+ *    Tom Morris
+ *    Bob Tarling
  *******************************************************************************
  *
  * Some portions of this file was previously release using the BSD License:
@@ -103,6 +104,19 @@
      * @param elementType the type of model element to build
      * @param container the model element that will contain the 
      * newly built model element
+     * @param defaults the default values to apply to the new element
+     * @return the model element
+     */
+    Object buildNode(Object elementType, Object container, String property, UmlFactoryDefaults defaults);
+
+    
+    /**
+     * Creates a UML model element of the given type and adds 
+     * it to the passed in container.
+     * 
+     * @param elementType the type of model element to build
+     * @param container the model element that will contain the 
+     * newly built model element
      * @param property the property name of the containment
      * this is only required when a container has multiple
      * properties old containing the same type of object

Added: trunk/src/argouml-core-model/src/org/argouml/model/UmlFactoryDefaults.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model/src/org/argouml/model/UmlFactoryDefaults.java?view=markup&pathrev=19145
==============================================================================
--- (empty file)
+++ trunk/src/argouml-core-model/src/org/argouml/model/UmlFactoryDefaults.java	2011-03-30 09:15:11-0700
@@ -0,0 +1,29 @@
+/* $Id: org.eclipse.jdt.ui.prefs 17993 2010-02-11 21:46:56Z linus $
+ *******************************************************************************
+ * Copyright (c) 2011 Contributors - see below
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Bob Tarling
+ *******************************************************************************
+ */
+
+package org.argouml.model;
+
+/**
+ * Contains information on what default properties should be applied to a newly created
+ * model element.
+ * @author Bob Tarling
+ */
+public interface UmlFactoryDefaults {
+    
+    /**
+     * Get the default type to apply when creating on object of the given meta type.
+     * @param metaType that is to be created
+     * @return the type instance to apply to the newly created object
+     */
+    Object getDefaultType(Object metaType);
+}

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

To unsubscribe from this discussion, e-mail: [[email protected]].
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.