| 1 | package de.uka.ipd.sdq.cip.runtime.runconfig.tabs; |
| 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.swt.SWT; |
| 7 | import org.eclipse.swt.events.ModifyEvent; |
| 8 | import org.eclipse.swt.events.ModifyListener; |
| 9 | import org.eclipse.swt.events.SelectionAdapter; |
| 10 | import org.eclipse.swt.events.SelectionEvent; |
| 11 | import org.eclipse.swt.graphics.Image; |
| 12 | import org.eclipse.swt.layout.GridData; |
| 13 | import org.eclipse.swt.layout.GridLayout; |
| 14 | import org.eclipse.swt.widgets.Button; |
| 15 | import org.eclipse.swt.widgets.Composite; |
| 16 | import org.eclipse.swt.widgets.Group; |
| 17 | import org.eclipse.swt.widgets.Label; |
| 18 | import org.eclipse.swt.widgets.Text; |
| 19 | |
| 20 | import de.uka.ipd.sdq.cip.ConstantsContainer; |
| 21 | import de.uka.ipd.sdq.cip.runtime.RunConfigImages; |
| 22 | |
| 23 | public class CipConfigTab extends AbstractCipLaunchConfigurationTab { |
| 24 | |
| 25 | private Label locationLabel; |
| 26 | private Text outputPathField; |
| 27 | private Button clearButton; |
| 28 | private Button checkLoggingButton; |
| 29 | |
| 30 | @Override |
| 31 | public void createControl(Composite parent) { |
| 32 | final ModifyListener modifyListener = new ModifyListener(){ |
| 33 | |
| 34 | public void modifyText(ModifyEvent e) { |
| 35 | CipConfigTab.this.setDirty(true); |
| 36 | CipConfigTab.this.updateLaunchConfigurationDialog(); |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | Composite mainComponent = new Composite(parent,SWT.NONE); |
| 41 | setControl(mainComponent); |
| 42 | mainComponent.setLayout(new GridLayout()); |
| 43 | |
| 44 | /* Copyed from ConfigurationTab */ |
| 45 | /** Create outPath section */ |
| 46 | final Group outputPathGroup = new Group(mainComponent, SWT.NONE); |
| 47 | outputPathGroup.setText("Completion Plugin ID"); |
| 48 | final GridLayout gridLayout = new GridLayout(); |
| 49 | gridLayout.numColumns = 4; |
| 50 | outputPathGroup.setLayout(gridLayout); |
| 51 | final GridData gd_outputPathGroup = new GridData(SWT.FILL, SWT.CENTER, true, false); |
| 52 | outputPathGroup.setLayoutData(gd_outputPathGroup); |
| 53 | |
| 54 | /** default location button */ |
| 55 | final Button defaultLocationButton = new Button(outputPathGroup, |
| 56 | SWT.CHECK); |
| 57 | final GridData gridData_dl = new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1); |
| 58 | defaultLocationButton.setLayoutData(gridData_dl); |
| 59 | defaultLocationButton.setText("Use default location"); |
| 60 | defaultLocationButton.setSelection(true); |
| 61 | defaultLocationButton.addSelectionListener(new SelectionAdapter() { |
| 62 | |
| 63 | /* (non-Javadoc) |
| 64 | * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
| 65 | */ |
| 66 | public void widgetSelected(SelectionEvent e) { |
| 67 | setElementsEnabled(false); |
| 68 | outputPathField.setText(de.uka.ipd.sdq.cip.ConstantsContainer.COMPLETION_DEFAULT_PROJECT_ID); |
| 69 | |
| 70 | if (!defaultLocationButton.getSelection()) { |
| 71 | setElementsEnabled(true); |
| 72 | outputPathField.setSelection(0); |
| 73 | |
| 74 | } |
| 75 | } |
| 76 | }); |
| 77 | |
| 78 | locationLabel = new Label(outputPathGroup, SWT.NONE); |
| 79 | locationLabel.setLayoutData(new GridData(48, SWT.DEFAULT)); |
| 80 | locationLabel.setText("Location:"); |
| 81 | |
| 82 | outputPathField = new Text(outputPathGroup, SWT.BORDER); |
| 83 | final GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, |
| 84 | false); |
| 85 | gridData.widthHint = 20; |
| 86 | outputPathField.setLayoutData(gridData); |
| 87 | outputPathField.setText(de.uka.ipd.sdq.cip.ConstantsContainer.COMPLETION_DEFAULT_PROJECT_ID); |
| 88 | outputPathField.addModifyListener(modifyListener); |
| 89 | |
| 90 | /** Clear group*/ |
| 91 | final Group clearGroup = new Group(mainComponent, SWT.NONE); |
| 92 | clearGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 93 | clearGroup.setText("Generated models"); |
| 94 | clearGroup.setLayout(new GridLayout()); |
| 95 | clearButton = new Button(clearGroup, |
| 96 | SWT.CHECK); |
| 97 | clearButton.setLayoutData( new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1)); |
| 98 | clearButton.setText("Delete generated models at simulation end"); |
| 99 | clearButton.setSelection(true); |
| 100 | clearButton.addSelectionListener(new SelectionAdapter() { |
| 101 | |
| 102 | /* (non-Javadoc) |
| 103 | * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
| 104 | */ |
| 105 | public void widgetSelected(SelectionEvent e) { |
| 106 | CipConfigTab.this.setDirty(true); |
| 107 | CipConfigTab.this.updateLaunchConfigurationDialog(); |
| 108 | } |
| 109 | }); |
| 110 | |
| 111 | /** Logging group*/ |
| 112 | final Group loggingGroup = new Group(mainComponent, SWT.NONE); |
| 113 | loggingGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); |
| 114 | loggingGroup.setText("QVT Logging"); |
| 115 | loggingGroup.setLayout(new GridLayout()); |
| 116 | checkLoggingButton = new Button(loggingGroup, SWT.CHECK); |
| 117 | checkLoggingButton.setText("Enable verbose logging"); |
| 118 | checkLoggingButton.addSelectionListener(new SelectionAdapter() { |
| 119 | |
| 120 | /* (non-Javadoc) |
| 121 | * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
| 122 | */ |
| 123 | public void widgetSelected(SelectionEvent e) { |
| 124 | CipConfigTab.this.setDirty(true); |
| 125 | CipConfigTab.this.updateLaunchConfigurationDialog(); |
| 126 | } |
| 127 | }); |
| 128 | checkLoggingButton.setSelection(false); |
| 129 | |
| 130 | // disabled widget |
| 131 | setElementsEnabled(false); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Those makes enabled/disabled for the input the responsible widget |
| 136 | */ |
| 137 | private void setElementsEnabled(boolean enable) { |
| 138 | locationLabel.setEnabled(enable); |
| 139 | outputPathField.setEnabled(enable); |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public String getName() { |
| 144 | return "CIP Configuration"; |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public Image getImage() { |
| 149 | return RunConfigImages.getCompletionTabImage(); |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public void initializeFrom(ILaunchConfiguration configuration) { |
| 154 | try { |
| 155 | outputPathField.setText(configuration.getAttribute( |
| 156 | ConstantsContainer.COMPLETION_PROJECT_ID, de.uka.ipd.sdq.cip.ConstantsContainer.COMPLETION_DEFAULT_PROJECT_ID)); |
| 157 | } catch (CoreException e) { |
| 158 | //CipPlugin.errorLogger(getName(),"Location", e.getMessage()); |
| 159 | } |
| 160 | try { |
| 161 | clearButton.setSelection(configuration.getAttribute( |
| 162 | ConstantsContainer.COMPLETION_DELETE_PLUGIN, true)); |
| 163 | } catch (CoreException e) { |
| 164 | clearButton.setSelection(true); |
| 165 | } |
| 166 | try { |
| 167 | checkLoggingButton.setSelection(configuration.getAttribute( |
| 168 | ConstantsContainer.COMPLETION_QVT_VERBOSE_LOGGING, false)); |
| 169 | } catch (CoreException e) { |
| 170 | checkLoggingButton.setSelection(false); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | @Override |
| 175 | public void performApply(ILaunchConfigurationWorkingCopy configuration) { |
| 176 | configuration.setAttribute(ConstantsContainer.COMPLETION_PROJECT_ID, |
| 177 | outputPathField.getText()); |
| 178 | configuration.setAttribute(ConstantsContainer.COMPLETION_DELETE_PLUGIN, |
| 179 | clearButton.getSelection()); |
| 180 | configuration.setAttribute(ConstantsContainer.COMPLETION_QVT_VERBOSE_LOGGING, |
| 181 | checkLoggingButton.getSelection()); |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {} |
| 186 | |
| 187 | public boolean isValid(ILaunchConfiguration launchConfig) { |
| 188 | setErrorMessage(null); |
| 189 | |
| 190 | if (outputPathField.getText().equals("")){ |
| 191 | setErrorMessage("The output path location is not specified!"); |
| 192 | return false; |
| 193 | } |
| 194 | return true; |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public void activated(ILaunchConfigurationWorkingCopy workingCopy) { |
| 199 | // Leave this method empty to prevent unnecessary invocation of |
| 200 | // initializeFrom() and multiple resulting invocations of |
| 201 | // performApply(). |
| 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {} |
| 206 | |
| 207 | } |