-
Notifications
You must be signed in to change notification settings - Fork 85
/
DWF_DC_12_Resolver.java
87 lines (80 loc) · 3.75 KB
/
DWF_DC_12_Resolver.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) 2023 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.data.fa.ui.quickfix.resolver;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IMarker;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.polarsys.capella.common.data.modellingcore.AbstractTrace;
import org.polarsys.capella.common.ef.command.AbstractReadWriteCommand;
import org.polarsys.capella.common.helpers.TransactionHelper;
import org.polarsys.capella.common.ui.toolkit.dialogs.SelectElementsDialog;
import org.polarsys.capella.core.data.cs.Component;
import org.polarsys.capella.core.data.fa.AbstractFunction;
import org.polarsys.capella.core.data.fa.ComponentFunctionalAllocation;
import org.polarsys.capella.core.platform.sirius.ui.commands.CapellaDeleteCommand;
/**
* DWF_DC_12 - Function must be allocated to only one component, including actor
*/
public class DWF_DC_12_Resolver extends AbstractSelectOneResolver {
public DWF_DC_12_Resolver() {
}
protected void openSelectionDialog(EObject semanticElement, IMarker marker) {
List<Component> allocatingComponents = new ArrayList<Component>();
for (ComponentFunctionalAllocation cfa : ((AbstractFunction) semanticElement).getComponentFunctionalAllocations()) {
Component comp = (Component) cfa.getSourceElement();
allocatingComponents.add(comp);
}
AbstractReadWriteCommand command = new AbstractReadWriteCommand() {
@Override
public void run() {
Shell activeShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
SelectElementsDialog dialog = new SelectElementsDialog(activeShell, "Function Allocation",
"Please select a single allocating Component\nOther allocations will be removed", allocatingComponents);
if (dialog.open() == Dialog.OK) {
Component result = (Component) dialog.getResult().get(0);
allocatingComponents.remove(result);
List<ComponentFunctionalAllocation> cfaToBeDeleted = new ArrayList<ComponentFunctionalAllocation>();
for (Component toBeDeallocated : allocatingComponents) {
for (AbstractTrace outgoing : toBeDeallocated.getOutgoingTraces()) {
if (outgoing instanceof ComponentFunctionalAllocation) {
ComponentFunctionalAllocation cfa = (ComponentFunctionalAllocation) outgoing;
if (cfa.getFunction() == semanticElement) {
cfaToBeDeleted.add(cfa);
}
}
}
}
boolean confirmDeletion = CapellaDeleteCommand
.confirmDeletion(TransactionHelper.getExecutionManager(semanticElement), cfaToBeDeleted);
if (confirmDeletion) {
CapellaDeleteCommand command = new CapellaDeleteCommand(
TransactionHelper.getExecutionManager(semanticElement), cfaToBeDeleted, false, false, true);
if (command.canExecute()) {
command.execute();
deleteMarker(marker);
}
}
}
}
};
TransactionHelper.getExecutionManager(semanticElement).execute(command);
}
@Override
protected boolean isAvailableFor(EObject obj) {
return obj != null && obj instanceof AbstractFunction;
}
}