Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b8f866f61be13b6e76591d625dc0061eaa493cf6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*****************************************************************************
 * Copyright (c) 2008 CEA LIST.
 *
 *    
 * 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:
 *  Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.diagram.clazz.custom.command;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.papyrus.diagram.clazz.edit.commands.PropertyForComponentCreateCommand;
import org.eclipse.papyrus.diagram.clazz.providers.ElementInitializers;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;

/**
 * The Class PropertyCommandForAssociation use to create a property into an association (ownedEnd)
 */
public class PropertyCommandForAssociation extends PropertyForComponentCreateCommand {

	/**
	 * Instantiates a new property command for association.
	 * 
	 * @param req
	 *        the req to launch the command
	 */
	public PropertyCommandForAssociation(CreateElementRequest req) {
		super(req);
	}

	/**
	 * {@inheritDoc}
	 */
	protected EObject doDefaultElementCreation() {
		Property newElement = UMLFactory.eINSTANCE.createProperty();

		Association owner = (Association)getElementToEdit();

		Object type = getRequest().getParameter("type");
		if(type != null && type instanceof Type) {
			newElement.setType((Type)type);
			newElement.setName(((Type)type).getName());
		}
		owner.getOwnedEnds().add(newElement);
		ElementInitializers.getInstance().init_Property_3005(newElement);
		if(type != null && type instanceof Type) {
			newElement.setName(((Type)type).getName());
		}
		return newElement;
	}

	/**
	 * {@inheritedDoc}
	 */
	protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
		Property newElement = (Property)doDefaultElementCreation();

		((CreateElementRequest)getRequest()).setNewElement(newElement);
		return CommandResult.newOKCommandResult(newElement);
	}

	/**
	 * 
	 * {@inheritDoc}
	 */
	protected EClass getEClassToEdit() {
		return UMLPackage.eINSTANCE.getAssociation();
	}

}

Back to the top