svn commit: r12998 - branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: b00__1
Date: 2007-07-08 09:26:42-0700
New Revision: 12998

Added:
   branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/RunnableClass.java   (contents, props changed)
Modified:
   branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/CoreFactoryEUMLImpl.java
   branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java
   branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java

Log:
Implemented Association and Abstraction.

Modified: branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/CoreFactoryEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/CoreFactoryEUMLImpl.java?view=diff&rev=12998&p1=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/CoreFactoryEUMLImpl.java&p2=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/CoreFactoryEUMLImpl.java&r1=12997&r2=12998
==============================================================================
--- branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/CoreFactoryEUMLImpl.java	(original)
+++ branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/CoreFactoryEUMLImpl.java	2007-07-08 09:26:42-0700
@@ -31,6 +31,8 @@
 import org.argouml.model.AbstractModelFactory;
 import org.argouml.model.CoreFactory;
 import org.argouml.model.NotImplementedException;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.uml2.common.edit.command.ChangeCommand;
 import org.eclipse.uml2.uml.Abstraction;
 import org.eclipse.uml2.uml.AggregationKind;
 import org.eclipse.uml2.uml.Artifact;
@@ -60,6 +62,9 @@
 import org.eclipse.uml2.uml.UMLFactory;
 import org.eclipse.uml2.uml.Usage;
 import org.eclipse.uml2.uml.VisibilityKind;
+import org.eclipse.uml2.uml.internal.impl.AssociationImpl;
+import org.eclipse.uml2.uml.internal.impl.PropertyImpl;
+import org.eclipse.uml2.uml.internal.impl.TypeImpl;
 
 
 /**
@@ -71,6 +76,10 @@
      * The model implementation.
      */
     private EUMLModelImplementation modelImpl;
+    
+    private EditingDomain editingDomain;
+    
+    private UMLFactory uml = UMLFactory.eINSTANCE;
 
     /**
      * Constructor.
@@ -79,57 +88,69 @@
      */
     public CoreFactoryEUMLImpl(EUMLModelImplementation implementation) {
         modelImpl = implementation;
+        editingDomain = implementation.getEditingDomain();
     }
 
     public Abstraction buildAbstraction(String name, Object supplier, Object client) {
-        Abstraction abstraction = createAbstraction();
+        Abstraction abstraction = uml.createAbstraction();
         abstraction.setName(name);
         abstraction.getSuppliers().add((NamedElement) supplier);
         abstraction.getClients().add((NamedElement) client);
         return abstraction;
     }
 
-    // TODO: A few different ways of building Associations.  Pick one that
-    // works and is efficient - tfm
-    public Object buildAssociation(Object fromClassifier,
-            Object aggregationKind1, Object toClassifier,
-            Object aggregationKind2, Boolean unidirectional) {
-        
-//        return ((Type) fromClassifier).createAssociation(
-//                true, (AggregationKind) aggregationKind1, null, 1, 1, 
-//                (Type) toClassifier, 
-//                true, (AggregationKind) aggregationKind2, null, 1, 1); 
-
-        Association assoc = (Association) createAssociation();
-        Property end1 = assoc.createNavigableOwnedEnd(null, (Type) fromClassifier);
-        Property end2 = assoc.createOwnedEnd(null, (Type) toClassifier);
-        boolean uni = false;
-        if (unidirectional != null && unidirectional.booleanValue()) {
-            uni = true;
-        }
-        end2.setIsNavigable(uni);
-        return assoc;
-        
+    @SuppressWarnings("all")
+    public Association buildAssociation(final Object type1,
+	    final Boolean navigability1, final Object aggregationKind1,
+	    final String name1, final Object type2,
+	    final Boolean navigability2, final Object aggregationKind2,
+	    final String name2, final String associationName) {
+
+	RunnableClass run = new RunnableClass() {
+	    public void run() {
+		Association assoc = ((Type) type1).createAssociation(
+			navigability1,
+			aggregationKind1 == null ? AggregationKind.NONE_LITERAL
+				: (AggregationKind) aggregationKind1, name1, 0,
+			1, (Type) type2, navigability2,
+			aggregationKind2 == null ? AggregationKind.NONE_LITERAL
+				: (AggregationKind) aggregationKind2, name2, 0,
+			1);
+		if (associationName != null) {
+		    assoc.setName(associationName);
+		}
+		getParams().add(assoc);
+	    }
+	};
+	editingDomain.getCommandStack().execute(
+		new ChangeCommand(editingDomain, run));
+
+	return (Association) run.getParams().get(0);
+
+    }
+    
+    public Association buildAssociation(Object fromClassifier,
+	    Object aggregationKind1, Object toClassifier,
+	    Object aggregationKind2, Boolean unidirectional) {
+
+	return buildAssociation(fromClassifier, true, aggregationKind1, null,
+		toClassifier, !unidirectional, aggregationKind2, null, null);
+
     }
 
-    public Object buildAssociation(Object classifier1, Object classifier2) {
-        return buildAssociation(
-                classifier1, AggregationKind.NONE_LITERAL, classifier2,
-                AggregationKind.NONE_LITERAL, false);
+    public Association buildAssociation(Object classifier1, Object classifier2) {
+	return buildAssociation(classifier1, true,
+		AggregationKind.NONE_LITERAL, null, classifier2, true,
+		AggregationKind.NONE_LITERAL, null, null);
     }
 
-    public Object buildAssociation(Object c1, boolean nav1, Object c2,
-            boolean nav2, String name) {
-        Association assoc = (Association) createAssociation();
-        Property end1 = assoc.createOwnedEnd(null, (Type) c1);
-        end1.setIsNavigable(nav1);
-        Property end2 = assoc.createOwnedEnd(null, (Type) c2);
-        end2.setIsNavigable(nav1);
-        assoc.setName(name);
-        return assoc;
+    public Association buildAssociation(Object c1, boolean nav1, Object c2,
+	    boolean nav2, String name) {
+	return buildAssociation(c1, nav1, AggregationKind.NONE_LITERAL, null,
+		c2, nav2, AggregationKind.NONE_LITERAL, null, name);
     }
 
-    public Object buildAssociationClass(Object end1, Object end2) {
+    public Association buildAssociationClass(Object end1, Object end2) {
         // TODO Auto-generated method stub
         return null;
     }

Modified: branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java?view=diff&rev=12998&p1=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java&p2=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java&r1=12997&r2=12998
==============================================================================
--- branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java	(original)
+++ branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/EUMLModelImplementation.java	2007-07-08 09:26:42-0700
@@ -201,29 +201,8 @@
      * Constructor.
      */
     public EUMLModelImplementation() {
-//	theModelEventPump = new ModelEventPumpEUMLImpl(this);
-//        LOG.debug("EUML Init - event pump started"); //$NON-NLS-1$
-
 	initializeEditingDomain();
 	LOG.debug("EUML Init - editing domain initialized"); //$NON-NLS-1$
-	
-//        theModelEventPump.startPumpingEvents();
-
-        // We may want to initialize some basic packages first,
-        // but we should try to use lazy initialization for most/all.
-//        // DataTypes is next so it's available for Kinds, ModelManagement,
-//        // & Extensions
-//        theDataTypesFactory = new DataTypesFactoryEUMLImpl(this);
-//        theDataTypesHelper = new DataTypesHelperEUMLImpl(this);
-//
-//        theAggregationKind = new AggregationKindEUMLImpl(this);
-//        theChangeableKind = new ChangeableKindEUMLImpl(this);
-//        theConcurrencyKind = new ConcurrencyKindEUMLImpl(this);
-//        theDirectionKind = new DirectionKindEUMLImpl(this);
-//        theOrderingKind = new OrderingKindEUMLImpl(this);
-//        thePseudostateKind = new PseudostateKindEUMLImpl(this);
-//        theScopeKind = new ScopeKindEUMLImpl(this);
-//        theVisibilityKind = new VisibilityKindEUMLImpl(this);
     }
     
     /**
@@ -242,7 +221,8 @@
 	    @Override
 	    protected void handleError(Exception exception) {
 		super.handleError(exception);
-		LOG.error("Command error - " + exception); //$NON-NLS-1$
+		exception.printStackTrace();
+		throw new RuntimeException(exception);
 	    }
 
 	};

Modified: branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java?view=diff&rev=12998&p1=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java&p2=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java&r1=12997&r2=12998
==============================================================================
--- branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java	(original)
+++ branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/FacadeEUMLImpl.java	2007-07-08 09:26:42-0700
@@ -1249,7 +1249,7 @@
 
     public boolean isAAssociationEnd(Object handle) {
         return handle instanceof Property
-                && ((Property) handle).getOwningAssociation() != null;
+                && ((Property) handle).getAssociation() != null;
     }
 
     public boolean isAAssociationEndRole(Object handle) {

Added: branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/RunnableClass.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/RunnableClass.java?view=auto&rev=12998
==============================================================================
--- (empty file)
+++ branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/RunnableClass.java	2007-07-08 09:26:42-0700
@@ -0,0 +1,48 @@
+// $Id$
+// Copyright (c) 2007, The ArgoUML Project
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above copyright
+//       notice, this list of conditions and the following disclaimer in the
+//       documentation and/or other materials provided with the distribution.
+//     * Neither the name of the ArgoUML Project nor the
+//       names of its contributors may be used to endorse or promote products
+//       derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE ArgoUML PROJECT ``AS IS'' AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE ArgoUML PROJECT BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+package org.argouml.model.euml;
+
+import java.util.ArrayList;
+
+/**
+ * This is a utility class useful in conjunction with 
+ * {@link org.eclipse.uml2.common.edit.command.ChangeCommand ChangeCommand}
+ * 
+ * @author Bogdan Pistol
+ */
+public abstract class RunnableClass implements Runnable {
+    
+    /**
+     * A list of parameters useful for extraction/insertion of parameters
+     * into a Runnable instance.
+     */
+    private ArrayList<Object> params = new ArrayList<Object>();
+    
+    public ArrayList<Object> getParams() {
+	return params;
+    }
+}
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.