Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b681382305ef1df446a2eec222c6072241fef378 (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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
/*******************************************************************************
 * Copyright (c) 2012 Red Hat.
 * 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:
 *     Red Hat - Sami Wagiaalla
 *******************************************************************************/

package org.eclipse.linuxtools.internal.systemtap.ui.ide.launcher;

import java.util.ArrayList;
import java.util.LinkedList;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin;
import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IDataSet;
import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IDataSetParser;
import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.row.RowDataSet;
import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.row.RowParser;
import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.GraphData;
import org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets.ExceptionErrorDialog;
import org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.dataset.DataSetFactory;
import org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.graph.GraphFactory;
import org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.graph.SelectGraphWizard;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
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.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;

public class SystemTapScriptGraphOptionsTab extends
		AbstractLaunchConfigurationTab {

	static final String RUN_WITH_CHART = "runWithChart"; //$NON-NLS-1$
	static final String NUMBER_OF_COLUMNS = "numberOfColumns"; //$NON-NLS-1$
	static final String REGEX_BOX = "regexBox_"; //$NON-NLS-1$

	private static final String NUMBER_OF_GRAPHS = "numberOfGraphs"; //$NON-NLS-1$
	private static final String GRAPH_TITLE = "graphTitle"; //$NON-NLS-1$
	private static final String GRAPH_KEY = "graphKey"; //$NON-NLS-1$
	private static final String GRAPH_X_SERIES = "graphXSeries"; //$NON-NLS-1$
	private static final String GRAPH_ID = "graphID"; //$NON-NLS-1$
	private static final String GRAPH_Y_SERIES_LENGTH = "graphYSeriesLength"; //$NON-NLS-1$
	private static final String GRAPH_Y_SERIES = "graphYSeries"; //$NON-NLS-1$

	private ModifyListener regExListener = new ModifyListener() {
		@Override
		public void modifyText(ModifyEvent e) {
			updateLaunchConfigurationDialog();
			refreshRegEx();
		}
	};

	private static final int COLUMNS = 3;
	private static final int MAX_SERIES = 24;

	private Label lblRegEx;
	private Composite textFieldsComposite;

	private Spinner numberOfColumnsSpinner;

	private ScrolledComposite regexTextScrolledComposite;
	private Group outputParsingGroup;
	private Button runWithChartCheckButton;

	private Table graphsTable;
	private Button addGraphButton, duplicateGraphButton, editGraphButton, removeGraphButton;
	private TableItem selectedTableItem;
	private Group graphsGroup;

	public static IDataSetParser createDatasetParser(ILaunchConfiguration configuration) {
		int n;
		try {
			n = configuration.getAttribute(NUMBER_OF_COLUMNS, 0);
			ArrayList<String> regEx = new ArrayList<String>(n * (COLUMNS - 1));

			for (int i = 0; i < (n * COLUMNS); i++) {
				if (i % COLUMNS != 0) {
					String text = configuration.getAttribute(REGEX_BOX + i,
							(String) null);
					regEx.add(text);
				}
			}

			return new RowParser(regEx.toArray(new String[] {}));
		} catch (CoreException e) {
			ExceptionErrorDialog.openError(Messages.SystemTapScriptGraphOptionsTab_0, e);
		}
		return null;
	}

	public static IDataSet createDataset(ILaunchConfiguration configuration) {
		int n;
		try {
			n = configuration.getAttribute(NUMBER_OF_COLUMNS, 0);
			ArrayList<String> labels = new ArrayList<String>(n);

			for (int i = 0; i < (n * COLUMNS); i++) {
				if (i % COLUMNS == 0) {
					String text = configuration.getAttribute(REGEX_BOX + i,
							(String) null);
					labels.add(text);
				}
			}

			return DataSetFactory.createDataSet(RowDataSet.ID, labels.toArray(new String[] {}));
		} catch (CoreException e) {
			ExceptionErrorDialog.openError(Messages.SystemTapScriptGraphOptionsTab_1, e);
		}
		return null;
	}

	public static LinkedList<GraphData> createGraphsFromConfiguration (ILaunchConfiguration configuration) throws CoreException {
		LinkedList<GraphData> graphs = new LinkedList<GraphData>();
		int n = configuration.getAttribute(NUMBER_OF_GRAPHS, 0);
		for (int i = 0; i < n; i++) {
			GraphData graphData = new GraphData();
			graphData.title = configuration.getAttribute (GRAPH_TITLE + i, ""); //$NON-NLS-1$

			graphData.key = configuration.getAttribute(GRAPH_KEY + i, ""); //$NON-NLS-1$
			graphData.xSeries = configuration.getAttribute(GRAPH_X_SERIES + i, 0);
			graphData.graphID = configuration.getAttribute(GRAPH_ID + i, ""); //$NON-NLS-1$

			int ySeriesLength = configuration.getAttribute(GRAPH_Y_SERIES_LENGTH, 0);
			int[] ySeries = new int[ySeriesLength];
			for (int j = 0; j < ySeriesLength; j++) {
				ySeries[j] = configuration.getAttribute(GRAPH_Y_SERIES + i + "_" + j, 0); //$NON-NLS-1$
			}
			graphData.ySeries = ySeries;

			graphs.add(graphData);
		}

		return graphs;
	}

	@Override
	public void createControl(Composite parent) {
		GridLayout layout = new GridLayout();
		Composite top = new Composite(parent, SWT.NONE);
		setControl(top);
		top.setLayout(layout);
		top.setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, true));

		this.runWithChartCheckButton = new Button(top, SWT.CHECK);
		runWithChartCheckButton.setText(Messages.SystemTapScriptGraphOptionsTab_2);
		runWithChartCheckButton.addSelectionListener(new SelectionListener() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				setGraphingEnabled(runWithChartCheckButton.getSelection());
			}

			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				setGraphingEnabled(runWithChartCheckButton.getSelection());
			}
		});

		runWithChartCheckButton.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_3);

		this.outputParsingGroup = new Group(top, SWT.SHADOW_ETCHED_IN);
		outputParsingGroup.setText(Messages.SystemTapScriptGraphOptionsTab_4);
		outputParsingGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
		this.createColumnSelector(outputParsingGroup);

		this.graphsGroup = new Group(top, SWT.SHADOW_ETCHED_IN);
		graphsGroup.setText(Messages.SystemTapScriptGraphOptionsTab_graphsTitle);
		graphsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		createGraphCreateArea(graphsGroup);

		setGraphingEnabled(false);
		runWithChartCheckButton.setSelection(false);
	}

	protected void createColumnSelector(Composite parent) {

		GridLayout layout = new GridLayout();
		parent.setLayout(layout);

		Composite numberOfColumnsComposite = new Composite(parent, SWT.NONE);
		GridLayout twoColumns = new GridLayout();
		twoColumns.numColumns = 2;
		numberOfColumnsComposite.setLayout(twoColumns);

		Label lblSeries = new Label(numberOfColumnsComposite, SWT.NONE);
		lblSeries.setText(Messages.ParsingWizardPage_NumberOfColumns);

		this.numberOfColumnsSpinner = new Spinner (numberOfColumnsComposite, SWT.BORDER);
		numberOfColumnsSpinner.setMinimum(1);
		numberOfColumnsSpinner.setMaximum(MAX_SERIES);
		numberOfColumnsSpinner.setSelection(3);
		numberOfColumnsSpinner.setIncrement(1);
		numberOfColumnsSpinner.addModifyListener(new ModifyListener() {
			@Override
			public void modifyText(ModifyEvent e) {
				refreshRegexRows();
				refreshRegEx();
				updateLaunchConfigurationDialog();
			}
		});

		GridLayout threeColumnLayout = new GridLayout();
		threeColumnLayout.numColumns = 3;
		threeColumnLayout.makeColumnsEqualWidth = true;
		Composite expressionTableLabels = new Composite(parent, SWT.NONE);
		expressionTableLabels.setLayout(threeColumnLayout);
		expressionTableLabels.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

		Label label = new Label(expressionTableLabels, SWT.NONE);
		label.setText(Messages.ParsingWizardPage_Title);
		label.setAlignment(SWT.CENTER);
		label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

		label = new Label(expressionTableLabels, SWT.NONE);
		label.setText(Messages.ParsingWizardPage_RegularExpression);
		label.setAlignment(SWT.CENTER);
		label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

		label = new Label(expressionTableLabels, SWT.NONE);
		label.setText(Messages.ParsingWizardPage_Delimiter);
		label.setAlignment(SWT.CENTER);
		label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

		this.regexTextScrolledComposite = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		regexTextScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

		textFieldsComposite = new Composite(regexTextScrolledComposite, SWT.NONE);
		textFieldsComposite.setLayout(threeColumnLayout);
		textFieldsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
		regexTextScrolledComposite.setContent(textFieldsComposite);
		regexTextScrolledComposite.setExpandHorizontal(true);
		regexTextScrolledComposite.setExpandVertical(true);

		Composite regexSummaryComposite = new Composite(parent, SWT.NONE);
		regexSummaryComposite.setLayout(twoColumns);

		Label lblRegExTitle = new Label(regexSummaryComposite, SWT.NONE);
		lblRegExTitle.setText(Messages.ParsingWizardPage_RegularExpression + ":"); //$NON-NLS-1$
		lblRegEx = new Label(regexSummaryComposite, SWT.NONE);
		lblRegEx.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

		refreshRegexRows();
	}

	private IDataSet getDataset() {
		int n = this.numberOfColumnsSpinner.getSelection();
		ArrayList<String> labels = new ArrayList<String>(n);
		Control[] regExTexts = textFieldsComposite.getChildren();

		for (int i = 0; i < (n * COLUMNS); i++) {
			if (i % COLUMNS == 0) {
				String text = ((Text)regExTexts[i]).getText();
				labels.add(text);
			}
		}
		return DataSetFactory.createDataSet(RowDataSet.ID, labels.toArray(new String[] {}));
	}

	private void createGraphCreateArea(Composite comp){
		GridLayout twoColumnsLayout = new GridLayout();
		comp.setLayout(twoColumnsLayout);
		twoColumnsLayout.numColumns = 2;

		graphsTable = new Table(comp, SWT.SINGLE | SWT.BORDER);
		GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
		graphsTable.setLayoutData(layoutData);

		// Button to add another graph
		Composite buttonComposite = new Composite(comp, SWT.NONE);
		buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));

		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 1;

		buttonComposite.setLayout(gridLayout);
		// Button to add a new graph
		addGraphButton = new Button(buttonComposite, SWT.PUSH);
		addGraphButton.setText(Messages.SystemTapScriptGraphOptionsTab_AddGraphButton);
		addGraphButton.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_AddGraphButtonToolTip);
		addGraphButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

		// Button to copy an existing graph
		duplicateGraphButton = new Button(buttonComposite, SWT.PUSH);
		duplicateGraphButton.setText(Messages.SystemTapScriptGraphOptionsTab_DuplicateGraphButton);
		duplicateGraphButton.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_DuplicateGraphButtonToolTip);
		duplicateGraphButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

		// Button to edit an existing graph
		editGraphButton = new Button(buttonComposite, SWT.PUSH);
		editGraphButton.setText(Messages.SystemTapScriptGraphOptionsTab_EditGraphButton);
		editGraphButton.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_EditGraphButtonToolTip);
		editGraphButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

		// Button to remove the selected graph/filter
		removeGraphButton = new Button(buttonComposite, SWT.PUSH);
		removeGraphButton.setText(Messages.SystemTapScriptGraphOptionsTab_RemoveGraphButton);
		removeGraphButton.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_RemoveGraphButtonToolTip);
		removeGraphButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

		// Action to notify the buttons when to enable/disable themselves based
		// on list selection
		graphsTable.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				selectedTableItem = (TableItem) e.item;
				setSelectionControlsEnabled(true);
			}
		});

		// Brings up a new dialog box when user clicks the add button. Allows
		// selecting a new graph to display.
		addGraphButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				SelectGraphWizard wizard = new SelectGraphWizard(getDataset(), null);
				IWorkbench workbench = PlatformUI.getWorkbench();
				wizard.init(workbench, null);
				WizardDialog dialog = new WizardDialog(workbench
						.getActiveWorkbenchWindow().getShell(), wizard);
				dialog.create();
				dialog.open();

				GraphData gd = wizard.getGraphData();

				if (null != gd) {
					TableItem item = new TableItem(graphsTable, SWT.NONE);
					item.setText(GraphFactory.getGraphName(gd.graphID) + ":" //$NON-NLS-1$
							+ gd.title);
					item.setData(gd);
					updateLaunchConfigurationDialog();
				}
			}
		});

		// Adds a new entry to the list of graphs that is a copy of the one selected.
		duplicateGraphButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				GraphData gd = (GraphData) selectedTableItem.getData();

				TableItem item = new TableItem(graphsTable, SWT.NONE);
				item.setText(GraphFactory.getGraphName(gd.graphID) + ":" //$NON-NLS-1$
						+ gd.title);
				item.setData(gd);
				updateLaunchConfigurationDialog();
			}
		});

		// When button is clicked, brings up same wizard as the one for adding
		// a graph. Data in the wizard is filled out to match the properties
		// of the selected graph.
		editGraphButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				SelectGraphWizard wizard = new SelectGraphWizard(getDataset(),
						(GraphData) selectedTableItem.getData());
				IWorkbench workbench = PlatformUI.getWorkbench();
				wizard.init(workbench, null);
				WizardDialog dialog = new WizardDialog(workbench
						.getActiveWorkbenchWindow().getShell(), wizard);
				dialog.create();
				dialog.open();

				GraphData gd = wizard.getGraphData();

				if (null != gd) {
					selectedTableItem.setText(GraphFactory.getGraphName(gd.graphID) + ":" //$NON-NLS-1$
							+ gd.title);
					selectedTableItem.setData(gd);
					updateLaunchConfigurationDialog();
				}
			}
		});

		// Removes the selected graph/filter from the table
		removeGraphButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				selectedTableItem.dispose();
				setSelectionControlsEnabled(false);
				updateLaunchConfigurationDialog();
			}
		});
	}

	private void refreshRegexRows() {
		int numberOfColumns = numberOfColumnsSpinner.getSelection();
		int currentNumberOfColumns = textFieldsComposite.getChildren().length/3;

		while (currentNumberOfColumns < numberOfColumns){
			addColumn();
			currentNumberOfColumns++;
		}

		while (currentNumberOfColumns > numberOfColumns){
			removeColumn();
			currentNumberOfColumns--;
		}

		refreshRegEx();
	}

	private void addColumn(){
		Text text = new Text(textFieldsComposite, SWT.BORDER);
		text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
		text.addModifyListener(regExListener);

		text = new Text(textFieldsComposite, SWT.BORDER);
		text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
		text.setText("\\d+"); //$NON-NLS-1$
		text.addModifyListener(regExListener);

		text = new Text(textFieldsComposite, SWT.BORDER);
		text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
		text.setText("\\D+"); //$NON-NLS-1$
		text.addModifyListener(regExListener);

		regexTextScrolledComposite.setMinSize(textFieldsComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		textFieldsComposite.layout();
	}

	private void removeColumn(){
		Control[] children = textFieldsComposite.getChildren();
		int i = children.length - 1;
		children[i--].dispose();
		children[i--].dispose();
		children[i--].dispose();

		regexTextScrolledComposite.setMinSize(textFieldsComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		textFieldsComposite.layout();
	}

	private void refreshRegEx() {
		int series = numberOfColumnsSpinner.getSelection();
		series *= COLUMNS;
		StringBuilder s = new StringBuilder();
		for(int i=0; i<series; i++) {
			if(0 != i%COLUMNS) {
				s.append(((Text)textFieldsComposite.getChildren()[i]).getText());
			}
		}
		lblRegEx.setText(s.toString());
		lblRegEx.getParent().pack();
	}

	public boolean canFlipToNextPage() {
		return false;
	}

	@Override
	public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
		configuration.setAttribute(RUN_WITH_CHART, false);
		configuration.setAttribute(NUMBER_OF_COLUMNS, 3);
		configuration.setAttribute(NUMBER_OF_GRAPHS, 0);
	}

	@Override
	public void initializeFrom(ILaunchConfiguration configuration) {
		try {
			boolean chart = configuration.getAttribute(RUN_WITH_CHART, false);
			setGraphingEnabled(chart);
			this.runWithChartCheckButton.setSelection(chart);

			int n = configuration.getAttribute(NUMBER_OF_COLUMNS, 0);
			numberOfColumnsSpinner.setSelection(n);
			Control[] textBoxes = this.textFieldsComposite.getChildren();
			for (int i = 0; i < textBoxes.length; i++) {
				String text = configuration.getAttribute(REGEX_BOX+i, (String)null);
				if (text != null) {
					((Text)textBoxes[i]).setText(text);
				}
			}

			// Add graphs
			graphsTable.removeAll();
			LinkedList<GraphData> graphs = createGraphsFromConfiguration(configuration);
			for (GraphData graphData : graphs) {
				TableItem item = new TableItem(graphsTable, SWT.NONE);
				item.setText(GraphFactory.getGraphName(graphData.graphID) + ":" //$NON-NLS-1$
						+ graphData.title);
				item.setData(graphData);
			}

		} catch (CoreException e) {
			ExceptionErrorDialog.openError(Messages.SystemTapScriptGraphOptionsTab_5, e);
		}
	}

	@Override
	public void performApply(ILaunchConfigurationWorkingCopy configuration) {
		configuration.setAttribute(RUN_WITH_CHART, this.runWithChartCheckButton.getSelection());

		int n = numberOfColumnsSpinner.getSelection();
		configuration.setAttribute(NUMBER_OF_COLUMNS, n);
		Control[] textBoxes = this.textFieldsComposite.getChildren();
		for (int i = 0; i < textBoxes.length; i++) {
			String text = ((Text)textBoxes[i]).getText();
			configuration.setAttribute(REGEX_BOX+i, text);
		}

		// Save graphs.
		TableItem[] list = this.graphsTable.getItems();
		configuration.setAttribute(NUMBER_OF_GRAPHS, list.length);
		for (int i = 0; i < list.length; i++) {
			GraphData graphData = (GraphData)list[i].getData();
			configuration.setAttribute(GRAPH_TITLE + i, graphData.title);

			configuration.setAttribute(GRAPH_KEY + i, graphData.key);
			configuration.setAttribute(GRAPH_X_SERIES + i, graphData.xSeries);
			configuration.setAttribute(GRAPH_ID + i, graphData.graphID);

			configuration.setAttribute(GRAPH_Y_SERIES_LENGTH, graphData.ySeries.length);
			for (int j = 0; j < graphData.ySeries.length; j++) {
				configuration.setAttribute(GRAPH_Y_SERIES + i + "_" + j, graphData.ySeries[j]); //$NON-NLS-1$
			}
		}
	}

	@Override
	public boolean isValid(ILaunchConfiguration launchConfig) {
		setErrorMessage(null);

		// If graphic is disabled then everything is valid.
		if (this.runWithChartCheckButton.getSelection() == false){
			return true;
		}

		// Check that all regex boxes are filled in
		int series = numberOfColumnsSpinner.getSelection();

		for(int i=0; i<(series*COLUMNS); i++) {
			if(((Text)textFieldsComposite.getChildren()[i]).getText().isEmpty()) {
				setErrorMessage(Messages.SystemTapScriptGraphOptionsTab_6);
				return false;
			}
		}

		return true;
	}

	@Override
	public String getName() {
		return Messages.SystemTapScriptGraphOptionsTab_7;
	}

	@Override
	public Image getImage() {
		return AbstractUIPlugin.imageDescriptorFromPlugin(IDEPlugin.PLUGIN_ID,
				"icons/graphing_tab.gif").createImage(); //$NON-NLS-1$
	}

	private void setGraphingEnabled(boolean enabled){
		this.setControlEnabled(outputParsingGroup, enabled);
		this.setControlEnabled(graphsGroup, enabled);
		// Disable buttons that rely on a selected graph if no graph is selected.
		this.setSelectionControlsEnabled(selectedTableItem != null);
		updateLaunchConfigurationDialog();
	}

	private void setControlEnabled(Composite composite, boolean enabled){
		composite.setEnabled(enabled);
		for (Control child : composite.getChildren()) {
				child.setEnabled(enabled);
			if(child instanceof Composite){
				setControlEnabled((Composite)child, enabled);
			}
		}
	}

	/**
	 * Call this to enable/disable all buttons whose actions depend on a selected graph.
	 * @param enabled Set to true to enable the buttons; set to false to disable them.
	 */
	private void setSelectionControlsEnabled(boolean enabled) {
		duplicateGraphButton.setEnabled(enabled);
		editGraphButton.setEnabled(enabled);
		removeGraphButton.setEnabled(enabled);
	}
}

Back to the top