Commit 986271bb authored by Levi Lucio's avatar Levi Lucio

added code to handle grouping of constraints

refs 3039
parent 5c712150
...@@ -51,3 +51,4 @@ Bundle-ClassPath: ., ...@@ -51,3 +51,4 @@ Bundle-ClassPath: .,
lib/de.cau.cs.kieler.klay.force-0.4.0.201602160301.jar, lib/de.cau.cs.kieler.klay.force-0.4.0.201602160301.jar,
lib/de.cau.cs.kieler.klay.layered-0.13.0.201602160301.jar, lib/de.cau.cs.kieler.klay.layered-0.13.0.201602160301.jar,
lib/de.cau.cs.kieler.klay.tree-0.4.0.201602160301.jar lib/de.cau.cs.kieler.klay.tree-0.4.0.201602160301.jar
Import-Package: org.fortiss.af3.project.model.development
AdvancedTreeViewerEditorBase.java c1275888a1552dac396d3f2968faca0c33232847 GREEN AdvancedTreeViewerEditorBase.java c1275888a1552dac396d3f2968faca0c33232847 GREEN
AllocationDiagramEditorBase.java 54c21b4c04fdf7bb85cd1b687dcf4b70927f55d1 GREEN AllocationDiagramEditorBase.java 54c21b4c04fdf7bb85cd1b687dcf4b70927f55d1 GREEN
CommonDiagramEditorBase.java 2a380b7dbefef8fb1b50c53d4eb7089d9594e244 RED CommonDiagramEditorBase.java 2a380b7dbefef8fb1b50c53d4eb7089d9594e244 RED
ConstraintBasedProcessEditor.java fe439469c7209d1ff6a1f0b5d2cb8de1ed1719bc YELLOW ConstraintBasedProcessEditor.java a178fb8d2333b774fcc4db19370e3a5d03ee33f8 YELLOW
DiagramEditorBase.java ffd082dc0572cbde9db536320cd7ff2158bc330c GREEN DiagramEditorBase.java ffd082dc0572cbde9db536320cd7ff2158bc330c GREEN
DiagramKeyHandler.java 32d7e2713bb34afddf9a826c24663ca16af11c17 GREEN DiagramKeyHandler.java 32d7e2713bb34afddf9a826c24663ca16af11c17 GREEN
FormsEditorBase.java e547415effcbba764aebb9f40d827fd1644f803c GREEN FormsEditorBase.java e547415effcbba764aebb9f40d827fd1644f803c GREEN
......
...@@ -19,12 +19,14 @@ package org.fortiss.tooling.base.ui.editor; ...@@ -19,12 +19,14 @@ package org.fortiss.tooling.base.ui.editor;
import static org.eclipse.core.runtime.IStatus.ERROR; import static org.eclipse.core.runtime.IStatus.ERROR;
import static org.eclipse.jface.dialogs.ErrorDialog.openError; import static org.eclipse.jface.dialogs.ErrorDialog.openError;
import static org.eclipse.swt.widgets.Display.getCurrent;
import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.DEFAULT_CONFIGURATION_NAME; import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.DEFAULT_CONFIGURATION_NAME;
import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.getActiveConfigurationsTransitively; import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.getActiveConfigurationsTransitively;
import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.getActiveConstraintsTransitively; import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.getActiveConstraintsTransitively;
import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.retrieveDefaultConfig; import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.retrieveDefaultConfig;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -32,9 +34,11 @@ import java.util.stream.Collectors; ...@@ -32,9 +34,11 @@ import java.util.stream.Collectors;
import org.conqat.ide.commons.ui.jface.TreeContentProviderBase; import org.conqat.ide.commons.ui.jface.TreeContentProviderBase;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EContentAdapter; import org.eclipse.emf.ecore.util.EContentAdapter;
import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTreeViewer; import org.eclipse.jface.viewers.CheckboxTreeViewer;
...@@ -52,17 +56,19 @@ import org.eclipse.jface.viewers.TreeViewerColumn; ...@@ -52,17 +56,19 @@ import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator; import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.swt.widgets.TreeColumn;
import org.fortiss.af3.project.model.development.ConstraintBasedDevelopmentProcess;
import org.fortiss.tooling.base.model.element.ConstraintConfiguration; import org.fortiss.tooling.base.model.element.ConstraintConfiguration;
import org.fortiss.tooling.base.model.element.ElementFactory; import org.fortiss.tooling.base.model.element.ElementFactory;
import org.fortiss.tooling.base.model.element.IConstraintBasedProcess; import org.fortiss.tooling.base.model.element.IConstraintBasedProcess;
import org.fortiss.tooling.base.ui.ToolingBaseUIActivator; import org.fortiss.tooling.base.ui.ToolingBaseUIActivator;
import org.fortiss.tooling.base.ui.utils.ConstraintsBaseUIUtils; import org.fortiss.tooling.base.ui.utils.ConstraintsBaseUIUtils;
import org.fortiss.tooling.base.ui.utils.StatusUtils;
import org.fortiss.tooling.kernel.extension.IConstraint; import org.fortiss.tooling.kernel.extension.IConstraint;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement; import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceContainer; import org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceContainer;
...@@ -84,11 +90,16 @@ import org.fortiss.tooling.kernel.utils.EcoreUtils; ...@@ -84,11 +90,16 @@ import org.fortiss.tooling.kernel.utils.EcoreUtils;
* @author aravantinos * @author aravantinos
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating YELLOW Hash: 8584EC3808931699CDD5E434E160D2BF
*/ */
public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> extends public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> extends
EditorBase<CBP> implements ContextMenuContextProvider, ISelectionProvider { EditorBase<CBP> implements ContextMenuContextProvider, ISelectionProvider {
/** {@inheritDoc} */
@Override
public void addPartPropertyListener(IPropertyChangeListener listener) {
super.addPartPropertyListener(listener);
}
/** Model context of the edited project. */ /** Model context of the edited project. */
private ITopLevelElement top; private ITopLevelElement top;
...@@ -160,9 +171,8 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e ...@@ -160,9 +171,8 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e
MenuManager menuManager = IContextMenuService.getInstance().createDefaultContextMenu(this); MenuManager menuManager = IContextMenuService.getInstance().createDefaultContextMenu(this);
Menu menu = menuManager.createContextMenu(treeViewer.getTree()); Menu menu = menuManager.createContextMenu(treeViewer.getTree());
treeViewer.getTree().setMenu(menu); treeViewer.getTree().setMenu(menu);
createCurrentObjectivePart(parent);
refreshAdapter = new EContentAdapter() { refreshAdapter = new EContentAdapter() {
@Override @Override
public void notifyChanged(Notification notification) { public void notifyChanged(Notification notification) {
treeViewer.refresh(); treeViewer.refresh();
...@@ -180,6 +190,12 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e ...@@ -180,6 +190,12 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e
super.dispose(); super.dispose();
} }
/** Create current the controls "Current objective:". */
private void createCurrentObjectivePart(Composite parent) {
Composite currentObjComposite = new Composite(parent, SWT.None);
currentObjComposite.setLayout(new GridLayout(2, false));
}
/** Fake child used to add new elements. */ /** Fake child used to add new elements. */
private static class FakeChild { private static class FakeChild {
// Nothing to implement: just a marker class // Nothing to implement: just a marker class
...@@ -187,6 +203,7 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e ...@@ -187,6 +203,7 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e
/** Content provider for the configuration tree. */ /** Content provider for the configuration tree. */
private class ConfigTreeContentProvider extends TreeContentProviderBase { private class ConfigTreeContentProvider extends TreeContentProviderBase {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public Object[] getChildren(Object parentElement) { public Object[] getChildren(Object parentElement) {
...@@ -202,11 +219,7 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e ...@@ -202,11 +219,7 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e
IConstraintUIService.getInstance().getAllConstraints(); IConstraintUIService.getInstance().getAllConstraints();
availableCstrs.removeAll(IConstraintUIService.getInstance() availableCstrs.removeAll(IConstraintUIService.getInstance()
.getAlwaysActivatedConstraints()); .getAlwaysActivatedConstraints());
types.addAll(availableCstrs
.stream()
.map(c -> new ConstraintWithContextualConfiguration(c,
(ConstraintConfiguration)parentElement))
.collect(Collectors.toList()));
if(editedObject.getConfigurations().size() > 1) { if(editedObject.getConfigurations().size() > 1) {
List<ConfigurationRefWithContextualConfiguration> refs = List<ConfigurationRefWithContextualConfiguration> refs =
editedObject editedObject
...@@ -217,15 +230,60 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e ...@@ -217,15 +230,60 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e
.collect(Collectors.toList()); .collect(Collectors.toList());
types.add(refs); types.add(refs);
} }
Set<Class<? extends IConstraint>> availableConstraints =
IConstraintUIService.getInstance().getAllConstraints();
IConstraintUIService cuis = IConstraintUIService.getInstance();
// Collecting the groups and putting the constraints in the groups in the array list
List<String> groupName = new ArrayList<String>();
for(Class<? extends IConstraint> c : availableConstraints) {
String constGroupName = IConstraintService.getInstance().getGroupName(c);
if(!groupName.contains(constGroupName)) {
groupName.add(constGroupName);
types.add(constGroupName);
HashMap<String, String> constraintInfo = new HashMap<String, String>();
for(Class<? extends IConstraint> ctr : availableConstraints) {
String ctrGroupName =
IConstraintService.getInstance().getGroupName(ctr);
String desc = cuis.getDescription(ctr);
constraintMap.put(ctr.getName(), desc);
if(ctrGroupName.equalsIgnoreCase(constGroupName)) {
constraintInfo.put(ctr.getName(), cuis.getDescription(ctr));
}
}
groupNameAndConstraints.put(constGroupName, constraintInfo);
}
}
return types.toArray(); return types.toArray();
} else if(parentElement instanceof List<?>) { } else if(parentElement instanceof List<?>) {
return ((List<?>)parentElement).toArray(); return ((List<?>)parentElement).toArray();
} }
// Add the constraints to the tree based on the group name.
else if(parentElement instanceof String) {
// Loop over all the names of the groups
for(String constraintGroupName : groupNameAndConstraints.keySet()) {
if(parentElement.toString().equalsIgnoreCase(constraintGroupName.toString())) {
// Return complete keySet of the HashMap inside the value field of the
// HashMap groupNameAndConstraints<String, "HashMap<String",String>> that
// contains the names of the constraints that are grouped under a particular
// constraint group
return groupNameAndConstraints.get(constraintGroupName).keySet().toArray();
}
}
}
return new Object[0]; return new Object[0];
} }
} }
/** Text labels for the tree of configuratinos. */ /** This constraint map contains the name and the description of all of the constraints */
HashMap<String, String> constraintMap = new HashMap<String, String>();
/** This HashMap contains the groups and the the grouped constraints (as a HashMap) */
HashMap<String, HashMap<String, String>> groupNameAndConstraints =
new HashMap<String, HashMap<String, String>>();
/** Text labels for the tree of configurations. */
private String getLabelText(Object element) { private String getLabelText(Object element) {
if(element instanceof FakeChild) { if(element instanceof FakeChild) {
return "click to add a new configuration"; return "click to add a new configuration";
...@@ -238,6 +296,16 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e ...@@ -238,6 +296,16 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e
return ((ConfigurationRefWithContextualConfiguration)element).target.getName(); return ((ConfigurationRefWithContextualConfiguration)element).target.getName();
} else if(element instanceof List<?>) { } else if(element instanceof List<?>) {
return "Required configurations"; return "Required configurations";
} else if(element instanceof String) {
if(groupNameAndConstraints.containsKey(element)) {
for(String constraintGroupName : groupNameAndConstraints.keySet()) {
if(element.toString().equalsIgnoreCase(constraintGroupName.toString())) {
return constraintGroupName;
}
}
} else if(constraintMap.containsKey(element)) {
return constraintMap.get(element);
}
} }
return null; return null;
} }
...@@ -248,7 +316,9 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e ...@@ -248,7 +316,9 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public boolean isGrayed(Object element) { public boolean isGrayed(Object element) {
return !(element instanceof ConstraintWithContextualConfiguration || element instanceof ConfigurationRefWithContextualConfiguration); return !(element instanceof ConstraintWithContextualConfiguration ||
element instanceof ConfigurationRefWithContextualConfiguration || constraintMap
.containsKey(element));
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
...@@ -264,6 +334,8 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e ...@@ -264,6 +334,8 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e
ConfigurationRefWithContextualConfiguration configRef = ConfigurationRefWithContextualConfiguration configRef =
(ConfigurationRefWithContextualConfiguration)element; (ConfigurationRefWithContextualConfiguration)element;
return configRef.config.getIncludedConfigurations().contains(configRef.target); return configRef.config.getIncludedConfigurations().contains(configRef.target);
} else if(constraintMap.containsKey(element)) {
return editedObject.getCurrentObjective().getActiveConstraints().contains(element);
} }
return true; return true;
} }
...@@ -274,28 +346,34 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e ...@@ -274,28 +346,34 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void checkStateChanged(CheckStateChangedEvent event) { public void checkStateChanged(CheckStateChangedEvent event) {
// Get object element from the state changed
Object element = event.getElement(); Object element = event.getElement();
IConstraintService cs = IConstraintService.getInstance();
IConstraintUIService cuis = IConstraintUIService.getInstance();
ConstraintConfiguration currentObj = editedObject.getCurrentObjective();
if(element instanceof ConstraintWithContextualConfiguration) { if(element instanceof ConstraintWithContextualConfiguration) {
ConstraintWithContextualConfiguration cstrInContext = ConstraintWithContextualConfiguration cstrInContext =
(ConstraintWithContextualConfiguration)element; (ConstraintWithContextualConfiguration)element;
IConstraintService cs = IConstraintService.getInstance();
String name = cs.getName(cstrInContext.cstr); String name = cs.getName(cstrInContext.cstr);
top.runAsCommand(() -> { top.runAsCommand(new Runnable() {
IConstraintUIService cuis = IConstraintUIService.getInstance();
ConstraintConfiguration currentObj = editedObject.getCurrentObjective(); @Override
if(event.getChecked()) { public void run() {
cstrInContext.config.getActiveConstraints().add(name); if(event.getChecked()) {
List<ConstraintConfiguration> activeConfigs = cstrInContext.config.getActiveConstraints().add(name);
getActiveConfigurationsTransitively(currentObj, null); List<ConstraintConfiguration> activeConfigs =
if(activeConfigs.contains(cstrInContext.config)) { getActiveConfigurationsTransitively(currentObj, null);
cuis.activate(cstrInContext.cstr, cstrContainer); if(activeConfigs.contains(cstrInContext.config)) {
} cuis.activate(cstrInContext.cstr, cstrContainer);
} else { }
cstrInContext.config.getActiveConstraints().remove(name); } else {
List<Class<? extends IConstraint>> stillActiveCstrs = cstrInContext.config.getActiveConstraints().remove(name);
getActiveConstraintsTransitively(currentObj, cstrInContext.config); List<Class<? extends IConstraint>> stillActiveCstrs =
if(!stillActiveCstrs.contains(cstrInContext.cstr)) { getActiveConstraintsTransitively(currentObj,
cuis.deactivate(cstrInContext.cstr, cstrContainer); cstrInContext.config);
if(!stillActiveCstrs.contains(cstrInContext.cstr)) {
cuis.deactivate(cstrInContext.cstr, cstrContainer);
}
} }
} }
}); });
...@@ -314,16 +392,69 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e ...@@ -314,16 +392,69 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e
} }
}); });
} }
// Check if the constraint belongs to the constraints HashMap
else if(constraintMap.containsKey(element)) {
top.runAsCommand(new Runnable() {
@Override
public void run() {
// Get the constraintName as a full class path (e.g.,
// a.b.c.constraintName.Java)
String constraintName = element.toString();
if(event.getChecked()) {
// If the constraint is checked than add it to the active
// constraints list
editedObject.getCurrentObjective().getActiveConstraints()
.add(constraintName);
// Collect all the active constraints in the list of constraints
List<ConstraintConfiguration> activeConfigs =
getActiveConfigurationsTransitively(currentObj, null);
// If the selected constraint is in the active constraints list
EList<String> activeConstraints =
activeConfigs.get(0).getActiveConstraints();
if(activeConstraints.contains(cs.getConstraintByName(constraintName)
.getCanonicalName())) {
// Activate the constraint
cuis.activate(cs.getConstraintByName(constraintName), cstrContainer);
}
} else {
// If the constraint is unchecked from the tree remove the
// constraint from
// the active constraints list
editedObject.getCurrentObjective().getActiveConstraints()
.remove(constraintName);
List<ConstraintConfiguration> stillActiveConfigs =
getActiveConfigurationsTransitively(currentObj, null);
// If the constraint is still not active
EList<String> stillActiveConstraints =
stillActiveConfigs.get(0).getActiveConstraints();
if(!stillActiveConstraints.contains(cs.getConstraintByName(
constraintName).getCanonicalName())) {
Class<? extends IConstraint> constrainttoDeActivate =
cs.getConstraintByName(constraintName);
// Deactivate the constraint
cuis.deactivate(constrainttoDeActivate, cstrContainer);
}
}
}
});
}
} }
} }
/** Tree for configurations. */ /** Tree for configurations. */
private class ConfigTree extends CheckboxTreeViewer implements ISelectionChangedListener { private class ConfigTree extends CheckboxTreeViewer implements ISelectionChangedListener {
/** {@inheritDoc} */
@Override
public void addSelectionChangedListener(ISelectionChangedListener listener) {
super.addSelectionChangedListener(listener);
}
/** Constructor. */ /** Constructor. */
public ConfigTree(Composite parent) { public ConfigTree(Composite parent) {
super(parent); super(parent);
getTree().setLayoutData(new GridData(800, 300)); getTree().setLayoutData(new GridData(800, 600));
setContentProvider(new ConfigTreeContentProvider()); setContentProvider(new ConfigTreeContentProvider());
setCheckStateProvider(new ConfigTreeCheckStateProvider()); setCheckStateProvider(new ConfigTreeCheckStateProvider());
addCheckStateListener(new ConfigTreeCheckStateListener()); addCheckStateListener(new ConfigTreeCheckStateListener());
...@@ -343,8 +474,7 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e ...@@ -343,8 +474,7 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e
treeViewer = new ConfigTree(parent); treeViewer = new ConfigTree(parent);
TreeColumn column = new TreeColumn(treeViewer.getTree(), SWT.LEFT); TreeColumn column = new TreeColumn(treeViewer.getTree(), SWT.LEFT);
column.setText("Constraint configurations"); column.setText("Constraint configurations");
column.setWidth(800); column.setWidth(1300);
TreeViewerColumn onlyViewerColumn = new TreeViewerColumn(treeViewer, column); TreeViewerColumn onlyViewerColumn = new TreeViewerColumn(treeViewer, column);
onlyViewerColumn.setLabelProvider(new ColumnLabelProvider() { onlyViewerColumn.setLabelProvider(new ColumnLabelProvider() {
...@@ -353,9 +483,27 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e ...@@ -353,9 +483,27 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e
public String getText(Object element) { public String getText(Object element) {
return getLabelText(element); return getLabelText(element);
} }
@Override
public Color getForeground(Object element) {
return getConstraintForeGround(element, colorCtr);
}
@Override
public Color getBackground(Object element) {
// Collect all the active constraints from the currentObject (i.e., the current
// active configuration)
List<String> activeConstraints =
editedObject.getCurrentObjective().getActiveConstraints();
if(constraintMap.containsKey(element)) {
// Ask for the constraint color based on status
return getConstraintBackgroundColor(element, activeConstraints);
}
return null;
}
}); });
onlyViewerColumn.setEditingSupport(new EditingSupport(treeViewer) {
onlyViewerColumn.setEditingSupport(new EditingSupport(treeViewer) {
@Override @Override
protected void setValue(Object element, Object value) { protected void setValue(Object element, Object value) {
if(element instanceof FakeChild) { if(element instanceof FakeChild) {
...@@ -392,13 +540,74 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e ...@@ -392,13 +540,74 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e
@Override @Override
protected boolean canEdit(Object element) { protected boolean canEdit(Object element) {
return element instanceof ConstraintConfiguration || element instanceof FakeChild; return element instanceof ConstraintConfiguration || element instanceof FakeChild ||
constraintMap.containsKey(element);
} }
}); });
treeViewer.setComparator(new ConstraintComparator()); treeViewer.setComparator(new ConstraintComparator());
treeViewer.setInput(editedObject); treeViewer.setInput(editedObject);
} }
/**
* @param element
* is the selected constraint
* @param activeConstraints
* active constraints in the current objective
* @return return the color (i.e., red (Failed), green (Successful) or white(not active))
*/
public Color getConstraintBackgroundColor(Object element, List<String> activeConstraints) {
// Get the complete path of the constraint class (e.g., a.b.c.constraint.java)
String constraintToFind = element.toString();
// If the constraint is in the active constraint list and the status is true
// than make the background color green
if(activeConstraints.contains(constraintToFind) &&
StatusUtils.areAllInstancesSuccessful(constraintToFind,
(ConstraintBasedDevelopmentProcess)editedObject) == true) {
return getCurrent().getSystemColor(SWT.COLOR_GREEN);
}
// If the constraint doesn't belong to the active list of constrains than let
// the color remain white
else if(activeConstraints.contains(constraintToFind) == false) {
return getCurrent().getSystemColor(SWT.COLOR_WHITE);
}
// If the constraint is active and the status is false than make the background
// color red
if(activeConstraints.contains(constraintToFind) &&
StatusUtils.areAllInstancesSuccessful(constraintToFind,
(ConstraintBasedDevelopmentProcess)editedObject) == false) {
return getCurrent().getSystemColor(SWT.COLOR_RED);
}
return null;
}
/** Color Array for at least seven groups. */
int[] colorArray = {SWT.COLOR_DARK_GREEN, SWT.COLOR_DARK_BLUE, SWT.COLOR_DARK_YELLOW,
SWT.COLOR_BLACK, SWT.COLOR_DARK_RED, SWT.COLOR_GREEN, SWT.COLOR_CYAN};
/** Counter for the colorArray */
int colorCtr = 0;
/**
* @param element
* the groupName for which we need to set the background.
* @param colorIndex
* index used for the colors in the colorArray.
* @return color required for a particular group.
*/
public Color getConstraintForeGround(Object element, int colorIndex) {
if(groupNameAndConstraints.keySet().contains(element)) {
if(colorIndex != colorCtr + 1) {
if(groupNameAndConstraints.keySet().size() == colorCtr + 1) {
colorCtr = 0;
} else {
colorCtr++;
}
return getCurrent().getSystemColor(colorArray[colorIndex]);
}