EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.codegen.simucontroller.runconfig]

COVERAGE SUMMARY FOR SOURCE FILE [SimuComConfigurationTab.java]

nameclass, %method, %block, %line, %
SimuComConfigurationTab.java0%   (0/8)0%   (0/47)0%   (0/2048)0%   (0/470)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimuComConfigurationTab0%   (0/1)0%   (0/33)0%   (0/1889)0%   (0/441)
<static initializer> 0%   (0/1)0%   (0/4)0%   (0/2)
SimuComConfigurationTab (): void 0%   (0/1)0%   (0/8)0%   (0/2)
access$0 (SimuComConfigurationTab, boolean): void 0%   (0/1)0%   (0/4)0%   (0/1)
access$1 (SimuComConfigurationTab): void 0%   (0/1)0%   (0/3)0%   (0/1)
access$10 (SimuComConfigurationTab, boolean): void 0%   (0/1)0%   (0/4)0%   (0/1)
access$11 (SimuComConfigurationTab): void 0%   (0/1)0%   (0/3)0%   (0/1)
access$12 (SimuComConfigurationTab): Button 0%   (0/1)0%   (0/3)0%   (0/1)
access$13 (SimuComConfigurationTab): Label 0%   (0/1)0%   (0/3)0%   (0/1)
access$14 (SimuComConfigurationTab): Text 0%   (0/1)0%   (0/3)0%   (0/1)
access$15 (SimuComConfigurationTab): Label 0%   (0/1)0%   (0/3)0%   (0/1)
access$16 (SimuComConfigurationTab): Text 0%   (0/1)0%   (0/3)0%   (0/1)
access$2 (SimuComConfigurationTab): Button 0%   (0/1)0%   (0/3)0%   (0/1)
access$3 (SimuComConfigurationTab): Label 0%   (0/1)0%   (0/3)0%   (0/1)
access$4 (SimuComConfigurationTab): Text 0%   (0/1)0%   (0/3)0%   (0/1)
access$5 (SimuComConfigurationTab): Label 0%   (0/1)0%   (0/3)0%   (0/1)
access$6 (SimuComConfigurationTab): Text 0%   (0/1)0%   (0/3)0%   (0/1)
access$7 (SimuComConfigurationTab): Label 0%   (0/1)0%   (0/3)0%   (0/1)
access$8 (SimuComConfigurationTab): Text 0%   (0/1)0%   (0/3)0%   (0/1)
access$9 (SimuComConfigurationTab): Button 0%   (0/1)0%   (0/3)0%   (0/1)
activated (ILaunchConfigurationWorkingCopy): void 0%   (0/1)0%   (0/53)0%   (0/16)
createControl (Composite): void 0%   (0/1)0%   (0/736)0%   (0/136)
deactivated (ILaunchConfigurationWorkingCopy): void 0%   (0/1)0%   (0/1)0%   (0/1)
enableBatchMeansSettings (boolean): void 0%   (0/1)0%   (0/53)0%   (0/6)
getImage (): Image 0%   (0/1)0%   (0/4)0%   (0/2)
getName (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getUsageScenarioFromURI (URI): UsageScenario 0%   (0/1)0%   (0/21)0%   (0/7)
initializeFrom (ILaunchConfiguration): void 0%   (0/1)0%   (0/341)0%   (0/94)
isValid (ILaunchConfiguration): boolean 0%   (0/1)0%   (0/298)0%   (0/71)
loadModelFiles (): ResourceSet 0%   (0/1)0%   (0/36)0%   (0/8)
performApply (ILaunchConfigurationWorkingCopy): void 0%   (0/1)0%   (0/114)0%   (0/35)
setDefaults (ILaunchConfigurationWorkingCopy): void 0%   (0/1)0%   (0/83)0%   (0/21)
showSelectModelElementDialog (): void 0%   (0/1)0%   (0/65)0%   (0/19)
updateModelElementField (UsageScenario): void 0%   (0/1)0%   (0/17)0%   (0/5)
     
class SimuComConfigurationTab$10%   (0/1)0%   (0/2)0%   (0/14)0%   (0/5)
SimuComConfigurationTab$1 (SimuComConfigurationTab): void 0%   (0/1)0%   (0/6)0%   (0/2)
modifyText (ModifyEvent): void 0%   (0/1)0%   (0/8)0%   (0/3)
     
class SimuComConfigurationTab$20%   (0/1)0%   (0/2)0%   (0/10)0%   (0/4)
SimuComConfigurationTab$2 (SimuComConfigurationTab): void 0%   (0/1)0%   (0/6)0%   (0/2)
widgetSelected (SelectionEvent): void 0%   (0/1)0%   (0/4)0%   (0/2)
     
class SimuComConfigurationTab$30%   (0/1)0%   (0/2)0%   (0/54)0%   (0/13)
SimuComConfigurationTab$3 (SimuComConfigurationTab): void 0%   (0/1)0%   (0/6)0%   (0/2)
widgetSelected (SelectionEvent): void 0%   (0/1)0%   (0/48)0%   (0/11)
     
class SimuComConfigurationTab$40%   (0/1)0%   (0/2)0%   (0/10)0%   (0/4)
SimuComConfigurationTab$4 (SimuComConfigurationTab): void 0%   (0/1)0%   (0/6)0%   (0/2)
widgetSelected (SelectionEvent): void 0%   (0/1)0%   (0/4)0%   (0/2)
     
class SimuComConfigurationTab$50%   (0/1)0%   (0/2)0%   (0/51)0%   (0/9)
SimuComConfigurationTab$5 (SimuComConfigurationTab): void 0%   (0/1)0%   (0/6)0%   (0/2)
widgetSelected (SelectionEvent): void 0%   (0/1)0%   (0/45)0%   (0/7)
     
class SimuComConfigurationTab$60%   (0/1)0%   (0/2)0%   (0/10)0%   (0/4)
SimuComConfigurationTab$6 (SimuComConfigurationTab): void 0%   (0/1)0%   (0/6)0%   (0/2)
widgetSelected (SelectionEvent): void 0%   (0/1)0%   (0/4)0%   (0/2)
     
class SimuComConfigurationTab$70%   (0/1)0%   (0/2)0%   (0/10)0%   (0/4)
SimuComConfigurationTab$7 (SimuComConfigurationTab): void 0%   (0/1)0%   (0/6)0%   (0/2)
widgetSelected (SelectionEvent): void 0%   (0/1)0%   (0/4)0%   (0/2)

1/**
2 *
3 */
4package de.uka.ipd.sdq.codegen.simucontroller.runconfig;
5 
6import java.util.ArrayList;
7 
8import org.apache.log4j.Logger;
9import org.eclipse.core.runtime.CoreException;
10import org.eclipse.debug.core.ILaunchConfiguration;
11import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
12import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
13import org.eclipse.debug.ui.ILaunchConfigurationTab;
14import org.eclipse.emf.common.util.URI;
15import org.eclipse.emf.ecore.EObject;
16import org.eclipse.emf.ecore.resource.ResourceSet;
17import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
18import org.eclipse.emf.ecore.util.EcoreUtil;
19import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
20import org.eclipse.swt.SWT;
21import org.eclipse.swt.custom.CTabFolder;
22import org.eclipse.swt.events.ModifyEvent;
23import org.eclipse.swt.events.ModifyListener;
24import org.eclipse.swt.events.SelectionAdapter;
25import org.eclipse.swt.events.SelectionEvent;
26import org.eclipse.swt.graphics.Image;
27import org.eclipse.swt.layout.GridData;
28import org.eclipse.swt.layout.GridLayout;
29import org.eclipse.swt.widgets.Button;
30import org.eclipse.swt.widgets.Combo;
31import org.eclipse.swt.widgets.Composite;
32import org.eclipse.swt.widgets.Group;
33import org.eclipse.swt.widgets.Label;
34import org.eclipse.swt.widgets.MessageBox;
35import org.eclipse.swt.widgets.Text;
36 
37import de.uka.ipd.sdq.codegen.simucontroller.SimuControllerImages;
38import de.uka.ipd.sdq.pcm.dialogs.selection.PalladioSelectEObjectDialog;
39import de.uka.ipd.sdq.pcm.usagemodel.UsageModel;
40import de.uka.ipd.sdq.pcm.usagemodel.UsageScenario;
41import de.uka.ipd.sdq.pcm.usagemodel.provider.UsagemodelItemProviderAdapterFactory;
42import de.uka.ipd.sdq.pcmbench.ui.provider.PalladioItemProviderAdapterFactory;
43import de.uka.ipd.sdq.pipesandfilters.framework.recorder.launch.RecorderExtensionHelper;
44import de.uka.ipd.sdq.pipesandfilters.framework.recorder.launch.RecorderTabGroup;
45import de.uka.ipd.sdq.simucomframework.SimuComConfig;
46import de.uka.ipd.sdq.simulation.AbstractSimulationConfig;
47import de.uka.ipd.sdq.workflow.launchconfig.tabs.TabHelper;
48import de.uka.ipd.sdq.workflow.pcm.ConstantsContainer;
49 
50/**
51 * The class defines a tab, which is responsible for the SimuCom configuration.
52 *
53 * @author Roman Andrej
54 */
55public class SimuComConfigurationTab extends AbstractLaunchConfigurationTab {
56 
57        /** Logger of this class. */
58        private static final Logger logger = Logger.getLogger(SimuComConfigurationTab.class);
59 
60        private Text nameField;
61        private Text timeField;
62        private Text maxMeasurementsField;
63        private Button checkLoggingButton;
64        
65        /** Confidence settings */
66        private Button useConfidenceCheckBox;
67        private Label levelLabel;
68        private Text levelField;
69        private Label halfWidthLabel;
70        private Text halfWidthField;
71        private Label selectModelElementLabel;
72        private Text selectModelElementField;
73        private Button selectModelElementButton;
74        private String selectedModelElementName;
75        private URI selectedModelElementURI;
76        /** Batch means settings */
77        private Button useAutomatedBatchMeansCheckBox;
78        private Label batchSizeLabel;
79        private Text batchSizeField;
80        private Label minNumberOfBatchesLabel;
81        private Text minNumberOfBatchesField;
82        
83        private Combo persistenceCombo;
84        private Combo simulatorCombo;
85        private ArrayList<String> modelFiles = new ArrayList<String>();
86 
87        private RecorderTabGroup recorderTabGroup;
88        protected Composite container;
89 
90 
91 
92        /* (non-Javadoc)
93         * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
94         */
95        public void createControl(Composite parent) {
96                final ModifyListener modifyListener = new ModifyListener(){
97                        public void modifyText(ModifyEvent e) {
98                                SimuComConfigurationTab.this.setDirty(true);
99                                SimuComConfigurationTab.this.updateLaunchConfigurationDialog();
100                        }
101                };
102 
103                container = new Composite(parent, SWT.NONE);
104                container.setLayout(new GridLayout());
105                setControl(container);
106 
107                /** Create Simulator section */
108                final Group simulatorGroup = new Group(container, SWT.NONE);
109        simulatorGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
110        final GridLayout simulatorLayout = new GridLayout();
111        simulatorLayout.numColumns = 3;
112        simulatorGroup.setLayout(simulatorLayout);
113        simulatorGroup.setText("Simulator");
114                
115        final Label simulatorLabel = new Label(simulatorGroup, SWT.NONE);
116        simulatorLabel.setText("Simulator implementation:");
117        
118        String[] simulatorNames = null;
119        try {
120            simulatorNames = SimulatorExtensionHelper.getSimulatorNames();
121        } catch (CoreException e1) {
122            logger.warn("Could not retrieve names of simulator extensions.", e1);
123        }
124        simulatorCombo = new Combo(simulatorGroup, SWT.READ_ONLY);
125        simulatorCombo.setItems(simulatorNames);
126        simulatorCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
127        simulatorCombo.addSelectionListener (new SelectionAdapter() {
128            @Override
129            public void widgetSelected(SelectionEvent e) {
130                updateLaunchConfigurationDialog();
131            }
132        });
133        
134                /** Create Stop Conditions section */
135                final Group stopConditionsGroup = new Group(container, SWT.NONE);
136                stopConditionsGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
137                final GridLayout gridLayout_1 = new GridLayout();
138                gridLayout_1.numColumns = 3;
139                stopConditionsGroup.setLayout(gridLayout_1);
140                stopConditionsGroup.setText("Stop Conditions");
141 
142                final Label timeLabel = new Label(stopConditionsGroup, SWT.NONE);
143                timeLabel.setText("Maximum simulation time:");
144 
145                timeField = new Text(stopConditionsGroup, SWT.BORDER);
146                timeField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
147                timeField.addModifyListener(modifyListener);
148 
149                final Label secLabel = new Label(stopConditionsGroup, SWT.NONE);
150                secLabel.setText("Simulated Time Units");
151 
152                final Label maxLabel = new Label(stopConditionsGroup, SWT.NONE);
153                maxLabel.setText("Maximum measurements count:");
154 
155                maxMeasurementsField = new Text(stopConditionsGroup, SWT.BORDER);
156                maxMeasurementsField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
157                maxMeasurementsField.addModifyListener(modifyListener);
158 
159                /** Create Confidence Stop Condition section */
160                final Group confidenceGroup = new Group(container, SWT.NONE);
161                confidenceGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
162                final GridLayout confidenceLayout = new GridLayout();
163                confidenceLayout.numColumns = 3;
164                confidenceGroup.setLayout(confidenceLayout);
165                confidenceGroup.setText("Confidence Stop Condition");
166 
167                useConfidenceCheckBox = new Button(confidenceGroup, SWT.CHECK);
168                useConfidenceCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
169                useConfidenceCheckBox.setText("Stop when reaching confidence");
170                useConfidenceCheckBox.setSelection(false);
171                useConfidenceCheckBox.addSelectionListener(new SelectionAdapter() {
172                        public void widgetSelected(SelectionEvent e) {
173                                // enable level and half-with fields if and only if check box is checked
174                                boolean selected = useConfidenceCheckBox.getSelection();
175                                levelLabel.setEnabled(selected);
176                                levelField.setEnabled(selected);
177                                halfWidthLabel.setEnabled(selected);
178                                halfWidthField.setEnabled(selected);
179                                selectModelElementLabel.setEnabled(selected);
180                                selectModelElementField.setEnabled(selected);
181                                selectModelElementButton.setEnabled(selected);
182                                enableBatchMeansSettings(selected);
183 
184                                SimuComConfigurationTab.this.updateLaunchConfigurationDialog();
185                        }
186 
187                });
188 
189                levelLabel = new Label(confidenceGroup, SWT.NONE);
190                levelLabel.setText("Confidence level (%):");
191                levelLabel.setEnabled(false);
192 
193                levelField = new Text(confidenceGroup, SWT.BORDER);
194                levelField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
195                levelField.addModifyListener(modifyListener);
196                levelField.setEnabled(false);
197 
198                halfWidthLabel = new Label(confidenceGroup, SWT.NONE);
199                halfWidthLabel.setText("Confidence interval half-width (%):");
200                halfWidthLabel.setEnabled(false);
201 
202                halfWidthField = new Text(confidenceGroup, SWT.BORDER);
203                halfWidthField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
204                halfWidthField.addModifyListener(modifyListener);
205                halfWidthField.setEnabled(false);
206 
207                selectModelElementLabel = new Label(confidenceGroup, SWT.NONE);
208                selectModelElementLabel.setText("Monitor Response Time of:");
209                selectModelElementLabel.setEnabled(false);
210 
211                selectModelElementField = new Text(confidenceGroup, SWT.BORDER);
212                selectModelElementField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
213                selectModelElementField.addModifyListener(modifyListener);
214                selectModelElementField.setEditable(false);
215                selectModelElementField.setEnabled(false);
216 
217                selectModelElementButton = new Button(confidenceGroup, SWT.NONE);
218                selectModelElementButton.setText("Select Model Element...");
219                selectModelElementButton.addSelectionListener(new SelectionAdapter() {
220                        public void widgetSelected(final SelectionEvent e) {
221                                showSelectModelElementDialog();
222                        }
223                });
224                
225                /** Batch means configuration */
226                useAutomatedBatchMeansCheckBox = new Button(confidenceGroup, SWT.CHECK);
227                useAutomatedBatchMeansCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
228                useAutomatedBatchMeansCheckBox.setText("Automatically determine batch size (Beware: Manual batch size can lead to invalid results, only use it care).");
229                useAutomatedBatchMeansCheckBox.setSelection(false);
230                useAutomatedBatchMeansCheckBox.addSelectionListener(new SelectionAdapter() {
231                        public void widgetSelected(SelectionEvent e) {
232                                // enable level and half-with fields if and only if check box is checked
233                                boolean selected = useAutomatedBatchMeansCheckBox.getSelection();
234                                batchSizeLabel.setEnabled(!selected);
235                                batchSizeField.setEnabled(!selected);
236                                minNumberOfBatchesLabel.setEnabled(!selected);
237                                minNumberOfBatchesField.setEnabled(!selected);
238 
239                                SimuComConfigurationTab.this.updateLaunchConfigurationDialog();
240                        }
241                });
242                
243                batchSizeLabel = new Label(confidenceGroup, SWT.NONE);
244                batchSizeLabel.setText("Batch size:");
245                batchSizeLabel.setEnabled(false);
246 
247                batchSizeField = new Text(confidenceGroup, SWT.BORDER);
248                batchSizeField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
249                batchSizeField.addModifyListener(modifyListener);
250                batchSizeField.setEnabled(false);
251                
252                minNumberOfBatchesLabel = new Label(confidenceGroup, SWT.NONE);
253                minNumberOfBatchesLabel.setText("Minimum number of batches:");
254                minNumberOfBatchesLabel.setEnabled(false);
255 
256                minNumberOfBatchesField = new Text(confidenceGroup, SWT.BORDER);
257                minNumberOfBatchesField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
258                minNumberOfBatchesField.addModifyListener(modifyListener);
259                minNumberOfBatchesField.setEnabled(false);
260 
261                /** Create Experiment Run section */
262                final Group experimentrunGroup = new Group(container, SWT.NONE);
263                experimentrunGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
264                final GridLayout gridLayout = new GridLayout();
265                gridLayout.numColumns = 2;
266                experimentrunGroup.setLayout(gridLayout);
267                experimentrunGroup.setText("Experiment Run");
268 
269                Label nameLabel = new Label(experimentrunGroup, SWT.NONE);
270                nameLabel.setText("Experiment Name:");
271 
272                nameField = new Text(experimentrunGroup, SWT.BORDER);
273                final GridData gd_nameField = new GridData(SWT.FILL, SWT.CENTER, true, false);
274                gd_nameField.widthHint = 70;
275                nameField.setLayoutData(gd_nameField);
276                nameField.addModifyListener(modifyListener);
277 
278                /** DataSet group */
279                final Group persistenceGroup = new Group(container, SWT.NONE);
280                persistenceGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
281                                false));
282                persistenceGroup.setLayout(new GridLayout(2, false));
283                persistenceGroup.setText("Simulation Results");
284 
285                final Label persistenceLabel = new Label(persistenceGroup, SWT.NONE);
286                persistenceLabel.setText("Persistence Framework:");
287 
288                String[] recorderNames = null;
289                try {
290                        recorderNames = RecorderExtensionHelper.getRecorderNames();
291                } catch (CoreException e1) {
292                        logger.warn("Could not access RecorderNames.", e1);
293                }
294                persistenceCombo = new Combo(persistenceGroup, SWT.READ_ONLY);
295                persistenceCombo.setItems(recorderNames);
296                persistenceCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
297                persistenceCombo.addSelectionListener (new SelectionAdapter() {
298                        @Override
299                        public void widgetSelected(SelectionEvent e) {
300                                updateLaunchConfigurationDialog();
301                        }
302                });
303 
304                recorderTabGroup = new RecorderTabGroup();
305                CTabFolder tabFolder = TabHelper.createTabFolder(recorderTabGroup,
306                                getLaunchConfigurationDialog(),
307                                getLaunchConfigurationDialog().getMode(),
308                                persistenceGroup, SWT.BORDER | SWT.FLAT);
309                tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
310 
311                /** Logging group*/
312                final Group loggingGroup = new Group(container, SWT.NONE);
313                loggingGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
314                loggingGroup.setText("Logging");
315                loggingGroup.setLayout(new GridLayout());
316                checkLoggingButton = new Button(loggingGroup, SWT.CHECK);
317                checkLoggingButton.setText("Enable verbose logging");
318                checkLoggingButton.addSelectionListener(new SelectionAdapter() {
319 
320                        /* (non-Javadoc)
321                         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
322                         */
323                        public void widgetSelected(SelectionEvent e) {
324                                SimuComConfigurationTab.this.updateLaunchConfigurationDialog();
325                        }
326                });
327                checkLoggingButton.setSelection(false);
328        }
329 
330        /**
331         * needs the value of useAutomatedBatchMeansCheckBox to be initialised. 
332         * @param parentSelected
333         */
334        private void enableBatchMeansSettings(boolean parentSelected) {
335                useAutomatedBatchMeansCheckBox.setEnabled(parentSelected);
336                
337                // depend on useAutomatedBatchMeans, too
338                batchSizeLabel.setEnabled(parentSelected && !useAutomatedBatchMeansCheckBox.getSelection());
339                batchSizeField.setEnabled(parentSelected && !useAutomatedBatchMeansCheckBox.getSelection());
340                minNumberOfBatchesLabel.setEnabled(parentSelected && !useAutomatedBatchMeansCheckBox.getSelection());
341                minNumberOfBatchesField.setEnabled(parentSelected && !useAutomatedBatchMeansCheckBox.getSelection());
342        }
343        
344        private void showSelectModelElementDialog() {
345                ResourceSet rs = loadModelFiles();
346                ArrayList<Object> filter = new ArrayList<Object>();
347                filter.add(UsageModel.class);
348                filter.add(UsageScenario.class);
349                PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog
350                        (this.getShell(), filter, rs);
351                if (dialog.open() == org.eclipse.jface.dialogs.Dialog.OK) {
352                        EObject modelElement = dialog.getResult();
353                        if (modelElement instanceof UsageScenario) {
354                                UsageScenario usageScenario = (UsageScenario)modelElement;
355                                selectedModelElementURI = EcoreUtil.getURI(modelElement);
356                                selectedModelElementName = usageScenario.getEntityName();
357                                updateModelElementField(usageScenario);
358                        } else {
359                                MessageBox warningBox = new MessageBox(selectModelElementField
360                                                .getShell(), SWT.ICON_WARNING | SWT.OK);
361                                warningBox.setText("Warning");
362                                warningBox.setMessage("No response times will be available for " +
363                                                "the selected model element. Please select a suitable " +
364                                                "model element.");
365                                warningBox.open();
366                        }
367                }
368        }
369 
370        private void updateModelElementField(UsageScenario modelElement) {
371                AdapterFactoryLabelProvider labelProvider = new AdapterFactoryLabelProvider(
372                                new PalladioItemProviderAdapterFactory(
373                                                new UsagemodelItemProviderAdapterFactory()));
374                selectModelElementField.setText(labelProvider.getText(modelElement));
375        }
376 
377        /* (non-Javadoc)
378         * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
379         */
380        public String getName() {
381                return "Simulation";
382        }
383 
384        /* (non-Javadoc)
385         * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
386         */
387        public void initializeFrom(ILaunchConfiguration configuration) {
388                recorderTabGroup.initializeFrom(configuration);
389                
390        try {
391            String simulatorId = configuration.getAttribute(AbstractSimulationConfig.SIMULATOR_ID,
392                    AbstractSimulationConfig.DEFAULT_SIMULATOR_ID);
393            String simulatorName = SimulatorExtensionHelper.getSimulatorNameForId(simulatorId);
394            String[] items = simulatorCombo.getItems();
395            for (int i = 0; i < items.length; i++) {
396                String currentItemName = items[i];
397                if (currentItemName.equals(simulatorName)) {
398                    simulatorCombo.select(i);
399                }
400            }
401        } catch (CoreException e) {
402            logger.warn("Could not initialise simulator selection.", e);
403        }
404                
405                try {
406                        nameField.setText(configuration.getAttribute(
407                                        AbstractSimulationConfig.EXPERIMENT_RUN, ""));
408                } catch (CoreException e) {
409                        nameField.setText("MyRun");
410                }
411 
412                try {
413                        timeField.setText(configuration.getAttribute(
414                                        AbstractSimulationConfig.SIMULATION_TIME, ""));
415                } catch (CoreException e) {
416                        timeField.setText("150000");
417                }
418 
419                try {
420                        maxMeasurementsField.setText(configuration.getAttribute(
421                                        AbstractSimulationConfig.MAXIMUM_MEASUREMENT_COUNT, ""));
422                } catch (CoreException e) {
423                        maxMeasurementsField.setText("10000");
424                }
425 
426                try {
427                        String persistenceFrameworkName = configuration.getAttribute(
428                                        AbstractSimulationConfig.PERSISTENCE_RECORDER_NAME, "");
429                        String[] items = persistenceCombo.getItems();
430                        for (int i=0; i<items.length; i++){
431                                String str = items[i];
432                                if (str.equals(persistenceFrameworkName)){
433                                        persistenceCombo.select(i);
434                                }
435                        }
436                } catch (CoreException e) {
437                        logger.warn("Could not access persistency recorder name.", e);
438                }
439 
440                try {
441                        checkLoggingButton.setSelection(configuration.getAttribute(
442                                        AbstractSimulationConfig.VERBOSE_LOGGING, false));
443                } catch (CoreException e) {
444                        checkLoggingButton.setSelection(false);
445                }
446 
447                try {
448                        levelField.setText(configuration.getAttribute(
449                                        SimuComConfig.CONFIDENCE_LEVEL, "95"));
450                } catch (CoreException e) {
451                        levelField.setText(""+SimuComConfig.DEFAULT_CONFIDENCE_LEVEL);
452                }
453 
454                try {
455                        halfWidthField.setText(configuration.getAttribute(
456                                        SimuComConfig.CONFIDENCE_HALFWIDTH, "10"));
457                } catch (CoreException e) {
458                        halfWidthField.setText(""+SimuComConfig.DEFAULT_CONFIDENCE_HALFWIDTH);
459                }
460                
461 
462                String defaultBatchSize = ""+SimuComConfig.DEFAULT_CONFIDENCE_BATCH_SIZE;
463                try {
464                        batchSizeField.setText(configuration.getAttribute(
465                                        SimuComConfig.CONFIDENCE_BATCH_SIZE, defaultBatchSize));
466                } catch (CoreException e) {
467                        batchSizeField.setText(defaultBatchSize);
468                }
469                
470                String defaultMinNumberOfBatches = ""+SimuComConfig.DEFAULT_CONFIDENCE_MIN_NUMBER_OF_BATCHES;
471                try {
472                        minNumberOfBatchesField.setText(configuration.getAttribute(
473                                        SimuComConfig.CONFIDENCE_MIN_NUMBER_OF_BATCHES, defaultMinNumberOfBatches));
474                } catch (CoreException e) {
475                        minNumberOfBatchesField.setText(defaultMinNumberOfBatches);
476                }
477 
478                try {
479                        String usageFile = configuration.getAttribute(
480                                        ConstantsContainer.USAGE_FILE, "");
481                        modelFiles.clear();
482                        if (!usageFile.isEmpty()) {
483                                modelFiles.add(usageFile);
484        }
485                } catch (CoreException e) {
486                }
487 
488                try {
489                        selectedModelElementURI = URI.createURI(configuration.getAttribute(
490                                        SimuComConfig.CONFIDENCE_MODELELEMENT_URI, ""));
491                        UsageScenario usageScenario = getUsageScenarioFromURI(selectedModelElementURI);
492                        selectedModelElementName = usageScenario.getEntityName();
493                        updateModelElementField(usageScenario);
494                } catch (Exception e) {
495                        selectedModelElementURI = null;
496                        selectedModelElementName = "";
497                        selectModelElementField.setText("");
498                }
499                
500        
501                // decide how to enable / disable them after initialising the values. 
502                try {
503                        boolean isAutomaticBatches = configuration.getAttribute(
504                                        SimuComConfig.CONFIDENCE_USE_AUTOMATIC_BATCHES, false);
505                        useAutomatedBatchMeansCheckBox.setSelection(isAutomaticBatches);
506                        
507                        boolean select = configuration.getAttribute(
508                                        SimuComConfig.USE_CONFIDENCE, false);
509                        useConfidenceCheckBox.setSelection(select);
510                        
511                        levelLabel.setEnabled(select);
512                        levelField.setEnabled(select);
513                        halfWidthLabel.setEnabled(select);
514                        halfWidthField.setEnabled(select);
515                        selectModelElementLabel.setEnabled(select);
516                        selectModelElementField.setEnabled(select);
517                        selectModelElementButton.setEnabled(select);
518                        
519                        // needs the value of useAutomatedBatchMeansCheckBox to be initialised.  
520                        enableBatchMeansSettings(select);
521                        
522                } catch (CoreException e) {
523                        useConfidenceCheckBox.setSelection(false);
524                        levelLabel.setEnabled(false);
525                        levelField.setEnabled(false);
526                        halfWidthLabel.setEnabled(false);
527                        halfWidthField.setEnabled(false);
528                        selectModelElementLabel.setEnabled(false);
529                        selectModelElementField.setEnabled(false);
530                        selectModelElementButton.setEnabled(false);
531                        enableBatchMeansSettings(false);
532                        
533                }
534        }
535 
536        /* (non-Javadoc)
537         * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
538         */
539        public void performApply(ILaunchConfigurationWorkingCopy configuration) {
540        // delegate this method call to recorder tab group
541        recorderTabGroup.performApply(configuration);
542 
543        // apply simulator selection
544        try {
545            // find simulator id for the given simulator name
546            String simulatorId = SimulatorExtensionHelper.getSimulatorIdForName(simulatorCombo.getText());
547            configuration.setAttribute(AbstractSimulationConfig.SIMULATOR_ID, simulatorId);
548        } catch (CoreException e) {
549            logger.error("Failed to retrieve the id for simulator \"" + simulatorCombo.getText() + "\"");
550        }
551        
552                configuration.setAttribute(AbstractSimulationConfig.EXPERIMENT_RUN,
553                                nameField.getText());
554                configuration.setAttribute(AbstractSimulationConfig.SIMULATION_TIME,
555                                timeField.getText());
556                configuration.setAttribute(AbstractSimulationConfig.MAXIMUM_MEASUREMENT_COUNT,
557                                                maxMeasurementsField.getText());
558                configuration.setAttribute(AbstractSimulationConfig.PERSISTENCE_RECORDER_NAME,
559                                persistenceCombo.getText());
560                configuration.setAttribute(AbstractSimulationConfig.VERBOSE_LOGGING,
561                                checkLoggingButton.getSelection());
562                configuration.setAttribute(SimuComConfig.USE_CONFIDENCE,
563                                useConfidenceCheckBox.getSelection());
564                configuration.setAttribute(SimuComConfig.CONFIDENCE_LEVEL,
565                                levelField.getText());
566                configuration.setAttribute(SimuComConfig.CONFIDENCE_HALFWIDTH,
567                                halfWidthField.getText());
568                configuration.setAttribute(SimuComConfig.CONFIDENCE_MODELELEMENT_NAME,
569                                selectedModelElementName);
570 
571                if (selectedModelElementURI != null) {
572                        configuration.setAttribute(SimuComConfig.CONFIDENCE_MODELELEMENT_URI,
573                                        selectedModelElementURI.toString());
574                } else {
575                        configuration.setAttribute(
576                                        SimuComConfig.CONFIDENCE_MODELELEMENT_URI, "");
577                }
578                configuration.setAttribute(SimuComConfig.CONFIDENCE_USE_AUTOMATIC_BATCHES,
579                                useAutomatedBatchMeansCheckBox.getSelection());
580                configuration.setAttribute(SimuComConfig.CONFIDENCE_BATCH_SIZE,
581                                batchSizeField.getText());
582                configuration.setAttribute(SimuComConfig.CONFIDENCE_MIN_NUMBER_OF_BATCHES,
583                                minNumberOfBatchesField.getText());
584        }
585 
586        /* (non-Javadoc)
587         * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
588         */
589        public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
590                // delegate this method call to recorder tab group
591                if (recorderTabGroup != null) {
592                        recorderTabGroup.setDefaults(configuration);
593                }
594 
595                configuration.setAttribute(AbstractSimulationConfig.SIMULATOR_ID, AbstractSimulationConfig.DEFAULT_SIMULATOR_ID);
596        configuration.setAttribute(AbstractSimulationConfig.EXPERIMENT_RUN, AbstractSimulationConfig.DEFAULT_EXPERIMENT_RUN);
597        configuration.setAttribute(AbstractSimulationConfig.SIMULATION_TIME, AbstractSimulationConfig.DEFAULT_SIMULATION_TIME);
598        configuration.setAttribute(AbstractSimulationConfig.MAXIMUM_MEASUREMENT_COUNT, AbstractSimulationConfig.DEFAULT_MAXIMUM_MEASUREMENT_COUNT);
599        configuration.setAttribute(AbstractSimulationConfig.PERSISTENCE_RECORDER_NAME, AbstractSimulationConfig.DEFAULT_PERSISTENCE_RECORDER_NAME);
600                configuration.setAttribute(SimuComConfig.USE_CONFIDENCE, SimuComConfig.DEFAULT_USE_CONFIDENCE);
601                configuration.setAttribute(SimuComConfig.CONFIDENCE_LEVEL, SimuComConfig.DEFAULT_CONFIDENCE_LEVEL);
602                configuration.setAttribute(SimuComConfig.CONFIDENCE_HALFWIDTH, SimuComConfig.DEFAULT_CONFIDENCE_HALFWIDTH);
603                configuration.setAttribute(SimuComConfig.CONFIDENCE_MODELELEMENT_NAME, SimuComConfig.DEFAULT_CONFIDENCE_MODELELEMENT_NAME);
604                configuration.setAttribute(SimuComConfig.CONFIDENCE_MODELELEMENT_URI, SimuComConfig.DEFAULT_CONFIDENCE_MODELELEMENT_URI);
605                configuration.setAttribute(SimuComConfig.CONFIDENCE_USE_AUTOMATIC_BATCHES, SimuComConfig.DEFAULT_CONFIDENCE_USE_AUTOMATIC_BATCHES);
606                configuration.setAttribute(SimuComConfig.CONFIDENCE_BATCH_SIZE, SimuComConfig.DEFAULT_CONFIDENCE_BATCH_SIZE);
607                configuration.setAttribute(SimuComConfig.CONFIDENCE_MIN_NUMBER_OF_BATCHES, SimuComConfig.DEFAULT_CONFIDENCE_MIN_NUMBER_OF_BATCHES);
608 
609                // set default value for persistence framework
610                try {
611                        String[] recorderNames = RecorderExtensionHelper.getRecorderNames();
612                        if (recorderNames.length > 0){
613                                configuration.setAttribute(AbstractSimulationConfig.PERSISTENCE_RECORDER_NAME, recorderNames[0]);
614                        }
615                } catch (CoreException e1) {
616                        logger.error("Could not set default value for persistence framework.", e1);
617                }
618        }
619 
620        /* (non-Javadoc)
621         * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#getImage()
622         */
623        @Override
624        public Image getImage() {
625                return SimuControllerImages.imageRegistry
626                                .get(SimuControllerImages.SIMUCOM_CONF);
627        }
628 
629        /* (non-Javadoc)
630         * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
631         */
632        @Override
633        public boolean isValid(ILaunchConfiguration launchConfig) {
634                setErrorMessage(null);
635 
636                String simulatorName = simulatorCombo.getText();
637        if (simulatorName == null || simulatorName.isEmpty()) {
638            setErrorMessage("Simulator implementation is missing!");
639            return false;
640        }
641                if (nameField.getText().equals("")){
642                        setErrorMessage("ExperimentRun name is missing!");
643                        return false;
644                }
645                if (timeField.getText().equals("")){
646                        setErrorMessage("Simulation time is missing!");
647                        return false;
648                }
649                if (maxMeasurementsField.getText().equals("")){
650                        setErrorMessage("Maximum Measurement counter is missing!");
651                        return false;
652                }
653                String persistenceFrameworkName = persistenceCombo.getText();
654                if (persistenceFrameworkName == null || persistenceFrameworkName.isEmpty()) {
655                        setErrorMessage("Persistence Framework is missing!");
656                        return false;
657                }
658                // delegate validation to persistence framework tabs
659                ILaunchConfigurationTab[] recorderTabs = recorderTabGroup.getTabs();
660                for (ILaunchConfigurationTab tab : recorderTabs) {
661                        if (tab.getName().equals(persistenceFrameworkName) && !tab.isValid(launchConfig)) {
662                                setErrorMessage(persistenceFrameworkName + ": " + tab.getErrorMessage());
663                                return false;
664                        }
665                }
666                // check confidence level
667                if (useConfidenceCheckBox.getSelection() && "".equals(levelField.getText())) {
668                        setErrorMessage("Confidence level is missing!");
669                        return false;
670                } else if (useConfidenceCheckBox.getSelection() && "".equals(halfWidthField.getText())) {
671                        setErrorMessage("Confidence interval half-width is missing!");
672                        return false;
673                } else if (useConfidenceCheckBox.getSelection() && "".equals(selectModelElementField.getText())) {
674                        setErrorMessage("Specify the usage scenario for which the confidence interval should be determined.");
675                        return false;
676                } else if (useConfidenceCheckBox.getSelection() && !"".equals(levelField.getText())) {
677                        try {
678                                double level = Double.parseDouble(levelField.getText());
679                                if (level < 0 || level > 100) {
680                                        setErrorMessage("Confidence level has to be a percentage!");
681                                        return false;
682                                }
683                        } catch (NumberFormatException ex) {
684                                setErrorMessage("Confidence level has to be an number!");
685                                return false;
686                        }
687                }
688                // check confidence interval half-width
689                if (useConfidenceCheckBox.getSelection() && halfWidthField.getText().equals("")) {
690                        setErrorMessage("Confidence interval half-width is missing!");
691                        return false;
692                } else if (useConfidenceCheckBox.getSelection() && halfWidthField.getText().length() > 0) {
693                        try {
694                                int halfWidth = Integer.parseInt(halfWidthField.getText());
695                                if (halfWidth < 0 || halfWidth > 100) {
696                                        setErrorMessage("Half-width has to be a percentage!");
697                                        return false;
698                                }
699                        } catch (NumberFormatException ex) {
700                                setErrorMessage("Half-width has to be an integer!");
701                                return false;
702                        }
703                }
704                // check, whether a model element is selected
705                if (useConfidenceCheckBox.getSelection()
706                                && selectedModelElementURI == null) {
707                        setErrorMessage("Select a model element whose response times are " +
708                                        "to be monitored!");
709                }
710                
711                // check validity of batch size and number settings
712                if (useConfidenceCheckBox.getSelection() 
713                                && !useAutomatedBatchMeansCheckBox.getSelection()){
714                        if ("".equals(batchSizeField.getText())){
715                                setErrorMessage("Batch size has to be specified if not determined automatically.");
716                                return false;
717                        } else if ("".equals(minNumberOfBatchesField.getText())){
718                                setErrorMessage("Minimum number of batches have to be specified if not determined automatically.");
719                                return false;
720                        }
721                        
722                        try {
723                                Integer.parseInt(batchSizeField.getText());
724                        } catch (NumberFormatException ex) {
725                                setErrorMessage("Batch size has to be an integer!");
726                                return false;
727                        }
728                        
729                        try {
730                                Integer.parseInt(minNumberOfBatchesField.getText());
731                        } catch (NumberFormatException ex) {
732                                setErrorMessage("Minimum number of batches has to be an integer!");
733                                return false;
734                        }
735                        
736                }
737                
738                return true;
739        }
740 
741        @Override
742        public void activated(ILaunchConfigurationWorkingCopy configuration) {
743                try {
744                        String usageFile = configuration.getAttribute(
745                                        ConstantsContainer.USAGE_FILE, "");
746 
747                        if (!usageFile.isEmpty()) {
748                                // Prevent reloading the model elements when usage file has not
749                                // changed
750                                if (!modelFiles.contains(usageFile)) {
751                                        modelFiles.clear();
752                                        modelFiles.add(usageFile);
753 
754                                        selectedModelElementURI = URI.createURI(configuration.getAttribute(
755                                                        SimuComConfig.CONFIDENCE_MODELELEMENT_URI, ""));
756                                        UsageScenario usageScenario = getUsageScenarioFromURI(selectedModelElementURI);
757                                        selectedModelElementName = usageScenario.getEntityName();
758                                        updateModelElementField(usageScenario);
759}
760                        }
761                } catch (Exception e) {
762                        selectedModelElementURI = null;
763                        selectedModelElementName = "";
764                        selectModelElementField.setText("");
765                }
766 
767        }
768 
769        @Override
770        public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {}
771 
772        private ResourceSet loadModelFiles() {
773                ResourceSet rs = new ResourceSetImpl();
774                for (String file : modelFiles) {
775                        try {
776                                rs.getResource(URI.createURI(file), true);
777                        } catch (Exception ex) {
778                                try {
779                                        rs.getResource(URI.createFileURI(file), true);
780                                } catch (Exception exInner) {
781                                }
782                        }
783                }
784                EcoreUtil.resolveAll(rs);
785                return rs;
786        }
787 
788        private UsageScenario getUsageScenarioFromURI(URI selectedModelElementURI)
789                        throws Exception {
790                ResourceSet rs = loadModelFiles();
791                EObject selectedModelElement = rs.getEObject(selectedModelElementURI,
792                                false);
793 
794                if (selectedModelElement != null
795                                && selectedModelElement instanceof UsageScenario) {
796                        return (UsageScenario) selectedModelElement;
797                } else {
798                        throw new RuntimeException("selectedModelElement " +
799                                        "is null or of wrong type");
800                }
801        }
802 
803}

[all classes][de.uka.ipd.sdq.codegen.simucontroller.runconfig]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov