1
/*******************************************************************************
2
* Copyright (c) 2006 IBM Corporation.
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
9
* IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse, Anithra P J
10
*******************************************************************************/
12
package org.eclipse.linuxtools.systemtap.ui.dashboard.views;
14
import java.util.ArrayList;
16
import org.eclipse.jface.preference.IPreferenceStore;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.custom.CTabFolder;
19
import org.eclipse.swt.custom.CTabFolder2Listener;
20
import org.eclipse.swt.custom.CTabFolderEvent;
21
import org.eclipse.swt.custom.CTabItem;
22
import org.eclipse.swt.events.SelectionEvent;
23
import org.eclipse.swt.events.SelectionListener;
24
import org.eclipse.swt.graphics.Color;
25
import org.eclipse.swt.graphics.Cursor;
26
import org.eclipse.swt.layout.FormAttachment;
27
import org.eclipse.swt.layout.FormData;
28
import org.eclipse.swt.layout.FormLayout;
29
import org.eclipse.swt.widgets.Composite;
30
import org.eclipse.swt.widgets.Display;
33
import org.eclipse.ui.PlatformUI;
34
import org.eclipse.ui.part.ViewPart;
36
import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSet;
37
import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.GraphData;
38
import org.eclipse.linuxtools.systemtap.ui.logging.LogManager;
39
import org.eclipse.linuxtools.systemtap.ui.structures.UpdateManager;
40
import org.eclipse.linuxtools.systemtap.ui.structures.listeners.ITabListener;
41
import org.eclipse.linuxtools.systemtap.ui.dashboard.DashboardAdapter;
42
import org.eclipse.linuxtools.systemtap.ui.dashboard.DashboardComposite;
43
import org.eclipse.linuxtools.systemtap.ui.dashboard.internal.DashboardPlugin;
44
import org.eclipse.linuxtools.systemtap.ui.dashboard.preferences.DashboardPreferenceConstants;
48
* This is the main view of the dashboard. It is where all of the graphs are displayed
49
* when they are run. It utalizes <code>DashboardComposite</code> to handle all of the
50
* layout data for the view.
51
* @author Henry Hughes
54
public class DashboardView extends ViewPart {
56
public DashboardView() {
58
LogManager.logDebug("Start DashboardView:", this);
59
LogManager.logInfo("Initializing", this);
60
composites = new ArrayList<DashboardComposite>();
61
tabListeners = new ArrayList<ITabListener>();
62
moduleNames = new ArrayList<String>();
63
LogManager.logDebug("End DashboardView:", this);
69
* This method will create a new composite for the module
70
* The composite will be given a new tab item at the end of
72
* @param title The name to be shown on the new tab
74
public void createComposite(String title) {
77
item = new CTabItem(scriptFolder, SWT.CLOSE);
80
Composite parent = new Composite(scriptFolder, SWT.NONE);
81
parent.setBackground(new Color(parent.getDisplay(), 0, 0, 255));
82
DashboardComposite comp = new DashboardComposite(parent, SWT.BORDER);
83
IPreferenceStore p = DashboardPlugin.getDefault().getPreferenceStore();
84
int delay = p.getInt(DashboardPreferenceConstants.P_DASHBOARD_UPDATE_DELAY);
85
updater = new UpdateManager(delay);
87
moduleNames.add(title);
88
item.setControl(parent);
90
scriptFolder.setSelection(item);
95
* This method creates the layout for the view. It makes use of
96
* <code>DashboardComposite</code> to handle positioning of all of the graphs.
97
* @param parent The composite that contains all elements added by this view.
99
/* public void createPartControl(Composite parent) {
100
composite[CompositeNo] = new DashboardComposite(parent, SWT.BORDER);
101
IPreferenceStore p = DashboardPlugin.getDefault().getPreferenceStore();
102
int delay = p.getInt(DashboardPreferenceConstants.P_DASHBOARD_UPDATE_DELAY);
103
updater = new UpdateManager(delay);
106
public void createPartControl(Composite parent) {
107
LogManager.logDebug("Start createPartControl: parent-" + parent, this);
109
FormData data2 = new FormData();
110
data2.left = new FormAttachment(0, 0);
111
data2.top = new FormAttachment(0, 0);
112
data2.right = new FormAttachment(100, 0);
113
data2.bottom = new FormAttachment(100, 0);
114
Composite cmpGraph = new Composite(parent, SWT.NONE);
115
cmpGraph.setLayoutData(data2);
117
//This is for the tab view
118
cmpGraph.setLayout(new FormLayout());
119
FormData data3 = new FormData();
120
data3.left = new FormAttachment(0, 0);
121
data3.top = new FormAttachment(0, 0);
122
data3.right = new FormAttachment(100, 0);
123
data3.bottom = new FormAttachment(6, 0);
124
// while (DashboardModuleLocator.moduleNames == null) {}
125
// allModuleNames = new ArrayList<String>(DashboardModuleBrowserView.getmoduleNames());
128
/* Composite toolbar = new Composite(cmpGraph, SWT.NONE);
129
Button modbutton = new Button(toolbar,SWT.PUSH);
130
// modbutton.setBackground(new Color(Display.getCurrent(), IGraphColorConstants.COLORS[0]));
131
modbutton.setText(allModuleNames.get(1));
132
//modbutton.setText("text0");
133
modbutton = new Button(toolbar,SWT.PUSH);
134
//modbutton.setBackground(new Color(Display.getCurrent(), IGraphColorConstants.COLORS[1]));
135
modbutton.setText(allModuleNames.get(0));
136
for (int i = 2; i < 5; i++) {
137
modbutton = new Button(toolbar, SWT.PUSH);
138
modbutton.setText(allModuleNames.get(i));
139
// modbutton.setBackground(new Color(Display.getCurrent(), IGraphColorConstants.COLORS[i]));
141
toolbar.setLayout(new RowLayout());
142
toolbar.setLayoutData(data3);
145
/* ToolBar bar = new ToolBar(cmpGraph, SWT.BORDER);
146
ToolItem item = new ToolItem(bar, SWT.PUSH);
147
item.setText(allModuleNames.get(1));
148
item = new ToolItem(bar, SWT.PUSH);
149
item.setText(allModuleNames.get(0));
151
for (int i = 2; i < allModuleNames.size(); i++) {
152
item = new ToolItem(bar, SWT.PUSH);
153
item.setText(allModuleNames.get(i));
155
bar.setLayoutData(data3);
159
//Create the folder for all of the script sets, so it takes up all of the parent composite
160
scriptFolder = new CTabFolder(cmpGraph, SWT.NONE);
161
FormData data = new FormData();
162
data.top = new FormAttachment(0, 0);
163
data.left = new FormAttachment(0, 0);
164
data.right = new FormAttachment(100, 0);
165
data.bottom = new FormAttachment(100, 0);
166
scriptFolder.setLayoutData(data);
167
scriptFolder.addSelectionListener(new SelectionListener() {
168
public void widgetSelected(SelectionEvent e) {
169
fireTabChangedEvent();
172
public void widgetDefaultSelected(SelectionEvent e) {}
176
scriptFolder.addCTabFolder2Listener(new CTabFolder2Listener() {
177
public void restore(CTabFolderEvent e) {}
178
public void showList(CTabFolderEvent e) {}
179
public void minimize(CTabFolderEvent e) {}
180
public void maximize(CTabFolderEvent e) {}
181
public void close(CTabFolderEvent e) {
182
composites.remove(scriptFolder.indexOf((CTabItem)e.item));
183
moduleNames.remove(scriptFolder.indexOf((CTabItem)e.item));
188
Display display = parent.getShell().getDisplay();
190
/*scriptFolder.setSelectionBackground(new Color[] {
191
display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW),
192
display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),
193
display.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW)}, new int[] { 50,
196
scriptFolder.setSelectionBackground(display.getSystemColor(SWT.COLOR_GRAY));
197
//scriptFolder.setForeground(display.getSystemColor(SWT.COLOR_YELLOW));
198
scriptFolder.setMaximizeVisible(true);
199
scriptFolder.setSelectionForeground(display.getSystemColor(SWT.COLOR_BLACK));
201
LogManager.logDebug("End createPartControl", this);
205
public void setFocus() {}
207
/*public Composite getComposite() {
208
return composite.deadComposite;
212
* This method creates a new graph in the view. It creates a wrapper for the graph
213
* and then adds an update listener to the graph, and finally registers it with
215
* @param gd The data needed to create a new graph
216
* @param ds The dataset used to store all script output data
217
* @return The newly create graph component.
219
/* public DashboardAdapter createGraph(GraphData gd, IDataSet ds) {
220
DashboardAdapter adapter = new DashboardAdapter(composite, gd, ds);
221
updater.addUpdateListener(adapter.getGraph());
222
composite.add(adapter);
227
* This method creates a new graph in the view. It creates a wrapper for the graph
228
* and then adds an update listener to the graph, and finally registers it with
230
* @param gd The data needed to create a new graph
231
* @param ds The dataset used to store all script output data
232
* @return The newly create graph component.
234
public DashboardAdapter createGraph(GraphData gd, IDataSet ds, String moduleName) {
235
Display disp = PlatformUI.getWorkbench().getDisplay();
236
Cursor cursor = new Cursor(disp, SWT.CURSOR_WAIT);
237
PlatformUI.getWorkbench().getDisplay().getActiveShell().setCursor(cursor);
238
// while (ds.getRowCount() <= 0 ) {}
239
int index = searchModuleNames(moduleName);
241
DashboardAdapter adapter = null;
244
createComposite(moduleName);
245
index = searchModuleNames(moduleName);
247
adapter = new DashboardAdapter(composites.get(index), gd, ds, moduleName);
248
updater.addUpdateListener(adapter.getGraph());
249
composites.get(index).add(adapter);
250
PlatformUI.getWorkbench().getDisplay().getActiveShell().setCursor(null);
255
private int searchModuleNames(String moduleName) {
256
for (int i = 0; i<moduleNames.size();i++)
259
if (moduleName.equals(moduleNames.get(i))) return i;
264
public UpdateManager getUpdater() {
268
public void removeGraph(DashboardAdapter graph, String moduleName) {
269
int index = searchModuleNames(moduleName);
270
composites.get(index).remove(graph);
272
/*if (composites.get(index).getusedSlots() == 0)
274
composites.remove(index);
275
moduleNames.remove(index);
276
tabListeners.remove(index);
281
public void closeComposite(String moduleName)
283
int index = searchModuleNames(moduleName);
284
if (composites.get(index).getusedSlots() <= 0)
286
scriptFolder.getItem(index).dispose();
287
moduleNames.remove(index);
288
composites.remove(index);
292
public void addTabListener(ITabListener listener) {
293
tabListeners.add(listener);
296
public void removeTabListener(ITabListener listener) {
297
tabListeners.remove(listener);
300
private void fireTabCloseEvent() {
301
for(int i=0; i<tabListeners.size(); i++)
302
((ITabListener)tabListeners.get(i)).tabClosed();
306
private void fireTabOpenEvent() {
307
for(int i=0; i<tabListeners.size(); i++)
308
((ITabListener)tabListeners.get(i)).tabOpened();
311
private void fireTabChangedEvent() {
312
for(int i=0; i<tabListeners.size(); i++)
313
((ITabListener)tabListeners.get(i)).tabChanged();
317
* Removes all internal references in this class. Nothing should make any references
318
* to anyting in this class after calling the dispose method.
320
public void dispose() {
321
LogManager.logDebug("Start dispose:", this);
322
LogManager.logInfo("Disposing", this);
325
if(null != scriptFolder)
326
scriptFolder.dispose();
328
if(null != composites)
329
composites.removeAll(composites);
332
if(null != tabListeners)
333
tabListeners.removeAll(tabListeners);
335
LogManager.logDebug("End dispose:", this);
339
public static void addmodulename(String str)
341
if (allModuleNames == null) allModuleNames = new ArrayList<String>();
343
allModuleNames.add(str);
346
private ArrayList<DashboardComposite> composites;
347
private ArrayList<String> moduleNames;
348
public static ArrayList<String> allModuleNames = null;
349
private ArrayList<ITabListener> tabListeners;
350
private UpdateManager updater;
351
private CTabFolder scriptFolder;
352
public static final String ID = "org.eclipse.linuxtools.systemtap.ui.dashboard.views.DashboardView";