summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapSettingDialog.java
blob: 760715c63f815c2bb1431933d67b9377fbbf95c7 (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
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
/*******************************************************************************
 * Copyright (c) 2010 Intel 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:
 * Intel - initial API and implementation
 *******************************************************************************/
package org.yocto.sdk.remotetools.actions;

import java.io.File;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.DirectoryDialog;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.yocto.remote.utils.CommonHelper;
import org.yocto.sdk.remotetools.Activator;
import org.yocto.sdk.remotetools.Messages;
import org.yocto.sdk.remotetools.SWTFactory;

public class SystemtapSettingDialog extends Dialog {

	static protected String TITLE="Systemtap Crosstap";
	protected String title;
	protected String metadata_location;
	protected String builddir_location;
	protected String systemtap_script;
	protected String user_id;
	protected String remote_host;
	protected String systemtap_args;
	protected boolean okPressed;
	protected Button metadataLocationBtn;
	protected Button builddirLocationBtn;
	protected Button systemtapScriptBtn;
	protected Text userIDText;
	protected Text remoteHostText;
	protected Text systemtapArgsText;
	protected Text systemtapScriptText;
	protected Text metadataLocationText;
	protected Text builddirLocationText;
	
	protected SystemtapSettingDialog(Shell parentShell, String title) {
		super(parentShell);
		this.title = title;
		this.okPressed = false;
		setShellStyle(getShellStyle() | SWT.RESIZE);
	}
	
	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText(title);
	}

	public boolean isOKPressed() {
		return okPressed;
	}
	
	public String getSystemtapScript() {
		return systemtap_script;
	}
	
	public String getMetadataLocation() {
		return metadata_location;
	}
	
	public String getBuilddirLocation() {
		return builddir_location;
	}

	public String getRemoteHost() {
		return remote_host;
	}
	
	public String getUserID() {
		return user_id;
	}
	
	public String getSystemtapArgs() {
		return systemtap_args;
	}
	@Override
	protected Control createDialogArea(Composite parent) {
		Composite comp=(Composite)super.createDialogArea(parent);
		GridLayout topLayout = new GridLayout();
		comp.setLayout(topLayout);
		
		/*argument*/
		SWTFactory.createVerticalSpacer(comp, 1);
		createInternal(comp);
		
		return comp;
	}
	
	protected void createInternal(Composite parent)
	{
		Composite projComp = new Composite(parent, SWT.NONE);
		GridLayout projLayout = new GridLayout();
		projLayout.numColumns = 2;
		projLayout.marginHeight = 0;
		projLayout.marginWidth = 0;
		projComp.setLayout(projLayout);
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
		projComp.setLayoutData(gd);
		
		Label label = new Label(projComp, SWT.NONE);
		label.setText(Messages.Metadata_Location);
		Composite textContainer = new Composite(projComp, SWT.NONE);
		textContainer.setLayout(new GridLayout(2, false));
		textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		metadataLocationText = (Text)addTextControl(textContainer, metadata_location);
		metadataLocationBtn = addDirSelectButton(textContainer, metadataLocationText);
		
		label = new Label(projComp, SWT.NONE);
		label.setText(Messages.Builddir_Location);
		textContainer = new Composite(projComp, SWT.NONE);
		textContainer.setLayout(new GridLayout(2, false));
		textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		builddirLocationText = (Text)addTextControl(textContainer, builddir_location);
		builddirLocationBtn = addDirSelectButton(textContainer, builddirLocationText);

		label = new Label(projComp, SWT.NONE);
		label.setText(Messages.User_ID);
		userIDText = new Text(projComp, SWT.SINGLE | SWT.BORDER);
		
		if(user_id!=null)
			userIDText.setText(user_id);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 1;
		userIDText.setLayoutData(gd);
		
		label = new Label(projComp, SWT.NONE);
		label.setText(Messages.Remote_Host);
		
		remoteHostText = new Text(projComp, SWT.SINGLE | SWT.BORDER);
		if(remote_host != null)
			remoteHostText.setText(remote_host);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 1;
		remoteHostText.setLayoutData(gd);
		
		label = new Label(projComp, SWT.NONE);
		label.setText(Messages.Systemtap_Script);
		textContainer = new Composite(projComp, SWT.NONE);
		textContainer.setLayout(new GridLayout(2, false));
		textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		systemtapScriptText = (Text)addTextControl(textContainer, systemtap_script);
		systemtapScriptBtn = addFileSelectButton(textContainer, systemtapScriptText);
		
		label = new Label(projComp, SWT.NONE);
		label.setText(Messages.Systemtap_Args);
		
		systemtapArgsText = new Text(projComp, SWT.SINGLE | SWT.BORDER);
		if(systemtap_args != null)
			systemtapArgsText.setText(systemtap_args);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 1;
		systemtapArgsText.setLayoutData(gd);
	}

	private Control addTextControl(final Composite parent, String value) {
		final Text text;

		text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
		text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		if (value != null)
			text.setText(value);
		text.setSize(10, 150);
		return (Control)text;
	}

	private Button addDirSelectButton(final Composite parent, final Text text) {
		Button button = new Button(parent, SWT.PUSH | SWT.LEAD);
		button.setText("Browse");
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent event) {
				String dirName;
				
				dirName = new DirectoryDialog(parent.getShell()).open();
				if (dirName != null) {
					text.setText(dirName);
				}
			}
		});
		return button;
	}		

	private Button addFileSelectButton(final Composite parent, final Text text) {
		Button button = new Button(parent, SWT.PUSH | SWT.LEAD);
		button.setText("Browse");
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent event) {
				String fileName;
				
				fileName = new FileDialog(parent.getShell()).open();
				if (fileName != null) {
					text.setText(fileName);
				}
			}
		});
		return button;
	}		
	
 	@Override
	protected void okPressed() {
		IDialogSettings settings = Activator.getDefault().getDialogSettings();
		metadata_location = metadataLocationText.getText();
		if ( (metadata_location == null) || metadata_location.isEmpty()) {
			CommonHelper.showErrorDialog("SystemTap Error", null, "Please specify your metadata location!");
			return;
		} 
		File metadata_dir = new File(metadata_location);
		if (!metadata_dir.exists()) {
			CommonHelper.showErrorDialog("SystemTap Error", null, "The specified metadata location does not exist!");
			return;
		}
		if (!metadata_dir.isDirectory()) {
			CommonHelper.showErrorDialog("SystemTap Error", null, "The specified metadata location is not a directory!");
			return;
		}
		builddir_location = builddirLocationText.getText();
		if ( (builddir_location == null) || builddir_location.isEmpty()) {
			CommonHelper.showErrorDialog("SystemTap Error", null, "Please specify your builddir location!");
			return;
		}
		File builddir_dir = new File(builddir_location);
		if (!builddir_dir.exists()) {
			CommonHelper.showErrorDialog("SystemTap Error", null, "The specified builddir location does not exist!");
		}
		if (!metadata_dir.isDirectory()) {
			CommonHelper.showErrorDialog("SystemTap Error", null, "The specified builddir location is not a directory!");
			return;
		}
		user_id = userIDText.getText();
		if ( (user_id == null) || user_id.isEmpty()) {
			CommonHelper.showErrorDialog("SystemTap Error", null, "Please specify remote user id!");
			return;
		}
		
		remote_host = remoteHostText.getText();
		if ( (remote_host == null) || remote_host.isEmpty()) {
			CommonHelper.showErrorDialog("SystemTap Error", null, "Please specify remote host IP!");
			return;
		}
		
		systemtap_script = systemtapScriptText.getText();
		if ( (systemtap_script == null) || systemtap_script.isEmpty()) {
			CommonHelper.showErrorDialog("SystemTap Error", null, "Please specify your systemtap script");
			return;
		}
	    File script_file = new File(systemtap_script);
	    if (!script_file.exists()) {
	    	CommonHelper.showErrorDialog("SystemTap Error", null, "The specified systemtap script does not exist!");
			return;
	    }
	    if (!script_file.isFile()) {
	    	CommonHelper.showErrorDialog("SystemTap Error", null, "The specified systemtap script is not a file!");
			return;
	    }
	    systemtap_args = systemtapArgsText.getText();
	    okPressed = true;
		super.okPressed();
	}
}