1 | package de.uka.ipd.sdq.codegen.simucontroller.runconfig; |
2 | |
3 | import org.eclipse.core.runtime.CoreException; |
4 | import org.eclipse.debug.core.ILaunchConfiguration; |
5 | import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
6 | import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; |
7 | import org.eclipse.jface.viewers.CheckStateChangedEvent; |
8 | import org.eclipse.jface.viewers.ICheckStateListener; |
9 | import org.eclipse.swt.SWT; |
10 | import org.eclipse.swt.events.ModifyEvent; |
11 | import org.eclipse.swt.events.ModifyListener; |
12 | import org.eclipse.swt.events.SelectionEvent; |
13 | import org.eclipse.swt.events.SelectionListener; |
14 | import org.eclipse.swt.graphics.Image; |
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.Group; |
20 | import org.eclipse.swt.widgets.Label; |
21 | import org.eclipse.swt.widgets.Text; |
22 | |
23 | import de.uka.ipd.sdq.featureinstance.FeatureConfigWidget; |
24 | import de.uka.ipd.sdq.workflow.launchconfig.RunConfigImages; |
25 | import de.uka.ipd.sdq.workflow.launchconfig.tabs.TabHelper; |
26 | import de.uka.ipd.sdq.workflow.pcm.ConstantsContainer; |
27 | |
28 | /** |
29 | * The class defines a tab, where the specific characteristics for the |
30 | * simulation can be set. |
31 | * |
32 | * @author Roman Andrej |
33 | * @author groenda |
34 | */ |
35 | public class FeatureOptionsTab extends AbstractLaunchConfigurationTab { |
36 | |
37 | /** The id of this plug-in. */ |
38 | public static final String PLUGIN_ID = "de.uka.ipd.sdq.codegen.simucontroller"; |
39 | /** The path to the image file for the tab icon. */ |
40 | private static final String FEATURE_OPTIONS_TAB_IMAGE_PATH = "icons/feature_tab.gif"; |
41 | |
42 | private static final String TITLE_FEATURE_CONFIG_SECTION = "PCM2EJB Feature Configuration File"; |
43 | private static final String LABEL_SIMULATE_NETWORK = "Simulate throughput of linking resources and middleware marshalling / demarshalling of remote calls."; |
44 | private static final String SIMULATE_NETWORK_EXPLANATION = "Latency is always simulated if linking resources connect containers. The linking resource is treated as a FCFS resource."; |
45 | |
46 | // Default values |
47 | private static final Boolean DEFAULT_SIMULATE_FAILURES = false; |
48 | private static final Boolean DEFAULT_SIMULATE_LINKING_RESOURCES = false; |
49 | private static final String DEFAULT_FEATURE_CONFIGURATION_FILE_LABEL = "Feature Configuration File"; |
50 | // UI elements |
51 | private Button simulateLinkingResourcesButton; |
52 | private Button simulateFailuresButton; |
53 | private Text textFeatureConfig; |
54 | private Text textTargetConfig; |
55 | private FeatureConfigWidget editorWidget; |
56 | private String sourceFile; |
57 | private String targetFile; |
58 | private Button modelSaveButton; |
59 | |
60 | private boolean editorValid = true; |
61 | |
62 | /* |
63 | * (non-Javadoc) |
64 | * |
65 | * @see |
66 | * org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse |
67 | * .swt.widgets.Composite) |
68 | */ |
69 | public void createControl(Composite parent) { |
70 | |
71 | final ModifyListener modifyListener = new ModifyListener() { |
72 | |
73 | public void modifyText(ModifyEvent e) { |
74 | if (e.getSource().equals(textFeatureConfig)) { |
75 | if (sourceFile == null || !sourceFile.equals(textFeatureConfig.getText())) { |
76 | sourceFile = textFeatureConfig.getText(); |
77 | |
78 | if (sourceFile != null && targetFile != null) { |
79 | editorWidget.setSourceInput(sourceFile); |
80 | editorWidget.setTargetInput(targetFile); |
81 | editorValid = editorWidget.createPages(); |
82 | } |
83 | } |
84 | } else if (e.getSource().equals(textTargetConfig)) { |
85 | if (targetFile == null || !targetFile.equals(textTargetConfig.getText())) { |
86 | targetFile = textTargetConfig.getText(); |
87 | |
88 | if (sourceFile != null && targetFile != null) { |
89 | editorWidget.setSourceInput(sourceFile); |
90 | editorWidget.setTargetInput(targetFile); |
91 | editorValid = editorWidget.createPages(); |
92 | } |
93 | } |
94 | } |
95 | FeatureOptionsTab.this.setDirty(true); |
96 | FeatureOptionsTab.this.updateLaunchConfigurationDialog(); |
97 | } |
98 | }; |
99 | |
100 | final SelectionListener selectionListener = new SelectionListener() { |
101 | |
102 | public void widgetDefaultSelected(SelectionEvent e) { |
103 | FeatureOptionsTab.this.setDirty(true); |
104 | FeatureOptionsTab.this.updateLaunchConfigurationDialog(); |
105 | } |
106 | |
107 | public void widgetSelected(SelectionEvent e) { |
108 | FeatureOptionsTab.this.setDirty(true); |
109 | FeatureOptionsTab.this.updateLaunchConfigurationDialog(); |
110 | } |
111 | }; |
112 | |
113 | final ICheckStateListener checkListener = new ICheckStateListener() { |
114 | public void checkStateChanged(CheckStateChangedEvent event) { |
115 | if (modelSaveButton != null) { |
116 | modelSaveButton.setEnabled(true); |
117 | } |
118 | } |
119 | }; |
120 | |
121 | // Create the top-level container: |
122 | Composite container = new Composite(parent, SWT.NONE); |
123 | |
124 | setControl(container); |
125 | container.setLayout(new GridLayout()); |
126 | |
127 | // Create networking section: |
128 | final Group networkingGroup = new Group(container, SWT.NONE); |
129 | networkingGroup.setText("Networking"); |
130 | final GridData gd_networkingGroup = new GridData(SWT.FILL, SWT.CENTER, |
131 | true, false); |
132 | networkingGroup.setLayoutData(gd_networkingGroup); |
133 | networkingGroup.setLayout(new GridLayout()); |
134 | simulateLinkingResourcesButton = new Button(networkingGroup, SWT.CHECK); |
135 | final GridData gd_simulateLinkingResourcesButton = new GridData( |
136 | SWT.FILL, SWT.CENTER, true, false); |
137 | simulateLinkingResourcesButton |
138 | .setLayoutData(gd_simulateLinkingResourcesButton); |
139 | simulateLinkingResourcesButton.setText(FeatureOptionsTab.LABEL_SIMULATE_NETWORK); |
140 | simulateLinkingResourcesButton.addSelectionListener(selectionListener); |
141 | |
142 | Label simulateLinkingResourceLabel = new Label(networkingGroup, SWT.NONE); |
143 | simulateLinkingResourceLabel.setText(SIMULATE_NETWORK_EXPLANATION); |
144 | simulateLinkingResourceLabel.setEnabled(true); |
145 | |
146 | // Create reliability section: |
147 | final Group reliabilityGroup = new Group(container, SWT.NONE); |
148 | reliabilityGroup.setText("Reliability"); |
149 | final GridData gd_reliabilityGroup = new GridData(SWT.FILL, SWT.CENTER, |
150 | true, false); |
151 | reliabilityGroup.setLayoutData(gd_reliabilityGroup); |
152 | reliabilityGroup.setLayout(new GridLayout()); |
153 | simulateFailuresButton = new Button(reliabilityGroup, SWT.CHECK); |
154 | final GridData gd_simulateFailuresButton = new GridData( |
155 | SWT.FILL, SWT.CENTER, true, false); |
156 | simulateFailuresButton |
157 | .setLayoutData(gd_simulateFailuresButton); |
158 | simulateFailuresButton.setText("Simulate failures"); |
159 | simulateFailuresButton.addSelectionListener(selectionListener); |
160 | |
161 | // Create PCM2EJB feature configuration section: |
162 | final Group featureConfigGroup = new Group(container, SWT.NONE); |
163 | final GridLayout glReposetoryTypeGroup = new GridLayout(); |
164 | glReposetoryTypeGroup.numColumns = 3; |
165 | featureConfigGroup.setLayout(glReposetoryTypeGroup); |
166 | featureConfigGroup.setText(FeatureOptionsTab.TITLE_FEATURE_CONFIG_SECTION); |
167 | featureConfigGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, |
168 | true, false)); |
169 | textFeatureConfig = new Text(featureConfigGroup, SWT.SINGLE |
170 | | SWT.BORDER); |
171 | final GridData gd_textResourceTypeRepository = new GridData(SWT.FILL, |
172 | SWT.CENTER, true, false); |
173 | gd_textResourceTypeRepository.widthHint = 200; |
174 | textFeatureConfig.setLayoutData(gd_textResourceTypeRepository); |
175 | textFeatureConfig.addModifyListener(modifyListener); |
176 | TabHelper.createFileInputSection(featureConfigGroup, modifyListener, |
177 | DEFAULT_FEATURE_CONFIGURATION_FILE_LABEL, |
178 | ConstantsContainer.FEATURECONFIG_EXTENSION, textFeatureConfig, |
179 | getShell(), ConstantsContainer.DEFAULT_FEATURE_CONFIGURATION_FILE); |
180 | |
181 | //FIXME: re-enable |
182 | // // Create target feature configuration section: |
183 | // final Group targetConfigGroup = new Group(container, SWT.NONE); |
184 | // final GridLayout glRepositoryTypeGroup = new GridLayout(); |
185 | // glRepositoryTypeGroup.numColumns = 3; |
186 | // targetConfigGroup.setLayout(glRepositoryTypeGroup); |
187 | // targetConfigGroup.setText("Target featureconfig file"); |
188 | // targetConfigGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, |
189 | // true, false)); |
190 | // textTargetConfig = new Text(targetConfigGroup, SWT.SINGLE |
191 | // | SWT.BORDER); |
192 | // final GridData gd_textTResourceTypeRepository = new GridData(SWT.FILL, |
193 | // SWT.CENTER, true, false); |
194 | // gd_textTResourceTypeRepository.widthHint = 200; |
195 | // textTargetConfig.setLayoutData(gd_textTResourceTypeRepository); |
196 | // textTargetConfig.addModifyListener(modifyListener); |
197 | // final Button targetButton = new Button(targetConfigGroup, SWT.NONE); |
198 | // targetButton.setText("Workspace..."); |
199 | // targetButton |
200 | // .addSelectionListener(new WorkspaceButtonSelectionListener( |
201 | // textTargetConfig, |
202 | // ConstantsContainer.FEATURECONFIG_EXTENSION)); |
203 | // final Button buttonTResourceTypeRepository = new Button( |
204 | // targetConfigGroup, SWT.NONE); |
205 | // buttonTResourceTypeRepository.setLayoutData(new GridData()); |
206 | // buttonTResourceTypeRepository.setText("File System..."); |
207 | // buttonTResourceTypeRepository |
208 | // .addSelectionListener(new SelectionAdapter() { |
209 | // |
210 | // public void widgetSelected(SelectionEvent e) { |
211 | // textTargetConfig |
212 | // .setText(openFileDialog(ConstantsContainer.FEATURECONFIG_EXTENSION)); |
213 | // } |
214 | // }); |
215 | // |
216 | // // Create Editor widget |
217 | // final Group editorGroup = new Group(container, SWT.NONE); |
218 | // editorGroup.setText("FeatureConfig Editor:"); |
219 | // editorGroup.setLayout(new RowLayout(SWT.VERTICAL)); |
220 | // editorWidget = new FeatureConfigWidget(editorGroup); |
221 | // editorWidget.addCheckStateListener(checkListener); |
222 | // modelSaveButton = new Button(editorGroup, SWT.NONE); |
223 | // modelSaveButton.setText("Save featureconfig"); |
224 | // modelSaveButton.setEnabled(false); |
225 | // modelSaveButton.addSelectionListener(new SelectionAdapter() { |
226 | // public void widgetSelected(SelectionEvent e) { |
227 | // editorWidget.doSave(new NullProgressMonitor()); |
228 | // modelSaveButton.setEnabled(false); |
229 | // } |
230 | // }); |
231 | // Button validateButton = new Button(editorGroup, SWT.NONE); |
232 | // validateButton.setText("Validate"); |
233 | // validateButton.addSelectionListener(new SelectionAdapter() { |
234 | // public void widgetSelected(SelectionEvent e) { |
235 | // if (editorWidget != null) { |
236 | // editorWidget.validate(); |
237 | // } |
238 | // } |
239 | // }); |
240 | } |
241 | |
242 | @Override |
243 | public boolean isValid(ILaunchConfiguration launchConfig) { |
244 | setErrorMessage(null); |
245 | |
246 | if (!TabHelper.validateFilenameExtension(textFeatureConfig.getText(), |
247 | ConstantsContainer.FEATURECONFIG_EXTENSION)) { |
248 | setErrorMessage("Source model file is missing!"); |
249 | return false; |
250 | } |
251 | |
252 | //FIXME: re-enable |
253 | // if (!validateFilePath(textTargetConfig.getText(), |
254 | // ConstantsContainer.FEATURECONFIG_EXTENSION)) { |
255 | // setErrorMessage("Target model file is missing!"); |
256 | // return false; |
257 | // } |
258 | // if (editorWidget != null) { |
259 | // if (!editorValid) { |
260 | // setErrorMessage(editorWidget.getErrorMessage()); |
261 | // } |
262 | // return false; |
263 | // } |
264 | |
265 | return true; |
266 | } |
267 | |
268 | /* |
269 | * (non-Javadoc) |
270 | * |
271 | * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName() |
272 | */ |
273 | public String getName() { |
274 | return "Feature Settings"; |
275 | } |
276 | |
277 | /* |
278 | * (non-Javadoc) |
279 | * |
280 | * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#getImage() |
281 | */ |
282 | @Override |
283 | public Image getImage() { |
284 | return RunConfigImages.getTabImage(PLUGIN_ID,FEATURE_OPTIONS_TAB_IMAGE_PATH); |
285 | } |
286 | |
287 | /* |
288 | * (non-Javadoc) |
289 | * |
290 | * @see |
291 | * org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse |
292 | * .debug.core.ILaunchConfiguration) |
293 | */ |
294 | public void initializeFrom(ILaunchConfiguration configuration) { |
295 | try { |
296 | simulateLinkingResourcesButton |
297 | .setSelection(configuration |
298 | .getAttribute( |
299 | ConstantsContainer.SIMULATE_LINKING_RESOURCES, |
300 | true)); |
301 | } catch (CoreException e) { |
302 | simulateLinkingResourcesButton.setSelection(true); |
303 | } |
304 | try { |
305 | simulateFailuresButton.setSelection(configuration.getAttribute( |
306 | ConstantsContainer.SIMULATE_FAILURES, true)); |
307 | } catch (CoreException e) { |
308 | simulateFailuresButton.setSelection(false); |
309 | } |
310 | try { |
311 | textFeatureConfig.setText(configuration.getAttribute( |
312 | ConstantsContainer.FEATURE_CONFIG, ConstantsContainer.DEFAULT_FEATURE_CONFIGURATION_FILE)); |
313 | } catch (CoreException e) { |
314 | textFeatureConfig.setText(ConstantsContainer.DEFAULT_FEATURE_CONFIGURATION_FILE); |
315 | } |
316 | //FIXME: re-enable |
317 | // try { |
318 | // textTargetConfig.setText(configuration.getAttribute( |
319 | // ConstantsContainer.FEATURE_CONFIG_TARGET, "")); |
320 | // } catch (CoreException e) { |
321 | // simulateLinkingResourcesButton.setSelection(true); |
322 | // } |
323 | } |
324 | |
325 | /* |
326 | * (non-Javadoc) |
327 | * |
328 | * @see |
329 | * org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse |
330 | * .debug.core.ILaunchConfigurationWorkingCopy) |
331 | */ |
332 | public void performApply(ILaunchConfigurationWorkingCopy configuration) { |
333 | configuration.setAttribute( |
334 | ConstantsContainer.SIMULATE_LINKING_RESOURCES, |
335 | this.simulateLinkingResourcesButton.getSelection()); |
336 | configuration.setAttribute( |
337 | ConstantsContainer.SIMULATE_FAILURES, |
338 | this.simulateFailuresButton.getSelection()); |
339 | configuration.setAttribute(ConstantsContainer.FEATURE_CONFIG, |
340 | textFeatureConfig.getText()); |
341 | //FIXME: re-enable |
342 | // configuration.setAttribute(ConstantsContainer.FEATURE_CONFIG_TARGET, |
343 | // textTargetConfig.getText()); |
344 | } |
345 | |
346 | |
347 | /* TODO: Maybe this can be used to check whether models are needed |
348 | @Override |
349 | public boolean isValid(ILaunchConfiguration launchConfig) { |
350 | |
351 | setErrorMessage(null); |
352 | |
353 | //if linking resources shall be simulated, the connector config must be specified |
354 | if (simulateLinkingResourcesButton.getSelection() && (this.textFeatureConfig.getText() == null || this.textFeatureConfig.getText().equals(""))){ |
355 | setErrorMessage("If \""+FeatureOptionsTab.LABEL_SIMULATE_NETWORK+"\" is checked, a connector config has to be chosen for "+FeatureOptionsTab.TITLE_FEATURE_CONFIG_SECTION); |
356 | return false; |
357 | } |
358 | |
359 | return super.isValid(launchConfig); |
360 | }*/ |
361 | |
362 | |
363 | /* |
364 | * (non-Javadoc) |
365 | * |
366 | * @see |
367 | * org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse. |
368 | * debug.core.ILaunchConfigurationWorkingCopy) |
369 | */ |
370 | public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { |
371 | configuration.setAttribute( |
372 | ConstantsContainer.SIMULATE_LINKING_RESOURCES, DEFAULT_SIMULATE_LINKING_RESOURCES); |
373 | configuration.setAttribute( |
374 | ConstantsContainer.SIMULATE_FAILURES, DEFAULT_SIMULATE_FAILURES); |
375 | ; configuration.setAttribute(ConstantsContainer.FEATURE_CONFIG, |
376 | ConstantsContainer.DEFAULT_FEATURE_CONFIGURATION_FILE); |
377 | } |
378 | |
379 | |
380 | /* (non-Javadoc) |
381 | * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#activated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) |
382 | */ |
383 | @Override |
384 | public void activated(ILaunchConfigurationWorkingCopy workingCopy) { |
385 | // Leave this method empty to prevent unnecessary invocation of |
386 | // initializeFrom() and multiple resulting invocations of |
387 | // performApply(). |
388 | } |
389 | |
390 | /* (non-Javadoc) |
391 | * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) |
392 | */ |
393 | @Override |
394 | public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) { |
395 | // Intentionally left empty. |
396 | } |
397 | |
398 | /* |
399 | * (non-Javadoc) |
400 | * |
401 | * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#getId() |
402 | */ |
403 | @Override |
404 | public String getId() { |
405 | return "de.uka.ipd.sdq.codegen.runconfig.tabs.FileNamesInputTab"; |
406 | } |
407 | |
408 | } |