forked from camunda/camunda-eclipse-plugin
/
AddExpandableActivityFeature.java
87 lines (74 loc) · 3.21 KB
/
AddExpandableActivityFeature.java
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
/*******************************************************************************
* Copyright (c) 2011 Red Hat, Inc.
* All rights reserved.
* This program is 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:
* Red Hat, Inc. - initial API and implementation
*
* @author Innar Made
******************************************************************************/
package org.camunda.bpm.modeler.ui.features.activity.subprocess;
import org.camunda.bpm.modeler.core.features.activity.AbstractAddActivityFeature;
import org.camunda.bpm.modeler.core.preferences.Bpmn2Preferences;
import org.camunda.bpm.modeler.core.utils.GraphicsUtil;
import org.camunda.bpm.modeler.core.utils.StyleUtil;
import org.eclipse.bpmn2.Activity;
import org.eclipse.graphiti.datatypes.IRectangle;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.mm.algorithms.MultiText;
import org.eclipse.graphiti.mm.algorithms.styles.Orientation;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.services.IPeService;
public class AddExpandableActivityFeature<T extends Activity>
extends AbstractAddActivityFeature<T> {
public AddExpandableActivityFeature(IFeatureProvider fp) {
super(fp);
}
@Override
protected void postCreateHook(IAddContext context, IRectangle newShapeBounds, ContainerShape newShape) {
super.postCreateHook(context, newShapeBounds, newShape);
IPeService peService = Graphiti.getPeService();
IGaService gaService = Graphiti.getGaService();
T activity = getBusinessObject(context);
Shape textShape = peService.createShape(newShape, false);
MultiText text = gaService.createDefaultMultiText(getDiagram(), textShape, activity.getName());
gaService.setLocationAndSize(text, 5, 5, newShapeBounds.getWidth() - 10, newShapeBounds.getHeight() - 10);
StyleUtil.applyStyle(text, activity);
text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
text.setVerticalAlignment(Orientation.ALIGNMENT_TOP);
link(textShape, activity);
}
@Override
protected void postAddHook(IAddContext context, ContainerShape newShape) {
super.postAddHook(context, newShape);
// set a property on the decorators so we can distinguish them from the
// real children (i.e. tasks, etc.)
for (PictogramElement pe : newShape.getChildren()) {
Graphiti.getPeService().setPropertyValue(pe, ACTIVITY_DECORATOR, "true");
}
}
@Override
public int getDefaultWidth() {
if (Bpmn2Preferences.getInstance().isExpandedDefault())
return GraphicsUtil.SUB_PROCEESS_DEFAULT_WIDTH;
return GraphicsUtil.TASK_DEFAULT_WIDTH;
}
@Override
public int getDefaultHeight() {
if (Bpmn2Preferences.getInstance().isExpandedDefault())
return GraphicsUtil.SUB_PROCESS_DEFAULT_HEIGHT;
return GraphicsUtil.TASK_DEFAULT_HEIGHT;
}
@Override
protected boolean isCreateExternalLabel() {
return false;
}
}