1402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*******************************************************************************
2402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Copyright (c) 2000, 2009 IBM Corporation and others.
3402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * All rights reserved. This program and the accompanying materials
4402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * are made available under the terms of the Eclipse Public License v1.0
5402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * which accompanies this distribution, and is available at
6402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * http://www.eclipse.org/legal/epl-v10.html
7402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
8402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Contributors:
9402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *     IBM Corporation - initial API and implementation
10402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *******************************************************************************/
11402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpackage org.eclipse.test.internal.performance.results.ui;
12402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
13402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.io.BufferedOutputStream;
14402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.io.DataOutputStream;
15402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.io.File;
16402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.io.FileNotFoundException;
17402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.io.FileOutputStream;
18402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.io.IOException;
19402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.util.HashSet;
20402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.util.Iterator;
21402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.util.Set;
22402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
23402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.core.runtime.preferences.InstanceScope;
24402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
25402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.jface.action.Action;
26402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.jface.action.IAction;
27402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.jface.action.IMenuManager;
28402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.jface.action.Separator;
29402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.jface.dialogs.MessageDialog;
30402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.jface.resource.JFaceResources;
31402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.jface.viewers.AbstractTreeViewer;
32402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.jface.viewers.ISelectionChangedListener;
33402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.jface.viewers.SelectionChangedEvent;
34402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.jface.viewers.StructuredSelection;
35402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.jface.viewers.TreeViewer;
36402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.jface.viewers.Viewer;
37402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.jface.viewers.ViewerFilter;
38402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.jface.viewers.ViewerSorter;
39402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.swt.SWT;
40402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.swt.graphics.Font;
41402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.swt.graphics.FontData;
42402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.swt.widgets.Composite;
43402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.swt.widgets.Display;
44402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.model.BuildResultsElement;
45402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.model.ComponentResultsElement;
46402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.model.ConfigResultsElement;
47402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.model.ResultsElement;
48402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.model.ScenarioResultsElement;
49402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.utils.IPerformancesConstants;
50402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.utils.Util;
51402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.ui.IMemento;
52402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.ui.PlatformUI;
53402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.ui.model.WorkbenchContentProvider;
54402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.ui.model.WorkbenchLabelProvider;
55402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
56402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
57402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * View to see the performance results of all the components in a hierarchical tree.
58402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * <p>
59402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * A component defines several performance scenarios which are run on several
60402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * machines (aka config). All builds results are stored onto each configuration
61402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * and 2 dimensions have been stored for each result: the "Elapsed Process Time"
62402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * and the "CPU Time".
63402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * </p><p>
64402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * There's only one available action from this view: read the local data files. This
65402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * populates the hierarchy with the numbers stored in these files.
66402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * </p><p>
67402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * There's also the possibility to filter the results:
68402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 	<ul>
69402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *	<li>Filter for builds:
70402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *		<ul>
71402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *		<li>Filter baselines:	hide the baselines (starting with R-3.x)</li>
72402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *		<li>Filter nightly:	hide the nightly builds (starting with 'N')</li>
73402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *		<li>Filter non-important builds:	hide all non-important builds, which means non-milestone builds and those after the last milestone</li>
74402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *		</ul>
75402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *	</li>
76402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *	</li>Filter for scenarios:
77402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *		<ul>
78402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *		<li>Filter non-fingerprints: hide the scenarios which are not in the fingerprints</li>
79402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *		</ul>
80402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *	</li>
81402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *	</ul>
82402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * </p>
83402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @see ComponentResultsView
84402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
85402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic class ComponentsView extends PerformancesView {
86402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
87402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Viewer filters
88402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	final static ViewerFilter FILTER_ADVANCED_SCENARIOS = new ViewerFilter() {
89402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		public boolean select(Viewer v, Object parentElement, Object element) {
90402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (element instanceof ScenarioResultsElement) {
91402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				ScenarioResultsElement scenarioElement = (ScenarioResultsElement) element;
92402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				return scenarioElement.hasSummary();
93402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
94402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	        return true;
95402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll        }
96402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	};
97402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
98402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Views
99402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	PerformancesView buildsView;
100402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	ComponentResultsView componentResultsView = null;
101402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
102402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Internal
103402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	Set expandedComponents = new HashSet();
104402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	File resultsDir = null;
105402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
106402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Actions
107402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	Action filterAdvancedScenarios;
108402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	Action writeStatus;
109402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
110402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// SWT resources
111402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	Font boldFont;
112402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
113402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Write Status
114402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	static int WRITE_STATUS;
115402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
116402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
117402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Default constructor.
118402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
119402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic ComponentsView() {
120402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//	this.onlyFingerprintsImageDescriptor = ImageDescriptor.createFromFile(getClass(), "filter_ps.gif");
121402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	super();
122402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
123402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Get preferences
124402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.preferences = new InstanceScope().getNode(IPerformancesConstants.PLUGIN_ID);
125402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
126402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Init status
127402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	WRITE_STATUS = this.preferences.getInt(IPerformancesConstants.PRE_WRITE_STATUS, IPerformancesConstants.DEFAULT_WRITE_STATUS);
128402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
129402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
130402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
131402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
132402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * (non-Javadoc)
133402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @see org.eclipse.test.internal.performance.results.ui.PerformancesView#createPartControl(org.eclipse.swt.widgets.Composite)
134402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
135402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic void createPartControl(Composite parent) {
136402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	super.createPartControl(parent);
137402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
138402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Create the viewer
139402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
140402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
141402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Set the content provider: first level is components list
142402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	WorkbenchContentProvider contentProvider = new WorkbenchContentProvider() {
143402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		public Object[] getElements(Object o) {
144402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			return ComponentsView.this.getElements();
145402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
146402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	};
147402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.viewer.setContentProvider(contentProvider);
148402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
149402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Set the label provider
150402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	WorkbenchLabelProvider labelProvider = new WorkbenchLabelProvider() {
151402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
152402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		protected String decorateText(String input, Object element) {
153402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			String text = super.decorateText(input, element);
154402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (element instanceof BuildResultsElement) {
155402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				BuildResultsElement buildElement = (BuildResultsElement) element;
156402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				if (buildElement.isMilestone()) {
157402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					text = Util.getMilestoneName(buildElement.getName()) + " - "+text;
158402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				}
159402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
160402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			return text;
161402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
162402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
163402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		// When all scenarios are displayed, then set fingerprints one in bold.
164402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		public Font getFont(Object element) {
165402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			Font font = super.getFont(element);
166402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (element instanceof ScenarioResultsElement) {
167402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//				Action fingerprints = ComponentsView.this.filterNonFingerprints;
168402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//				if (fingerprints != null && !fingerprints.isChecked()) {
169402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				boolean fingerprints = ComponentsView.this.preferences.getBoolean(IPerformancesConstants.PRE_FILTER_ADVANCED_SCENARIOS, IPerformancesConstants.DEFAULT_FILTER_ADVANCED_SCENARIOS);
170402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				if (!fingerprints) {
171402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					ScenarioResultsElement scenarioElement = (ScenarioResultsElement) element;
172402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					if (scenarioElement.hasSummary()) {
173402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll						return getBoldFont(font);
174402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					}
175402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				}
176402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
177402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (element instanceof BuildResultsElement) {
178402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				BuildResultsElement buildElement = (BuildResultsElement) element;
179402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				if (Util.isMilestone(buildElement.getName())) {
180402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					return getBoldFont(font);
181402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				}
182402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
183402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			return font;
184402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
185402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	};
186402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.viewer.setLabelProvider(labelProvider);
187402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
188402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Set the children sorter
189402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	ViewerSorter nameSorter = new ViewerSorter() {
190402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
191402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		// Sort children using specific comparison (see the implementation
192402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		// of the #compareTo(Object) in the ResultsElement hierarchy
193402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		public int compare(Viewer view, Object e1, Object e2) {
194402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			// Config and Build results are sorted in reverse order
195402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (e1 instanceof BuildResultsElement) {
196402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				ResultsElement element = (ResultsElement) e2;
197402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				return element.compareTo(e1);
198402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
199402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (e1 instanceof ResultsElement) {
200402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				ResultsElement element = (ResultsElement) e1;
201402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				return element.compareTo(e2);
202402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
203402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			return super.compare(view, e1, e2);
204402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
205402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	};
206402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.viewer.setSorter(nameSorter);
207402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
208402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Add results view as listener to viewer selection changes
209402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	Display.getDefault().asyncExec(new Runnable() {
210402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		public void run() {
211402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			ISelectionChangedListener listener = getResultsView();
212402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (listener != null) {
213402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				ComponentsView.this.viewer.addSelectionChangedListener(listener);
214402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
215402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
216402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	});
217402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
218402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Finalize viewer initialization
219402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	PlatformUI.getWorkbench().getHelpSystem().setHelp(this.viewer.getControl(), "org.eclipse.test.performance.ui.components");
220402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	finalizeViewerCreation();
221402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
222402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
223402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
224402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * (non-Javadoc)
225402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @see org.eclipse.ui.part.WorkbenchPart#dispose()
226402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
227402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic void dispose() {
228402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.boldFont != null) {
229402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.boldFont.dispose();
230402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
231402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//	JFaceResources.getResources().destroyImage(this.onlyFingerprintsImageDescriptor);
232402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	super.dispose();
233402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
234402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
235402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
236402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * (non-Javadoc)
237402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @see org.eclipse.test.internal.performance.results.ui.PerformancesView#fillLocalPullDown(org.eclipse.jface.action.IMenuManager)
238402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
239402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid fillFiltersDropDown(IMenuManager manager) {
240402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	super.fillFiltersDropDown(manager);
241402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	manager.add(this.filterOldBuilds);
242402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	manager.add(this.filterLastBuilds);
243402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	manager.add(new Separator());
244402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	manager.add(this.filterAdvancedScenarios);
245402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
246402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
247402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid fillLocalPullDown(IMenuManager manager) {
248402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	super.fillLocalPullDown(manager);
249402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	manager.add(new Separator());
250402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	manager.add(this.writeStatus);
251402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
252402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
253402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
254402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Filter non fingerprints scenarios action run.
255402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
256402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid filterAdvancedScenarios(boolean fingerprints, boolean updatePreference) {
257402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.results.setFingerprints(fingerprints);
258402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (fingerprints) {
259402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.viewFilters.add(FILTER_ADVANCED_SCENARIOS);
260402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	} else {
261402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.viewFilters.remove(FILTER_ADVANCED_SCENARIOS);
262402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
263402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.preferences.putBoolean(IPerformancesConstants.PRE_FILTER_ADVANCED_SCENARIOS, fingerprints);
264402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	updateFilters();
265402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
266402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
267402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
268402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns the bold font.
269402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
270402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael MollFont getBoldFont(Font font) {
271402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.boldFont == null) {
272402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		FontData[] fontData = (font==null ? JFaceResources.getDefaultFont() : font).getFontData();
273402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		FontData boldFontData = new FontData(fontData[0].getName(), fontData[0].getHeight(), SWT.BOLD);
274402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.boldFont = new Font(this.display, boldFontData);
275402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
276402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.boldFont;
277402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
278402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
279402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
280402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Get all the components from the model.
281402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
282402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael MollObject[] getElements() {
283402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.results == null) {
284402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		initResults();
285402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (this.filterAdvancedScenarios != null) {
286402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			this.results.setFingerprints(this.filterAdvancedScenarios.isChecked());
287402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
288402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
289402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.results.getElements();
290402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
291402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
292402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
293402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Return the components results view.
294402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
295402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael MollComponentResultsView getResultsView() {
296402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.componentResultsView == null) {
297402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.componentResultsView = (ComponentResultsView) getWorkbenchView("org.eclipse.test.internal.performance.results.ui.ComponentsResultsView");
298402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
299402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.componentResultsView;
300402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
301402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
302402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
303402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Return the builds view.
304402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
305402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael MollPerformancesView getSiblingView() {
306402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.buildsView == null) {
307402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.buildsView = (PerformancesView) getWorkbenchView("org.eclipse.test.internal.performance.results.ui.BuildsView");
308402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
309402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.buildsView;
310402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
311402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
312402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
313402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * (non-Javadoc)
314402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @see org.eclipse.test.internal.performance.results.ui.PerformancesView#makeActions()
315402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
316402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid makeActions() {
317402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
318402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	super.makeActions();
319402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
320402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Filter non-fingerprints action
321402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.filterAdvancedScenarios = new Action("Advanced &Scenarios", IAction.AS_CHECK_BOX) {
322402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		public void run() {
323402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			filterAdvancedScenarios(isChecked(), true/*update preference*/);
324402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll        }
325402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	};
326402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.filterAdvancedScenarios.setChecked(true);
327402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.filterAdvancedScenarios.setToolTipText("Filter advanced scenarios (i.e. not fingerprint ones)");
328402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
329402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Write status
330402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.writeStatus = new Action("Write status") {
331402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		public void run() {
332402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
333402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			// Get write directory
334402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			String filter = (ComponentsView.this.resultsDir == null) ? null : ComponentsView.this.resultsDir.getPath();
335402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			final File writeDir = changeDir(filter, "Select a directory to write the status");
336402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (writeDir != null) {
337402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				writeStatus(writeDir);
338402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
339402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll        }
340402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	};
341402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.writeStatus.setEnabled(true);
342402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.writeStatus.setToolTipText("Write component status to a file");
343402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
344402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Set filters default
345402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.filterBaselineBuilds.setChecked(true);
346402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.filterNightlyBuilds.setChecked(false);
347402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
348402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
349402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* (non-Javadoc)
350402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
351402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
352402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic void preferenceChange(PreferenceChangeEvent event) {
353402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	String propertyName = event.getKey();
354402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	Object newValue = event.getNewValue();
355402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
356402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Filter non-fingerprints change
357402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (propertyName.equals(IPerformancesConstants.PRE_FILTER_ADVANCED_SCENARIOS)) {
358402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		boolean checked = newValue == null ? IPerformancesConstants.DEFAULT_FILTER_ADVANCED_SCENARIOS : "true".equals(newValue);
359402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		filterAdvancedScenarios(checked, false/*do not update preference*/);
360402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.filterAdvancedScenarios.setChecked(checked);
361402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
362402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
363402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Filter non-milestone change
364402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (propertyName.equals(IPerformancesConstants.PRE_FILTER_OLD_BUILDS)) {
365402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		boolean checked = newValue == null ? IPerformancesConstants.DEFAULT_FILTER_OLD_BUILDS : "true".equals(newValue);
366402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		filterOldBuilds(checked, false/*do not update preference*/);
367402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.filterOldBuilds.setChecked(checked);
368402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
369402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
370402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Write status
371402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (propertyName.equals(IPerformancesConstants.PRE_WRITE_STATUS)) {
372402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		WRITE_STATUS = newValue == null ? IPerformancesConstants.DEFAULT_WRITE_STATUS : Integer.parseInt((String)newValue);
373402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
374402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
375402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	super.preferenceChange(event);
376402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
377402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
378402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid restoreState() {
379402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	super.restoreState();
380402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
381402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Filter baselines action default
382402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.viewState == null) {
383402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.filterBaselineBuilds.setChecked(true);
384402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.viewFilters.add(FILTER_BASELINE_BUILDS);
385402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	} else {
386402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		String dir = this.viewState.getString(IPerformancesConstants.PRE_WRITE_RESULTS_DIR);
387402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (dir != null) {
388402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			this.resultsDir = new File(dir);
389402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
390402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
391402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
392402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Filter non fingerprints action state
393402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	boolean checked = this.preferences.getBoolean(IPerformancesConstants.PRE_FILTER_ADVANCED_SCENARIOS, IPerformancesConstants.DEFAULT_FILTER_ADVANCED_SCENARIOS);
394402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.filterAdvancedScenarios.setChecked(checked);
395402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (checked) {
396402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.viewFilters.add(FILTER_ADVANCED_SCENARIOS);
397402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
398402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
399402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
400402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic void saveState(IMemento memento) {
401402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.resultsDir != null) {
402402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		memento.putString(IPerformancesConstants.PRE_WRITE_RESULTS_DIR, this.resultsDir.getPath());
403402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
404402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	super.saveState(memento);
405402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
406402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
407402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
408402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Select a results element in the tree.
409402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
410402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic void select(ComponentResultsElement componentResults, String configName, String scenarioName, String buildName) {
411402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
412402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Collapse previous expanded components except the requested one
413402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// TODO (frederic) also collapse expanded components children elements
414402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.expandedComponents.remove(componentResults);
415402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	Iterator iterator = this.expandedComponents.iterator();
416402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	while (iterator.hasNext()) {
417402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.viewer.collapseToLevel(iterator.next(), AbstractTreeViewer.ALL_LEVELS);
418402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
419402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.expandedComponents.clear();
420402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
421402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Set the tree selection
422402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	ScenarioResultsElement scenarioResultsElement = (ScenarioResultsElement) componentResults.getResultsElement(scenarioName);
423402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (scenarioResultsElement != null) {
424402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		ConfigResultsElement configResultsElement = (ConfigResultsElement) scenarioResultsElement.getResultsElement(configName);
425402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (configResultsElement != null) {
426402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			BuildResultsElement buildResultsElement = (BuildResultsElement) configResultsElement.getResultsElement(buildName);
427402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (buildResultsElement != null) {
428402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				this.viewer.setSelection(new StructuredSelection(buildResultsElement), true);
429402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				this.setFocus();
430402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
431402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
432402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
433402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
434402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
435402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
436402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * (non-Javadoc)
437402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @see org.eclipse.test.internal.performance.results.ui.PerformancesView#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
438402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
439402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic void selectionChanged(SelectionChangedEvent event) {
440402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	super.selectionChanged(event);
441402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	ResultsElement eventResultsElement = (ResultsElement) ((StructuredSelection)event.getSelection()).getFirstElement();
442402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (eventResultsElement != null) {
443402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		ResultsElement eventComponentElement = eventResultsElement;
444402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (!(eventComponentElement instanceof ComponentResultsElement)) {
445402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			while (!(eventComponentElement instanceof ComponentResultsElement)) {
446402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				eventComponentElement = (ResultsElement) eventComponentElement.getParent(null);
447402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
448402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			this.expandedComponents.add(eventComponentElement);
449402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
450402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
451402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
452402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
453402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollprotected void writeStatus(File writeDir) {
454402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.resultsDir = writeDir;
455402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (this.filterAdvancedScenarios.isChecked()) {
456402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			writeDir = new File(writeDir, "fingerprints");
457402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		} else {
458402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			writeDir = new File(writeDir, "all");
459402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
460402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		writeDir.mkdir();
461402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if ((WRITE_STATUS & IPerformancesConstants.STATUS_VALUES) != 0) {
462402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			writeDir = new File(writeDir, "values");
463402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
464402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		int buildsNumber = WRITE_STATUS & IPerformancesConstants.STATUS_BUILDS_NUMBER_MASK;
465402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (buildsNumber > 1) {
466402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			writeDir = new File(writeDir, Integer.toString(buildsNumber));
467402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
468402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		writeDir.mkdirs();
469402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		String prefix = this.results.getName();
470402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		File resultsFile = new File(writeDir, prefix+".log");
471402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		File exclusionDir = new File(writeDir, "excluded");
472402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		exclusionDir.mkdir();
473402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		File exclusionFile = new File(exclusionDir, prefix+".log");
474402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (resultsFile.exists()) {
475402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			int i=0;
476402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			File saveDir = new File(writeDir, "save");
477402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			saveDir.mkdir();
478402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			while (true) {
479402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				String newFileName = prefix+"_";
480402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				if (i<10) newFileName += "0";
481402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				newFileName += i;
482402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				File renamedFile = new File(saveDir, newFileName+".log");
483402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				if (resultsFile.renameTo(renamedFile)) {
484402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					File renamedExclusionFile = new File(exclusionDir, newFileName+".log");
485402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					exclusionFile.renameTo(renamedExclusionFile);
486402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					break;
487402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				}
488402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				i++;
489402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
490402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
491402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
492402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		// Write status
493402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		StringBuffer excluded = this.results.writeStatus(resultsFile, WRITE_STATUS);
494402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (excluded == null) {
495402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			MessageDialog.openWarning(this.shell, getTitleToolTip(), "The component is not read, hence no results can be written!");
496402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
497402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
498402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		// Write exclusion file
499402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		try {
500402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			DataOutputStream stream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(exclusionFile)));
501402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			try {
502402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				stream.write(excluded.toString().getBytes());
503402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
504402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			finally {
505402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				stream.close();
506402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
507402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		} catch (FileNotFoundException e) {
508402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			System.err.println("Can't create exclusion file"+exclusionFile); //$NON-NLS-1$
509402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		} catch (IOException e) {
510402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			e.printStackTrace();
511402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
512402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
513402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}