Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ce9d7467605492dfcdccf2ec32ea3eae6d5a3809 (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
/*******************************************************************************
 * 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 static org.eclipse.linuxtools.internal.systemtap.ui.ide.preferences.IDEPreferenceConstants.KEY;
import static org.eclipse.linuxtools.internal.systemtap.ui.ide.preferences.IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS;
import static org.eclipse.linuxtools.internal.systemtap.ui.ide.preferences.IDEPreferenceConstants.STAP_CMD_OPTION;

import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin;
import org.eclipse.linuxtools.internal.systemtap.ui.ide.preferences.IDEPreferenceConstants;
import org.eclipse.linuxtools.systemtap.graphing.ui.widgets.ExceptionErrorDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
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.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;

public class SystemTapScriptOptionsTab extends AbstractLaunchConfigurationTab {

    static final String MISC_COMMANDLINE_OPTIONS = "MiscComandLineOptions"; //$NON-NLS-1$

    private Button checkBox[] = new Button[IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS.length];
    private Text text[] = new Text[IDEPreferenceConstants.STAP_STRING_OPTIONS.length];
    private Text targetProgramText;

    private ModifyListener modifyListener = new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            updateLaunchConfigurationDialog();
        }
    };
    private FileDialog fileDialog;
    private Text miscCommandsText;

    private Button dyninstCheckBox;

    private Text targetPidText;

    @Override
    public void createControl(Composite parent) {

        GridLayout singleColumnGridLayout = new GridLayout();
        singleColumnGridLayout.numColumns = 1;
        Composite comp = new Composite(parent, SWT.NONE);
        setControl(comp);
        comp.setLayout(singleColumnGridLayout);
        comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        this.fileDialog = new FileDialog(PlatformUI.getWorkbench()
                .getActiveWorkbenchWindow().getShell(), SWT.OPEN);
        fileDialog.setText(Messages.SystemTapScriptOptionsTab_selectExec);
        fileDialog.setFilterPath(Platform.getLocation().toOSString());
        // Target Executable path
        Group targetExecutableGroup = new Group(comp, SWT.SHADOW_ETCHED_IN);
        targetExecutableGroup.setText(Messages.SystemTapScriptOptionsTab_targetExec);
        targetExecutableGroup
                .setToolTipText(Messages.SystemTapScriptOptionsTab_targetToolTip);

        targetExecutableGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
                true, false));
        GridLayout twoColumnGridLayout = new GridLayout();
        twoColumnGridLayout.numColumns = 2;
        targetExecutableGroup.setLayout(twoColumnGridLayout);
        this.targetProgramText = new Text(targetExecutableGroup, SWT.SINGLE
                | SWT.BORDER);
        targetProgramText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
                true));
        targetProgramText.addModifyListener(modifyListener);
        Button selectTargetProgramButton = new Button(targetExecutableGroup, 0);
        GridData gridData = new GridData();

        selectTargetProgramButton.setLayoutData(gridData);
        selectTargetProgramButton
                .setText(Messages.SystemTapScriptLaunchConfigurationTab_browse);
        selectTargetProgramButton.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                String fileName = fileDialog.open();
                if (fileName != null) {
                    targetProgramText.setText(fileName);
                }
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });

        // Check boxes
        Composite cmpChkBoxes = new Composite(comp, SWT.NONE);
        cmpChkBoxes.setLayout(twoColumnGridLayout);
        cmpChkBoxes.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

        for (int i = 0; i < IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS.length; i++) {
            checkBox[i] = new Button(cmpChkBoxes, SWT.CHECK);
            checkBox[i]
                    .setText(IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS[i][IDEPreferenceConstants.LABEL]
                            + " (" + IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS[i][IDEPreferenceConstants.FLAG] + ")"); //$NON-NLS-1$//$NON-NLS-2$
            checkBox[i].addSelectionListener(new SelectionListener() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    updateLaunchConfigurationDialog();
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                    updateLaunchConfigurationDialog();
                }
            });
            checkBox[i]
                    .setToolTipText(IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS[i][IDEPreferenceConstants.TOOLTIP]);

            if (IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS[i][IDEPreferenceConstants.FLAG]
                    .contains(Messages.SystemTapScriptOptionsTab_dyninst)) {
                this.dyninstCheckBox = checkBox[i];
            }
        }

        // Labels and Text fields
        Composite cmpTxtBoxes = new Composite(comp, SWT.NONE);
        cmpTxtBoxes.setLayout(twoColumnGridLayout);
        cmpTxtBoxes.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

        Label label;
        for (int i = 0; i < IDEPreferenceConstants.STAP_STRING_OPTIONS.length; i++) {
            label = new Label(cmpTxtBoxes, SWT.NONE);
            label.setText(IDEPreferenceConstants.STAP_STRING_OPTIONS[i][IDEPreferenceConstants.LABEL]
                    + " (" + IDEPreferenceConstants.STAP_STRING_OPTIONS[i][IDEPreferenceConstants.FLAG] + ")"); //$NON-NLS-1$ //$NON-NLS-2$
            label.setToolTipText(IDEPreferenceConstants.STAP_STRING_OPTIONS[i][IDEPreferenceConstants.TOOLTIP]);
            text[i] = new Text(cmpTxtBoxes, SWT.BORDER);
            text[i].setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, true));
            text[i].addModifyListener(modifyListener);
            text[i].setToolTipText(IDEPreferenceConstants.STAP_STRING_OPTIONS[i][IDEPreferenceConstants.TOOLTIP]);

            if (IDEPreferenceConstants.STAP_STRING_OPTIONS[i][IDEPreferenceConstants.FLAG]
                    .contains("-x")) { //$NON-NLS-1$
                this.targetPidText = text[i];
            }
        }

        label = new Label(cmpTxtBoxes, SWT.NONE);
        label.setText(Messages.SystemTapScriptOptionsTab_otherOptions);
        miscCommandsText = new Text(cmpTxtBoxes, SWT.BORDER);
        miscCommandsText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING,
                true, true));
        miscCommandsText.addModifyListener(modifyListener);
    }

    @Override
    public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
        IPreferenceStore store = IDEPlugin.getDefault().getPreferenceStore();

        configuration.setAttribute(STAP_CMD_OPTION[KEY],
                store.getString(STAP_CMD_OPTION[IDEPreferenceConstants.KEY]));

        for (int i = 0; i < IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS.length; i++) {
            configuration
                    .setAttribute(
                            IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS[i][IDEPreferenceConstants.KEY],
                            store.getBoolean(IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS[i][IDEPreferenceConstants.KEY]));
        }

        for (int i = 0; i < IDEPreferenceConstants.STAP_STRING_OPTIONS.length; i++) {
            configuration
                    .setAttribute(
                            IDEPreferenceConstants.STAP_STRING_OPTIONS[i][IDEPreferenceConstants.KEY],
                            store.getString(IDEPreferenceConstants.STAP_STRING_OPTIONS[i][IDEPreferenceConstants.KEY]));
        }

        configuration.setAttribute(MISC_COMMANDLINE_OPTIONS,
                store.getString(MISC_COMMANDLINE_OPTIONS));
    }

    @Override
    public void initializeFrom(ILaunchConfiguration configuration) {
        try {
            targetProgramText.setText(configuration.getAttribute(
                    STAP_CMD_OPTION[KEY], "")); //$NON-NLS-1$

            for (int i = 0; i < IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS.length; i++) {
                checkBox[i]
                        .setSelection(configuration
                                .getAttribute(
                                        IDEPreferenceConstants.STAP_BOOLEAN_OPTIONS[i][IDEPreferenceConstants.KEY],
                                        false));
            }

            for (int i = 0; i < IDEPreferenceConstants.STAP_STRING_OPTIONS.length; i++) {
                text[i].setText(configuration
                        .getAttribute(
                                IDEPreferenceConstants.STAP_STRING_OPTIONS[i][IDEPreferenceConstants.KEY],
                                "")); //$NON-NLS-1$
            }

            miscCommandsText.setText(configuration.getAttribute(
                    MISC_COMMANDLINE_OPTIONS, "")); //$NON-NLS-1$

        } catch (Exception e) {
            ExceptionErrorDialog
                    .openError(
                            Messages.SystemTapScriptOptionsTab_initializeConfigurationFailed,
                            e);
        }
    }

    @Override
    public void performApply(ILaunchConfigurationWorkingCopy configuration) {

        configuration.setAttribute(STAP_CMD_OPTION[KEY],
                targetProgramText.getText());

        for (int i = 0; i < STAP_BOOLEAN_OPTIONS.length; i++) {
            configuration.setAttribute(STAP_BOOLEAN_OPTIONS[i][KEY],
                    checkBox[i].getSelection());
        }

        for (int i = 0; i < IDEPreferenceConstants.STAP_STRING_OPTIONS.length; i++) {
            configuration.setAttribute(
                    IDEPreferenceConstants.STAP_STRING_OPTIONS[i][KEY],
                    text[i].getText());
        }

        configuration.setAttribute(MISC_COMMANDLINE_OPTIONS,
                miscCommandsText.getText());
    }

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

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

        // If dyninst is being used a pid or a target executable must be
        // specified.
        if (this.dyninstCheckBox.getSelection()
                && this.targetProgramText.getText().isEmpty()
                && this.targetPidText.getText().isEmpty()) {
            setErrorMessage(Messages.SystemTapScriptOptionsTab_dyninstError);
            return false;
        }

        if (!this.targetPidText.getText().isEmpty() && !this.targetPidText.getText().matches("[0-9]*")) { //$NON-NLS-1$
            setErrorMessage(Messages.SystemTapScriptOptionsTab_pidError);
            return false;
        }

        return true;
    }

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

}

Back to the top