-
Notifications
You must be signed in to change notification settings - Fork 13
/
MoveFromLaneToLaneFeature.java
99 lines (81 loc) · 3.38 KB
/
MoveFromLaneToLaneFeature.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
88
89
90
91
92
93
94
95
96
97
98
99
/*******************************************************************************
* 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
******************************************************************************/
package org.eclipse.bpmn2.modeler.core.features.lane;
import java.io.IOException;
import org.eclipse.bpmn2.Lane;
import org.eclipse.bpmn2.LaneSet;
import org.eclipse.bpmn2.Participant;
import org.eclipse.bpmn2.modeler.core.Activator;
import org.eclipse.bpmn2.modeler.core.ModelHandler;
import org.eclipse.bpmn2.modeler.core.di.DIImport;
import org.eclipse.bpmn2.modeler.core.utils.FeatureSupport;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IMoveShapeContext;
import org.eclipse.graphiti.features.context.ITargetContext;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
public class MoveFromLaneToLaneFeature extends MoveLaneFeature {
public MoveFromLaneToLaneFeature(IFeatureProvider fp) {
super(fp);
}
@Override
public boolean canMoveShape(IMoveShapeContext context) {
Lane targetLane = getTargetLane(context);
if (targetLane.getFlowNodeRefs() != null && targetLane.getFlowNodeRefs().size() > 0) {
return false;
}
Lane movedLane = getMovedLane(context);
if (targetLane.getChildLaneSet() != null && targetLane.getChildLaneSet().getLanes().contains(movedLane)) {
return false;
}
return true;
}
@Override
protected void internalMove(IMoveShapeContext context) {
Lane movedLane = getMovedLane(context);
Lane targetLane = getTargetLane(context);
Lane sourceLane = getSourceLane(context);
modifyModelStructure(sourceLane, targetLane, movedLane);
FeatureSupport.redraw(context.getSourceContainer());
FeatureSupport.redraw(context.getTargetContainer());
}
private void modifyModelStructure(Lane sourceLane, Lane targetLane, Lane movedLane) {
if (targetLane.getChildLaneSet() == null) {
LaneSet createLaneSet = ModelHandler.FACTORY.createLaneSet();
// createLaneSet.setId(EcoreUtil.generateUUID());
targetLane.setChildLaneSet(createLaneSet);
DIImport.setID(createLaneSet);
}
try {
ModelHandler handler = ModelHandler.getInstance(getDiagram());
Participant sourceParticipant = handler.getParticipant(sourceLane);
Participant targetParticipant = handler.getParticipant(targetLane);
if (!sourceParticipant.equals(targetParticipant)) {
handler.moveLane(movedLane, sourceParticipant, targetParticipant);
}
} catch (IOException e) {
Activator.logError(e);
}
targetLane.getChildLaneSet().getLanes().add(movedLane);
sourceLane.getChildLaneSet().getLanes().remove(movedLane);
if (sourceLane.getChildLaneSet().getLanes().isEmpty()) {
sourceLane.setChildLaneSet(null);
}
}
private Lane getTargetLane(ITargetContext context) {
ContainerShape targetContainer = context.getTargetContainer();
return (Lane) getBusinessObjectForPictogramElement(targetContainer);
}
private Lane getSourceLane(IMoveShapeContext context) {
ContainerShape sourceContainer = context.getSourceContainer();
return (Lane) getBusinessObjectForPictogramElement(sourceContainer);
}
}