~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.ui.dashboard/src/org/eclipse/linuxtools/systemtap/ui/dashboard/views/DashboardView.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 *     IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse, Anithra P J
 
10
 *******************************************************************************/
 
11
 
 
12
package org.eclipse.linuxtools.systemtap.ui.dashboard.views;
 
13
 
 
14
import java.util.ArrayList;
 
15
 
 
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;
 
31
 
 
32
 
 
33
import org.eclipse.ui.PlatformUI;
 
34
import org.eclipse.ui.part.ViewPart;
 
35
 
 
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;
 
45
 
 
46
 
 
47
/**
 
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
 
52
 * @author Ryan Morse
 
53
 */
 
54
public class DashboardView extends ViewPart {
 
55
 
 
56
        public DashboardView() {
 
57
        super();
 
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);
 
64
 
 
65
}
 
66
 
 
67
        
 
68
        /**
 
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 
 
71
         * the list.
 
72
         * @param title The name to be shown on the new tab
 
73
         */
 
74
        public void createComposite(String title) {
 
75
                CTabItem item;
 
76
 
 
77
                item = new CTabItem(scriptFolder, SWT.CLOSE);
 
78
                item.setText(title);
 
79
                
 
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);
 
86
                composites.add(comp);
 
87
                moduleNames.add(title);
 
88
                item.setControl(parent);
 
89
 
 
90
                scriptFolder.setSelection(item);
 
91
                fireTabOpenEvent();
 
92
        }
 
93
 
 
94
 /*
 
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.
 
98
         */
 
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);
 
104
        }*/
 
105
        
 
106
        public void createPartControl(Composite parent) {
 
107
                LogManager.logDebug("Start createPartControl: parent-" + parent, this);
 
108
             //bar.pack();
 
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);
 
116
                
 
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());
 
126
        
 
127
                
 
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]));
 
140
                    }
 
141
                toolbar.setLayout(new RowLayout());
 
142
                toolbar.setLayoutData(data3);
 
143
                toolbar.pack();*/
 
144
                
 
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));
 
150
        
 
151
                    for (int i = 2; i < allModuleNames.size(); i++) {
 
152
                      item = new ToolItem(bar, SWT.PUSH);
 
153
                      item.setText(allModuleNames.get(i));
 
154
                    }
 
155
                 bar.setLayoutData(data3);
 
156
                 bar.pack(); */
 
157
        
 
158
 
 
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();
 
170
                        }
 
171
                        
 
172
                        public void widgetDefaultSelected(SelectionEvent e) {}
 
173
                });
 
174
                
 
175
 
 
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));
 
184
                                fireTabCloseEvent();
 
185
                        }
 
186
                });
 
187
                
 
188
                Display display = parent.getShell().getDisplay();
 
189
                
 
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,
 
194
                        100});*/
 
195
                
 
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));
 
200
         
 
201
                LogManager.logDebug("End createPartControl", this);
 
202
        }
 
203
 
 
204
 
 
205
        public void setFocus() {}
 
206
 
 
207
        /*public Composite getComposite() {
 
208
                return composite.deadComposite;
 
209
        }*/
 
210
        
 
211
        /**
 
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
 
214
         * the composite.
 
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.
 
218
         */
 
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);
 
223
                
 
224
                return adapter;
 
225
        }*/
 
226
        /**
 
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
 
229
         * the composite.
 
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.
 
233
         */
 
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);
 
240
        
 
241
                DashboardAdapter adapter = null;
 
242
                if (index == -1)
 
243
                {
 
244
                                createComposite(moduleName);
 
245
                        index = searchModuleNames(moduleName);
 
246
                }
 
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);
 
251
                  cursor.dispose();
 
252
                return adapter;
 
253
        }
 
254
        
 
255
        private int searchModuleNames(String moduleName) {
 
256
                for (int i = 0; i<moduleNames.size();i++)
 
257
                {
 
258
                        
 
259
                        if (moduleName.equals(moduleNames.get(i))) return i;
 
260
                }
 
261
                return -1;
 
262
        }
 
263
 
 
264
        public UpdateManager getUpdater() {
 
265
                return updater;
 
266
        }
 
267
 
 
268
        public void removeGraph(DashboardAdapter graph, String moduleName) {
 
269
                int index = searchModuleNames(moduleName);
 
270
                composites.get(index).remove(graph);
 
271
                graph.dispose();
 
272
                /*if (composites.get(index).getusedSlots() == 0)
 
273
                {
 
274
                        composites.remove(index);
 
275
                        moduleNames.remove(index);
 
276
                        tabListeners.remove(index);
 
277
                        fireTabCloseEvent();
 
278
                }*/
 
279
        }
 
280
        
 
281
        public void closeComposite(String moduleName)
 
282
        {
 
283
                int index = searchModuleNames(moduleName);
 
284
                if (composites.get(index).getusedSlots() <= 0)
 
285
                {
 
286
                scriptFolder.getItem(index).dispose();
 
287
                moduleNames.remove(index);
 
288
                composites.remove(index);
 
289
                }
 
290
        }
 
291
        
 
292
        public void addTabListener(ITabListener listener) {
 
293
                tabListeners.add(listener);
 
294
        }
 
295
 
 
296
        public void removeTabListener(ITabListener listener) {
 
297
                tabListeners.remove(listener);
 
298
        }
 
299
 
 
300
        private void fireTabCloseEvent() {
 
301
                for(int i=0; i<tabListeners.size(); i++)
 
302
                        ((ITabListener)tabListeners.get(i)).tabClosed();
 
303
        }
 
304
        
 
305
        
 
306
        private void fireTabOpenEvent() {
 
307
                for(int i=0; i<tabListeners.size(); i++)
 
308
                        ((ITabListener)tabListeners.get(i)).tabOpened();
 
309
        }
 
310
 
 
311
        private void fireTabChangedEvent() {
 
312
                for(int i=0; i<tabListeners.size(); i++)
 
313
                        ((ITabListener)tabListeners.get(i)).tabChanged();
 
314
        }
 
315
        
 
316
        /**
 
317
         * Removes all internal references in this class.  Nothing should make any references
 
318
         * to anyting in this class after calling the dispose method.
 
319
         */
 
320
        public void dispose() {
 
321
                LogManager.logDebug("Start dispose:", this);
 
322
                LogManager.logInfo("Disposing", this);
 
323
                super.dispose();
 
324
 
 
325
                if(null != scriptFolder)
 
326
                        scriptFolder.dispose();
 
327
                scriptFolder = null;
 
328
                if(null != composites)
 
329
                        composites.removeAll(composites);
 
330
                composites = null;
 
331
                scriptFolder = null;
 
332
                if(null != tabListeners)
 
333
                        tabListeners.removeAll(tabListeners);
 
334
                tabListeners = null;
 
335
                LogManager.logDebug("End dispose:", this);
 
336
                
 
337
        }
 
338
        
 
339
        public static void addmodulename(String str)
 
340
        {
 
341
                if (allModuleNames == null) allModuleNames = new ArrayList<String>();
 
342
                
 
343
                allModuleNames.add(str);
 
344
        }
 
345
        
 
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";
 
353
        
 
354
}
 
355
 
 
356
 
 
357