| 1 | package de.uka.ipd.sdq.dsexplore.analysis.cost; |
| 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.ILaunchConfigurationTab; |
| 7 | import org.eclipse.swt.SWT; |
| 8 | import org.eclipse.swt.events.ModifyEvent; |
| 9 | import org.eclipse.swt.events.ModifyListener; |
| 10 | import org.eclipse.swt.graphics.Image; |
| 11 | import org.eclipse.swt.layout.GridLayout; |
| 12 | import org.eclipse.swt.widgets.Composite; |
| 13 | import org.eclipse.swt.widgets.Text; |
| 14 | |
| 15 | import de.uka.ipd.sdq.dsexplore.launch.DSEConstantsContainer; |
| 16 | import de.uka.ipd.sdq.workflow.launchconfig.RunConfigPlugin; |
| 17 | import de.uka.ipd.sdq.workflow.launchconfig.tabs.TabHelper; |
| 18 | import de.uka.ipd.sdq.workflow.pcm.runconfig.FileNamesInputTab; |
| 19 | |
| 20 | public class CostAnalysisTab extends de.uka.ipd.sdq.workflow.pcm.runconfig.FileNamesInputTab implements |
| 21 | ILaunchConfigurationTab { |
| 22 | |
| 23 | private Text textCostModel; |
| 24 | |
| 25 | @Override |
| 26 | public void createControl(Composite parent) { |
| 27 | |
| 28 | // Create a listener for GUI modification events: |
| 29 | final ModifyListener modifyListener = new ModifyListener() { |
| 30 | |
| 31 | public void modifyText(ModifyEvent e) { |
| 32 | CostAnalysisTab.this.setDirty(true); |
| 33 | CostAnalysisTab.this.updateLaunchConfigurationDialog(); |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | // Create a new Composite to hold the page's controls: |
| 38 | final Composite container = new Composite(parent, SWT.NONE); |
| 39 | setControl(container); |
| 40 | container.setLayout(new GridLayout()); |
| 41 | |
| 42 | /** |
| 43 | * Add cost model input section |
| 44 | */ |
| 45 | this.textCostModel = new Text(container, SWT.SINGLE | SWT.BORDER); |
| 46 | TabHelper.createFileInputSection(container, modifyListener, "Cost Model File", DSEConstantsContainer.COST_MODEL_EXTENSION, textCostModel, getShell(), DSEConstantsContainer.DEFAULT_COST_MODEL_FILE); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public String getName() { |
| 51 | return "Cost Analysis"; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void initializeFrom(ILaunchConfiguration configuration) { |
| 56 | try { |
| 57 | this.textCostModel.setText(configuration.getAttribute( |
| 58 | DSEConstantsContainer.COST_FILE, "")); |
| 59 | } catch (CoreException e) { |
| 60 | RunConfigPlugin.errorLogger(getName(),DSEConstantsContainer.COST_FILE, e.getMessage()); |
| 61 | } |
| 62 | |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public void performApply(ILaunchConfigurationWorkingCopy configuration) { |
| 67 | configuration.setAttribute( |
| 68 | DSEConstantsContainer.COST_FILE, |
| 69 | this.textCostModel.getText()); |
| 70 | |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { |
| 75 | |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public void activated(ILaunchConfigurationWorkingCopy workingCopy) { |
| 80 | // Leave this method empty to prevent unnecessary invocation of |
| 81 | // initializeFrom() and multiple resulting invocations of |
| 82 | // performApply(). |
| 83 | |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) { |
| 88 | |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public void dispose() { |
| 93 | super.dispose(); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public Image getImage() { |
| 98 | return null; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public boolean isValid(ILaunchConfiguration launchConfig) { |
| 103 | String extension = DSEConstantsContainer.COST_MODEL_EXTENSION[0].replace("*", ""); |
| 104 | if (this.textCostModel.getText().equals("") || !this.textCostModel.getText().contains(extension)){ |
| 105 | setErrorMessage("Cost model is missing!"); |
| 106 | return false; |
| 107 | } |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | |
| 113 | } |