1 package org
.argeo
.slc
.ide
.ui
.launch
.script
;
3 import org
.eclipse
.core
.resources
.IResource
;
4 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
5 import org
.eclipse
.core
.runtime
.CoreException
;
6 import org
.eclipse
.debug
.core
.ILaunchConfiguration
;
7 import org
.eclipse
.debug
.core
.ILaunchConfigurationWorkingCopy
;
8 import org
.eclipse
.debug
.ui
.AbstractLaunchConfigurationTab
;
9 import org
.eclipse
.jface
.window
.Window
;
10 import org
.eclipse
.swt
.SWT
;
11 import org
.eclipse
.swt
.events
.ModifyEvent
;
12 import org
.eclipse
.swt
.events
.ModifyListener
;
13 import org
.eclipse
.swt
.events
.SelectionEvent
;
14 import org
.eclipse
.swt
.events
.SelectionListener
;
15 import org
.eclipse
.swt
.layout
.GridData
;
16 import org
.eclipse
.swt
.layout
.GridLayout
;
17 import org
.eclipse
.swt
.widgets
.Button
;
18 import org
.eclipse
.swt
.widgets
.Composite
;
19 import org
.eclipse
.swt
.widgets
.Label
;
20 import org
.eclipse
.swt
.widgets
.Text
;
21 import org
.eclipse
.ui
.dialogs
.ResourceSelectionDialog
;
23 public class SlcScriptLaunchConfigurationTab
extends
24 AbstractLaunchConfigurationTab
{
26 private Text scriptTF
;
27 private Text propertiesTF
;
28 private Text runtimeTF
;
29 private Text targetsTF
;
30 private Button pre093B
;
32 public void createControl(Composite parent
) {
33 Composite body
= new Composite(parent
, SWT
.NONE
);
35 body
.setLayout(new GridLayout(1, false));
36 body
.setFont(parent
.getFont());
38 createLabel(body
, "Script location");
39 scriptTF
= createSingleText(body
);
40 createWorkspaceButton(body
);
42 createLabel(body
, "Runtime");
43 runtimeTF
= createSingleText(body
);
45 createLabel(body
, "Targets");
46 targetsTF
= createSingleText(body
);
48 createLabel(body
, "Properties");
49 propertiesTF
= createMultipleText(body
, 10);
51 pre093B
= createCheckBox(body
, "Pre SLC v0.9.3");
54 public String
getName() {
58 public void initializeFrom(ILaunchConfiguration configuration
) {
60 scriptTF
.setText(configuration
.getAttribute(
61 SlcScriptUtils
.ATTR_SCRIPT
, ""));
63 boolean pre093
= configuration
.getAttribute(
64 SlcScriptUtils
.ATTR_PRE093
, false);
66 propertiesTF
.setText(configuration
.getAttribute(
67 SlcScriptUtils
.ATTR_PROPERTIES
, ""));
68 runtimeTF
.setText(configuration
.getAttribute(
69 SlcScriptUtils
.ATTR_RUNTIME
, ""));
70 targetsTF
.setText(configuration
.getAttribute(
71 SlcScriptUtils
.ATTR_TARGETS
, ""));
72 pre093B
.setSelection(pre093
);
73 } catch (CoreException e
) {
74 throw new RuntimeException("Cannot initialize tab", e
);
79 public void performApply(ILaunchConfigurationWorkingCopy configuration
) {
80 configuration
.setAttribute(SlcScriptUtils
.ATTR_SCRIPT
, scriptTF
82 configuration
.setAttribute(SlcScriptUtils
.ATTR_PROPERTIES
, propertiesTF
84 configuration
.setAttribute(SlcScriptUtils
.ATTR_RUNTIME
, runtimeTF
86 configuration
.setAttribute(SlcScriptUtils
.ATTR_TARGETS
, targetsTF
88 configuration
.setAttribute(SlcScriptUtils
.ATTR_PRE093
, pre093B
92 public void setDefaults(ILaunchConfigurationWorkingCopy configuration
) {
93 configuration
.setAttribute(SlcScriptUtils
.ATTR_SCRIPT
, "");
94 configuration
.setAttribute(SlcScriptUtils
.ATTR_PROPERTIES
, "");
95 configuration
.setAttribute(SlcScriptUtils
.ATTR_RUNTIME
, "");
96 configuration
.setAttribute(SlcScriptUtils
.ATTR_TARGETS
, "");
97 configuration
.setAttribute(SlcScriptUtils
.ATTR_PRE093
, false);
101 protected Label
createLabel(Composite parent
, String text
) {
102 Label t
= new Label(parent
, SWT
.NONE
| SWT
.WRAP
);
104 t
.setFont(parent
.getFont());
105 GridData gd
= new GridData(GridData
.FILL_HORIZONTAL
);
106 gd
.horizontalSpan
= 1;
111 protected Text
createSingleText(Composite parent
) {
112 Text t
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
);
113 t
.setFont(parent
.getFont());
114 GridData gd
= new GridData(GridData
.FILL_HORIZONTAL
);
115 gd
.horizontalSpan
= 1;
117 t
.addModifyListener(modifyListener
);
121 protected Text
createMultipleText(Composite parent
, int verticalSpan
) {
122 Text t
= new Text(parent
, SWT
.MULTI
| SWT
.BORDER
);
123 t
.setFont(parent
.getFont());
124 GridData gd
= new GridData(GridData
.FILL
, GridData
.FILL
, true, true);
125 gd
.horizontalSpan
= 1;
126 gd
.verticalSpan
= verticalSpan
;
128 t
.addModifyListener(modifyListener
);
132 protected Button
createCheckBox(Composite parent
, String label
) {
133 Button b
= new Button(parent
, SWT
.CHECK
);
134 b
.setFont(parent
.getFont());
136 b
.addSelectionListener(selectionListener
);
141 protected Button
createWorkspaceButton(Composite parent
) {
142 Button b
= new Button(parent
, SWT
.PUSH
);
143 b
.setFont(parent
.getFont());
144 b
.setText("Workspace...");
145 b
.addSelectionListener(new SelectionListener() {
146 public void widgetDefaultSelected(SelectionEvent e
) {
149 public void widgetSelected(SelectionEvent e
) {
150 handleWorkspaceLocationButtonSelected();
156 protected void handleWorkspaceLocationButtonSelected() {
157 ResourceSelectionDialog dialog
;
158 dialog
= new ResourceSelectionDialog(getShell(), ResourcesPlugin
159 .getWorkspace().getRoot(), "Select a file");
160 if (dialog
.open() == Window
.OK
) {
161 Object
[] results
= dialog
.getResult();
162 if (results
== null || results
.length
< 1) {
165 IResource resource
= (IResource
) results
[0];
166 scriptTF
.setText(SlcScriptUtils
167 .convertToWorkspaceLocation(resource
));
168 updateLaunchConfigurationDialog();
174 * Modify listener that simply updates the owning launch configuration
177 private ModifyListener modifyListener
= new ModifyListener() {
178 public void modifyText(ModifyEvent evt
) {
179 updateLaunchConfigurationDialog();
182 private SelectionListener selectionListener
= new SelectionListener() {
183 public void widgetDefaultSelected(SelectionEvent e
) {
186 public void widgetSelected(SelectionEvent e
) {
187 updateLaunchConfigurationDialog();