| 1 | /** |
| 2 | * |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.codegen.simucontroller.runconfig; |
| 5 | |
| 6 | import java.util.ArrayList; |
| 7 | |
| 8 | import org.eclipse.core.runtime.CoreException; |
| 9 | import org.eclipse.debug.core.ILaunchConfiguration; |
| 10 | import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
| 11 | import org.eclipse.emf.common.util.URI; |
| 12 | import org.eclipse.emf.ecore.EObject; |
| 13 | import org.eclipse.emf.ecore.resource.ResourceSet; |
| 14 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; |
| 15 | import org.eclipse.emf.ecore.util.EcoreUtil; |
| 16 | import org.eclipse.swt.SWT; |
| 17 | import org.eclipse.swt.events.SelectionAdapter; |
| 18 | import org.eclipse.swt.events.SelectionEvent; |
| 19 | import org.eclipse.swt.layout.GridData; |
| 20 | import org.eclipse.swt.layout.GridLayout; |
| 21 | import org.eclipse.swt.widgets.Button; |
| 22 | import org.eclipse.swt.widgets.Composite; |
| 23 | import org.eclipse.swt.widgets.Group; |
| 24 | import org.eclipse.swt.widgets.Label; |
| 25 | import org.eclipse.swt.widgets.Text; |
| 26 | |
| 27 | import de.uka.ipd.sdq.pcm.dialogs.selection.PalladioSelectEObjectDialog; |
| 28 | import de.uka.ipd.sdq.simulation.AbstractSimulationConfig; |
| 29 | import de.uka.ipd.sdq.workflow.pcm.ConstantsContainer; |
| 30 | import de.uka.ipd.sdq.workflow.pcm.runconfig.ConfigurationTab; |
| 31 | |
| 32 | /** |
| 33 | * The class extends ConfigurationTab by CheckBox. User can decide whether that |
| 34 | * generated instance of Palladio Component Model after simulating must be |
| 35 | * deleted. |
| 36 | * |
| 37 | * @see de.uka.ipd.sdq.workflow.pcm.runconfig.ConfigurationTab |
| 38 | * |
| 39 | * @author Roman Andrej |
| 40 | */ |
| 41 | public class SimuConfigurationTab extends ConfigurationTab { |
| 42 | |
| 43 | // Sensitivity Analysis |
| 44 | private Text variableText; |
| 45 | private Text minimumText; |
| 46 | private Text maximumText; |
| 47 | private Text stepWidthText; |
| 48 | private ArrayList<String> modelFiles = new ArrayList<String>(); |
| 49 | // Random Number Generator Seed(s) |
| 50 | private Button fixedSeedButton; |
| 51 | private Text[] seedText; |
| 52 | |
| 53 | /* (non-Javadoc) |
| 54 | * @see de.uka.ipd.sdq.codegen.runconfig.tabs.ConfigurationTab#createControl(org.eclipse.swt.widgets.Composite) |
| 55 | */ |
| 56 | @Override |
| 57 | public void createControl(Composite parent) { |
| 58 | super.createControl(parent); |
| 59 | Composite container = (Composite) getControl(); |
| 60 | |
| 61 | final Group sensitivityAnalysisParametersGroup = new Group(container, SWT.NONE); |
| 62 | sensitivityAnalysisParametersGroup.setText("Sensitivity Analysis Parameters"); |
| 63 | final GridData gd_sensitivityAnalysisParametersGroup = new GridData(SWT.FILL, SWT.CENTER, true, false); |
| 64 | sensitivityAnalysisParametersGroup.setLayoutData(gd_sensitivityAnalysisParametersGroup); |
| 65 | final GridLayout gridLayout_1 = new GridLayout(); |
| 66 | gridLayout_1.numColumns = 3; |
| 67 | sensitivityAnalysisParametersGroup.setLayout(gridLayout_1); |
| 68 | |
| 69 | final Label variableToAdaptLabel = new Label(sensitivityAnalysisParametersGroup, SWT.NONE); |
| 70 | final GridData gd_variableToAdaptLabel = new GridData(SWT.RIGHT, SWT.CENTER, false, false); |
| 71 | variableToAdaptLabel.setLayoutData(gd_variableToAdaptLabel); |
| 72 | variableToAdaptLabel.setText("Variable:"); |
| 73 | |
| 74 | variableText = new Text(sensitivityAnalysisParametersGroup, SWT.BORDER); |
| 75 | variableText.setEnabled(true); |
| 76 | variableText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 77 | variableText.addModifyListener(modifyListener); |
| 78 | |
| 79 | final Button selectVariableButton = new Button(sensitivityAnalysisParametersGroup, SWT.NONE); |
| 80 | selectVariableButton.addSelectionListener(new SelectionAdapter() { |
| 81 | public void widgetSelected(final SelectionEvent e) { |
| 82 | selectVariable(); |
| 83 | } |
| 84 | }); |
| 85 | selectVariableButton.setText("Select Variable..."); |
| 86 | |
| 87 | final Composite composite = new Composite(sensitivityAnalysisParametersGroup, SWT.NONE); |
| 88 | final GridData gd_composite = new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1); |
| 89 | composite.setLayoutData(gd_composite); |
| 90 | final GridLayout gridLayout_2 = new GridLayout(); |
| 91 | gridLayout_2.numColumns = 6; |
| 92 | composite.setLayout(gridLayout_2); |
| 93 | |
| 94 | final Label minimumLabel = new Label(composite, SWT.NONE); |
| 95 | minimumLabel.setText("Minimum:"); |
| 96 | |
| 97 | minimumText = new Text(composite, SWT.BORDER); |
| 98 | minimumText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 99 | minimumText.addModifyListener(modifyListener); |
| 100 | |
| 101 | final Label maximumLabel = new Label(composite, SWT.NONE); |
| 102 | maximumLabel.setText("Maximum:"); |
| 103 | |
| 104 | maximumText = new Text(composite, SWT.BORDER); |
| 105 | maximumText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 106 | maximumText.addModifyListener(modifyListener); |
| 107 | |
| 108 | final Label stepWidthLabel = new Label(composite, SWT.NONE); |
| 109 | stepWidthLabel.setText("Step Width:"); |
| 110 | |
| 111 | stepWidthText = new Text(composite, SWT.BORDER); |
| 112 | stepWidthText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 113 | stepWidthText.addModifyListener(modifyListener); |
| 114 | |
| 115 | final Group randomNumberGeneratorParametersGroup = new Group(container, SWT.NONE); |
| 116 | randomNumberGeneratorParametersGroup.setText("Random Number Generator Seed"); |
| 117 | final GridData gd_randomNumberGeneratorParametersGroup = new GridData(SWT.FILL, SWT.CENTER, true, false); |
| 118 | randomNumberGeneratorParametersGroup.setLayoutData(gd_randomNumberGeneratorParametersGroup); |
| 119 | final GridLayout gridLayout_3 = new GridLayout(); |
| 120 | gridLayout_3.numColumns = 12; |
| 121 | randomNumberGeneratorParametersGroup.setLayout(gridLayout_3); |
| 122 | |
| 123 | fixedSeedButton = new Button(randomNumberGeneratorParametersGroup, |
| 124 | SWT.CHECK); |
| 125 | fixedSeedButton.setLayoutData( new GridData(SWT.LEFT, SWT.CENTER, false, false, 12, 1)); |
| 126 | fixedSeedButton.setText("Use a fixed seed in simulation run"); |
| 127 | fixedSeedButton.setSelection(false); |
| 128 | fixedSeedButton.addSelectionListener(selectionListener); |
| 129 | |
| 130 | seedText = new Text[6]; Label[] seedLabel = new Label[6]; |
| 131 | for (int i = 0; i < 6; i++) { |
| 132 | seedLabel[i] = new Label(randomNumberGeneratorParametersGroup,SWT.NONE); |
| 133 | seedLabel[i].setText("Seed "+i); |
| 134 | seedText[i] = new Text(randomNumberGeneratorParametersGroup,SWT.BORDER); |
| 135 | seedText[i].setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 136 | seedText[i].addModifyListener(modifyListener); |
| 137 | seedText[i].setText(i+""); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | |
| 142 | protected void selectVariable() { |
| 143 | ResourceSet rs = new ResourceSetImpl(); |
| 144 | ArrayList<Object> filter = new ArrayList<Object>(); |
| 145 | filter.add(EObject.class); |
| 146 | for (String file : modelFiles) { |
| 147 | try { |
| 148 | rs.getResource(URI.createURI(file), true); |
| 149 | } catch (Exception ex) { |
| 150 | rs.getResource(URI.createFileURI(file), true); |
| 151 | } |
| 152 | } |
| 153 | EcoreUtil.resolveAll(rs); |
| 154 | PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog |
| 155 | (this.getShell(), |
| 156 | filter, |
| 157 | rs); |
| 158 | if (dialog.open() == org.eclipse.jface.dialogs.Dialog.OK) { |
| 159 | variableText.setText(EcoreUtil.getURI(dialog.getResult()).toString()); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | |
| 164 | /* (non-Javadoc) |
| 165 | * @see de.uka.ipd.sdq.codegen.runconfig.tabs.ConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration) |
| 166 | */ |
| 167 | @Override |
| 168 | public void initializeFrom(ILaunchConfiguration configuration) { |
| 169 | super.initializeFrom(configuration); |
| 170 | |
| 171 | try { |
| 172 | clearButton.setSelection(configuration.getAttribute( |
| 173 | ConstantsContainer.DELETE_TEMPORARY_DATA_AFTER_ANALYSIS, true)); |
| 174 | } catch (CoreException e) { |
| 175 | clearButton.setSelection(true); |
| 176 | } |
| 177 | |
| 178 | try { |
| 179 | fixedSeedButton.setSelection(configuration.getAttribute( |
| 180 | AbstractSimulationConfig.USE_FIXED_SEED, false)); |
| 181 | } catch (CoreException e) { |
| 182 | fixedSeedButton.setSelection(false); |
| 183 | } |
| 184 | |
| 185 | for (int i=0; i<6; i++) { |
| 186 | try { |
| 187 | seedText[i].setText(configuration.getAttribute( |
| 188 | AbstractSimulationConfig.FIXED_SEED_PREFIX+i, i+"")); |
| 189 | } catch (CoreException e) { |
| 190 | seedText[i].setText(i+""); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | try { |
| 195 | variableText.setText(configuration.getAttribute( |
| 196 | ConstantsContainer.VARIABLE_TEXT, "")); |
| 197 | } catch (CoreException e) { |
| 198 | variableText.setText(""); |
| 199 | } |
| 200 | |
| 201 | try { |
| 202 | minimumText.setText(configuration.getAttribute( |
| 203 | ConstantsContainer.MINIMUM_TEXT, "")); |
| 204 | } catch (CoreException e) { |
| 205 | minimumText.setText(""); |
| 206 | } |
| 207 | |
| 208 | try { |
| 209 | maximumText.setText(configuration.getAttribute( |
| 210 | ConstantsContainer.MAXIMUM_TEXT, "")); |
| 211 | } catch (CoreException e) { |
| 212 | maximumText.setText(""); |
| 213 | } |
| 214 | |
| 215 | try { |
| 216 | stepWidthText.setText(configuration.getAttribute( |
| 217 | ConstantsContainer.STEP_WIDTH_TEXT, "")); |
| 218 | } catch (CoreException e) { |
| 219 | stepWidthText.setText(""); |
| 220 | } |
| 221 | |
| 222 | try { |
| 223 | modelFiles.clear(); |
| 224 | modelFiles.add(configuration.getAttribute( |
| 225 | ConstantsContainer.REPOSITORY_FILE, "")); |
| 226 | modelFiles.add(configuration.getAttribute( |
| 227 | ConstantsContainer.SYSTEM_FILE, "")); |
| 228 | modelFiles.add(configuration.getAttribute( |
| 229 | ConstantsContainer.ALLOCATION_FILE, "")); |
| 230 | modelFiles.add(configuration.getAttribute( |
| 231 | ConstantsContainer.USAGE_FILE, "")); |
| 232 | } catch (CoreException e) { |
| 233 | stepWidthText.setText(""); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | /* (non-Javadoc) |
| 238 | * @see de.uka.ipd.sdq.codegen.runconfig.tabs.ConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) |
| 239 | */ |
| 240 | @Override |
| 241 | public void performApply(ILaunchConfigurationWorkingCopy configuration) { |
| 242 | super.performApply(configuration); |
| 243 | |
| 244 | configuration.setAttribute(ConstantsContainer.DELETE_TEMPORARY_DATA_AFTER_ANALYSIS, |
| 245 | clearButton.getSelection()); |
| 246 | configuration.setAttribute(AbstractSimulationConfig.USE_FIXED_SEED, |
| 247 | fixedSeedButton.getSelection()); |
| 248 | for (int i=0; i<6; i++){ |
| 249 | configuration.setAttribute(AbstractSimulationConfig.FIXED_SEED_PREFIX+i, |
| 250 | seedText[i].getText()); |
| 251 | } |
| 252 | configuration.setAttribute(ConstantsContainer.VARIABLE_TEXT, |
| 253 | variableText.getText()); |
| 254 | configuration.setAttribute(ConstantsContainer.MINIMUM_TEXT, |
| 255 | minimumText.getText()); |
| 256 | configuration.setAttribute(ConstantsContainer.MAXIMUM_TEXT, |
| 257 | maximumText.getText()); |
| 258 | configuration.setAttribute(ConstantsContainer.STEP_WIDTH_TEXT, |
| 259 | stepWidthText.getText()); |
| 260 | |
| 261 | } |
| 262 | } |