aboutsummaryrefslogtreecommitdiff
path: root/basebuilder-3.6.2/org.eclipse.releng.basebuilder/plugins/org.eclipse.test.performance.ui/src/org/eclipse/test/internal/performance/results/model/ComponentResultsElement.java
blob: c8b21f3db55637d1eae149054af9537bed2a377a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*******************************************************************************
 * Copyright (c) 2000, 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.test.internal.performance.results.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.test.internal.performance.results.db.AbstractResults;
import org.eclipse.test.internal.performance.results.db.ComponentResults;
import org.eclipse.test.internal.performance.results.db.PerformanceResults;
import org.eclipse.test.internal.performance.results.db.ScenarioResults;
import org.eclipse.test.internal.performance.results.utils.IPerformancesConstants;
import org.eclipse.test.internal.performance.results.utils.Util;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;

public class ComponentResultsElement extends ResultsElement {

	// Property descriptors
	static final String P_ID_NAME = "ComponentResultsElement.name"; //$NON-NLS-1$
	static final String P_ID_CURRENT_BUILD = "ComponentResultsElement.currentbuild"; //$NON-NLS-1$
	static final String P_ID_BASELINE_BUILD = "ComponentResultsElement.baselinebuild"; //$NON-NLS-1$

	static final String P_STR_NAME = "name"; //$NON-NLS-1$
	static final String P_STR_CURRENT_BUILD = "current build"; //$NON-NLS-1$
	static final String P_STR_BASELINE_BUILD = "baseline build"; //$NON-NLS-1$

	private static final TextPropertyDescriptor NAME_DESCRIPTOR = new TextPropertyDescriptor(P_ID_NAME, P_STR_NAME);
	private static final PropertyDescriptor CURRENT_BUILD_DESCRIPTOR = new PropertyDescriptor(P_ID_CURRENT_BUILD, P_STR_CURRENT_BUILD);
	private static final PropertyDescriptor BASELINE_BUILD_DESCRIPTOR = new PropertyDescriptor(P_ID_BASELINE_BUILD, P_STR_BASELINE_BUILD);

    private static Vector DESCRIPTORS;
    static Vector initDescriptors(int status) {
        DESCRIPTORS = new Vector();
		// Status category
		DESCRIPTORS.add(getInfosDescriptor(status));
		DESCRIPTORS.add(getWarningsDescriptor(status));
		DESCRIPTORS.add(ERROR_DESCRIPTOR);
		ERROR_DESCRIPTOR.setCategory("Status");
		// Results category
		DESCRIPTORS.addElement(NAME_DESCRIPTOR);
		NAME_DESCRIPTOR.setCategory("Results");
		DESCRIPTORS.addElement(CURRENT_BUILD_DESCRIPTOR);
		CURRENT_BUILD_DESCRIPTOR.setCategory("Results");
		DESCRIPTORS.addElement(BASELINE_BUILD_DESCRIPTOR);
		BASELINE_BUILD_DESCRIPTOR.setCategory("Results");
		// Survey category
		DESCRIPTORS.add(COMMENT_DESCRIPTOR);
		COMMENT_DESCRIPTOR.setCategory("Survey");
        return DESCRIPTORS;
	}
    static Vector getDescriptors() {
    	return DESCRIPTORS;
	}

public ComponentResultsElement(String name, ResultsElement parent) {
	super(name, parent);
}

public ComponentResultsElement(AbstractResults results, ResultsElement parent) {
	super(results, parent);
}

/*
 * Do not create non-fingerprint child when only fingerprint is specified.
 *
 * @see org.eclipse.test.internal.performance.results.model.ResultsElement#createChild(org.eclipse.test.internal.performance.results.db.AbstractResults)
 */
ResultsElement createChild(AbstractResults testResults) {
//	if (onlyFingerprints()) {
//		ScenarioResults scenarioResults = (ScenarioResults) testResults;
//		if (!scenarioResults.hasSummary()) {
//			return null;
//		}
//	}
	return new ScenarioResultsElement(testResults, this);
}

/**
 * Get all results numbers for a given machine of the current component.
 *
 * @param configName The name of the configuration to get numbers
 * @param fingerprints Set whether only fingerprints scenario should be taken into account
 * @return A list of lines. Each line represent a build and is a list of either strings or values.
 */
public List getConfigNumbers(String configName, boolean fingerprints) {
	if (this.results == null) return null;
	return ((ComponentResults)this.results).getConfigNumbers(configName, fingerprints, new ArrayList());
}

/* (non-Javadoc)
 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
 */
public IPropertyDescriptor[] getPropertyDescriptors() {
	Vector descriptors = getDescriptors();
	if (descriptors == null) {
		descriptors = initDescriptors(getStatus());
	}
	int size = descriptors.size();
	IPropertyDescriptor[] descriptorsArray = new IPropertyDescriptor[size];
	descriptorsArray[0] = getInfosDescriptor(getStatus());
	descriptorsArray[1] = getWarningsDescriptor(getStatus());
	for (int i=2; i<size; i++) {
		descriptorsArray[i] = (IPropertyDescriptor) descriptors.get(i);
	}
	return descriptorsArray;
}

/* (non-Javadoc)
 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
 */
public Object getPropertyValue(Object propKey) {
	if (propKey.equals(P_ID_NAME)) {
		return getName();
	}
	if (propKey.equals(P_ID_CURRENT_BUILD)) {
		if (this.results == null) {
			PerformanceResultsElement performanceResultsElement = (PerformanceResultsElement) getParent(null);
			return performanceResultsElement.getName();
		}
		PerformanceResults performanceResults = (PerformanceResults) this.results.getParent();
		return performanceResults.getName();
	}
	if (propKey.equals(P_ID_BASELINE_BUILD)) {
		if (this.results == null) {
			return "?";
		}
		PerformanceResults performanceResults = (PerformanceResults) this.results.getParent();
		return performanceResults.getBaselineName();
	}
    return super.getPropertyValue(propKey);
}

/**
 * Get the list of the scenarios results from the model. Put only fingerprint ones if specified.
 *
 * @param fingerprint Tell whether only fingerprint scenarios are expected or not.
 * @return A list of {@link ScenarioResults}.
 */
public List getScenarios(boolean fingerprint) {
	if (!fingerprint) {
		return Arrays.asList(this.results.getChildren());
	}
	List scenarios = new ArrayList();
	if (this.results != null) {
		Iterator iterator = this.results.getResults();
		while (iterator.hasNext()) {
			ScenarioResults scenarioResults = (ScenarioResults) iterator.next();
			if (scenarioResults.hasSummary()) {
				scenarios.add(scenarioResults);
			}
		}
	}
	return scenarios;
}

/**
 * Get the list of the scenarios names. Put only fingerprint ones if specified.
 *
 * @param fingerprint Tell whether only fingerprint scenarios are expected or not.
 * @return A list of {@link String}.
 */
public List getScenariosLabels(boolean fingerprint) {
	List labels = new ArrayList();
	if (this.results != null) {
		AbstractResults[] scenarios = this.results.getChildren();
		int length = scenarios.length;
		for (int i=0; i<length; i++) {
			ScenarioResults scenarioResults = (ScenarioResults) scenarios[i];
			if (!fingerprint || scenarioResults.hasSummary()) {
				labels.add(scenarioResults.getLabel());
			}
		}
	}
	return labels;
}

/*
 * (non-Javadoc)
 * @see org.eclipse.test.internal.performance.results.model.ResultsElement#initStatus()
 */
void initStatus() {
	if (this.results == null) {
		this.status = UNREAD;
	} else {
		super.initStatus();
	}
}

StringBuffer writableStatus(StringBuffer buffer, int kind, StringBuffer excluded) {
	// Write status for scenarios having error
	if ((getStatus() & ERROR_MASK) != 0) {

		// Get children status
		StringBuffer childrenBuffer = super.writableStatus(new StringBuffer(), kind, excluded);

		// Write status on file if not excluded
		if (childrenBuffer.length() > 0) {
			buffer.append(getName());
			IEclipsePreferences preferences = new InstanceScope().getNode(IPerformancesConstants.PLUGIN_ID);
			String comment = preferences.get(getId(), null);
			if (comment != null) {
				if ((kind & IPerformancesConstants.STATUS_VALUES) != 0) {
					buffer.append("												");
				} else {
					buffer.append("			");
				}
				buffer.append(comment);
			}
			buffer.append(Util.LINE_SEPARATOR);
			buffer.append(childrenBuffer);
			buffer.append(Util.LINE_SEPARATOR);
		}
	}
	return buffer;
}

}