diff --git a/core/plugins/org.polarsys.capella.core.data.core.properties/src/org/polarsys/capella/core/data/core/properties/fields/BasicElementGroup.java b/core/plugins/org.polarsys.capella.core.data.core.properties/src/org/polarsys/capella/core/data/core/properties/fields/BasicElementGroup.java index 9cabf92370..ad0685d884 100644 --- a/core/plugins/org.polarsys.capella.core.data.core.properties/src/org/polarsys/capella/core/data/core/properties/fields/BasicElementGroup.java +++ b/core/plugins/org.polarsys.capella.core.data.core.properties/src/org/polarsys/capella/core/data/core/properties/fields/BasicElementGroup.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 @@ -21,6 +21,7 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; import org.polarsys.capella.common.data.modellingcore.ModellingcorePackage; import org.polarsys.capella.common.mdsofa.common.constant.ICommonConstants; +import org.polarsys.capella.core.data.capellacore.CapellaElement; import org.polarsys.capella.core.data.capellacore.CapellacorePackage; import org.polarsys.capella.core.data.core.properties.Messages; import org.polarsys.capella.core.ui.properties.fields.AbstractSemanticField; @@ -145,5 +146,9 @@ public void enableSummaryField(boolean enabled) { public void setEnabled(boolean enabled) { LockHelper.getInstance().enable(nameTextField, enabled); LockHelper.getInstance().enable(summaryTextField, enabled); + if (enabled && semanticElement instanceof CapellaElement) { + // Refresh widgets from semantic element in case of remote update + loadData(semanticElement); + } } } diff --git a/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/ABServices.java b/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/ABServices.java index 34fbebe370..17ab560787 100644 --- a/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/ABServices.java +++ b/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/ABServices.java @@ -319,7 +319,7 @@ private EObject _dndABComponent(NamedElement pcMoved, EObject newOwner, NamedEle // Remove all port outgoing allocations for (Port port : ComponentExt.getOwnedComponentPort(component)) { - FaServices.getFaServices().removeUselessPortRealizations(port, false, true, false, false); + FaServices.getFaServices().removeUselessPortAllocations(port, newContainer, false, true, false, false); } FaServices.getFaServices().removeUselessExchanges(component); diff --git a/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/FaServices.java b/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/FaServices.java index 64574c7dab..2769ccb155 100644 --- a/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/FaServices.java +++ b/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/FaServices.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 @@ -16,7 +16,6 @@ import java.util.AbstractMap; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -25,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -93,6 +93,7 @@ import org.polarsys.capella.core.data.epbs.ConfigurationItem; import org.polarsys.capella.core.data.epbs.PhysicalArtifactRealization; 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.ComponentExchangeEnd; import org.polarsys.capella.core.data.fa.ComponentExchangeFunctionalExchangeAllocation; @@ -2367,19 +2368,19 @@ else if ((oldComponent != null) && (newContainer instanceof Role)) { // outGoing functiaonalExchages(component // Exchange Allocation) if (!oldContainer.equals(newComponent)) { - removeUseLessPortRealizationAndComponentExchangeAllocation(function, functions); + removeUseLessPortRealizationAndComponentExchangeAllocation(function, functions, newContainer); } return function; } private void removeUseLessPortRealizationAndComponentExchangeAllocation(AbstractFunction function, - Collection functions) { + Collection functions, NamedElement newContainer) { Collection functionalExchanges = new HashSet<>(); for (AbstractFunction fct : functions) { // Find all PortRealization and component exchanges to be deleted for (Port port : FunctionExt.getOwnedFunctionPorts(fct)) { - removeUselessPortRealizations(port, true, true, false, false); + removeUselessPortAllocations(port, newContainer, true, true, false, false); } } // consider incoming and outgoing functionalExchanges of target function @@ -2985,7 +2986,7 @@ public EObject dndABDeployment(NamedElement pcMoved, NamedElement oldContainer, // Remove all port outgoing allocations for (Port port : ComponentExt.getOwnedComponentPort(component)) { - removeUselessPortRealizations(port, false, true, false, false); + removeUselessPortAllocations(port, newContainer, false, true, false, false); } // move all deploying links @@ -3006,7 +3007,7 @@ public EObject dndABDeployment(NamedElement pcMoved, NamedElement oldContainer, // Remove all port outgoing allocations for (Port port : ComponentExt.getOwnedComponentPort(component)) { - removeUselessPortRealizations(port, false, true, false, false); + removeUselessPortAllocations(port, newContainer, false, true, false, false); } // move all deploying links @@ -3022,6 +3023,15 @@ public EObject dndABDeployment(NamedElement pcMoved, NamedElement oldContainer, return pcMoved; } + EObject removeUselessPortAllocations(Port port, NamedElement newContainer, boolean includeFunctionalRealization, boolean includeComponentRealization, + boolean topDelegation, boolean bottomDelegation) { + Collection elements = new HashSet<>(); + elements.addAll(retrievePortDelegations(port, topDelegation, bottomDelegation)); + elements.addAll(retrieveObsoletePortAllocations(port, newContainer, includeFunctionalRealization, includeComponentRealization, bottomDelegation, bottomDelegation)); + CapellaServices.getService().removeElements(elements); + return port; + } + /** * Perform a dnd of a port. * @@ -3030,7 +3040,14 @@ public EObject dndABDeployment(NamedElement pcMoved, NamedElement oldContainer, EObject removeUselessPortRealizations(Port port, boolean includeFunctionalRealization, boolean includeComponentRealization, boolean topDelegation, boolean bottomDelegation) { Collection elements = new HashSet<>(); + elements.addAll(retrievePortDelegations(port, topDelegation, bottomDelegation)); + elements.addAll(retrievePortAllocations(port, includeFunctionalRealization, includeComponentRealization)); + CapellaServices.getService().removeElements(elements); + return port; + } + private Collection retrievePortDelegations(Port port, boolean topDelegation, boolean bottomDelegation) { + Collection delegations = new HashSet<>(); if (port instanceof ComponentPort) { // Retrieve delegation to delete, according to parameters for (ComponentExchange exchange : PortExt.getDelegationComponentExchanges((ComponentPort) port)) { @@ -3046,13 +3063,94 @@ EObject removeUselessPortRealizations(Port port, boolean includeFunctionalRealiz } if (topDelegation && CsServices.getService().getContainersOfParts(containingPort).contains(delegatedPort)) { - elements.add(exchange); - } else if (bottomDelegation - && CsServices.getService().getContainersOfParts(delegatedPort).contains(containingPort)) { - elements.add(exchange); + delegations.add(exchange); + } else if (bottomDelegation && CsServices.getService().getContainersOfParts(delegatedPort).contains(containingPort)) { + delegations.add(exchange); } } } + return delegations; + } + + /** + * This method retrieve all the port's allocations and return those that should be deleted (as they do not make sense + * for the new element) + * + * @param movingPort + * the port that is being D&Ded + * @param newContainer + * the container the port was just Dropped on. + * @param includeFunctionalRealization + * @param includeComponentRealization + * @param topDelegation + * @param bottomDelegation + * @return + */ + private Collection retrieveObsoletePortAllocations(Port movingPort, NamedElement newContainer, boolean includeFunctionalRealization, + boolean includeComponentRealization, boolean topDelegation, boolean bottomDelegation) { + Collection elements = new HashSet(); + Collection allocations = retrievePortAllocations(movingPort, includeFunctionalRealization, includeComponentRealization); + if (newContainer instanceof Part) { + // case where moving the component's port + Component instanciatedComponent = PartExt.getComponentOfPart((Part) newContainer); + for (Allocation allocation : allocations) { + Port delegatedPort = (allocation.getSourceElement() == movingPort) ? (Port) allocation.getTargetElement() : (Port) allocation.getSourceElement(); + if (instanciatedComponent == null || !isEObjectInHierarchyOfContainer(delegatedPort.eContainer(), instanciatedComponent)) { + elements.add(allocation); + } + } + } else if (newContainer instanceof AbstractFunction) { + // case where moving the function's port + for (Allocation allocation : allocations) { + if (!isEObjectInHierarchyOfContainer(newContainer, allocation.getSourceElement().eContainer())) { + elements.add(allocation); + } + } + } + return elements; + } + + /** + * Test two objects to determine if the first one is a subElement of the other. Should eObject be an AbstractFunction, + * the test will be done on each of its FunctionalAllocation instead. + * + * @param eObject + * @param container + * @return + */ + private boolean isEObjectInHierarchyOfContainer(EObject eObject, EObject container) { + if (eObject == null || container == null) { + return false; + } else if (eObject == container) { + return true; + } else if (eObject instanceof AbstractFunction) { + AbstractFunction eFunction = (AbstractFunction) eObject; + if (eFunction.getComponentFunctionalAllocations().stream().anyMatch(cfa -> isEObjectInHierarchyOfContainer(cfa, container))) { + return true; + } + } + if (eObject instanceof ModelElement && eObject.eContainer() != null) { + return isEObjectInHierarchyOfContainer(getOwningComponent((ModelElement) eObject), container); + } + return false; + } + + private EObject getOwningComponent(ModelElement eObject) { + if (eObject instanceof AbstractFunction) { + AbstractFunction eFunction = (AbstractFunction) eObject; + Optional optional = eFunction.getAllocationBlocks().stream().filter(e -> ComponentExt.getAllSubUsedComponents((Component) e).contains(eObject)).findFirst(); + if (optional.isPresent()) { + return optional.get(); + } + } + if (eObject.eContainer() != null) { + return eObject.eContainer(); + } + return null; + } + + private Collection retrievePortAllocations(Port port, boolean includeFunctionalRealization, boolean includeComponentRealization) { + Collection elements = new HashSet<>(); Collection allocations = new HashSet<>(); allocations.addAll(port.getIncomingPortAllocations()); @@ -3063,27 +3161,21 @@ EObject removeUselessPortRealizations(Port port, boolean includeFunctionalRealiz // Retrieve port allocation according to parameters for (Allocation realization : allocations) { if (isValidAllocation(realization)) { - if ((realization.getSourceElement() != null) && (realization.getTargetElement() != null)) { - if (includeFunctionalRealization && (realization.getTargetElement() instanceof FunctionPort)) { - elements.add(realization); - } + if (includeFunctionalRealization && (realization.getTargetElement() instanceof FunctionPort)) { + elements.add(realization); + } - if ((port instanceof FunctionPort) && includeComponentRealization - && (realization.getSourceElement() instanceof FunctionPort)) { - elements.add(realization); - } + if ((port instanceof FunctionPort) && includeComponentRealization && (realization.getSourceElement() instanceof FunctionPort)) { + elements.add(realization); + } - if (includeComponentRealization && ((realization.getTargetElement() instanceof ComponentPort) - || (realization.getTargetElement() instanceof PhysicalPort))) { - elements.add(realization); - } + if (includeComponentRealization && ((realization.getTargetElement() instanceof ComponentPort) || (realization.getTargetElement() instanceof PhysicalPort))) { + elements.add(realization); } } } - - CapellaServices.getService().removeElements(elements); - return port; + return elements; } /** @@ -3095,7 +3187,7 @@ EObject removeUselessPortRealizations(Port port, boolean includeFunctionalRealiz */ public EObject dndABFunctionPort(FunctionPort port, NamedElement oldContainer, NamedElement newContainer) { - removeUselessPortRealizations(port, true, true, false, false); + removeUselessPortAllocations(port, newContainer, true, true, false, false); // move the port in the new function container if (newContainer instanceof AbstractFunction) { @@ -3119,8 +3211,7 @@ public EObject dndABFunctionPort(FunctionPort port, NamedElement oldContainer, N } moveFunctionalExchanges(port); - removeComponentExchangeAllocations(getFunctionalExchanges(port)); - + return port; } @@ -3139,7 +3230,7 @@ public EObject dndABPhysicalPort(PhysicalPort port, Part oldContainer, Part newC if (!port.eContainer().equals(newContainer.getType())) { removeUselessExchanges(port); - removeUselessPortRealizations(port, true, true, false, false); + removeUselessPortAllocations(port, newContainer, true, true, false, false); ((Component) newContainer.getType()).getOwnedFeatures().add(port); updateExchanges(port, oldContainer, newContainer); @@ -3163,7 +3254,7 @@ public EObject dndABComponentPort(ComponentPort port, Part oldContainer, Part ne if (!port.eContainer().equals(newContainer.getType())) { removeUselessExchanges(port); - removeUselessPortRealizations(port, true, true, false, false); + removeUselessPortAllocations(port, newContainer, true, true, false, false); ((Component) newContainer.getType()).getOwnedFeatures().add(port); updateComponentExchanges(port, oldContainer, newContainer); @@ -3365,8 +3456,6 @@ protected void moveFunctionalExchanges(FunctionPort port) { for (FunctionalExchange exchange : functionalExchanges) { moveFunctionalExchange(exchange); } - - removeComponentExchangeAllocations(functionalExchanges); } /** diff --git a/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/AbstractSemanticButtonGroup.java b/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/AbstractSemanticButtonGroup.java index a60a28418b..4359d11b02 100644 --- a/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/AbstractSemanticButtonGroup.java +++ b/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/AbstractSemanticButtonGroup.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 @@ -14,6 +14,7 @@ import java.util.List; +import org.eclipse.emf.ecore.EAttribute; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; @@ -61,7 +62,12 @@ protected Button createButton(Composite group, String label, Object data, boolea */ protected void enableButton(Button button, boolean enabled) { if (null != button && !button.isDisposed()) { - button.setEnabled(enabled); + button.setEnabled(enabled); + if (enabled && semanticElement != null && button.getData() instanceof EAttribute + && semanticElement.eGet((EAttribute) button.getData()) instanceof Boolean) { + // Refresh widget from semantic element in case of remote update + button.setSelection((Boolean) semanticElement.eGet(((EAttribute) button.getData()))); + } } } diff --git a/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/BooleanValueGroup.java b/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/BooleanValueGroup.java index 6b6cb8665e..088b90ec32 100644 --- a/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/BooleanValueGroup.java +++ b/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/BooleanValueGroup.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 @@ -107,6 +107,10 @@ protected void fillComboField(CCombo comboField) { public void setEnabled(boolean enabled) { if (null != _valueField && !_valueField.isDisposed()) { _valueField.setEnabled(enabled); + if (enabled) { + // Refresh widget from semantic element in case of remote update + loadComboValue(); + } } } } diff --git a/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/BrowseSemanticField.java b/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/BrowseSemanticField.java index 105ef9faf7..c914a6c907 100644 --- a/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/BrowseSemanticField.java +++ b/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/BrowseSemanticField.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 @@ -305,6 +305,10 @@ public void setEnabled(boolean enabled) { LockHelper.getInstance().enable(_valueOpenBtn, enabled); LockHelper.getInstance().enable(_valueShortcutBtn, enabled); LockHelper.getInstance().update(_valueTextField, enabled); + if (enabled && this.semanticElement != null && this.semanticFeature != null) { + // Refresh widget from semantic element in case of remote update + setValueTextField(this.semanticElement.eGet(this.semanticFeature)); + } } /** diff --git a/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/EnumerationValueGroup.java b/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/EnumerationValueGroup.java index 1bb7ccc54d..79b6aed307 100644 --- a/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/EnumerationValueGroup.java +++ b/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/EnumerationValueGroup.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 @@ -167,6 +167,10 @@ protected void fillComboField(CCombo comboField) { public void setEnabled(boolean enabled) { if (null != _valueField && !_valueField.isDisposed()) { _valueField.setEnabled(enabled); + if (enabled) { + // Refresh widget from semantic element in case of remote update + loadComboValue(); + } } } } diff --git a/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/TextValueGroup.java b/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/TextValueGroup.java index 4f99cf5fea..2b9150743b 100644 --- a/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/TextValueGroup.java +++ b/core/plugins/org.polarsys.capella.core.ui.properties/src/org/polarsys/capella/core/ui/properties/fields/TextValueGroup.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 @@ -152,6 +152,10 @@ protected void fillTextField(Text textField) { public void setEnabled(boolean enabled) { if (null != valueField && !valueField.isDisposed()) { valueField.setEnabled(enabled); + if (enabled) { + // Refresh widget from semantic element in case of remote update + loadTextValue(); + } } if (null != valueResetBtn && !valueResetBtn.isDisposed()) { valueResetBtn.setEnabled(enabled);