]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/org.argeo.slc.ui.launch/src/main/java/org/argeo/slc/ui/launch/script/SlcScriptLaunchConfigurationTab.java
Improve shortcut
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.ui.launch / src / main / java / org / argeo / slc / ui / launch / script / SlcScriptLaunchConfigurationTab.java
1 package org.argeo.slc.ui.launch.script;
2
3 import org.eclipse.core.resources.IFile;
4 import org.eclipse.core.runtime.CoreException;
5 import org.eclipse.debug.core.ILaunchConfiguration;
6 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
7 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.events.ModifyEvent;
10 import org.eclipse.swt.events.ModifyListener;
11 import org.eclipse.swt.events.SelectionEvent;
12 import org.eclipse.swt.events.SelectionListener;
13 import org.eclipse.swt.layout.GridData;
14 import org.eclipse.swt.layout.GridLayout;
15 import org.eclipse.swt.widgets.Button;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Label;
18 import org.eclipse.swt.widgets.Text;
19
20 public class SlcScriptLaunchConfigurationTab extends
21 AbstractLaunchConfigurationTab {
22
23 private Text scriptL;
24 private Text propertiesTF;
25 private Text runtimeTF;
26 private Text targetsTF;
27 private Button pre093B;
28
29 public void createControl(Composite parent) {
30 Composite body = new Composite(parent, SWT.NONE);
31 setControl(body);
32 body.setLayout(new GridLayout(1, false));
33 body.setFont(parent.getFont());
34
35 createLabel(body, "Script location");
36 scriptL = createSingleText(body);
37 scriptL.setEditable(false);
38 scriptL.setBackground(body.getBackground());
39
40 createLabel(body, "Runtime");
41 runtimeTF = createSingleText(body);
42
43 createLabel(body, "Targets");
44 targetsTF = createSingleText(body);
45
46 createLabel(body, "Properties");
47 propertiesTF = createMultipleText(body, 10);
48
49 pre093B = createCheckBox(body, "Pre SLC v0.9.3");
50 }
51
52 public String getName() {
53 return "SLC";
54 }
55
56 public void initializeFrom(ILaunchConfiguration configuration) {
57 try {
58 IFile script = (IFile) configuration.getMappedResources()[0];
59 scriptL.setText(script.getLocation().toFile().getAbsolutePath());
60
61 boolean pre093 = configuration.getAttribute(
62 SlcScriptLaunchDelegate.ATTR_PRE093, false);
63
64 propertiesTF.setText(configuration.getAttribute(
65 SlcScriptLaunchDelegate.ATTR_PROPERTIES, ""));
66 runtimeTF.setText(configuration.getAttribute(
67 SlcScriptLaunchDelegate.ATTR_RUNTIME, ""));
68 targetsTF.setText(configuration.getAttribute(
69 SlcScriptLaunchDelegate.ATTR_TARGETS, ""));
70 pre093B.setSelection(pre093);
71 } catch (CoreException e) {
72 throw new RuntimeException("Cannot initialize tab", e);
73 }
74
75 }
76
77 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
78 configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_PROPERTIES,
79 propertiesTF.getText());
80 configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_RUNTIME,
81 runtimeTF.getText());
82 configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_TARGETS,
83 targetsTF.getText());
84 configuration.setAttribute(SlcScriptLaunchDelegate.ATTR_PRE093, pre093B
85 .getSelection());
86 }
87
88 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
89 }
90
91 // UI Utils
92 protected Label createLabel(Composite parent, String text) {
93 Label t = new Label(parent, SWT.NONE | SWT.WRAP);
94 t.setText(text);
95 t.setFont(parent.getFont());
96 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
97 gd.horizontalSpan = 1;
98 t.setLayoutData(gd);
99 return t;
100 }
101
102 protected Text createSingleText(Composite parent) {
103 Text t = new Text(parent, SWT.SINGLE | SWT.BORDER);
104 t.setFont(parent.getFont());
105 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
106 gd.horizontalSpan = 1;
107 t.setLayoutData(gd);
108 t.addModifyListener(modifyListener);
109 return t;
110 }
111
112 protected Text createMultipleText(Composite parent, int verticalSpan) {
113 Text t = new Text(parent, SWT.MULTI | SWT.BORDER);
114 t.setFont(parent.getFont());
115 GridData gd = new GridData(GridData.FILL, GridData.FILL, true, true);
116 gd.horizontalSpan = 1;
117 gd.verticalSpan = verticalSpan;
118 t.setLayoutData(gd);
119 t.addModifyListener(modifyListener);
120 return t;
121 }
122
123 protected Button createCheckBox(Composite parent, String label) {
124 Button b = new Button(parent, SWT.CHECK);
125 b.setFont(parent.getFont());
126 b.setText(label);
127 b.addSelectionListener(selectionListener);
128 return b;
129
130 }
131
132 // LISTENERS
133 /**
134 * Modify listener that simply updates the owning launch configuration
135 * dialog.
136 */
137 private ModifyListener modifyListener = new ModifyListener() {
138 public void modifyText(ModifyEvent evt) {
139 updateLaunchConfigurationDialog();
140 }
141 };
142 private SelectionListener selectionListener = new SelectionListener() {
143 public void widgetDefaultSelected(SelectionEvent e) {
144 }
145
146 public void widgetSelected(SelectionEvent e) {
147 updateLaunchConfigurationDialog();
148 }
149 };
150
151 }