Commit 5caa52d6 authored by Levi Lucio's avatar Levi Lucio
Browse files

simplified process to only present info regarding current objective

refs 3039
parent 2638a43c
......@@ -22,9 +22,7 @@ import static org.fortiss.tooling.base.ui.utils.ConstraintsBaseUIUtils.deactivat
import static org.fortiss.tooling.base.utils.ConstraintsBaseUtils.getActiveConfigurationsTransitively;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.eclipse.core.resources.IResourceChangeEvent;
......@@ -70,7 +68,7 @@ import org.fortiss.tooling.kernel.utils.EcoreUtils;
* @author levilucio
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: F62C7C916DC001C5CCC6AEA35A25690A
* @ConQAT.Rating YELLOW Hash: A962AD431C18BFEFE647AE506E70A18F
*/
class CurrentObjectiveContributionItem extends ContributionItem implements ISelectionListener,
IResourceChangeListener {
......@@ -90,12 +88,6 @@ class CurrentObjectiveContributionItem extends ContributionItem implements ISele
/** Configuration of the current project selected in the combo box. */
private ConstraintBasedDevelopmentProcess currentDevelopmentProcess = null;
/** The map to keep the constraint names and their corresponding values **/
private Map<String, ConstraintResultHolder> constraintsMap;
/** The map to keep the configuration names and their corresponding scores **/
private Map<String, ConstraintResultHolder> percentageMap;
/** The constant representing the fact that this does not has to be considered */
float NOT_TO_BE_CONSIDERED = -1f;
......@@ -122,12 +114,11 @@ class CurrentObjectiveContributionItem extends ContributionItem implements ISele
@Override
public void widgetSelected(SelectionEvent e) {
String textInCombo = getActualNameFromComboValue(((Combo)e.getSource()).getText());
String textInCombo = ((Combo)e.getSource()).getText();
if(!textInCombo.isEmpty()) {
updateObjectiveByName(getActualNameFromComboValue(((Combo)e.getSource())
.getText()));
updateObjectiveByName(textInCombo);
}
}
});
......@@ -216,12 +207,6 @@ class CurrentObjectiveContributionItem extends ContributionItem implements ISele
updateObjectiveByName(currentDevelopmentProcess.getCurrentObjective()
.getName());
// if(successPercentage >= 0f) {
// currentObjectiveCombo.setToolTipText(new DecimalFormat("##")
// .format(successPercentage * 100) +
// "% of the constraints are satisfied");
// }
}
}
}
......@@ -263,28 +248,28 @@ class CurrentObjectiveContributionItem extends ContributionItem implements ISele
* in the tool tip and set the background color of the current objective accordingly.
*
* @param process
* @return returns the float score
*/
private float generateScoresAndUpdateUI(ConstraintBasedDevelopmentProcess process) {
private void generateScoresAndUpdateUI(ConstraintBasedDevelopmentProcess process) {
float successPercentage = -1f;
generateConstraintsResultMap(process);
generateScoresForConfig(process);
if(percentageMap.get(process.getCurrentObjective().getName()) != null) {
successPercentage =
percentageMap.get(process.getCurrentObjective().getName()).successCount /
percentageMap.get(process.getCurrentObjective().getName()).totalCount;
if(successPercentage <= .5) {
ConstraintResultHolder resultHolder = generateScoresForConfig(process);
if(resultHolder.totalCount == 0) {
currentObjectiveCombo.setBackground(null);
currentObjectiveCombo.setToolTipText(new DecimalFormat("##").format(0 * 100) +
"% of the constraints are satisfied");
} else {
successPercentage = resultHolder.successCount / resultHolder.totalCount;
if(successPercentage <= .5 && successPercentage >= 0) {
currentObjectiveCombo.setBackground(SWTResourceManager.getColor(new RGB(0,
(float).7 - (successPercentage) / 2, 1)));
} else {
}
if(successPercentage >= .5) {
currentObjectiveCombo.setBackground(SWTResourceManager.getColor(new RGB(130,
(successPercentage) - (float).3, 1)));
}
currentObjectiveCombo.setToolTipText(new DecimalFormat("##")
.format(successPercentage * 100) + "% of the constraints are satisfied");
}
return successPercentage;
}
/**
......@@ -318,7 +303,7 @@ class CurrentObjectiveContributionItem extends ContributionItem implements ISele
currentObjectiveCombo
.setText(currentDevelopmentProcess.getCurrentObjective().getName());
float successPercentage = generateScoresAndUpdateUI(currentDevelopmentProcess);
generateScoresAndUpdateUI(currentDevelopmentProcess);
List<String> configNames =
currentDevelopmentProcess.getConfigurations().stream().map(c -> c.getName())
.collect(Collectors.toList());
......@@ -331,44 +316,11 @@ class CurrentObjectiveContributionItem extends ContributionItem implements ISele
for(String comboString : configNamesArray) {
currentObjectiveCombo.add(comboString);
}
currentObjectiveCombo.redraw();
currentObjectiveCombo.update();
currentObjectiveCombo
.setText(currentDevelopmentProcess.getCurrentObjective().getName());
currentObjectiveCombo.setToolTipText(new DecimalFormat("##")
.format(successPercentage * 100) + "% of the constraints are satisfied");
}
}
/**
* Bootstrap for generating information about all constraints that are referenced by the current
* configuration or any of its dependencies.
*
* @param process
*/
private void generateConstraintsResultMap(ConstraintBasedDevelopmentProcess process) {
if(constraintsMap == null) {
constraintsMap = new HashMap<String, ConstraintResultHolder>();
} else
constraintsMap.clear();
EList<String> activeConstraints =
currentDevelopmentProcess.getCurrentObjective().getActiveConstraints();
for(String activeConstraintName : activeConstraints) {
ConstraintResultHolder constraintValueByName =
getConstraintValueObjectByName(activeConstraintName);
if(!constraintsMap.containsKey(activeConstraintName)) {
constraintsMap.put(activeConstraintName, constraintValueByName);
}
}
resetCurrentObjectiveAsActiveConfiguration(currentDevelopmentProcess.getCurrentObjective());
}
/**
* generates an object containing how many instances of a given constraints are satisfied and
* how many constraints in
......@@ -397,18 +349,14 @@ class CurrentObjectiveContributionItem extends ContributionItem implements ISele
}
/**
* Generates scores for all configurations and their dependencies and stores the results in map.
* Generates scores for configuration
*
* @param process
* the root process
* @return The class containing the total and satisfied constraint count
*/
private void generateScoresForConfig(ConstraintBasedDevelopmentProcess process) {
if(percentageMap == null) {
percentageMap = new HashMap<String, ConstraintResultHolder>();
} else {
percentageMap.clear();
}
private ConstraintResultHolder
generateScoresForConfig(ConstraintBasedDevelopmentProcess process) {
float totalConstraintCount = 0;
float satisfiedConstraintCount = 0;
......@@ -418,38 +366,12 @@ class CurrentObjectiveContributionItem extends ContributionItem implements ISele
for(String activeConstraintName : activeConstraints) {
ConstraintResultHolder constraintResultHolder =
constraintsMap.get(activeConstraintName);
satisfiedConstraintCount += constraintResultHolder.successCount;
totalConstraintCount += constraintResultHolder.totalCount;
}
if(totalConstraintCount > 0) {
percentageMap.put(currentDevelopmentProcess.getCurrentObjective().getName(),
new ConstraintResultHolder(satisfiedConstraintCount, totalConstraintCount));
ConstraintResultHolder constraintValueObjectByName =
getConstraintValueObjectByName(activeConstraintName);
satisfiedConstraintCount += constraintValueObjectByName.successCount;
totalConstraintCount += constraintValueObjectByName.totalCount;
}
}
/**
* Deactivates current configuration and sets the current objective as active.
*
* @param configuration
* the configuration to be deactivated
*/
private void resetCurrentObjectiveAsActiveConfiguration(ConstraintConfiguration configuration) {
ITopLevelElement modelContext =
IPersistencyService.getInstance().getTopLevelElementFor(currentDevelopmentProcess);
// deactivating and activating cycle for next part
modelContext.runAsNonDirtyingCommand(() -> {
// deactivate configuration to be checked
deactivateConfiguration(configuration,
currentDevelopmentProcess.getConstraintInstanceContainer());
// reactivate current configuration
activateConfiguration(currentDevelopmentProcess.getCurrentObjective(),
currentDevelopmentProcess.getConstraintInstanceContainer());
});
return new ConstraintResultHolder(satisfiedConstraintCount, totalConstraintCount);
}
/** {@inheritDoc} */
......@@ -458,22 +380,10 @@ class CurrentObjectiveContributionItem extends ContributionItem implements ISele
if(event.getType() == IResourceChangeEvent.POST_CHANGE && currentDevelopmentProcess != null) {
float successPercentage = generateScoresAndUpdateUI(currentDevelopmentProcess);
generateScoresAndUpdateUI(currentDevelopmentProcess);
List<String> configNames =
currentDevelopmentProcess.getConfigurations().stream().map(c -> c.getName())
.collect(Collectors.toList());
configNames
.forEach(item -> {
if(percentageMap.get(item) != null) {
String percentagevalue =
new DecimalFormat("##").format(percentageMap.get(item).successCount /
percentageMap.get(item).totalCount * 100);
configNames.set(configNames.indexOf(item), item + " (" +
percentagevalue + "%)");
} else
configNames.set(configNames.indexOf(item), item + " (N/A)");
});
String[] configNamesArray = new String[configNames.size()];
configNames.toArray(configNamesArray);
......@@ -482,34 +392,8 @@ class CurrentObjectiveContributionItem extends ContributionItem implements ISele
for(String comboString : configNamesArray) {
currentObjectiveCombo.add(comboString);
}
currentObjectiveCombo.redraw();
currentObjectiveCombo.update();
currentObjectiveCombo
.setText(currentDevelopmentProcess.getCurrentObjective().getName());
currentObjectiveCombo.setToolTipText(new DecimalFormat("##")
.format(successPercentage * 100) + "% of the constraints are satisfied");
}
}
/**
* Helper function for getting the name of the objective given the combo box name.
*
* @param comboBoxName
* the input name containing percentage value
* @return parsed string with the objective name
*/
public String getActualNameFromComboValue(String comboBoxName) {
EList<ConstraintConfiguration> configurationNames =
currentDevelopmentProcess.getConfigurations();
for(ConstraintConfiguration configuration : configurationNames) {
if(comboBoxName.contains(configuration.getName())) {
return configuration.getName();
}
}
return " ";
}
}
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