forked from eclipse-capella/capella
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creation of an accelerator for concretization of computed function
allocation.
- Loading branch information
1 parent
3c32690
commit 0aa8934
Showing
5 changed files
with
225 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
.../polarsys/capella/core/platform/sirius/ui/actions/ConcretizeFunctionAllocationAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
86 changes: 86 additions & 0 deletions
86
...olarsys/capella/core/platform/sirius/ui/commands/ConcretizeFunctionAllocationCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
createAlloction(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 createAlloction(Component component, AbstractFunction function) { | ||
ComponentFunctionalAllocation allocation = FaFactory.eINSTANCE.createComponentFunctionalAllocation(); | ||
if (component != null) { | ||
allocation.setSourceElement(component); | ||
allocation.setTargetElement(function); | ||
component.getOwnedFunctionalAllocation().add(allocation); | ||
} | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...olarsys/capella/core/platform/sirius/ui/handlers/ConcretizeFunctionAllocationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters