Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 371285 | Differences between
and this patch

Collapse All | Expand All

(-)a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfDataCollectionView.java (-1 / +131 lines)
Added Link Here
0
- 
1
/*******************************************************************************
2
 * Copyright (c) 2012 Red Hat, Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Camilo Bernal <cabernal@redhat.com> - Initial Implementation.
10
 *******************************************************************************/
11
package org.eclipse.linuxtools.internal.perf.ui;
12
13
import java.util.ArrayList;
14
15
import org.eclipse.jface.action.Action;
16
import org.eclipse.jface.action.IToolBarManager;
17
import org.eclipse.jface.viewers.ArrayContentProvider;
18
import org.eclipse.jface.viewers.ISelection;
19
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.jface.viewers.TableViewer;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.ui.IActionBars;
24
import org.eclipse.ui.ISelectionListener;
25
import org.eclipse.ui.IWorkbenchPart;
26
import org.eclipse.ui.model.WorkbenchLabelProvider;
27
import org.eclipse.ui.part.ViewPart;
28
29
public class PerfDataCollectionView extends ViewPart {
30
31
	private static final String ID = "org.eclipse.linuxtools.internal.perf.views.SessionCompareView";
32
33
	public static ArrayList<Object> selectedFiles = new ArrayList<Object>();
34
35
	private TableViewer tableviewer;
36
37
	// This keeps track of the first selection event
38
	private boolean starting = true;
39
40
	// listener registered with the selection service
41
	public ISelectionListener listener = new ISelectionListener() {
42
		public void selectionChanged(IWorkbenchPart sourcepart,
43
				ISelection selection) {
44
			if (selectedFiles.size() >= 2)
45
				return;
46
			// ignore our own selections
47
			if (sourcepart != PerfDataCollectionView.this) {
48
				if (starting) {
49
					starting = false;
50
					return;
51
				}
52
				showSelection(sourcepart, selection);
53
			}
54
		}
55
	};
56
57
	/**
58
	 * Show selected files
59
	 * 
60
	 * @param sourcepart
61
	 *            source part of selection
62
	 * @param selection
63
	 *            selected item
64
	 */
65
	public void showSelection(IWorkbenchPart sourcepart, ISelection selection) {
66
		if (selection instanceof IStructuredSelection) {
67
			IStructuredSelection ss = (IStructuredSelection) selection;
68
			Object[] o = ss.toArray();
69
			selectedFiles.add(o[0]);
70
			showItems(selectedFiles.toArray());
71
		}
72
	}
73
74
	private void showItems(Object[] items) {
75
		tableviewer.setInput(items);
76
		tableviewer.refresh();
77
	}
78
79
	public void createPartControl(Composite parent) {
80
		setContentDescription("Select data files to compare from the Project Explorer");
81
		tableviewer = new TableViewer(parent, SWT.NONE);
82
		tableviewer.setLabelProvider(new WorkbenchLabelProvider());
83
		tableviewer.setContentProvider(new ArrayContentProvider());
84
85
		// provide tableviewer selection
86
		getSite().setSelectionProvider(tableviewer);
87
88
		contributeToActionBars();
89
		getSite().getWorkbenchWindow().getSelectionService()
90
				.addSelectionListener(listener);
91
	}
92
93
	private void contributeToActionBars() {
94
		Action clearAction = new PerfDataClearAction();
95
		Action diffAction = new PerfDiffAction();
96
97
		IActionBars actionBars = getViewSite().getActionBars();
98
		IToolBarManager toolBar = actionBars.getToolBarManager();
99
		toolBar.add(clearAction);
100
		toolBar.add(diffAction);
101
	}
102
103
	public void setFocus() {
104
		tableviewer.getControl().setFocus();
105
	}
106
107
	public void refreshView() {
108
		showItems(selectedFiles.toArray());
109
	}
110
111
	public void dispose() {
112
		// remove listener when disposing view
113
		getSite().getWorkbenchWindow().getSelectionService()
114
				.removeSelectionListener(listener);
115
		super.dispose();
116
	}
117
118
	public void clearSelections() {
119
		starting = true;
120
		selectedFiles.clear();
121
		refreshView();
122
	}
123
124
	public void restart() {
125
		starting = true;
126
	}
127
128
	public ArrayList<Object> getSelectedFiles() {
129
		return selectedFiles;
130
	}
131
}

Return to bug 371285