HEAD - Some fixes and changes after all scenarios verif for 3.6M6
diff --git a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/db/ConfigResults.java b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/db/ConfigResults.java
index 7dbc07c..71a91a2 100644
--- a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/db/ConfigResults.java
+++ b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/db/ConfigResults.java
@@ -470,6 +470,7 @@
 	// Set baseline and current builds
 	BuildResults lastBaseline = null;
 	int size = size();
+	if (size == 0) return;
 	for (int i=0; i<size; i++) {
 		BuildResults buildResults = (BuildResults) this.children.get(i);
 		if (buildResults.values != null) {
diff --git a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/db/PerformanceResults.java b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/db/PerformanceResults.java
index d7cc894..39c2f75 100644
--- a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/db/PerformanceResults.java
+++ b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/db/PerformanceResults.java
@@ -494,29 +494,13 @@
 
 	// Look for missing builds
 	if (buildMissing) {
-		if (buildName == null) {
-			// Read all missing builds
-			String[] builds = DB_Results.getBuilds();
-			Arrays.sort(builds, Util.BUILD_DATE_COMPARATOR);
-			int lengthDB = builds.length;
-			int lengthLocal = names.length;
-			if (lengthLocal < lengthDB) {
-				int length= lengthDB-lengthLocal;
-				String[] addedBuilds = new String[length];
-				int idx = length-1;
-				int idxDB = lengthDB-1;
-				while (!this.allBuildNames[lengthLocal-1].equals(builds[idxDB])) {
-					addedBuilds[idx] = builds[idxDB];
-					idxDB--;
-					idx--;
-				}
-				for (int i=idx+1; i<length; i++) {
-					read(false, addedBuilds[i], configs, true, dataDir, null, subMonitor.newChild(900));
-				}
+		String[] builds = DB_Results.getBuilds();
+		Arrays.sort(builds, Util.BUILD_DATE_COMPARATOR);
+		for (int i=builds.length-1; i>=0; i--) {
+			if (Arrays.binarySearch(names, builds[i], Util.BUILD_DATE_COMPARATOR) >= 0) {
+				break;
 			}
-		} else {
-			// Read the missing build
-			read(false, buildName, configs, true, dataDir, null, subMonitor.newChild(900));
+			read(false, builds[i], configs, true, dataDir, null, subMonitor.newChild(900));
 		}
 	}
 	return this.allBuildNames;
diff --git a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/model/ConfigResultsElement.java b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/model/ConfigResultsElement.java
index c1ba531..1b090f9 100644
--- a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/model/ConfigResultsElement.java
+++ b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/model/ConfigResultsElement.java
@@ -451,13 +451,15 @@
 
 			// Statistics
 			if ((this.status & NOT_RELIABLE) != 0) {
-				if ((kind & IPerformancesConstants.STATUS_STATISTICS_ERRATIC) != 0) {
-					// Skip result
-					if (excluded != null) {
-						excluded.append(configResults+" excluded from status due to erratic statistics!");
-						excluded.append(Util.LINE_SEPARATOR);
-					}
-					return buffer;
+				switch (kind & IPerformancesConstants.STATUS_STATISTICS_MASK) {
+					case IPerformancesConstants.STATUS_STATISTICS_UNSTABLE:
+					case IPerformancesConstants.STATUS_STATISTICS_ERRATIC:
+						// Skip result
+						if (excluded != null) {
+							excluded.append(configResults+" excluded from status due to erratic statistics!");
+							excluded.append(Util.LINE_SEPARATOR);
+						}
+						return buffer;
 				}
 				localBuffer.append(separator);
 				localBuffer.append("erratic");
diff --git a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/ui/BuildsView.java b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/ui/BuildsView.java
index 207bcf6..3dabb41 100644
--- a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/ui/BuildsView.java
+++ b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/ui/BuildsView.java
@@ -620,7 +620,7 @@
 	this.updateAllBuilds.setText("&Update from DB");
 
 	// Update generate action
-	boolean enableGenerate = !force;
+	boolean enableGenerate = true;
 	if (enableGenerate) {
 		for (int i=0; i<length; i++) {
 			if (this.buildsResults[i].getName().startsWith(DB_Results.getDbBaselinePrefix())) {
diff --git a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/ui/PerformanceResultsPreferencePage.java b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/ui/PerformanceResultsPreferencePage.java
index 53d9f12..d5c4b6b 100644
--- a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/ui/PerformanceResultsPreferencePage.java
+++ b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/ui/PerformanceResultsPreferencePage.java
@@ -519,7 +519,7 @@
 		this.dbRelengRadioButton.setSelection(true);
 	}
 	this.databaseLocationCombo.removeAll();
-	this.databaseLocationCombo.setText(store.getString(PRE_DATABASE_LOCATION));
+	this.databaseLocationCombo.setText(store.getDefaultString(PRE_DATABASE_LOCATION));
 	updateDatabaseGroup();
 
 	// Init default status values
@@ -544,7 +544,7 @@
 	int index = 0;
 	while (milestone != null && milestone.length() > 0) {
 		this.milestonesCombo.add(milestone);
-		milestone = store.getDefaultString(prefix + index);
+		milestone = store.getDefaultString(prefix + ++index);
 	}
 
 	// Init last build
@@ -611,8 +611,7 @@
 	String milestone = store.getString(prefix + index);
 	while (milestone != null && milestone.length() > 0) {
 		this.milestonesCombo.add(milestone);
-		index++;
-		milestone = store.getString(prefix + index);
+		milestone = store.getString(prefix + ++index);
 	}
 
 	// Init last build
@@ -667,6 +666,11 @@
  */
 private void initStatusValues(int writeStatus) {
 	this.statusValuesCheckBox.setSelection((writeStatus & STATUS_VALUES) != 0);
+	this.statusErrorNoneRadioButton.setSelection(false);
+	this.statusErrorNoticeableRadioButton.setSelection(false);
+	this.statusErrorSuspiciousRadioButton.setSelection(false);
+	this.statusErrorWeirdRadioButton.setSelection(false);
+	this.statusErrorInvalidRadioButton.setSelection(false);
 	switch (writeStatus & STATUS_ERROR_LEVEL_MASK) {
 		case STATUS_ERROR_NONE:
 			this.statusErrorNoneRadioButton.setSelection(true);
@@ -684,6 +688,8 @@
 			this.statusErrorInvalidRadioButton.setSelection(true);
 			break;
 	}
+	this.statusSmallBuildValueCheckBox.setSelection(false);
+	this.statusSmallDeltaValueCheckBox.setSelection(false);
 	switch (writeStatus & STATUS_SMALL_VALUE_MASK) {
 		case STATUS_SMALL_VALUE_BUILD:
 			this.statusSmallBuildValueCheckBox.setSelection(true);
@@ -692,6 +698,9 @@
 			this.statusSmallDeltaValueCheckBox.setSelection(true);
 			break;
 	}
+	this.statusStatisticNoneRadioButton.setSelection(false);
+	this.statusStatisticErraticRadioButton.setSelection(false);
+	this.statusStatisticUnstableRadioButton.setSelection(false);
 	switch (writeStatus & STATUS_STATISTICS_MASK) {
 		case 0:
 			this.statusStatisticNoneRadioButton.setSelection(true);
@@ -733,9 +742,32 @@
 		// Verify the only digits are entered
 		String milestoneDate = this.milestonesCombo.getText();
 		final int mLength = milestoneDate.length();
-		if (mLength > 0 && !Character.isDigit(milestoneDate.charAt(mLength-1))) {
-			openMilestoneErrorMessage(milestoneDate);
-			return;
+		if (mLength > 0) {
+			for (int i=0; i<mLength; i++) {
+				if (!Character.isDigit(milestoneDate.charAt(i))) {
+					String[] items = this.milestonesCombo.getItems();
+					int length = items.length;
+					for (int j=0; j<length; j++) {
+						if (items[j].equals(milestoneDate)) {
+							// already existing milestone, leave silently
+							if (MessageDialog.openQuestion(getShell(), getDialogTitle(), "Do you want to select milestone "+milestoneDate+" as the last build?")) {
+								String builds[] = this.lastBuildCombo.getItems();
+								int bLength = builds.length;
+								String milestone = milestoneDate.substring(milestoneDate.indexOf('-')+1);
+								for (int b=0; b<bLength; b++) {
+									if (builds[b].length() > 0 && Util.getBuildDate(builds[b]).equals(milestone)) {
+										this.lastBuildCombo.select(b);
+										break;
+									}
+								}
+							}
+							return;
+						}
+					}
+					openMilestoneErrorMessage(milestoneDate);
+					return;
+				}
+			}
 		}
 
 		// Do not verify further until a complete milestone date is entered
@@ -855,7 +887,6 @@
 		catch (NumberFormatException nfe) {
 			this.statusBuildsToConfirm.setText("1");
 		}
-
 	}
 }
 
@@ -974,12 +1005,20 @@
 	store.setValue(PRE_WRITE_STATUS, writeStatus);
 
 	// Set milestones
+	String prefix = PRE_MILESTONE_BUILDS + "." + version;
 	count  = this.milestonesCombo.getItemCount();
 	for (i=0; i<count; i++) {
-		store.putValue(PRE_MILESTONE_BUILDS + "." + version + i, this.milestonesCombo.getItem(i));
+		store.putValue(prefix + i, this.milestonesCombo.getItem(i));
 	}
 	Util.setMilestones(this.milestonesCombo.getItems());
 
+	// Unset previous additional milestones
+	String milestone = store.getString(prefix + count);
+	while (milestone != null && milestone.length() > 0) {
+		store.putValue(prefix + count++, "");
+		milestone = store.getString(prefix + count);
+	}
+
 	// Set last build
 	String lastBuild = this.lastBuildCombo.getText();
 	store.putValue(PRE_LAST_BUILD, lastBuild);
diff --git a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/utils/IPerformancesConstants.java b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/utils/IPerformancesConstants.java
index 31f5a69..7c15295 100644
--- a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/utils/IPerformancesConstants.java
+++ b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/utils/IPerformancesConstants.java
@@ -60,7 +60,7 @@
 	// Status
     public static final String PRE_WRITE_STATUS = PREFIX + "write.status"; //$NON-NLS-1$
 	public static final int STATUS_BUILDS_NUMBER_MASK= 0x00FF;
-	public static final int DEFAULT_BUILDS_NUMBER = 1;
+	public static final int DEFAULT_BUILDS_NUMBER = 3;
 	public static final int STATUS_VALUES = 0x0100;
 	public static final int STATUS_ERROR_NONE = 0x0200;
 	public static final int STATUS_ERROR_NOTICEABLE = 0x0400;
diff --git a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/utils/Util.java b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/utils/Util.java
index 912b68c..5199381 100644
--- a/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/utils/Util.java
+++ b/bundles/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/utils/Util.java
@@ -270,18 +270,40 @@
 }
 
 /**
- * Returns the name the milestone matching the given date.
+ * Returns the milestone matching the given build name.
+ *
+ * @param buildName The name of the build
+ * @return The milestone as a string (e.g. M1)
+ */
+public static String getMilestone(String buildName) {
+	if (buildName != null && buildName.length() >= 12) {
+		int length = getMilestonesLength();
+		String buildDate = getBuildDate(buildName, DB_Results.getDbBaselinePrefix());
+		for (int i=0; i<length; i++) {
+			int start = MILESTONES[i].indexOf(buildDate);
+			if (start > 0) {
+				return MILESTONES[i];
+			}
+		}
+	}
+	return null;
+}
+
+/**
+ * Returns the name the milestone matching the given build name.
  *
  * @param buildName The name of the build
  * @return The milestone name as a string (e.g. M1)
  */
 public static String getMilestoneName(String buildName) {
-	int length = getMilestonesLength();
-	String buildDate = getBuildDate(buildName, DB_Results.getDbBaselinePrefix());
-	for (int i=0; i<length; i++) {
-		int start = MILESTONES[i].indexOf(buildDate);
-		if (start > 0) {
-			return MILESTONES[i].substring(0, start - 1);
+	if (buildName != null && buildName.length() >= 12) {
+		int length = getMilestonesLength();
+		String buildDate = getBuildDate(buildName, DB_Results.getDbBaselinePrefix());
+		for (int i=0; i<length; i++) {
+			int start = MILESTONES[i].indexOf(buildDate);
+			if (start > 0) {
+				return MILESTONES[i].substring(0, start - 1);
+			}
 		}
 	}
 	return null;