1
/*******************************************************************************
2
* Copyright (c) 2012 Red Hat.
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
9
* Red Hat - Sami Wagiaalla
10
*******************************************************************************/
12
package org.eclipse.linuxtools.internal.systemtap.ui.ide.launcher;
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.debug.core.ILaunchConfiguration;
18
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
19
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
20
import org.eclipse.jface.text.TextSelection;
21
import org.eclipse.jface.viewers.ISelection;
22
import org.eclipse.jface.viewers.TreeSelection;
23
import org.eclipse.linuxtools.systemtap.ui.editor.PathEditorInput;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.events.ModifyEvent;
26
import org.eclipse.swt.events.ModifyListener;
27
import org.eclipse.swt.events.SelectionEvent;
28
import org.eclipse.swt.events.SelectionListener;
29
import org.eclipse.swt.layout.GridData;
30
import org.eclipse.swt.layout.GridLayout;
31
import org.eclipse.swt.widgets.Button;
32
import org.eclipse.swt.widgets.Composite;
33
import org.eclipse.swt.widgets.Group;
34
import org.eclipse.swt.widgets.Label;
35
import org.eclipse.swt.widgets.Text;
36
import org.eclipse.ui.IEditorPart;
37
import org.eclipse.ui.IWorkbenchWindow;
38
import org.eclipse.ui.PlatformUI;
39
import org.eclipse.ui.ide.ResourceUtil;
41
public class SystemTapScriptLaunchConfigurationTab extends
42
AbstractLaunchConfigurationTab {
44
static final String SCRIPT_PATH_ATTR = "ScriptPath"; //$NON-NLS-1$
45
static final String CURRENT_USER_ATTR = "executeAsCurrentUser"; //$NON-NLS-1$
46
static final String USER_NAME_ATTR = "userName"; //$NON-NLS-1$
47
static final String USER_PASS_ATTR = "userPassword"; //$NON-NLS-1$
48
static final String LOCAL_HOST_ATTR = "executeOnLocalHost"; //$NON-NLS-1$
49
static final String HOST_NAME_ATTR = "hostName"; //$NON-NLS-1$
51
private Text scriptPathText;
52
private Button currentUserCheckButton;
53
private Text userNameText;
54
private Text userPasswordText;
55
private Button localHostCheckButton;
56
private Text hostNameText;
57
private Label userNameLabel;
58
private Label userPasswordLabel;
59
private Label hostNamelabel;
61
public void createControl(Composite parent) {
63
GridLayout layout = new GridLayout();
64
Composite top = new Composite(parent, SWT.NONE);
66
top.setLayout(layout);
67
top.setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, true));
70
Group scriptSettingsGroup = new Group(top, SWT.SHADOW_ETCHED_IN);
71
scriptSettingsGroup.setText(Messages.SystemTapScriptLaunchConfigurationTab_0);
72
scriptSettingsGroup.setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, false));
73
layout = new GridLayout();
74
layout.numColumns = 2;
75
scriptSettingsGroup.setLayout(layout);
76
this.scriptPathText = new Text(scriptSettingsGroup, SWT.SINGLE | SWT.BORDER);
77
scriptPathText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
78
scriptPathText.addModifyListener(new ModifyListener() {
79
public void modifyText(ModifyEvent e) {
80
updateLaunchConfigurationDialog();
83
Button selectScriptButon = new Button(scriptSettingsGroup, 0);
84
GridData gridData = new GridData();
85
gridData.widthHint = 110;
86
selectScriptButon.setLayoutData(gridData);
87
selectScriptButon.setText(Messages.SystemTapScriptLaunchConfigurationTab_1);
90
Group userSettingsGroup = new Group(top, SWT.SHADOW_ETCHED_IN);
91
layout = new GridLayout();
92
userSettingsGroup.setLayout(layout);
93
layout.numColumns = 2;
94
userSettingsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
96
this.currentUserCheckButton = new Button(userSettingsGroup, SWT.CHECK);
97
currentUserCheckButton.setText(Messages.SystemTapScriptLaunchConfigurationTab_2);
98
currentUserCheckButton.setSelection(true);
99
gridData = new GridData();
100
gridData.horizontalSpan = 2;
101
currentUserCheckButton.setLayoutData(gridData);
103
this.userNameLabel = new Label(userSettingsGroup, SWT.NONE);
104
userNameLabel.setText(Messages.SystemTapScriptLaunchConfigurationTab_3);
105
this.userNameText = new Text(userSettingsGroup, SWT.SINGLE | SWT.BORDER);
106
userNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
108
this.userPasswordLabel = new Label(userSettingsGroup, SWT.NONE);
109
userPasswordLabel.setText(Messages.SystemTapScriptLaunchConfigurationTab_4);
110
this.userPasswordText = new Text(userSettingsGroup, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
111
userPasswordText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
113
userSettingsGroup.setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, false));
114
userSettingsGroup.setText(Messages.SystemTapScriptLaunchConfigurationTab_5);
116
currentUserCheckButton.addSelectionListener(new SelectionListener() {
117
public void widgetSelected(SelectionEvent e) {
121
public void widgetDefaultSelected(SelectionEvent e) {
125
private void update(){
126
boolean enable = !currentUserCheckButton.getSelection();
127
setUserGroupEnablement(enable);
128
updateLaunchConfigurationDialog();
132
userNameText.addModifyListener(new ModifyListener() {
133
public void modifyText(ModifyEvent e) {
134
updateLaunchConfigurationDialog();
138
userPasswordText.addModifyListener(new ModifyListener() {
139
public void modifyText(ModifyEvent e) {
140
updateLaunchConfigurationDialog();
144
setUserGroupEnablement(false);
147
Group hostSettingsGroup = new Group(top, SWT.SHADOW_ETCHED_IN);
148
hostSettingsGroup.setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, false));
149
hostSettingsGroup.setText(Messages.SystemTapScriptLaunchConfigurationTab_6);
150
layout = new GridLayout();
151
hostSettingsGroup.setLayout(layout);
152
layout.numColumns = 2;
154
this.localHostCheckButton = new Button(hostSettingsGroup, SWT.CHECK);
155
localHostCheckButton.setText(Messages.SystemTapScriptLaunchConfigurationTab_7);
156
gridData = new GridData();
157
gridData.horizontalSpan = 2;
159
this.hostNamelabel = new Label(hostSettingsGroup, SWT.NONE);
160
hostNamelabel.setText(Messages.SystemTapScriptLaunchConfigurationTab_8);
161
this.hostNameText = new Text(hostSettingsGroup, SWT.SINGLE | SWT.BORDER);
162
hostNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
163
localHostCheckButton.setLayoutData(gridData);
164
localHostCheckButton.addSelectionListener(new SelectionListener() {
165
public void widgetSelected(SelectionEvent e) {
169
public void widgetDefaultSelected(SelectionEvent e) {
173
private void update(){
174
updateLaunchConfigurationDialog();
177
hostNameText.addModifyListener(new ModifyListener() {
178
public void modifyText(ModifyEvent e) {
179
updateLaunchConfigurationDialog();
184
private void setUserGroupEnablement(boolean enable){
185
userNameText.setEnabled(enable);
186
userNameLabel.setEnabled(enable);
187
userPasswordText.setEnabled(enable);
188
userPasswordLabel.setEnabled(enable);
191
private void setHostGroupEnablement(boolean enable){
192
hostNamelabel.setEnabled(enable);
193
hostNameText.setEnabled(enable);
196
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
197
configuration.setAttribute(SCRIPT_PATH_ATTR, this.getSelectedScriptPath());
198
configuration.setAttribute(CURRENT_USER_ATTR, true);
199
configuration.setAttribute(USER_NAME_ATTR, ""); //$NON-NLS-1$
200
configuration.setAttribute(USER_PASS_ATTR, ""); //$NON-NLS-1$
201
configuration.setAttribute(LOCAL_HOST_ATTR, true);
202
configuration.setAttribute(HOST_NAME_ATTR, ""); //$NON-NLS-1$
205
public void initializeFrom(ILaunchConfiguration configuration) {
207
this.scriptPathText.setText(configuration.getAttribute(SCRIPT_PATH_ATTR, "")); //$NON-NLS-1$
208
this.currentUserCheckButton.setSelection(configuration.getAttribute(CURRENT_USER_ATTR, true));
209
this.userNameText.setText(configuration.getAttribute(USER_NAME_ATTR, "")); //$NON-NLS-1$
210
this.userPasswordText.setText(configuration.getAttribute(USER_PASS_ATTR, "")); //$NON-NLS-1$
211
this.localHostCheckButton.setSelection(configuration.getAttribute(LOCAL_HOST_ATTR, true));
212
this.hostNameText.setText(configuration.getAttribute(HOST_NAME_ATTR, "")); //$NON-NLS-1$
213
} catch (CoreException e) {
218
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
219
configuration.setAttribute(SCRIPT_PATH_ATTR, this.scriptPathText.getText());
220
configuration.setAttribute(CURRENT_USER_ATTR, this.currentUserCheckButton.getSelection());
221
configuration.setAttribute(USER_NAME_ATTR, this.userNameText.getText());
222
configuration.setAttribute(USER_PASS_ATTR, this.userPasswordText.getText());
223
configuration.setAttribute(LOCAL_HOST_ATTR, this.localHostCheckButton.getSelection());
224
configuration.setAttribute(HOST_NAME_ATTR, this.hostNameText.getText());
226
boolean enable = !currentUserCheckButton.getSelection();
227
setUserGroupEnablement(enable);
229
enable = !localHostCheckButton.getSelection();
230
setHostGroupEnablement(enable);
233
public String getName() {
234
return Messages.SystemTapScriptLaunchConfigurationTab_9;
237
private String getSelectedScriptPath(){
238
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
240
String pathString = ""; //$NON-NLS-1$
244
ISelection selection = window.getSelectionService().getSelection();
246
// Figure out the selected systemtap script
247
if (selection instanceof TreeSelection){
248
Object selectedElement = ((TreeSelection)selection).getFirstElement();
249
if (selectedElement instanceof IFile)
251
IPath path = ((IFile)selectedElement).getLocation();
252
pathString = path.toOSString();
256
// If it is a text selection use the path from the active editor.
257
if (selection instanceof TextSelection){
258
IEditorPart ed = window.getActivePage().getActiveEditor();
259
if(ed.getEditorInput() instanceof PathEditorInput)
260
pathString = ((PathEditorInput)ed.getEditorInput()).getPath().toString();
262
pathString = ResourceUtil.getFile(ed.getEditorInput()).getLocation().toString();
266
if (pathString.endsWith(SystemTapScriptTester.STP_SUFFIX))
269
return ""; //$NON-NLS-1$