-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Based on QF for DWF_DC_45 prompt for an allocation to keep and remove the others Change-Id: I6ca321ba35198680872dd243a2880ee6c6201d52 Signed-off-by: Erwann Traisnel <erwann.traisnel@obeo.fr>
- Loading branch information
1 parent
3780bff
commit f5de001
Showing
4 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...ickfix/src/org/polarsys/capella/core/data/fa/ui/quickfix/resolver/DWF_DC_12_Resolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
...ickfix/src/org/polarsys/capella/core/data/fa/ui/quickfix/resolver/DWF_DC_27_Resolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/******************************************************************************* | ||
* 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.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.Status; | ||
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.eclipse.ui.statushandlers.StatusManager; | ||
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.fa.ComponentExchange; | ||
import org.polarsys.capella.core.data.fa.ComponentExchangeFunctionalExchangeAllocation; | ||
import org.polarsys.capella.core.data.fa.FunctionalExchange; | ||
import org.polarsys.capella.core.platform.sirius.ui.commands.CapellaDeleteCommand; | ||
import org.polarsys.capella.core.validation.ui.ide.PluginActivator; | ||
|
||
/** | ||
* DWF_DC_27 - SequenceLink with no associated FunctionalChainInvolvementLinks | ||
*/ | ||
public class DWF_DC_27_Resolver extends AbstractSelectOneResolver { | ||
public DWF_DC_27_Resolver() { | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void run(IMarker marker) { | ||
final List<EObject> modelElements = getModelElements(marker); | ||
|
||
if (!modelElements.isEmpty()) { | ||
if (modelElements.get(0) instanceof FunctionalExchange) { | ||
openSelectionDialog((FunctionalExchange) modelElements.get(0), marker); | ||
} | ||
} | ||
} | ||
|
||
protected void openSelectionDialog(EObject semanticElement, IMarker marker) { | ||
List<ComponentExchange> allocatingCEs = new ArrayList<ComponentExchange>( | ||
((FunctionalExchange) semanticElement).getAllocatingComponentExchanges()); | ||
|
||
AbstractReadWriteCommand command = new AbstractReadWriteCommand() { | ||
@Override | ||
public void run() { | ||
Shell activeShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); | ||
SelectElementsDialog dialog = new SelectElementsDialog(activeShell, "Component Exchange Allocation", | ||
"Please select a single Physical Link to allocate\nOthers will be deallocated", allocatingCEs); | ||
if (dialog.open() == Dialog.OK) { | ||
ComponentExchange result = (ComponentExchange) dialog.getResult().get(0); | ||
allocatingCEs.remove(result); | ||
|
||
List<ComponentExchangeFunctionalExchangeAllocation> cefeaToBeDeleted = new ArrayList<ComponentExchangeFunctionalExchangeAllocation>(); | ||
for (ComponentExchange toBeDeallocated : allocatingCEs) { | ||
for (AbstractTrace outgoing : toBeDeallocated.getOutgoingTraces()) { | ||
if (outgoing instanceof ComponentExchangeFunctionalExchangeAllocation) { | ||
ComponentExchangeFunctionalExchangeAllocation cefea = (ComponentExchangeFunctionalExchangeAllocation) outgoing; | ||
if (cefea.getAllocatedFunctionalExchange() == semanticElement) { | ||
cefeaToBeDeleted.add(cefea); | ||
} | ||
} | ||
} | ||
} | ||
boolean confirmDeletion = CapellaDeleteCommand | ||
.confirmDeletion(TransactionHelper.getExecutionManager(semanticElement), cefeaToBeDeleted); | ||
if (confirmDeletion) { | ||
CapellaDeleteCommand command = new CapellaDeleteCommand( | ||
TransactionHelper.getExecutionManager(semanticElement), cefeaToBeDeleted, false, false, true); | ||
if (command.canExecute()) { | ||
command.execute(); | ||
deleteMarker(marker); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
TransactionHelper.getExecutionManager(semanticElement).execute(command); | ||
} | ||
|
||
@Override | ||
protected void deleteMarker(IMarker marker) { | ||
// delete marker | ||
try { | ||
marker.delete(); | ||
} catch (CoreException exception) { | ||
StatusManager.getManager().handle( | ||
new Status(IStatus.ERROR, PluginActivator.getDefault().getPluginId(), exception.getMessage(), exception)); | ||
} | ||
} | ||
|
||
@Override | ||
protected boolean isAvailableFor(EObject obj) { | ||
return obj != null && obj instanceof FunctionalExchange; | ||
} | ||
|
||
} |