Commit ff8b877c authored by Simon Barner's avatar Simon Barner
Browse files

- Proper removal of TaskWcetTables along with TaskArchitectures

- TaskArchitectureUtils.transformIntoTaskArchitecture(): Create fresh ComponentToTaskAllocationTable
- Add menu entry to trigger CA -> TA transformation
refs 3067
parent 9db414dc
......@@ -75,4 +75,7 @@
</modelElementHandler>
</extension>
<extension point="org.fortiss.tooling.kernel.ui.contextMenuContribution">
<contextMenuContribution contributor="org.fortiss.af3.task.ui.commands.TransformComponentToTaskArchitectureMenu"/>
</extension>
</plugin>
TransformComponentToTaskArchitectureMenu.java 2d38dd95bac222b48f5b00caf401a3069f53283c YELLOW
/*-------------------------------------------------------------------------+
| Copyright 2018 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.task.ui.commands;
import static java.util.Collections.emptyList;
import static org.eclipse.jface.dialogs.MessageDialog.openConfirm;
import static org.fortiss.af3.project.utils.ProjectUtils.getFileProject;
import static org.fortiss.af3.task.ui.AF3TaskUIActivator.getImageDescriptor;
import static org.fortiss.af3.task.util.TaskArchitectureUtils.transformIntoTaskArchitecture;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getFirstChildWithType;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.widgets.Display;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.af3.task.model.TaskArchitecture;
import org.fortiss.af3.task.model.allocation.ComponentToTaskAllocationTable;
import org.fortiss.tooling.base.ui.layout.auto.IAutoLayouter;
import org.fortiss.tooling.base.ui.layout.auto.KielerAutoLayouter;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IElementCompositorService;
import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor;
import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
/**
* Context menu entry to transform a {@link ComponentArchitecture} into a {@link TaskArchitecture}.
*
* @author barner
*/
public class TransformComponentToTaskArchitectureMenu implements IContextMenuContributor {
/** String appearing in the context menu. */
private static String MENU_NAME = "Generate Task Architecture";
/** Declares where is located the icon to use for the menu contribution */
private static String MENU_ICON = "icons/task_architecture.png";
/** Returns the icon that is visible in the context menu for this entry. */
protected ImageDescriptor getActionIcon() {
return getImageDescriptor(MENU_ICON);
}
/** {@link Action} to execute automatic layout. */
protected class LaunchTransformComponentToTaskArchitectureAction extends Action {
/** {@link ComponentArchitecture} selected by user */
private final ComponentArchitecture ca;
/** Constructor. */
public LaunchTransformComponentToTaskArchitectureAction(ComponentArchitecture ca) {
super(MENU_NAME, getActionIcon());
this.ca = ca;
}
/** {@inheritDoc} */
@Override
public void run() {
FileProject fileProject = getFileProject(ca);
ITopLevelElement topLevelElement =
IPersistencyService.getInstance().getTopLevelElementFor(fileProject);
topLevelElement.runAsCommand(() -> {
IElementCompositorService cs = IElementCompositorService.getInstance();
if(isDeleteExistingTaskArchitectures(fileProject)) {
List<ComponentToTaskAllocationTable> ca2tas =
new ArrayList<ComponentToTaskAllocationTable>(getChildrenWithType(
fileProject, ComponentToTaskAllocationTable.class));
for(ComponentToTaskAllocationTable ca2ta : ca2tas) {
cs.decompose(ca2ta.getTargetView());
cs.decompose(ca2ta);
}
}
TaskArchitecture ta = transformIntoTaskArchitecture(ca.getTopComponent());
IAutoLayouter al = new KielerAutoLayouter();
cs.compose(fileProject, ta, null);
al.performAutoLayout(ta);
});
}
/** Predicate whether to delete existing {@link TaskArchitecture}s. */
private boolean isDeleteExistingTaskArchitectures(FileProject fileProject) {
boolean deleteExisting = false;
ComponentToTaskAllocationTable ca2ta =
getFirstChildWithType(fileProject, ComponentToTaskAllocationTable.class);
if(ca2ta != null && ca2ta.getSourceView() == ca && ca2ta.getTargetView() != null) {
deleteExisting =
openConfirm(
Display.getCurrent().getActiveShell(),
"Replace Task Architecture(s)",
"One or more Task Architectures already exist for selected Component Architecture. Hit:\n - OK to delete them.\n - Cancel to keep them and create another Task Architecture.");
}
return deleteExisting;
}
}
/** {@inheritDoc} */
@Override
public List<IContributionItem> getContributedItems(EObject selection,
ContextMenuContextProvider contextProvider) {
if(!(selection instanceof ComponentArchitecture)) {
return emptyList();
}
ComponentArchitecture ca = (ComponentArchitecture)selection;
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems.add(new ActionContributionItem(
new LaunchTransformComponentToTaskArchitectureAction(ca)));
return contributionItems;
}
/** {@inheritDoc} */
@Override
public String getMenuSectionID() {
return null;
}
}
ComponentToTaskAllocationTableCollectionCompositor.java 19733b43e4684d81799557e5c70c9b708e94b554 YELLOW
TaskArchitectureFileProjectCompositor.java 18f5a3e06bc20432d6853461b614b769bf37028d YELLOW
TaskArchitectureFileProjectCompositor.java c70325e56c165199b676fb9cac84ed55f7a65b6c YELLOW
TaskCompositor.java fb72faa5a865ac643227419749d3fa88a9eaa39c YELLOW
TaskConnectionCompositor.java 13c8268671e24ed4ee192f537bffe5aa794503d3 YELLOW
TaskPortCompositor.java 5a56d2990ffddd5f80c00629e5f78d73c2aac7f2 YELLOW
TaskToExecutionUnitAllocationTableCollectionCompositor.java 2495dd4c9fe63c90aae254dccdc388cd0722be70 YELLOW
TaskToExecutionUnitAllocationTableCollectionCompositor.java 3d0a3f0c9ab00606444c4cecd4d75a8d1977f710 YELLOW
TaskWcetTableCompositor.java aa91d730714883a2f35beb80672141ec40a89593 YELLOW
......@@ -22,7 +22,9 @@ import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.project.compositor.FileProjectCompositor;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.af3.task.model.TaskArchitecture;
import org.fortiss.af3.task.model.allocation.TaskWcetTable;
import org.fortiss.tooling.kernel.extension.data.IElementCompositionContext;
import org.fortiss.tooling.kernel.service.IElementCompositorService;
/**
* {@link FileProject} compositor for {@link TaskArchitecture}.
......@@ -44,4 +46,15 @@ public class TaskArchitectureFileProjectCompositor extends FileProjectCompositor
return super.canCompose(container, contained, context) &&
getFirstChildWithType(container, ComponentArchitecture.class) != null;
}
/** {@inheritDoc} */
@Override
public boolean decompose(EObject contained) {
TaskWcetTable wcetTable = ((TaskArchitecture)contained).getWcetTable();
boolean rval = true;
if(wcetTable != null) {
rval = IElementCompositorService.getInstance().decompose(wcetTable);
}
return super.decompose(contained) && rval;
}
}
......@@ -47,8 +47,10 @@ public class TaskToExecutionUnitAllocationTableCollectionCompositor extends
AllocationTableCollection atc = (AllocationTableCollection)contained.eContainer();
final TaskWcetTable taskWcetTable =
pickFirstInstanceOf(TaskWcetTable.class, atc.getAllocationTables());
taskWcetTableRemovalStatus =
IElementCompositorService.getInstance().decompose(taskWcetTable);
if(taskWcetTable != null) {
taskWcetTableRemovalStatus =
IElementCompositorService.getInstance().decompose(taskWcetTable);
}
}
return taskWcetTableRemovalStatus && super.decomposeSpecific(contained);
......
TaskAllocationUtils.java da58103cbd66cc6d5c47837aa9df7ee6e5d8aac0 RED
TaskArchitectureUtils.java 664e491a33133a8a7d4e7bd53cb26fb786d88b87 YELLOW
TaskArchitectureUtils.java 1b60d40a3eae450f6e4fdbfb1cd17543f91923f2 YELLOW
TaskModelElementFactory.java 9630bfe039d21b3bdeb29c101d17d9a37876ebaf YELLOW
......@@ -15,10 +15,12 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.task.util;
import static org.fortiss.af3.allocation.utils.AllocationModelElementFactory.createAllocationTableCollection;
import static org.fortiss.af3.allocation.utils.AllocationUtils.addAllocationEntry;
import static org.fortiss.af3.allocation.utils.AllocationUtils.getOrCreateAllocationTable;
import static org.fortiss.af3.component.utils.ComponentArchitectureUtils.isAtomicComponent;
import static org.fortiss.af3.component.utils.ComponentUtils.getAllSubComponentsRecursively;
import static org.fortiss.af3.project.utils.ProjectUtils.getFileProject;
import static org.fortiss.af3.task.util.TaskModelElementFactory.createComponentToTaskAllocationTable;
import static org.fortiss.af3.task.util.TaskModelElementFactory.createSignal;
import static org.fortiss.af3.task.util.TaskModelElementFactory.createTask;
import static org.fortiss.af3.task.util.TaskModelElementFactory.createTaskArchitecture;
......@@ -41,6 +43,7 @@ import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.component.model.OutputPort;
import org.fortiss.af3.component.model.Port;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.af3.task.model.Signal;
import org.fortiss.af3.task.model.Task;
import org.fortiss.af3.task.model.TaskArchitecture;
......@@ -53,6 +56,7 @@ import org.fortiss.af3.task.model.allocation.ComponentToTaskAllocationTable;
import org.fortiss.af3.task.model.allocation.InputPortToTaskInputPortAllocationEntry;
import org.fortiss.af3.task.model.allocation.OutputPortToTaskOutputPortAllocationEntry;
import org.fortiss.af3.task.model.allocation.TaskToExecutionUnitAllocationTable;
import org.fortiss.tooling.kernel.service.IElementCompositorService;
/**
* Utility methods for handling {@link TaskArchitecture}s and its sub elements.
......@@ -119,11 +123,17 @@ public class TaskArchitectureUtils {
(getAllSubComponentsRecursively(topLevelComponent)).stream()
.filter(c -> isAtomicComponent(c)).collect(Collectors.toList());
ComponentArchitecture ca =
ComponentArchitecture componentArchitecture =
getParentElement(topLevelComponent, ComponentArchitecture.class, false);
FileProject fileProject = getFileProject(topLevelComponent);
AllocationTableCollection atc = createAllocationTableCollection("Allocations");
ComponentToTaskAllocationTable ca2ta =
getOrCreateAllocationTable(ComponentToTaskAllocationTable.class, ca, null, ca
.getTopComponent().getName() + LEFT_ARROW + taskArchitecture.getName());
createComponentToTaskAllocationTable(componentArchitecture.getTopComponent()
.getName() + LEFT_ARROW + taskArchitecture.getName());
ca2ta.setSourceView(componentArchitecture);
ca2ta.setTargetView(taskArchitecture);
atc.getContainedElements().add(ca2ta);
IElementCompositorService.getInstance().compose(fileProject, atc, null);
// Create Tasks (including ports)
for(Component comp : components) {
......@@ -182,11 +192,10 @@ public class TaskArchitectureUtils {
}
fixMissingIDs(taskArchitecture, topLevelComponent);
return taskArchitecture;
}
/** Determines the {@link Task} to which the given {@link Component} is allocated. . */
/** Determines the {@link Task} to which the given {@link Component} is allocated. */
private static Task getTask(ComponentToTaskAllocationTable ca2ta, Component component) {
EList<Task> tasks = ca2ta.getTasks(component);
if(tasks.size() != 1) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment