]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/script/SlcScriptLaunchConfigurationTab.java
Clean up code
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.ide.ui / src / main / java / org / argeo / slc / ide / ui / launch / script / SlcScriptLaunchConfigurationTab.java
1 package org.argeo.slc.ide.ui.launch.script;
2
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;
22
23 public class SlcScriptLaunchConfigurationTab extends
24 AbstractLaunchConfigurationTab {
25
26 private Text scriptTF;
27 private Text propertiesTF;
28 private Text runtimeTF;
29 private Text targetsTF;
30 private Button pre093B;
31
32 public void createControl(Composite parent) {
33 Composite body = new Composite(parent, SWT.NONE);
34 setControl(body);
35 body.setLayout(new GridLayout(1, false));
36 body.setFont(parent.getFont());
37
38 createLabel(body, "Script location");
39 scriptTF = createSingleText(body);
40 createWorkspaceButton(body);
41
42 createLabel(body, "Runtime");
43 runtimeTF = createSingleText(body);
44
45 createLabel(body, "Targets");
46 targetsTF = createSingleText(body);
47
48 createLabel(body, "Properties");
49 propertiesTF = createMultipleText(body, 10);
50
51 pre093B = createCheckBox(body, "Pre SLC v0.9.3");
52 }
53
54 public String getName() {
55 return "SLC";
56 }
57
58 public void initializeFrom(ILaunchConfiguration configuration) {
59 try {
60 scriptTF.setText(configuration.getAttribute(
61 SlcScriptUtils.ATTR_SCRIPT, ""));
62
63 boolean pre093 = configuration.getAttribute(
64 SlcScriptUtils.ATTR_PRE093, false);
65
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);
75 }
76
77 }
78
79 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
80 configuration.setAttribute(SlcScriptUtils.ATTR_SCRIPT, scriptTF
81 .getText());
82 configuration.setAttribute(SlcScriptUtils.ATTR_PROPERTIES, propertiesTF
83 .getText());
84 configuration.setAttribute(SlcScriptUtils.ATTR_RUNTIME, runtimeTF
85 .getText());
86 configuration.setAttribute(SlcScriptUtils.ATTR_TARGETS, targetsTF
87 .getText());
88 configuration.setAttribute(SlcScriptUtils.ATTR_PRE093, pre093B
89 .getSelection());
90 }
91
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);
98 }
99
100 // UI Utils
101 protected Label createLabel(Composite parent, String text) {
102 Label t = new Label(parent, SWT.NONE | SWT.WRAP);
103 t.setText(text);
104 t.setFont(parent.getFont());
105 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
106 gd.horizontalSpan = 1;
107 t.setLayoutData(gd);
108 return t;
109 }
110
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;
116 t.setLayoutData(gd);
117 t.addModifyListener(modifyListener);
118 return t;
119 }
120
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;
127 t.setLayoutData(gd);
128 t.addModifyListener(modifyListener);
129 return t;
130 }
131
132 protected Button createCheckBox(Composite parent, String label) {
133 Button b = new Button(parent, SWT.CHECK);
134 b.setFont(parent.getFont());
135 b.setText(label);
136 b.addSelectionListener(selectionListener);
137 return b;
138
139 }
140
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) {
147 }
148
149 public void widgetSelected(SelectionEvent e) {
150 handleWorkspaceLocationButtonSelected();
151 }
152 });
153 return b;
154 }
155
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) {
163 return;
164 }
165 IResource resource = (IResource) results[0];
166 scriptTF.setText(SlcScriptUtils
167 .convertToWorkspaceLocation(resource));
168 updateLaunchConfigurationDialog();
169 }
170 }
171
172 // LISTENERS
173 /**
174 * Modify listener that simply updates the owning launch configuration
175 * dialog.
176 */
177 private ModifyListener modifyListener = new ModifyListener() {
178 public void modifyText(ModifyEvent evt) {
179 updateLaunchConfigurationDialog();
180 }
181 };
182 private SelectionListener selectionListener = new SelectionListener() {
183 public void widgetDefaultSelected(SelectionEvent e) {
184 }
185
186 public void widgetSelected(SelectionEvent e) {
187 updateLaunchConfigurationDialog();
188 }
189 };
190
191 }