~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/launcher/SystemTapScriptLaunchConfigurationTab.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-05-13 21:43:22 UTC
  • mfrom: (1.2.1) (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130513214322-6frgd9du1n0w2uo7
Tags: 1.2.1-1
* Team upload.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 *     Red Hat - Sami Wagiaalla
 
10
 *******************************************************************************/
 
11
 
 
12
package org.eclipse.linuxtools.internal.systemtap.ui.ide.launcher;
 
13
 
 
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;
 
40
 
 
41
public class SystemTapScriptLaunchConfigurationTab extends
 
42
                AbstractLaunchConfigurationTab {
 
43
 
 
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$
 
50
 
 
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;
 
60
 
 
61
        public void createControl(Composite parent) {
 
62
 
 
63
                GridLayout layout = new GridLayout();
 
64
                Composite top = new Composite(parent, SWT.NONE);
 
65
                setControl(top);
 
66
                top.setLayout(layout);
 
67
                top.setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, true));
 
68
 
 
69
                // Script path
 
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();
 
81
                        }
 
82
                });
 
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);
 
88
 
 
89
                // User Settings
 
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));
 
95
 
 
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);
 
102
 
 
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));
 
107
 
 
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));
 
112
 
 
113
                userSettingsGroup.setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, false));
 
114
                userSettingsGroup.setText(Messages.SystemTapScriptLaunchConfigurationTab_5);
 
115
 
 
116
                currentUserCheckButton.addSelectionListener(new SelectionListener() {
 
117
                        public void widgetSelected(SelectionEvent e) {
 
118
                                update();
 
119
                        }
 
120
 
 
121
                        public void widgetDefaultSelected(SelectionEvent e) {
 
122
                                update();
 
123
                        }
 
124
                        
 
125
                        private void update(){
 
126
                                boolean enable = !currentUserCheckButton.getSelection();
 
127
                                setUserGroupEnablement(enable);
 
128
                                updateLaunchConfigurationDialog();
 
129
                        }
 
130
                });
 
131
 
 
132
                userNameText.addModifyListener(new ModifyListener() {
 
133
                        public void modifyText(ModifyEvent e) {
 
134
                                updateLaunchConfigurationDialog();
 
135
                        }
 
136
                });
 
137
 
 
138
                userPasswordText.addModifyListener(new ModifyListener() {
 
139
                        public void modifyText(ModifyEvent e) {
 
140
                                updateLaunchConfigurationDialog();
 
141
                        }
 
142
                });
 
143
 
 
144
                setUserGroupEnablement(false);
 
145
 
 
146
                // Host settings
 
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;
 
153
 
 
154
                this.localHostCheckButton = new Button(hostSettingsGroup, SWT.CHECK);
 
155
                localHostCheckButton.setText(Messages.SystemTapScriptLaunchConfigurationTab_7);
 
156
                gridData = new GridData();
 
157
                gridData.horizontalSpan = 2;
 
158
 
 
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) {
 
166
                                update();
 
167
                        }
 
168
 
 
169
                        public void widgetDefaultSelected(SelectionEvent e) {
 
170
                                update();
 
171
                        }
 
172
 
 
173
                        private void update(){
 
174
                                updateLaunchConfigurationDialog();
 
175
                        }
 
176
                });
 
177
                hostNameText.addModifyListener(new ModifyListener() {
 
178
                        public void modifyText(ModifyEvent e) {
 
179
                                updateLaunchConfigurationDialog();
 
180
                        }
 
181
                });
 
182
        }
 
183
 
 
184
        private void setUserGroupEnablement(boolean enable){
 
185
                userNameText.setEnabled(enable);
 
186
                userNameLabel.setEnabled(enable);
 
187
                userPasswordText.setEnabled(enable);
 
188
                userPasswordLabel.setEnabled(enable);
 
189
        }
 
190
 
 
191
        private void setHostGroupEnablement(boolean enable){
 
192
                hostNamelabel.setEnabled(enable);
 
193
                hostNameText.setEnabled(enable);
 
194
        }
 
195
 
 
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$
 
203
        }
 
204
 
 
205
        public void initializeFrom(ILaunchConfiguration configuration) {
 
206
                try {
 
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) {
 
214
                        e.printStackTrace();
 
215
                }
 
216
        }
 
217
 
 
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());
 
225
 
 
226
                boolean enable = !currentUserCheckButton.getSelection();
 
227
                setUserGroupEnablement(enable);
 
228
 
 
229
                enable = !localHostCheckButton.getSelection();
 
230
                setHostGroupEnablement(enable);
 
231
        }
 
232
 
 
233
        public String getName() {
 
234
                return Messages.SystemTapScriptLaunchConfigurationTab_9; 
 
235
        }
 
236
 
 
237
        private String getSelectedScriptPath(){
 
238
                IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
 
239
 
 
240
                String pathString = ""; //$NON-NLS-1$
 
241
 
 
242
                if (window != null)
 
243
                {
 
244
                        ISelection selection = window.getSelectionService().getSelection();
 
245
 
 
246
                        // Figure out the selected systemtap script
 
247
                        if (selection instanceof TreeSelection){
 
248
                                Object selectedElement = ((TreeSelection)selection).getFirstElement();
 
249
                                if (selectedElement instanceof IFile)
 
250
                                {
 
251
                                        IPath path = ((IFile)selectedElement).getLocation();
 
252
                                        pathString = path.toOSString();
 
253
                                }
 
254
                        }
 
255
 
 
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();
 
261
                                else
 
262
                            pathString = ResourceUtil.getFile(ed.getEditorInput()).getLocation().toString();
 
263
                        }
 
264
                }
 
265
 
 
266
                if (pathString.endsWith(SystemTapScriptTester.STP_SUFFIX))
 
267
                        return pathString;
 
268
 
 
269
                return ""; //$NON-NLS-1$
 
270
        }
 
271
 
 
272
}