Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conservation port delegation master #2796

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<AbstractFunction> functions) {
Collection<AbstractFunction> functions, NamedElement newContainer) {
Collection<FunctionalExchange> 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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<EObject> 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.
*
Expand All @@ -3030,7 +3040,14 @@ public EObject dndABDeployment(NamedElement pcMoved, NamedElement oldContainer,
EObject removeUselessPortRealizations(Port port, boolean includeFunctionalRealization,
boolean includeComponentRealization, boolean topDelegation, boolean bottomDelegation) {
Collection<EObject> elements = new HashSet<>();
elements.addAll(retrievePortDelegations(port, topDelegation, bottomDelegation));
elements.addAll(retrievePortAllocations(port, includeFunctionalRealization, includeComponentRealization));
CapellaServices.getService().removeElements(elements);
return port;
}

private Collection<EObject> retrievePortDelegations(Port port, boolean topDelegation, boolean bottomDelegation) {
Collection<EObject> delegations = new HashSet<>();
if (port instanceof ComponentPort) {
// Retrieve delegation to delete, according to parameters
for (ComponentExchange exchange : PortExt.getDelegationComponentExchanges((ComponentPort) port)) {
Expand All @@ -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<Allocation> retrieveObsoletePortAllocations(Port movingPort, NamedElement newContainer, boolean includeFunctionalRealization,
boolean includeComponentRealization, boolean topDelegation, boolean bottomDelegation) {
Collection<Allocation> elements = new HashSet<Allocation>();
Collection<Allocation> 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<AbstractFunctionalBlock> 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<Allocation> retrievePortAllocations(Port port, boolean includeFunctionalRealization, boolean includeComponentRealization) {
Collection<Allocation> elements = new HashSet<>();

Collection<Allocation> allocations = new HashSet<>();
allocations.addAll(port.getIncomingPortAllocations());
Expand All @@ -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;
}

/**
Expand All @@ -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) {
Expand All @@ -3119,8 +3211,7 @@ public EObject dndABFunctionPort(FunctionPort port, NamedElement oldContainer, N
}

moveFunctionalExchanges(port);
removeComponentExchangeAllocations(getFunctionalExchanges(port));


return port;
}

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -3365,8 +3456,6 @@ protected void moveFunctionalExchanges(FunctionPort port) {
for (FunctionalExchange exchange : functionalExchanges) {
moveFunctionalExchange(exchange);
}

removeComponentExchangeAllocations(functionalExchanges);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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())));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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));
}
}

/**
Expand Down
Loading