diff --git a/core/plugins/org.polarsys.capella.core.platform.sirius.ui.actions/plugin.xml b/core/plugins/org.polarsys.capella.core.platform.sirius.ui.actions/plugin.xml index c7e5a62dc0..0a6884f77b 100644 --- a/core/plugins/org.polarsys.capella.core.platform.sirius.ui.actions/plugin.xml +++ b/core/plugins/org.polarsys.capella.core.platform.sirius.ui.actions/plugin.xml @@ -375,6 +375,22 @@ + + + + + + + + + + @@ -500,6 +516,15 @@ + + + + + + @@ -730,6 +755,12 @@ id="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.PropagateExchangeItemAllocations" name="%PropagateEIOnPorts"> + + + + selection) { + super(selection); + } + + @Override + protected void process(ModelElement element) { + if ((element instanceof LogicalFunction) || (element instanceof SystemFunction) || (element instanceof PhysicalFunction)) { + AbstractFunction motherFunction = (AbstractFunction) element; + Component component = resolveMotherFunctionAllocation(motherFunction); + if (component != null) { + createAlloction(component, motherFunction); + } + } + } + + private Component resolveMotherFunctionAllocation(AbstractFunction motherFunction) { + List motherFunctionAllocation = new ArrayList(); + // In case the function is a leaf, there are already + // two queries that do the job: + // - Function Actor Allocation + // - Function Component Allocation + if (!FunctionExt.isLeaf(motherFunction)) { + // Check block allocation + EList blockAllocations = motherFunction.getAllocationBlocks(); + + // If mother is already allocated, there are already queries + // that do the job so only get the leaves allocation in case the + // mother is not already allocated + if ((null == blockAllocations) || blockAllocations.isEmpty()) { + motherFunctionAllocation.addAll(AbstractFunctionExt.getMotherFunctionAllocation(motherFunction)); + if (motherFunctionAllocation.size() == 1) { + return AbstractFunctionExt.getMotherFunctionAllocation(motherFunction).get(0); + } + } + } + return null; + } + + private void createAlloction(Component component, AbstractFunction function) { + ComponentFunctionalAllocation allocation = FaFactory.eINSTANCE.createComponentFunctionalAllocation(); + if (component != null) { + allocation.setSourceElement(component); + allocation.setTargetElement(function); + component.getOwnedFunctionalAllocation().add(allocation); + } + } + +} diff --git a/core/plugins/org.polarsys.capella.core.platform.sirius.ui.actions/src/org/polarsys/capella/core/platform/sirius/ui/handlers/ConcretizeFunctionAllocationHandler.java b/core/plugins/org.polarsys.capella.core.platform.sirius.ui.actions/src/org/polarsys/capella/core/platform/sirius/ui/handlers/ConcretizeFunctionAllocationHandler.java new file mode 100644 index 0000000000..0dc7e0ea0b --- /dev/null +++ b/core/plugins/org.polarsys.capella.core.platform.sirius.ui.actions/src/org/polarsys/capella/core/platform/sirius/ui/handlers/ConcretizeFunctionAllocationHandler.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * 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 Global Services - initial API and implementation + *******************************************************************************/ +package org.polarsys.capella.core.platform.sirius.ui.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; +import org.polarsys.capella.common.ui.services.commands.ActionCommandDelegate; +import org.polarsys.capella.core.platform.sirius.ui.actions.ConcretizeFunctionAllocationAction; + +/** + * Handler for the ConcretizeFunctionAllocation accelerator, + * + * Delegate event handling and determine accelerator visibility. + * @author ebausson + */ +public class ConcretizeFunctionAllocationHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ActionCommandDelegate delegate = new ActionCommandDelegate(event); + ConcretizeFunctionAllocationAction action = new ConcretizeFunctionAllocationAction(); + action.selectionChanged(delegate, HandlerUtil.getCurrentSelection(event)); + action.run(delegate); + return null; + } + + @Override + public boolean isEnabled() { + ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite().getSelectionProvider().getSelection(); + return (selection != null && selection instanceof IStructuredSelection && !selection.isEmpty()); + } + +} diff --git a/core/plugins/org.polarsys.capella.core.platform.sirius.ui.menu/src/org/polarsys/capella/core/platform/sirius/ui/ActionPropertyTester.java b/core/plugins/org.polarsys.capella.core.platform.sirius.ui.menu/src/org/polarsys/capella/core/platform/sirius/ui/ActionPropertyTester.java index 7bfd5ab421..d25a4ce04f 100644 --- a/core/plugins/org.polarsys.capella.core.platform.sirius.ui.menu/src/org/polarsys/capella/core/platform/sirius/ui/ActionPropertyTester.java +++ b/core/plugins/org.polarsys.capella.core.platform.sirius.ui.menu/src/org/polarsys/capella/core/platform/sirius/ui/ActionPropertyTester.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2020 THALES GLOBAL SERVICES. + * Copyright (c) 2006, 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 @@ -13,16 +13,23 @@ package org.polarsys.capella.core.platform.sirius.ui; import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.emf.common.util.EList; import org.polarsys.capella.common.data.modellingcore.ModelElement; import org.polarsys.capella.common.ui.actions.ModelAdaptation; import org.polarsys.capella.core.data.capellacore.CapellaElement; import org.polarsys.capella.core.data.cs.Component; import org.polarsys.capella.core.data.cs.Part; +import org.polarsys.capella.core.data.ctx.SystemFunction; import org.polarsys.capella.core.data.epbs.ConfigurationItem; import org.polarsys.capella.core.data.fa.AbstractFunction; +import org.polarsys.capella.core.data.fa.AbstractFunctionalBlock; import org.polarsys.capella.core.data.fa.ComponentExchange; import org.polarsys.capella.core.data.fa.FunctionalExchange; +import org.polarsys.capella.core.data.helpers.fa.services.FunctionExt; import org.polarsys.capella.core.data.information.datavalue.LiteralNumericValue; +import org.polarsys.capella.core.data.la.LogicalFunction; +import org.polarsys.capella.core.data.pa.PhysicalFunction; +import org.polarsys.capella.core.model.helpers.AbstractFunctionExt; import org.polarsys.capella.core.model.utils.CapellaLayerCheckingExt; /** @@ -34,6 +41,7 @@ public class ActionPropertyTester extends PropertyTester { * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], * java.lang.Object) */ + @Override public boolean test(Object object_p, String propertyName_p, Object[] params_p, Object testedValue_p) { boolean result = false; if (propertyName_p.equals("actionMode") || propertyName_p.equals("graphicalActionMode")) { //$NON-NLS-1$ //$NON-NLS-2$ @@ -54,6 +62,9 @@ public boolean test(Object object_p, String propertyName_p, Object[] params_p, O if ("propagationPortRealizationsFromCE".equals(actionName)) { //$NON-NLS-1$ return isPropagationPortRealizationsFromCE(element); } + if ("concretizeFunctionAllocation".equals(actionName)) { //$NON-NLS-1$ + return isConcretizableFunctionAllocation(element); + } if ("convertClassPrimitive".equals(actionName)) { //$NON-NLS-1$ return isConvertPrimitive(element); } @@ -143,6 +154,19 @@ private boolean isPropagationPortRealizationsFromFE(ModelElement element_p) { return result; } + private boolean isConcretizableFunctionAllocation(ModelElement element) { + if ((element instanceof LogicalFunction) || (element instanceof SystemFunction) || (element instanceof PhysicalFunction)) { + AbstractFunction motherFunction = (AbstractFunction) element; + if (!FunctionExt.isLeaf(motherFunction)) { + EList blockAllocations = motherFunction.getAllocationBlocks(); + if ((null == blockAllocations) || blockAllocations.isEmpty()) { + return AbstractFunctionExt.getMotherFunctionAllocation(motherFunction).size() == 1; + } + } + } + return false; + } + /** * @param element_p * @return