Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ffe3fd9bc69f034b07f1673b6863ec7eae95696c (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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
/*****************************************************************************
 * Copyright (c) 2010 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.uml.diagram.activity.figures;

import java.util.List;

import org.eclipse.draw2d.AbstractLayout;
import org.eclipse.draw2d.BorderLayout;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.GridData;
import org.eclipse.draw2d.GridLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.StackLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gmf.runtime.diagram.ui.figures.ShapeCompartmentFigure;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure;

/**
 * Activity figure for the activity diagram
 *
 * @author PT202707
 *
 */
public class ActivityFigure extends RoundedCompartmentFigure {

	/**
	 * this is the layout manager in charge to place element in the enumeration
	 *
	 */
	protected class ActivityLayoutManager extends AbstractLayout {


		/** right and bottom margin of diagram. Set to 10 to be consistent with left and top margin */
		private int rightAndBottomMargin = 10;

		public int getRightAndBottomMargin() {
			return rightAndBottomMargin;
		}

		public void setRightAndBottomMargin(int rightAndBottomMargin) {
			this.rightAndBottomMargin = rightAndBottomMargin;
		}

		/**
		 * ---------------------------------------------------| |sterotypeLabel|
		 * precondition | |--------------| | |QualifiedName
		 * |-----------------------------------| |--------------| | |name |
		 * postcondition | |--------------------------------------------------|
		 * | stereotype compartment |
		 * |--------------------------------------------------| |parameter | |
		 * |----------- | | activity content |
		 * ----------------------------------------------------
		 *
		 * {@inheritDoc}
		 */
		@Override
		protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
			int minimumWidth = 0;
			int minimumHeight = 0;

			// take in account the content of the figure activity
			if ((getContentFigure().getChildren().size() > 0)) {
				IFigure content = (IFigure) getContentFigure().getChildren().get(0);
				minimumWidth = content.getPreferredSize().width + rightAndBottomMargin;
				minimumHeight = content.getPreferredSize().height + rightAndBottomMargin;
			}
			// display name
			if (getNameLabel() != null) {
				if (getNameLabel().getPreferredSize().width > minimumWidth) {
					minimumWidth = getNameLabel().getPreferredSize().width;
				}
				minimumHeight += getNameLabel().getPreferredSize().height;
			}
			if (getHeaderSingleExecution() != null) {
				if (getHeaderSingleExecution().getBounds().getTopRight().x > minimumWidth) {
					minimumWidth = getHeaderSingleExecution().getBounds().getTopRight().x;
				}
			}

			return new Dimension(minimumWidth, minimumHeight);
		}

		/**
		 *
		 * {@inheritDoc}
		 */
		@Override
		public void layout(IFigure container) {
			List childrenList = container.getChildren();
			for (int i = 0; i < container.getChildren().size(); i++) {
				Rectangle bound = new Rectangle(((IFigure) childrenList.get(i)).getBounds());
				bound.setSize(((IFigure) childrenList.get(i)).getPreferredSize());
				if (i > 0) {
					bound.y = ((IFigure) childrenList.get(i - 1)).getBounds().getBottomLeft().y + 1;
					bound.x = getBounds().x;
				} else {
					bound.x = getBounds().x;
					bound.y = getBounds().y;
				}
				((IFigure) childrenList.get(i)).setBounds(bound);
			}
			// container
			Rectangle lastRectangle = getContentFigure().getBounds();
			lastRectangle.height = getBounds().y + getBounds().height - lastRectangle.y;
			lastRectangle.x = container.getBounds().x;
			lastRectangle.width = getBounds().width;
			getContentFigure().setBounds(lastRectangle);
			if (getGMFContentContainer() != null) {
				getGMFContentContainer().setBounds(lastRectangle);
			}
			// place precondition
			// setX
			Rectangle preconditionBound = getPreconditionFigure().getBounds().getCopy();
			preconditionBound.x = getNameLabel().getBounds().getTopRight().x;
			// take in account stereotype label
			if (getStereotypesLabel() != null) {
				int posStererotypeLabel = getStereotypesLabel().getBounds().getTopRight().x;
				if (posStererotypeLabel > preconditionBound.x) {
					preconditionBound.x = posStererotypeLabel;
				}
			}
			// take in account qualified name
			if (getQualifiedNameLabel() != null) {
				int posqualifiedName = getQualifiedNameLabel().getBounds().getTopRight().x;
				if (posqualifiedName > preconditionBound.x) {
					preconditionBound.x = posqualifiedName;
				}
			}
			// take in account stereotype properties
			if (stereotypePropertiesInBraceContent != null) {
				int possterotypeInBrace = stereotypePropertiesInBraceContent.getBounds().getTopRight().x;
				if (possterotypeInBrace > preconditionBound.x) {
					preconditionBound.x = possterotypeInBrace;
				}
			}
			// take in account parameter figure
			if (getParameterFigure() != null) {
				int posparameter = getParameterFigure().getBounds().getTopRight().x;
				if (posparameter > preconditionBound.x) {
					preconditionBound.x = posparameter;
				}
			}
			// setY
			preconditionBound.y = ((IFigure) container.getChildren().get(0)).getBounds().y;
			getPreconditionFigure().setBounds(preconditionBound);
			if (getPreconditionFigure().getChildren().size() > 0) {
				((IFigure) getPreconditionFigure().getChildren().get(0)).setBounds(preconditionBound);
				;
			}
			// setPoscondtion
			Rectangle postconditionBound = getPostconditionFigure().getBounds().getCopy();
			postconditionBound.x = getPreconditionFigure().getBounds().x;
			postconditionBound.y = getPreconditionFigure().getBounds().y + getPreconditionFigure().getBounds().height;
			getPostconditionFigure().setBounds(postconditionBound);
			if (getPostconditionFigure().getChildren().size() > 0) {
				((IFigure) getPostconditionFigure().getChildren().get(0)).setBounds(postconditionBound);
				;
			}
			// setPoscondtion
			Rectangle singleExecutionBound = getHeaderSingleExecution().getBounds().getCopy();
			singleExecutionBound.x = getPreconditionFigure().getBounds().x + getPreconditionFigure().getBounds().width;
			;
			singleExecutionBound.y = getPreconditionFigure().getBounds().y;
			getHeaderSingleExecution().setBounds(singleExecutionBound);
			// replace compartment stereotype properties
			if (getStereotypePropertiesContent() != null) {
				Rectangle pscontainer = getStereotypePropertiesContent().getBounds().getCopy();
				if (getPostconditionFigure().getBounds().y + getPostconditionFigure().getBounds().height > pscontainer.y) {
					pscontainer.y = getPostconditionFigure().getBounds().y + getPostconditionFigure().getBounds().height;
				}
				getStereotypePropertiesContent().setBounds(pscontainer);
			}
			// place parameter
			// replace compartment stereotype properties
			if (getStereotypePropertiesContent() != null) {
				Rectangle paramBoundcontainer = getParameterFigure().getBounds().getCopy();
				paramBoundcontainer.y = getStereotypePropertiesContent().getBounds().getBottomLeft().y;
				getParameterFigure().setBounds(paramBoundcontainer);
				if (getParameterFigure().getChildren().size() > 0) {
					((IFigure) shapeCompartment.getChildren().get(0)).setBounds(paramBoundcontainer);
				}
			} else {
				Rectangle paramBoundcontainer = getParameterFigure().getBounds().getCopy();
				paramBoundcontainer.y = getNameLabel().getBounds().getBottomLeft().y;
				getParameterFigure().setBounds(paramBoundcontainer);
				if (getParameterFigure().getChildren().size() > 0) {
					((IFigure) shapeCompartment.getChildren().get(0)).setBounds(paramBoundcontainer);
					;
				}
			}
		}
	}

	private WrappingLabel fHeaderLabel;

	private RectangleFigure fActivityParametersCompartment;

	private RectangleFigure fActivityPreconditionsCompartment;

	private RectangleFigure fActivityPostconditionsCompartment;

	protected WrappingLabel fHeaderSingleExecution;

	private RectangleFigure fCompartmentFigure;

	private RectangleFigure shapeCompartment;

	private RectangleFigure preconditionFigure;

	private RectangleFigure postconditionFigure;

	private RectangleFigure parameterFigure;

	public ActivityFigure() {
		super();
		setLayoutManager(new ActivityLayoutManager());
		shapeCompartment = new RectangleFigure();
		shapeCompartment.setOpaque(false);
		shapeCompartment.setFill(false);
		shapeCompartment.setOutline(false);
		shapeCompartment.setLineWidth(0);
		add(shapeCompartment);
		preconditionFigure = new RectangleFigure();
		preconditionFigure.setOpaque(false);
		preconditionFigure.setFill(false);
		preconditionFigure.setOutline(false);
		preconditionFigure.setLineWidth(10);
		preconditionFigure.setBorder(null);
		preconditionFigure.setForegroundColor(ColorConstants.red);
		add(preconditionFigure);
		parameterFigure = new RectangleFigure();
		parameterFigure.setOpaque(false);
		parameterFigure.setFill(false);
		parameterFigure.setOutline(false);
		parameterFigure.setLineWidth(0);
		add(parameterFigure);
		postconditionFigure = new RectangleFigure();
		postconditionFigure.setOpaque(false);
		postconditionFigure.setFill(false);
		postconditionFigure.setOutline(false);
		postconditionFigure.setLineWidth(0);
		add(postconditionFigure);
		fHeaderSingleExecution = new WrappingLabel();
		add(fHeaderSingleExecution);
		// createContents();
	}

	public RectangleFigure getPreconditionFigure() {
		return preconditionFigure;
	}

	public RectangleFigure getPostconditionFigure() {
		return postconditionFigure;
	}

	public RectangleFigure getParameterFigure() {
		return parameterFigure;
	}

	public RectangleFigure getContentFigure() {
		return shapeCompartment;
	}

	/**
	 * get the gmf container figure of the package
	 *
	 * @return the gmf container
	 */
	public ShapeCompartmentFigure getGMFContentContainer() {
		if (shapeCompartment.getChildren().size() > 0) {
			return (ShapeCompartmentFigure) shapeCompartment.getChildren().get(0);
		}
		return null;
	}

	private void createContents() {
		RoundedRectangle activityBorderFigure0 = new RoundedRectangle();
		this.add(activityBorderFigure0, BorderLayout.CENTER);
		// to remove
		activityBorderFigure0.setBackgroundColor(ColorConstants.red);
		GridLayout layoutActivityBorderFigure0 = new GridLayout();
		layoutActivityBorderFigure0.numColumns = 3;
		layoutActivityBorderFigure0.makeColumnsEqualWidth = false;
		layoutActivityBorderFigure0.horizontalSpacing = 0;
		layoutActivityBorderFigure0.verticalSpacing = 0;
		layoutActivityBorderFigure0.marginWidth = 0;
		layoutActivityBorderFigure0.marginHeight = 0;
		activityBorderFigure0.setLayoutManager(layoutActivityBorderFigure0);
		RectangleFigure labelAndParameter1 = new RectangleFigure();
		labelAndParameter1.setFill(false);
		labelAndParameter1.setOutline(false);
		labelAndParameter1.setLineWidth(0);
		// to remove
		labelAndParameter1.setBackgroundColor(ColorConstants.blue);
		GridData constraintLabelAndParameter1 = new GridData();
		constraintLabelAndParameter1.verticalAlignment = GridData.CENTER;
		constraintLabelAndParameter1.horizontalAlignment = GridData.BEGINNING;
		constraintLabelAndParameter1.horizontalIndent = 0;
		constraintLabelAndParameter1.horizontalSpan = 1;
		constraintLabelAndParameter1.verticalSpan = 1;
		constraintLabelAndParameter1.grabExcessHorizontalSpace = true;
		constraintLabelAndParameter1.grabExcessVerticalSpace = false;
		activityBorderFigure0.add(labelAndParameter1, constraintLabelAndParameter1);
		GridLayout layoutLabelAndParameter1 = new GridLayout();
		layoutLabelAndParameter1.numColumns = 1;
		layoutLabelAndParameter1.makeColumnsEqualWidth = true;
		labelAndParameter1.setLayoutManager(layoutLabelAndParameter1);
		fHeaderLabel = new WrappingLabel();
		fHeaderLabel.setText("ActivityName");
		GridData constraintFHeaderLabel = new GridData();
		constraintFHeaderLabel.verticalAlignment = GridData.CENTER;
		constraintFHeaderLabel.horizontalAlignment = GridData.BEGINNING;
		constraintFHeaderLabel.horizontalIndent = 4;
		constraintFHeaderLabel.horizontalSpan = 1;
		constraintFHeaderLabel.verticalSpan = 1;
		constraintFHeaderLabel.grabExcessHorizontalSpace = true;
		constraintFHeaderLabel.grabExcessVerticalSpace = false;
		labelAndParameter1.add(fHeaderLabel, constraintFHeaderLabel);
		fActivityParametersCompartment = new RectangleFigure();
		// to remove
		fActivityParametersCompartment.setBackgroundColor(ColorConstants.green);
		fActivityParametersCompartment.setFill(false);
		fActivityParametersCompartment.setOutline(false);
		fActivityParametersCompartment.setLineWidth(0);
		GridData constraintFActivityParametersCompartment = new GridData();
		constraintFActivityParametersCompartment.verticalAlignment = GridData.CENTER;
		constraintFActivityParametersCompartment.horizontalAlignment = GridData.BEGINNING;
		constraintFActivityParametersCompartment.horizontalIndent = 0;
		constraintFActivityParametersCompartment.horizontalSpan = 1;
		constraintFActivityParametersCompartment.verticalSpan = 1;
		constraintFActivityParametersCompartment.grabExcessHorizontalSpace = true;
		constraintFActivityParametersCompartment.grabExcessVerticalSpace = false;
		labelAndParameter1.add(fActivityParametersCompartment, constraintFActivityParametersCompartment);
		fActivityParametersCompartment.setLayoutManager(new StackLayout());
		RectangleFigure prePostContions1 = new RectangleFigure();
		// to remove
		prePostContions1.setBackgroundColor(ColorConstants.cyan);
		prePostContions1.setFill(false);
		prePostContions1.setOutline(false);
		prePostContions1.setLineWidth(0);
		GridData constraintPrePostContions1 = new GridData();
		constraintPrePostContions1.verticalAlignment = GridData.CENTER;
		constraintPrePostContions1.horizontalAlignment = GridData.BEGINNING;
		constraintPrePostContions1.horizontalIndent = 0;
		constraintPrePostContions1.horizontalSpan = 1;
		constraintPrePostContions1.verticalSpan = 1;
		constraintPrePostContions1.grabExcessHorizontalSpace = true;
		constraintPrePostContions1.grabExcessVerticalSpace = false;
		activityBorderFigure0.add(prePostContions1, constraintPrePostContions1);
		GridLayout layoutPrePostContions1 = new GridLayout();
		layoutPrePostContions1.numColumns = 1;
		layoutPrePostContions1.makeColumnsEqualWidth = true;
		prePostContions1.setLayoutManager(layoutPrePostContions1);
		fActivityPreconditionsCompartment = new RectangleFigure();
		fActivityPreconditionsCompartment.setBackgroundColor(ColorConstants.darkBlue);
		fActivityPreconditionsCompartment.setFill(false);
		fActivityPreconditionsCompartment.setOutline(false);
		fActivityPreconditionsCompartment.setLineWidth(0);
		GridData constraintFActivityPreconditionsCompartment = new GridData();
		constraintFActivityPreconditionsCompartment.verticalAlignment = GridData.CENTER;
		constraintFActivityPreconditionsCompartment.horizontalAlignment = GridData.BEGINNING;
		constraintFActivityPreconditionsCompartment.horizontalIndent = 0;
		constraintFActivityPreconditionsCompartment.horizontalSpan = 1;
		constraintFActivityPreconditionsCompartment.verticalSpan = 1;
		constraintFActivityPreconditionsCompartment.grabExcessHorizontalSpace = true;
		constraintFActivityPreconditionsCompartment.grabExcessVerticalSpace = false;
		prePostContions1.add(fActivityPreconditionsCompartment, constraintFActivityPreconditionsCompartment);
		fActivityPreconditionsCompartment.setLayoutManager(new StackLayout());
		fActivityPostconditionsCompartment = new RectangleFigure();
		fActivityPostconditionsCompartment.setFill(false);
		fActivityPostconditionsCompartment.setOutline(false);
		fActivityPostconditionsCompartment.setLineWidth(0);
		GridData constraintFActivityPostconditionsCompartment = new GridData();
		constraintFActivityPostconditionsCompartment.verticalAlignment = GridData.CENTER;
		constraintFActivityPostconditionsCompartment.horizontalAlignment = GridData.BEGINNING;
		constraintFActivityPostconditionsCompartment.horizontalIndent = 0;
		constraintFActivityPostconditionsCompartment.horizontalSpan = 1;
		constraintFActivityPostconditionsCompartment.verticalSpan = 1;
		constraintFActivityPostconditionsCompartment.grabExcessHorizontalSpace = true;
		constraintFActivityPostconditionsCompartment.grabExcessVerticalSpace = false;
		prePostContions1.add(fActivityPostconditionsCompartment, constraintFActivityPostconditionsCompartment);
		fActivityPostconditionsCompartment.setLayoutManager(new StackLayout());
		fHeaderSingleExecution = new WrappingLabel();
		fHeaderSingleExecution.setText("");
		GridData constraintFHeaderSingleExecution = new GridData();
		constraintFHeaderSingleExecution.verticalAlignment = GridData.CENTER;
		constraintFHeaderSingleExecution.horizontalAlignment = GridData.BEGINNING;
		constraintFHeaderSingleExecution.horizontalIndent = 0;
		constraintFHeaderSingleExecution.horizontalSpan = 1;
		constraintFHeaderSingleExecution.verticalSpan = 2;
		constraintFHeaderSingleExecution.grabExcessHorizontalSpace = false;
		constraintFHeaderSingleExecution.grabExcessVerticalSpace = false;
		activityBorderFigure0.add(fHeaderSingleExecution, constraintFHeaderSingleExecution);
		fCompartmentFigure = new RectangleFigure();
		fCompartmentFigure.setFill(false);
		fCompartmentFigure.setOutline(false);
		fCompartmentFigure.setLineWidth(0);
		GridData constraintFCompartmentFigure = new GridData();
		constraintFCompartmentFigure.verticalAlignment = GridData.FILL;
		constraintFCompartmentFigure.horizontalAlignment = GridData.FILL;
		constraintFCompartmentFigure.horizontalIndent = 0;
		constraintFCompartmentFigure.horizontalSpan = 3;
		constraintFCompartmentFigure.verticalSpan = 1;
		constraintFCompartmentFigure.grabExcessHorizontalSpace = true;
		constraintFCompartmentFigure.grabExcessVerticalSpace = true;
		activityBorderFigure0.add(fCompartmentFigure, constraintFCompartmentFigure);
	}

	public WrappingLabel getHeaderLabel() {
		return fHeaderLabel;
	}

	public RectangleFigure getActivityParametersCompartment() {
		return fActivityParametersCompartment;
	}

	public RectangleFigure getActivityPreconditionsCompartment() {
		return fActivityPreconditionsCompartment;
	}

	public RectangleFigure getActivityPostconditionsCompartment() {
		return fActivityPostconditionsCompartment;
	}

	public WrappingLabel getHeaderSingleExecution() {
		return fHeaderSingleExecution;
	}

	public RectangleFigure getCompartmentFigure() {
		return fCompartmentFigure;
	}
	
	public void setRightAndBottomMargin(int rightAndBottomMargin){
		ActivityLayoutManager lm = (ActivityLayoutManager) getLayoutManager();
		
		if(lm != null){
			lm.setRightAndBottomMargin(rightAndBottomMargin);
		}
	}
}

Back to the top