Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 219df0375c548fc15e3bf81eea3c9ed558f2749b (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*****************************************************************************
 * Copyright (c) 2011 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:
 *		
 *		CEA LIST - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.sysml.diagram.blockdefinition.ui;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.uml2.uml.NamedElement;

/**
 * This class provides facilities to represent a New Element before its real creation.
 * We can store in this class :
 * <ul>
 * <li>the name of the new element</li>
 * <li>the parent of the new element</li>
 * <li>the {@link IHintedType} of the new element</li>
 * <li>the request to build the new element (optional)</li>
 * <li>the element itself when it has been created</li>
 * </ul>
 * 
 * 
 * 
 */
public class NewElementRepresentation {

	/** the name of the new element */
	private String name;

	/** the parent of the new element */
	private Object parent;

	/** the created element itself */
	private EObject createdElement;

	/** the {@link IHintedType} of the new element */
	private IHintedType hintedType;

	/** this field is used only when the element have an existing parent */
	private CreateElementRequest request;

	/**
	 * 
	 * Constructor.
	 * 
	 * @param name
	 *        the name of the new element
	 * @param parent
	 *        the parent of the new element
	 * @param hintedType
	 *        the hinted type of the new element
	 * @param request
	 *        the request to build the new element (can be <code>null</code>)
	 */
	public NewElementRepresentation(String name, Object parent, IHintedType hintedType, CreateElementRequest request) {
		this.name = name;
		this.parent = parent;
		this.createdElement = null;
		this.hintedType = hintedType;
		this.request = request;
	}

	/**
	 * Getter for {@link #hintedType}
	 * 
	 * @return
	 *         {@link #hintedType}
	 */
	public IHintedType getHintedType() {
		return this.hintedType;
	}

	/**
	 * Getter for {@link #name}
	 * 
	 * @return
	 *         {@link #name}
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * Getter for {@link #parent}
	 * 
	 * @return
	 *         {@link #parent}
	 */
	public Object getParent() {
		return this.parent;
	}

	/**
	 * Returns the parent of this element
	 * 
	 * @return
	 *         the parent of this element or <code>null</code> if the parent is a {@link NewElementRepresentation} itself and if it has not been
	 *         created
	 */
	public EObject getEObjectParent() {
		if(parent instanceof EObject) {
			return (EObject)this.parent;
		} else if(parent instanceof NewElementRepresentation) {
			return ((NewElementRepresentation)parent).getEObject();
		}
		return null;
	}

	/**
	 * Returns the created object
	 * 
	 * @return
	 *         the created Object or <code>null</code> if the object has not been created
	 */
	public EObject getEObject() {
		if(this.request != null) {
			return this.request.getNewElement();
		}
		return this.createdElement;
	}

	/**
	 * Setter for {@link #createdElement}
	 * 
	 * @param newElement
	 * 
	 */
	public void setCreateElement(EObject newElement) {
		this.createdElement = newElement;
	}

	/**
	 * Setter for {@link #request}
	 * 
	 * @return
	 *         {@link #request}
	 */
	public CreateElementRequest getCreateElementRequest() {
		return this.request;
	}

	/**
	 * 
	 * @see java.lang.Object#toString()
	 * 
	 * @return
	 */
	@Override
	public String toString() {
		return "Name : " + this.name + ", parent : " + this.parent;
	}

	public String getQualifiedName() {
		String qualifiedName = "";
		if(parent instanceof NewElementRepresentation) {
			qualifiedName = ((NewElementRepresentation)parent).getQualifiedName();
		} else if(parent instanceof NamedElement) {
			qualifiedName = ((NamedElement)parent).getQualifiedName() + "::" + this.name;
		}
		return qualifiedName;
	}
}

Back to the top