-
Notifications
You must be signed in to change notification settings - Fork 87
/
AllocationManagementAction.java
235 lines (219 loc) · 9.67 KB
/
AllocationManagementAction.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
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
/*******************************************************************************
* Copyright (c) 2006, 2020 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.platform.sirius.ui.actions;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.polarsys.capella.core.data.cs.Component;
import org.polarsys.capella.core.data.cs.CsFactory;
import org.polarsys.capella.core.data.cs.ExchangeItemAllocation;
import org.polarsys.capella.core.data.cs.Interface;
import org.polarsys.capella.core.data.cs.Part;
import org.polarsys.capella.core.data.cs.PhysicalLink;
import org.polarsys.capella.core.data.fa.AbstractFunction;
import org.polarsys.capella.core.data.fa.ComponentExchange;
import org.polarsys.capella.core.data.fa.ComponentExchangeAllocation;
import org.polarsys.capella.core.data.fa.ComponentExchangeFunctionalExchangeAllocation;
import org.polarsys.capella.core.data.fa.ComponentFunctionalAllocation;
import org.polarsys.capella.core.data.fa.FaFactory;
import org.polarsys.capella.core.data.fa.FunctionalExchange;
import org.polarsys.capella.core.data.information.ExchangeItem;
import org.polarsys.capella.core.data.oa.ActivityAllocation;
import org.polarsys.capella.core.data.oa.OaFactory;
import org.polarsys.capella.core.data.oa.Role;
import org.polarsys.capella.core.data.pa.deployment.DeploymentFactory;
import org.polarsys.capella.core.data.pa.deployment.PartDeploymentLink;
import org.polarsys.capella.core.model.helpers.ComponentExchangeExt;
import org.polarsys.capella.core.model.helpers.PhysicalComponentExt;
import org.polarsys.capella.core.model.helpers.PhysicalLinkExt;
import org.polarsys.capella.core.model.preferences.CapellaModelPreferencesPlugin;
/**
*/
public class AllocationManagementAction {
/**
*
*/
public AllocationManagementAction() {
// do nothing
}
/**
*
*/
public static AllocationManagementAction getInstance() {
return new AllocationManagementAction();
}
/**
* Action to perform allocation of all the targetElements(list of functions) to sourceElement(component or role(oa
* layer))
*
* @param targetElements
* list of functions
* @param sourceElement
* a component
*/
public void allocatingFunctionsToComponent(List<EObject> targetElements, EObject sourceElement) {
if (sourceElement != null) {
if (sourceElement instanceof Component) {
Component comp = (Component) sourceElement;
for (EObject modelElement : targetElements) {
if (modelElement instanceof AbstractFunction) {
AbstractFunction function = (AbstractFunction) modelElement;
// continue only is current function is not allocated by any other component
if (function.getAllocationBlocks().isEmpty()) {
// create ComponentFunctionalAllocation
ComponentFunctionalAllocation alloction = FaFactory.eINSTANCE.createComponentFunctionalAllocation();
// add ComponentFunctionalAllocation to Component
comp.getOwnedFunctionalAllocation().add(alloction);
// set source
alloction.setSourceElement(comp);
// set target
alloction.setTargetElement(function);
}
}
}
}
// functions can also be allocated by roles
else if (sourceElement instanceof Role) {
Role role = (Role) sourceElement;
for (EObject modelElement : targetElements) {
if (modelElement instanceof AbstractFunction) {
AbstractFunction function = (AbstractFunction) modelElement;
// continue only is current function is not allocated by any other component
if (function.getAllocationBlocks().isEmpty()) {
// create ComponentFunctionalAllocation
ActivityAllocation newAllocation = OaFactory.eINSTANCE.createActivityAllocation();
// add ComponentFunctionalAllocation to Component
role.getOwnedActivityAllocations().add(newAllocation);
// set source
newAllocation.setSourceElement(role);
// set target
newAllocation.setTargetElement(function);
}
}
}
}
}
}
/**
* Action to perform allocation of all the targetElements(list of exchangeItems) to sourceElements(Interfaces)
*
* @param selectedCapellaElement
* @param selectedElements
*/
public void allocatingExchangeItemsToInterfaces(List<EObject> targetElements, List<EObject> sourceElements) {
if (!sourceElements.isEmpty() && !targetElements.isEmpty()) {
for (EObject source : sourceElements) {
if (source instanceof Interface) {
// interface
Interface sourceElement = (Interface) source;
for (EObject target : targetElements) {
if (target instanceof ExchangeItem) {
// exchange item
ExchangeItem targetElement = (ExchangeItem) target;
// exchange item allocation of current interface
EList<ExchangeItemAllocation> allocations = sourceElement.getOwnedExchangeItemAllocations();
// new exchange item allocation
ExchangeItemAllocation newAllocation = CsFactory.eINSTANCE.createExchangeItemAllocation();
// add new allocation to interface
allocations.add(newAllocation);
// set its allocated item as current exchangeItem
newAllocation.setAllocatedItem(targetElement);
}
}
}
}
}
}
/**
* Action to perform deployment of physical component
*
* @param targetElements
* @param sourceElements
*/
public void allocatingPCPartsToPCPart(List<EObject> targetElements, EObject sourceElement) {
if (sourceElement != null) {
if (sourceElement instanceof Part) {
Part sourcePart = (Part) sourceElement;
for (EObject modelElement : targetElements) {
if (modelElement instanceof Part) {
Part targetPart = (Part) modelElement;
// continue only is current function is not allocated by any other component
if (targetPart.getDeployingLinks().isEmpty()) {
if (PhysicalComponentExt.isDeploymentPossible(sourcePart, targetPart)) {
// create ComponentFunctionalAllocation
PartDeploymentLink deployment = DeploymentFactory.eINSTANCE.createPartDeploymentLink();
// add ComponentFunctionalAllocation to Component
sourcePart.getOwnedDeploymentLinks().add(deployment);
// set DeployedElement
deployment.setDeployedElement(targetPart);
// set Location
deployment.setLocation(sourcePart);
}
}
}
}
}
}
}
/**
* Action to perform allocation of functional exchanges.
*
* @param selectedCapellaElement
* @param object
*/
public void allocatingFEsToComponentExchanges(List<EObject> targetElements, EObject sourceElement) {
if (sourceElement instanceof ComponentExchange) {
ComponentExchange componentExchange = (ComponentExchange) sourceElement;
boolean shouldSyncronize = CapellaModelPreferencesPlugin.getDefault()
.isSynchronizationOfComponentPortToFunctionPortAllowed();
for (EObject object : targetElements) {
if (object instanceof FunctionalExchange) {
FunctionalExchange functionalExchange = (FunctionalExchange) object;
ComponentExchangeFunctionalExchangeAllocation allocation = FaFactory.eINSTANCE
.createComponentExchangeFunctionalExchangeAllocation();
allocation.setSourceElement(componentExchange);
allocation.setTargetElement(functionalExchange);
componentExchange.getOwnedComponentExchangeFunctionalExchangeAllocations().add(allocation);
if (shouldSyncronize) {
ComponentExchangeExt.synchronizePortAllocations(componentExchange, functionalExchange);
}
}
}
}
}
/**
* Action to perform allocation of component Exchanges.
*
* @param selectedCapellaElement
* @param object
*/
public void allocatingCEsToPhysicalLinks(List<EObject> targetElements, EObject sourceElement) {
if (sourceElement instanceof PhysicalLink) {
PhysicalLink physicalLink = (PhysicalLink) sourceElement;
boolean shouldSyncronize = CapellaModelPreferencesPlugin.getDefault()
.isSynchronizationOfPhysicalPortToComponentPortOnPhysicalLinkAllowed();
for (EObject object : targetElements) {
if (object instanceof ComponentExchange) {
ComponentExchange componentExchange = (ComponentExchange) object;
ComponentExchangeAllocation allocation = FaFactory.eINSTANCE.createComponentExchangeAllocation();
allocation.setSourceElement(physicalLink);
allocation.setTargetElement(componentExchange);
physicalLink.getOwnedComponentExchangeAllocations().add(allocation);
if (shouldSyncronize) {
PhysicalLinkExt.synchronizeAllocations(physicalLink, componentExchange);
}
}
}
}
}
}