Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 317b8ac1160fbcf7492d7759df6bfafcdd64718b (plain) (blame)
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation.
 * 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 - Jeff Briggs, Henry Hughes, Ryan Morse, Anithra P J
 *******************************************************************************/

package org.eclipse.linuxtools.systemtap.ui.dashboard;

import org.eclipse.linuxtools.internal.systemtap.ui.dashboard.actions.StopGraphAction;
import org.eclipse.linuxtools.systemtap.ui.dashboard.internal.DashboardPlugin;
import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.DashboardGraphData;
import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.GraphTreeNode;
import org.eclipse.linuxtools.systemtap.ui.dashboard.views.ActiveModuleBrowserView;
import org.eclipse.linuxtools.systemtap.ui.dashboard.views.DashboardView;
import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSet;
import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.GraphData;
import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.charts.AbstractChartBuilder;
import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.widgets.GraphComposite;
import org.eclipse.linuxtools.systemtap.ui.structures.TreeNode;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetListener;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PlatformUI;

/**
 * This class is used to contain a graph for the DashboardComposite.  The class
 * provides a windowing framework that allows the user to close the graph at
 * will and to toggle whether or not to display the graph configuration settings.
 * @author Henry Hughes
 * @author Ryan Morse
 */
public class DashboardAdapter {
	/**
	 * This constructor sets up all of the basic internal components for class.
	 * @param parent This is the component that will act as the parent container
	 * @param gd The data that will be used to construct the internal graph
	 * @param ds The data used to populate the graph.
	 */
	public DashboardAdapter(DashboardComposite parent, GraphData gd, IDataSet ds, String moduleName) {
		folder = new CTabFolder(parent.deadComposite, SWT.ALL);
		FormLayout layout = new FormLayout();
		layout.marginHeight = 0; layout.marginWidth = 0;
		parent.deadComposite.setLayout(layout);

		FormData data = new FormData();
		data.left = new FormAttachment(0,0);
		data.top = new FormAttachment(0,0);
		data.right = new FormAttachment(100,0);
		data.bottom = new FormAttachment(100,0);

		folder.setLayoutData(folder);
		folder.setLayout(new FormLayout());

		ToolBar toolBar = new ToolBar (folder, SWT.FLAT | SWT.BORDER);
		min = new ToolItem(toolBar, SWT.PUSH);
		min.setImage(expandImage);
		close = new ToolItem(toolBar, SWT.PUSH);
		close.setImage(closeImage);
		max = new ToolItem(toolBar, SWT.PUSH);
		max.setImage(maxImage);
		toolBar.pack ();
		folder.setTopRight(toolBar);
         modulename = moduleName;
		resetDND(null, null);

		createGraph(gd, ds);
		wireButtons(parent);
	}

	/**
	 * This method creates the internal graph that will be displayed in this container.
	 * @param gd The graph data used to specify the graph that will be created.
	 * @param ds The data set that is used to populate the graph.
	 */
	private void createGraph(GraphData gd, IDataSet ds) {
		//Setup canvas
		CTabItem item = new CTabItem(folder, SWT.NONE);
		Composite c = new Composite(folder, SWT.NONE);
		FormData data = new FormData();
		data.left = new FormAttachment(0,0);
		data.top = new FormAttachment(0,0);
		data.left = new FormAttachment(100,0);
		data.right = new FormAttachment(100,0);
		c.setLayoutData(data);
		c.setLayout(new FormLayout());
		item.setControl(c);
		folder.setSelection(item);

		//Create graph
		gc = new GraphComposite(c, SWT.NONE, gd, ds);
		gc.configure(false);
		FormData fd = new FormData();
		fd.left = new FormAttachment(0,0);
		fd.right = new FormAttachment(100,0);
		fd.top = new FormAttachment(0,0);
		fd.bottom = new FormAttachment(100,0);
		gc.setLayoutData(fd);
	}

	/**
	 * This method resets all Drag And Drop information.
	 * @param drag This is the object that is being moved
	 * @param drop This is the object that occupies the desired location of the first object.
	 */
	public void resetDND(DragSourceListener drag, DropTargetListener drop) {
		if(drag != null) {
			dragSource.removeDragListener(drag);
		}
		if(drop != null) {
			dropTarget.removeDropListener(drop);
		}
		if(dragSource != null) {
			dragSource.dispose();
		}
		if(dropTarget != null) {
			dropTarget.dispose();
		}
		dragSource = new DragSource(folder, DND.DROP_MOVE);
		dragSource.setTransfer(types);
		dropTarget = new DropTarget(folder, DND.DROP_MOVE | DND.DROP_DEFAULT);
		dropTarget.setTransfer(types);
	}

	/**
	 * Creates and addes the action listeners for the buttons.
	 * @param comp The composite that is containing this class.
	 */
	private void wireButtons(DashboardComposite comp) {
		SelectionListener listener = new DashboardShimButtonController(this, comp);
		close.addSelectionListener(listener);
		min.addSelectionListener(listener);
		max.addSelectionListener(listener);
	}

	/**
	 * Updates the containers parent with the provided composite.
	 * @param c The new composite that will serve as the parent.
	 */
	public void setParent(Composite c) {
		folder.setParent(c);
	}

	/**
	 * Changes the layout information for this class.
	 * @param o The new layout informatino for the class.
	 */
	public void setLayoutData(Object o) {
		folder.setLayoutData(o);
	}

	/**
	 * Sets whether or not the graph is visible
	 * @param b Visibility flag.
	 */
	public void setVisible(boolean b) {
		folder.setVisible(b);
	}

	/**
	 * Returns the internal graph that is being displayed
	 * @return The graph that is held by this class.
	 */
	public AbstractChartBuilder getGraph() {
		return gc.getCanvas();

	}

	/**
	 * Closes this class and removes it from being displayed in the parent composite.
	 * Also updates its display information in the ActiveModuleBrowserView.
	 */
	private void closeShim() {
		IViewPart ivp = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(ActiveModuleBrowserView.ID);
		ActiveModuleBrowserView ambv = (ActiveModuleBrowserView)ivp;
		TreeNode root = (TreeNode)ambv.getViewer().getTree().getData();
		TreeNode node;
		GraphTreeNode child;
		for(int j,i=0; i<root.getChildCount(); i++) {
			node = root.getChildAt(i);
			for(j=0; j<node.getChildCount(); j++) {
				child = (GraphTreeNode)node.getChildAt(j);
				if(this == ((DashboardGraphData)child.getData()).adapter) {
					StopGraphAction sga = new StopGraphAction();
					sga.run(child);
					return;
				}
			}
		}
	}

	/**
	 * Removes all internal references in this class.  Nothing should make any references
	 * to anyting in this class after calling the dispose method.
	 */
	public void dispose() {
		if(null != folder) {
			folder.dispose();
		}
		folder = null;
		if(null != close) {
			close.dispose();
		}
		close = null;
		if(null != min) {
			min.dispose();
		}
		min = null;
		if(null != dragSource) {
			dragSource.dispose();
		}
		dragSource = null;
		if(null != dropTarget) {
			dropTarget.dispose();
		}
		dropTarget = null;
		IViewPart ivp = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(DashboardView.ID);
		((DashboardView)ivp).getUpdater().removeUpdateListener(getGraph());
		if(null != gc && !gc.isDisposed()) {
			gc.dispose();
		}
		gc = null;
		types = null;
	}

	/**
	 * This class handles the button clicks for the three buttons on the window bar.  It
	 * supports closing the window, as well as toggling whether or not to display the
	 * Graph display options.
	 * @author Henry Hughes
	 * @author Ryan Morse
	 */
	private class DashboardShimButtonController extends SelectionAdapter {
		DashboardAdapter shim;
		DashboardComposite composite;
		boolean maximized = false;
		public DashboardShimButtonController(DashboardAdapter shim, DashboardComposite composite) {
			this.shim = shim;
			this.composite = composite;
		}

		@Override
		public void widgetSelected(SelectionEvent e) {
			if(e.widget == close) {
				closeShim();
			}

			if(e.widget == min) {
				Composite c = (Composite)folder.getSelection().getControl();
				Control[] children = c.getChildren();
				for(int i = 0; i < children.length; i++) {
					if(children[i] instanceof GraphComposite) {
						GraphComposite gc = (GraphComposite)children[i];
						gc.configure(!gc.isSidebarVisible());
						if(gc.isSidebarVisible()) {
							min.setImage(collapseImage);
						} else {
							min.setImage(expandImage);
						}
					}
				}
			}
			if(e.widget == max) {
				Composite c = (Composite) folder.getSelection().getControl();
				Control[] children = c.getChildren();
				for (int i = 0; i < children.length; i++) {
					if (children[i] instanceof GraphComposite) {
						if (!maximized) {
							composite.maximize(shim);
							max.setImage(restoreImage);
							maximized = true;
						} else {
							composite.restore();
							max.setImage(maxImage);
							maximized = false;
						}
					}
				}
			}

		}

	}

	public String getmodulename() {
		return modulename;
	}

	public CTabFolder folder;
	public DragSource dragSource;
	public DropTarget dropTarget;
	private ToolItem close, min, max;
	private GraphComposite gc;
	private String modulename;
	Transfer[] types = new Transfer[] { TextTransfer.getInstance() };

	private static final Image closeImage = DashboardPlugin.getImageDescriptor("icons/actions/graph/close.gif").createImage(); //$NON-NLS-1$
	private static final Image collapseImage = DashboardPlugin.getImageDescriptor("icons/actions/graph/collapse.gif").createImage(); //$NON-NLS-1$
	private static final Image expandImage = DashboardPlugin.getImageDescriptor("icons/actions/graph/expand.gif").createImage(); //$NON-NLS-1$
	private static final Image maxImage = DashboardPlugin.getImageDescriptor("icons/actions/graph/maximize.gif").createImage(); //$NON-NLS-1$
	private static final Image restoreImage = DashboardPlugin.getImageDescriptor("icons/actions/graph/restore.gif").createImage(); //$NON-NLS-1$

}

Back to the top