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

Concretize function allocation #4

Open
wants to merge 3 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, 2022 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 @@ -26,6 +26,11 @@
*/
public interface ISemanticBrowserViewPart extends IViewPart {

/**
* Semantic browser id.
*/
public static final String SEMANTIC_BROWSER_ID = "org.polarsys.capella.core.ui.semantic.browser.view.SemanticBrowserID"; //$NON-NLS-1$

/**
* Sets the input of the Semantic Browser and <b>ALWAYS</b> triggers a refresh of the associated queries.
*
Expand Down Expand Up @@ -97,4 +102,8 @@ public interface ISemanticBrowserViewPart extends IViewPart {
public ISemanticBrowserModel getModel();

public void setInputOnViewers(Object input);

public static String getSemanticBrowserID() {
return SEMANTIC_BROWSER_ID;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,22 @@
</with>
</or>
</definition>
<definition
id="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.ConcretizeFunctionAllocation.expression">
<or>
<with
variable="selection">
<iterate
ifEmpty="false">
<test
forcePluginActivation="true"
property="org.polarsys.capella.core.platform.sirius.ui.actionMode"
value="concretizeFunctionAllocation">
</test>
</iterate>
</with>
</or>
</definition>

<definition
id="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.PropagateExchangeItemAllocations.expression">
Expand Down Expand Up @@ -488,6 +504,15 @@
</reference>
</visibleWhen>
</command>
<command
commandId="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.ConcretizeFunctionAllocation">
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.ConcretizeFunctionAllocation.expression">
</reference>
</visibleWhen>
</command>



Expand Down Expand Up @@ -703,6 +728,12 @@
id="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.PropagateExchangeItemAllocations"
name="%PropagateEIOnPorts">
</command>
<command
categoryId="org.polarsys.capella.core.accelerators"
defaultHandler="org.polarsys.capella.core.platform.sirius.ui.handlers.ConcretizeFunctionAllocationHandler"
id="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.ConcretizeFunctionAllocation"
name="Concretize Function Allocation">
</command>

<command
categoryId="org.polarsys.capella.core.accelerators"
Expand Down Expand Up @@ -766,6 +797,10 @@
commandId="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.SynchronizeExchangeItemAllocations"
icon="platform:/plugin/org.polarsys.capella.core.ui.resources/icons/full/obj16/capella_process.gif">
</image>
<image
commandId="org.polarsys.capella.core.platform.sirius.ui.actions.accelerator.ConcretizeFunctionAllocation"
icon="platform:/plugin/org.polarsys.capella.core.ui.resources/icons/full/obj16/capella_process.gif">
</image>

<image
commandId="org.polarsys.capella.core.platform.sirius.ui.actions.wizard.AllocationManagementWizardAction"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* 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.actions;

import org.eclipse.core.runtime.IProgressMonitor;
import org.polarsys.capella.common.ef.command.ICommand;
import org.polarsys.capella.core.platform.sirius.ui.commands.ConcretizeFunctionAllocationCommand;

/**
* Action for the ConcretizeFunctionAllocation accelerator
*
* @author ebausson
*/
public class ConcretizeFunctionAllocationAction extends AbstractFixAction {

@Override
protected ICommand createCommand(IProgressMonitor progressMonitor) {
return new ConcretizeFunctionAllocationCommand(getSelectedElements());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*******************************************************************************
* 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.commands;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.emf.common.util.EList;
import org.polarsys.capella.common.data.modellingcore.ModelElement;
import org.polarsys.capella.core.data.cs.Component;
import org.polarsys.capella.core.data.ctx.SystemFunction;
import org.polarsys.capella.core.data.fa.AbstractFunction;
import org.polarsys.capella.core.data.fa.AbstractFunctionalBlock;
import org.polarsys.capella.core.data.fa.ComponentFunctionalAllocation;
import org.polarsys.capella.core.data.fa.FaFactory;
import org.polarsys.capella.core.data.helpers.fa.services.FunctionExt;
import org.polarsys.capella.core.data.la.LogicalFunction;
import org.polarsys.capella.core.data.pa.PhysicalFunction;
import org.polarsys.capella.core.model.helpers.AbstractFunctionExt;

/**
* Command for the ConcretizeFunctionAllocation accelerator
*
* @author ebausson
*/
public class ConcretizeFunctionAllocationCommand extends AbstractFixCommand {

public ConcretizeFunctionAllocationCommand(Collection<ModelElement> 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) {
createAllocation(component, motherFunction);
}
}
}

private Component resolveMotherFunctionAllocation(AbstractFunction motherFunction) {
List<Component> motherFunctionAllocation = new ArrayList<Component>();
// 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<AbstractFunctionalBlock> 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 createAllocation(Component component, AbstractFunction function) {
ComponentFunctionalAllocation allocation = FaFactory.eINSTANCE.createComponentFunctionalAllocation();
if (component != null) {
allocation.setSourceElement(component);
allocation.setTargetElement(function);
component.getOwnedFunctionalAllocation().add(allocation);
}
}

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

}
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 @@ -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;

/**
Expand All @@ -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$
Expand All @@ -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);
}
Expand Down Expand Up @@ -136,6 +147,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<AbstractFunctionalBlock> blockAllocations = motherFunction.getAllocationBlocks();
if ((null == blockAllocations) || blockAllocations.isEmpty()) {
return AbstractFunctionExt.getMotherFunctionAllocation(motherFunction).size() == 1;
}
}
}
return false;
}

/**
* @param element_p
* @return
Expand Down
Loading