Commit 492952b7 authored by Marco Volpe's avatar Marco Volpe
Browse files

Addressed comments from review

* Fixed the naming for (de)coupling
* Naming is now updated when clicking
* Code style suggestions implemented

Issue-Ref: 3812
Issue-Url: https://af3-developer.fortiss.org/issues/3812

Signed-off-by: Marco Volpe's avatarMarco Volpe <volpe@fortiss.org>
parent bc58ca0b
......@@ -51,7 +51,7 @@ public class UtilizationPatternGUI extends Composite {
super(parent, style);
setLayout(new GridLayout(1, false));
header = new ConstraintPatternHeader(this, SWT.NONE);
header = new ConstraintPatternHeader(this, SWT.NONE, "UtilizationPattern");
header.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
header.setLayout(new GridLayout(2, false));
......
AllocationPatternCompositeBackend.java 056291311769496a5fa837f98f2dd26207432dfd RED
ConstraintPatternHeader.java f8a7e3b20d5b2dc3b34df1ac27be3f58e727e432 RED
AllocationPatternCompositeBackend.java e5ff1026f9d8f6116d638842d2a92bfb08555e32 YELLOW
ConstraintPatternHeader.java 2dd3ee55a70f6fbddd61c98904f679bf812a6283 YELLOW
ConstraintViewBackend.java 4099a405a81ccdf05e3f517d6b1de3f2f2b2d926 GREEN
FunctionCouplingCompositeBackend.java 16e20af26af36026ae2f1404b755f456b92760bf RED
FunctionCouplingCompositeBackend.java 5ac225275ab1ccc964d07b38bbee7463cecb124c YELLOW
MemoryPatternBackend.java c452fa46dce1d8646a60ba48ee7bcdd2b39debd7 GREEN
SafetyPatternBackend.java bfb2d61e387f33cdff9270978253868d50308b43 GREEN
......@@ -19,6 +19,7 @@ import static org.fortiss.af3.exploration.smt.util.Z3ModelElementFactory.createS
import static org.fortiss.af3.exploration.ui.perspective.service.IEventListener.DSE_EVENT.DSE_REMOVED_EVENT;
import static org.fortiss.af3.exploration.ui.perspective.service.IEventListener.DSE_EVENT.DSE_SELECTED_EVENT;
import static org.fortiss.af3.exploration.util.PatternFactoryUtils.calcPatternName;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import java.util.List;
......@@ -53,17 +54,9 @@ public class AllocationPatternCompositeBackend extends AllocationPatternComposit
implements IEventListener {
/** The left list of element(s). allocation source. */
// TODO (SB): List<Task>
private List<IModelElement> taskList;
// TODO (SB): List<ExecutionUnit>
private List<Task> taskList;
/** The right list of element(s). allocation destination. */
private List<IModelElement> ecuList;
// TODO (SB): private static final (or inline since it is used only once)
/** Separation marker for allocation targets. */
final String SEPARATION_STRING_LEFT = "; ";
// TODO (SB): private static final (or inline since it is used only once)
/** Separation marker for allocation targets. */
final String SEPARATION_STRING_RIGHT = " | ";
private List<ExecutionUnit> ecuList;
/** Constructor. */
public AllocationPatternCompositeBackend(Composite parent, int style) {
......@@ -79,8 +72,8 @@ public class AllocationPatternCompositeBackend extends AllocationPatternComposit
leftTreeViewer.setLabelProvider(new ModelElementLabelProvider());
leftTreeViewer.addSelectionChangedListener(new TreeModelElementSelectionListener());
btnAllocation.addSelectionListener(new OperatorSelctionAdapter());
btnDislocation.addSelectionListener(new OperatorSelctionAdapter());
btnAllocation.addSelectionListener(new OperatorSelectionAdapter());
btnDislocation.addSelectionListener(new OperatorSelectionAdapter());
rightTreeViewer.setContentProvider(new SuperSetContentProvider());
rightTreeViewer.setLabelProvider(new ModelElementLabelProvider());
......@@ -123,18 +116,16 @@ public class AllocationPatternCompositeBackend extends AllocationPatternComposit
((IStructuredSelection)event.getSelection()).toList();
Object eventSource = event.getSource();
if(eventSource.equals(leftTreeViewer)) {
// TODO (SB: EcoreUtils.pickInstanceOf(Tasks.class, selectionList);
taskList = selectionList;
taskList = pickInstanceOf(Task.class, selectionList);
} else if(eventSource.equals(rightTreeViewer)) {
// TODO (SB: EcoreUtils.pickInstanceOf(Tasks.class, ...);
ecuList = selectionList;
ecuList = pickInstanceOf(ExecutionUnit.class, selectionList);
}
updateConstraint();
}
}
/** Selection adapter for operator radio buttons. */
private class OperatorSelctionAdapter extends SelectionAdapter {
private class OperatorSelectionAdapter extends SelectionAdapter {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
......@@ -147,7 +138,7 @@ public class AllocationPatternCompositeBackend extends AllocationPatternComposit
// Calculate the name.
String constraintText = "";
if(taskList != null) {
constraintText = calcPatternName(taskList, SEPARATION_STRING_LEFT);
constraintText = calcPatternName(taskList, "; ");
}
if(btnAllocation.getSelection()) {
constraintText += " -> ";
......@@ -155,7 +146,7 @@ public class AllocationPatternCompositeBackend extends AllocationPatternComposit
constraintText += " -/> ";
}
if(ecuList != null) {
constraintText += calcPatternName(ecuList, SEPARATION_STRING_RIGHT);
constraintText += calcPatternName(ecuList, " | ");
}
// Update the GUI elements displaying the name.
......@@ -182,7 +173,6 @@ public class AllocationPatternCompositeBackend extends AllocationPatternComposit
DSE dse = IDSEPerspectiveManager.INSTANCE.getCurrentlySelectedDSE();
boolean isAllocation = btnAllocation.getSelection();
// Cannot use static import due to function name clash
// TODO (SB): Use static import
IExpression allocationPattern = PatternFactoryUtils.createAllocationPatternExpression(dse,
isAllocation, taskList, ecuList);
SMTConstraint constraint =
......
......@@ -54,7 +54,7 @@ public class AllocationPatternCompositeGUI extends Composite {
composite.setLayout(new GridLayout(1, false));
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
header = new ConstraintPatternHeader(composite, SWT.NONE);
header = new ConstraintPatternHeader(composite, SWT.NONE, "task -> ecu");
header.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
header.setLayout(new GridLayout(2, false));
......
......@@ -54,7 +54,7 @@ public class ConstraintPatternHeader extends Composite implements IEventListener
private Label description;
/** Constructor. */
public ConstraintPatternHeader(Composite parent, int style) {
public ConstraintPatternHeader(Composite parent, int style, String name) {
super(parent, style);
setLayout(new GridLayout(2, false));
......@@ -68,7 +68,7 @@ public class ConstraintPatternHeader extends Composite implements IEventListener
txtName = new Text(this, SWT.BORDER);
txtName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
txtName.setSize(83, 19);
txtName.setText("Pattern");
txtName.setText(name);
Label lblCategory = new Label(this, SWT.NONE);
lblCategory.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1));
......
......@@ -22,9 +22,9 @@ import static org.fortiss.af3.exploration.ui.perspective.service.IEventListener.
import static org.fortiss.af3.exploration.util.PatternFactoryUtils.calcPatternName;
import static org.fortiss.af3.exploration.util.PatternFactoryUtils.createFunctionCouplingPattern;
import static org.fortiss.tooling.kernel.ui.util.SelectionUtils.checkAndPickFirst;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import static org.fortiss.tooling.kernel.utils.UniqueIDUtils.prepareUniqueID;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.viewers.ISelectionChangedListener;
......@@ -56,6 +56,10 @@ import org.fortiss.tooling.kernel.ui.presentation.ModelElementLabelProvider;
*/
public class FunctionCouplingCompositeBackend extends FunctionCouplingCompositeGUI
implements IEventListener {
/** The list of selected tasks. */
private List<Task> taskList;
/** Constructor. */
public FunctionCouplingCompositeBackend(Composite parent, int style) {
super(parent, style);
......@@ -72,12 +76,21 @@ public class FunctionCouplingCompositeBackend extends FunctionCouplingCompositeG
private void createControls() {
treeViewerSet1Selection.setContentProvider(new SuperSetContentProvider());
treeViewerSet1Selection.setLabelProvider(new ModelElementLabelProvider());
btnCoupling.addSelectionListener(new OperatorSelectionAdapter());
btnDecoupling.addSelectionListener(new OperatorSelectionAdapter());
treeViewerSet1Selection.addSelectionChangedListener(new ISelectionChangedListener() {
/** */
@SuppressWarnings("unchecked")
@Override
public void selectionChanged(SelectionChangedEvent event) {
Task task = checkAndPickFirst(event.getSelection(), Task.class);
btnAdd.setEnabled(task != null);
List<IModelElement> selectionList =
((IStructuredSelection)event.getSelection()).toList();
taskList = pickInstanceOf(Task.class, selectionList);
updateConstraint();
}
});
......@@ -107,9 +120,6 @@ public class FunctionCouplingCompositeBackend extends FunctionCouplingCompositeG
/** Current Error Message for Predicate Creation. */
private String errorMessage = "No Error";
// TODO (SB): Remove unused variable
/** Name of the selected Constraint. */
private String selectedConstName;
/** Returns the {@link ExecutionUnit}s referenced in the current {@link SuperSetMap}. */
private List<ExecutionUnit> getExecutionUnits() {
......@@ -128,23 +138,11 @@ public class FunctionCouplingCompositeBackend extends FunctionCouplingCompositeG
return;
}
String name;
if(btnCoupling.getSelection()) {
name = "Coupling";
} else {
name = "Decoupling";
}
// TODO (SB, Remove unneeded copying)
List<IModelElement> elementList = new ArrayList<IModelElement>();
elementList.addAll(selectedTasks);
name = name + calcPatternName(elementList, ",");
header.setConstraintName(name);
IDSEPerspectiveManager pm = IDSEPerspectiveManager.INSTANCE;
DSE dse = pm.getCurrentlySelectedDSE();
SMTConstraint constraint = createSMTConstraint();
constraint.setName(name);
constraint.setName(header.getConstraintName());
constraint.setExpression(
createFunctionCouplingPattern(dse, btnCoupling.getSelection(), selectedTasks));
constraint.setDimension(header.getCategoryName());
......@@ -178,6 +176,39 @@ public class FunctionCouplingCompositeBackend extends FunctionCouplingCompositeG
}
}
/** Selection adapter for operator radio buttons. */
private class OperatorSelectionAdapter extends SelectionAdapter {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
updateConstraint();
}
}
/** Update the constraint expression with the given elements. */
private void updateConstraint() {
if(taskList == null) {
return;
}
// Calculate the name
String name;
if(btnCoupling.getSelection()) {
name = "Coupling";
} else {
name = "Decoupling";
}
if(taskList.size() == 1) {
name = name + "{";
}
name = name + calcPatternName(taskList, ",");
if(taskList.size() == 1) {
name = name + "}";
}
// Update the GUI elements displaying the name.
header.setConstraintName(name);
btnAdd.setEnabled(taskList.size() > 1);
}
/** {@inheritDoc} */
@Override
public void propertyChanged(Object source, DSE_EVENT event) {
......
......@@ -46,7 +46,7 @@ public class FunctionCouplingCompositeGUI extends Composite {
super(parent, style);
setLayout(new GridLayout(1, false));
header = new ConstraintPatternHeader(this, SWT.NONE);
header = new ConstraintPatternHeader(this, SWT.NONE, "Coupling{}");
header.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
header.setLayout(new GridLayout(2, false));
......
......@@ -51,7 +51,7 @@ public class SafetyPatternCompositeGUI extends Composite {
super(parent, style);
setLayout(new GridLayout(1, false));
header = new ConstraintPatternHeader(this, SWT.NONE);
header = new ConstraintPatternHeader(this, SWT.NONE, "SafetyPattern");
header.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
header.setLayout(new GridLayout(2, false));
......
......@@ -47,7 +47,7 @@ public class BusBandwidthOptimzationPatternCompositeGUI extends Composite {
super(parent, style);
setLayout(new GridLayout(1, false));
header = new ConstraintPatternHeader(this, SWT.NONE);
header = new ConstraintPatternHeader(this, SWT.NONE, "BusBandwidthOptimizationPattern");
header.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
header.setLayout(new GridLayout(2, false));
......
......@@ -6,4 +6,4 @@ ExplorationModelElementFactory.java bb48b2d09b92efcb1b2d3e382555089bb7ed5db5 GRE
ExplorationReflectionUtils.java 62731e1cef32fe93f2c2017f93f5ba1f054d5197 GREEN
ExplorationUtils.java 3e317c851bd1a0b48fbec3fdbe039d8b66506c51 GREEN
ModelSnapshotExtractUtils.java dde8b42c5a7228478ffe8c67820bcac91e875562 GREEN
PatternFactoryUtils.java 056fe2cda7c0cf93a45a0122274b68d228192236 RED
PatternFactoryUtils.java cd8b667ac74161df9be367f23618567d15384a92 YELLOW
......@@ -38,10 +38,8 @@ import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createSum
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createUses;
import static org.fortiss.af3.exploration.util.DSMLModelElementFactory.createWeight;
import static org.fortiss.af3.platform.utils.RouteUtils.busUsesRoute;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
......@@ -347,19 +345,17 @@ public class PatternFactoryUtils {
* @param isAllocation
* {@code boolean} specifying whether to generate an allocation constraint
* ({@code true}) or a dislocation constraint ({@code false})
* @param taskSet
* {@link Collection} of {@link IModelElement}s containing the {@link Task}s to
* @param taskList
* {@link List} of {@link Task}s containing the {@link Task}s to
* allocate or dislocate
* @param ecuSet
* {@link Collection} of {@link IModelElement}s containing the {@link ExecutionUnit}s
* @param ecuList
* {@link List} of {@link ExecutionUnit}s containing the {@link ExecutionUnit}s
* the expression applies to
* @return {@link IExpression} allocating/dislocating {@link Task}s to/from
* {@link ExecutionUnit}s
*/
// TODO (SB): Change to Collection<Task> taskSet, Collection<ExecutionUnit>, remove unneeded
// copying below, and update documentation / parameter names
public static IExpression createAllocationPatternExpression(DSE dse, boolean isAllocation,
Collection<IModelElement> taskSet, Collection<IModelElement> ecuSet) {
List<Task> taskList, List<ExecutionUnit> ecuList) {
SuperSetMap dseSets = dse.getCurrentStep().getSuperSetMap();
ILocationExpression locationConstraint = null;
......@@ -369,17 +365,14 @@ public class PatternFactoryUtils {
locationConstraint = createDislocation(null, null);
}
List<Task> tasks = pickInstanceOf(Task.class, new ArrayList<IModelElement>(taskSet));
SuperSet<Task> tSet = dseSets.get(Task.class);
Set<IModelElement> leftSet =
createSet(tSet, tasks, "Tasks", Task.class).getCastedSet(IModelElement.class);
createSet(tSet, taskList, "Tasks", Task.class).getCastedSet(IModelElement.class);
locationConstraint.setLeft(createModelElementLiteral(leftSet));
List<ExecutionUnit> executionUnits =
pickInstanceOf(ExecutionUnit.class, new ArrayList<IModelElement>(ecuSet));
SuperSet<ExecutionUnit> exUSet = dseSets.get(ExecutionUnit.class);
Set<IModelElement> rightSet =
createSet(exUSet, executionUnits, "ExecutionUnits", ExecutionUnit.class)
createSet(exUSet, ecuList, "ExecutionUnits", ExecutionUnit.class)
.getCastedSet(IModelElement.class);
locationConstraint.setRight(createModelElementLiteral(rightSet));
......@@ -471,8 +464,8 @@ public class PatternFactoryUtils {
* "too long". The contained elements of sets can still be easily seen by setting
* "DSE_DEBUG_VERBOSE" to "true" in the environment variable section.
*/
// TODO (SB): Change to "List<? extends INamedElement> selectedElements" and remove cast
public static String calcPatternName(List<IModelElement> selectedElements, String separator) {
public static String calcPatternName(List<? extends INamedElement> selectedElements,
String separator) {
String constraintNamePart = " ";
if(selectedElements != null) {
// Denote Sets if needed.
......@@ -482,8 +475,8 @@ public class PatternFactoryUtils {
constraintNamePart = "{";
}
// Add the element names.
constraintNamePart += selectedElements.stream()
.map(e -> ((INamedElement)e).getName() + separator).collect(joining());
constraintNamePart +=
selectedElements.stream().map(e -> e.getName() + separator).collect(joining());
// Remove the tailing separator.
if(constraintNamePart.length() > separator.length()) {
constraintNamePart = constraintNamePart.substring(0,
......
Markdown is supported
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