aboutsummaryrefslogtreecommitdiffstats
blob: 187ba65a9a2a260937c3d8b555e3238746449075 (plain)
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
/********************************************************************************
 * Copyright (c) 2008 Motorola Inc. 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
 *
 * Initial Contributor:
 * Otávio Ferranti (Motorola)
 *
 * Contributors:
 * {Name} (company) - description of contribution.
 ********************************************************************************/

package org.eclipse.tml.linuxtools.tools.cpuload;

import org.eclipse.tml.linuxtools.tools.ITool;

import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

/**
 * @author Otávio Ferranti
 */
public class DialogOptions extends TitleAreaDialog {

	final private String WINDOW_TITLE = Messages.OptionsDialog_Window_Title;
	final private String WINDOW_MESSAGE = Messages.OptionsDialog_Window_Message; 
	final private String LABEL_REFRESH = Messages.OptionsDialog_Label_Refresh_Rate;
	final private String LABEL_TIMEUNIT = "ms"; //$NON-NLS-1$

	private Spinner spinner;
	
	private ITool tool = null;
	
	/**
	 * The constructor.
	 * @param parent
	 */
	public DialogOptions(Shell parent, ITool tool) {
		super(parent);
		this.tool = tool;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
	protected Control createDialogArea(Composite parent) {
		setTitle(WINDOW_TITLE);
		setMessage(WINDOW_MESSAGE);
		
		Composite dialogArea = new Composite(parent, SWT.NONE);
		GridLayout gridLayout = new GridLayout(3, false);
		
		gridLayout.marginLeft = 7;
		gridLayout.marginRight = 7;
		
		dialogArea.setLayout(gridLayout);
		dialogArea.setLayoutData(new GridData(GridData.FILL_BOTH));
		dialogArea.setFont(parent.getFont());
	
		Label refreshLabel = new Label(dialogArea, SWT.NULL);
		refreshLabel.setText(LABEL_REFRESH);
		
		spinner = new Spinner(dialogArea, SWT.BORDER);
		
		Label timeUnit = new Label(dialogArea, SWT.NULL);
		timeUnit.setText(LABEL_TIMEUNIT);
				
		spinner.setMinimum(0);
		spinner.setMaximum(50000);
		spinner.setSelection(tool.getRefreshDelay());
		spinner.setIncrement(100);
		spinner.setPageIncrement(500);
		spinner.pack();
		
		return dialogArea;
	}
	
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.TitleAreaDialog#getInitialSize()
	 */
	protected Point getInitialSize() {
		return super.getInitialSize();
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
	 */
	protected void okPressed() {
		tool.setRefreshDelay(spinner.getSelection());
		super.okPressed();
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#cancelPressed()
	 */
	protected void cancelPressed() {
		super.cancelPressed();
	}
}