Skip to content

Commit

Permalink
#2743 Quickfix for DWF_DC_12 and 27
Browse files Browse the repository at this point in the history
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
etraisnel2 authored and pdulth committed Oct 23, 2023
1 parent 3780bff commit f5de001
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,24 @@
ruleId="DWF_DC_45">
</rules>
</resolver>
<resolver
class="org.polarsys.capella.core.data.fa.ui.quickfix.resolver.DWF_DC_12_Resolver"
desc="%quickFix.ComponentFunctionAllocation.desc"
icon="platform:/plugin/org.polarsys.capella.core.ui.resources/icons/full/obj16/capella_edit.gif"
label="%quickFix.ComponentFunctionAllocation.label">
<rules
ruleId="DWF_DC_12">
</rules>
</resolver>
<resolver
class="org.polarsys.capella.core.data.fa.ui.quickfix.resolver.DWF_DC_27_Resolver"
desc="%quickFix.ComponentExchangeFunctionalExchangeAllocation.desc"
icon="platform:/plugin/org.polarsys.capella.core.ui.resources/icons/full/obj16/capella_edit.gif"
label="%quickFix.ComponentExchangeFunctionalExchangeAllocation.label">
<rules
ruleId="DWF_DC_27">
</rules>
</resolver>
</extension>
<extension
point="org.eclipse.ui.ide.markerResolution">
Expand Down
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;
}
}
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;
}

}

0 comments on commit f5de001

Please sign in to comment.