From f5de0014cb0a8d2266118eff82941327cea84068 Mon Sep 17 00:00:00 2001 From: Erwann Traisnel Date: Tue, 17 Oct 2023 16:48:59 +0200 Subject: [PATCH] #2743 Quickfix for DWF_DC_12 and 27 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 --- .../plugin.properties | 7 ++ .../plugin.xml | 18 +++ .../quickfix/resolver/DWF_DC_12_Resolver.java | 87 +++++++++++++ .../quickfix/resolver/DWF_DC_27_Resolver.java | 115 ++++++++++++++++++ 4 files changed, 227 insertions(+) create mode 100644 core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/src/org/polarsys/capella/core/data/fa/ui/quickfix/resolver/DWF_DC_12_Resolver.java create mode 100644 core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/src/org/polarsys/capella/core/data/fa/ui/quickfix/resolver/DWF_DC_27_Resolver.java diff --git a/core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/plugin.properties b/core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/plugin.properties index 5cca086b0f..d3e50d08d4 100644 --- a/core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/plugin.properties +++ b/core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/plugin.properties @@ -18,6 +18,13 @@ quickFix.PortRealizationPropagationFromFE.desc = Propagate Port Realizations fro quickFix.PhysicalLinkComponentExchangeAllocation.label = Select a Physical Link to keep as allocator quickFix.PhysicalLinkComponentExchangeAllocation.desc = Select a Physical Link to keep as allocator + +quickFix.ComponentExchangeFunctionalExchangeAllocation.label = Select a Component Exchange to keep as allocator +quickFix.ComponentExchangeFunctionalExchangeAllocation.desc = Select a Component Exchange to keep as allocator + +quickFix.ComponentFunctionAllocation.label = Select a Component to keep as allocator +quickFix.ComponentFunctionAllocation.desc = Select a Component to keep as allocator + quickFix.ExchangeItemAllocationOnPorts.label = Propagate Exchange Items to Function Ports quickFix.ExchangeItemAllocationOnPorts.desc = Propagate Exchange Items to Function Ports diff --git a/core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/plugin.xml b/core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/plugin.xml index d0002ca586..7c92fc4019 100644 --- a/core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/plugin.xml +++ b/core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/plugin.xml @@ -389,6 +389,24 @@ ruleId="DWF_DC_45"> + + + + + + + + diff --git a/core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/src/org/polarsys/capella/core/data/fa/ui/quickfix/resolver/DWF_DC_12_Resolver.java b/core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/src/org/polarsys/capella/core/data/fa/ui/quickfix/resolver/DWF_DC_12_Resolver.java new file mode 100644 index 0000000000..25a7162865 --- /dev/null +++ b/core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/src/org/polarsys/capella/core/data/fa/ui/quickfix/resolver/DWF_DC_12_Resolver.java @@ -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 allocatingComponents = new ArrayList(); + 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 cfaToBeDeleted = new ArrayList(); + 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; + } +} diff --git a/core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/src/org/polarsys/capella/core/data/fa/ui/quickfix/resolver/DWF_DC_27_Resolver.java b/core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/src/org/polarsys/capella/core/data/fa/ui/quickfix/resolver/DWF_DC_27_Resolver.java new file mode 100644 index 0000000000..dd55623e20 --- /dev/null +++ b/core/plugins/org.polarsys.capella.core.data.fa.ui.quickfix/src/org/polarsys/capella/core/data/fa/ui/quickfix/resolver/DWF_DC_27_Resolver.java @@ -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 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 allocatingCEs = new ArrayList( + ((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 cefeaToBeDeleted = new ArrayList(); + 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; + } + +}