| 1 | package de.uka.ipd.sdq.workflow.pcm.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.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.workflow.launchconfig.RunConfigImages; |
| 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.ConstantsContainer; |
| 19 | |
| 20 | /** |
| 21 | * The class defines a tab, which is responsible for the input model(s) of |
| 22 | * the Palladio Component Model. |
| 23 | * |
| 24 | * @author Roman Andrej |
| 25 | * @author groenda |
| 26 | */ |
| 27 | public class FileNamesInputTab extends AbstractLaunchConfigurationTab { |
| 28 | |
| 29 | /** The id of this plug-in. */ |
| 30 | public static final String PLUGIN_ID = "de.uka.ipd.sdq.workflow.pcm"; |
| 31 | /** The path to the image file for the tab icon. */ |
| 32 | private static final String FILENAME_TAB_IMAGE_PATH = "icons/filenames_tab.gif"; |
| 33 | |
| 34 | // input fields |
| 35 | /** Text field for path to allocation model file. */ |
| 36 | protected Text textAllocation; |
| 37 | /** Text field for path to usage model file. */ |
| 38 | protected Text textUsage; |
| 39 | /** Text field for path to middleware model file. */ |
| 40 | protected Text mwtextRepository; |
| 41 | /** Text field for path to event middleware model file. */ |
| 42 | protected Text eventMiddlewareRepository; |
| 43 | |
| 44 | /** Container for UI elements. */ |
| 45 | protected Composite container; |
| 46 | |
| 47 | /* (non-Javadoc) |
| 48 | * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#getImage() |
| 49 | */ |
| 50 | @Override |
| 51 | public Image getImage() { |
| 52 | return RunConfigImages.getTabImage(PLUGIN_ID,FILENAME_TAB_IMAGE_PATH); |
| 53 | } |
| 54 | |
| 55 | /* (non-Javadoc) |
| 56 | * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite) |
| 57 | */ |
| 58 | public void createControl(Composite parent) { |
| 59 | final ModifyListener modifyListener = new ModifyListener() { |
| 60 | |
| 61 | public void modifyText(ModifyEvent e) { |
| 62 | FileNamesInputTab.this.setDirty(true); |
| 63 | FileNamesInputTab.this.updateLaunchConfigurationDialog(); |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | this.container = new Composite(parent, SWT.NONE); |
| 68 | setControl(container); |
| 69 | container.setLayout(new GridLayout()); |
| 70 | |
| 71 | /** |
| 72 | * Create MW repository section |
| 73 | */ |
| 74 | mwtextRepository = new Text(container, SWT.SINGLE | SWT.BORDER); |
| 75 | TabHelper.createFileInputSection(container, modifyListener, "Middleware Repository File", ConstantsContainer.REPOSITORY_EXTENSION, mwtextRepository, "Select Middleware Repository File", getShell(), ConstantsContainer.DEFAULT_MIDDLEWARE_REPOSITORY_FILE); |
| 76 | |
| 77 | /** |
| 78 | * Create event MW repository section |
| 79 | */ |
| 80 | eventMiddlewareRepository = new Text(container, SWT.SINGLE | SWT.BORDER); |
| 81 | TabHelper.createFileInputSection(container, modifyListener, "Event Middleware Repository File", ConstantsContainer.REPOSITORY_EXTENSION, eventMiddlewareRepository, "Select Event Middleware Repository File", getShell(), ConstantsContainer.DEFAULT_EVENT_MIDDLEWARE_FILE); |
| 82 | |
| 83 | /** |
| 84 | * Create allocation section |
| 85 | */ |
| 86 | textAllocation = new Text(container, SWT.SINGLE | SWT.BORDER); |
| 87 | TabHelper.createFileInputSection(container, modifyListener, "Allocation File", ConstantsContainer.ALLOCATION_EXTENSION, textAllocation, "Select Allocation File", getShell(), ConstantsContainer.DEFAULT_ALLOCATION_FILE); |
| 88 | |
| 89 | /** |
| 90 | * Create usage section |
| 91 | */ |
| 92 | //First set the text like this, will be changed to the right parent in createFileInputSection |
| 93 | textUsage = new Text(container, SWT.SINGLE | SWT.BORDER); |
| 94 | TabHelper.createFileInputSection(container, modifyListener, "Usage File", ConstantsContainer.USAGEMODEL_EXTENSION, textUsage, "Select Usage File", getShell(), ConstantsContainer.DEFAULT_USAGE_FILE); |
| 95 | |
| 96 | } |
| 97 | |
| 98 | /* (non-Javadoc) |
| 99 | * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName() |
| 100 | */ |
| 101 | public String getName() { |
| 102 | return "Architecture Model(s)"; |
| 103 | } |
| 104 | |
| 105 | /* (non-Javadoc) |
| 106 | * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration) |
| 107 | */ |
| 108 | public void initializeFrom(ILaunchConfiguration configuration) { |
| 109 | try { |
| 110 | textAllocation.setText(configuration.getAttribute( |
| 111 | ConstantsContainer.ALLOCATION_FILE, ConstantsContainer.DEFAULT_ALLOCATION_FILE)); |
| 112 | } catch (CoreException e) { |
| 113 | RunConfigPlugin.errorLogger(getName(),"Allocation File", e.getMessage()); |
| 114 | } |
| 115 | try { |
| 116 | mwtextRepository.setText(configuration.getAttribute( |
| 117 | ConstantsContainer.MWREPOSITORY_FILE, ConstantsContainer.DEFAULT_MIDDLEWARE_REPOSITORY_FILE)); |
| 118 | } catch (CoreException e) { |
| 119 | RunConfigPlugin.errorLogger(getName(),"Middleware Repository File", e.getMessage()); |
| 120 | } |
| 121 | |
| 122 | try { |
| 123 | eventMiddlewareRepository.setText(configuration.getAttribute( |
| 124 | ConstantsContainer.EVENT_MIDDLEWARE_REPOSITORY_FILE, ConstantsContainer.DEFAULT_EVENT_MIDDLEWARE_FILE)); |
| 125 | } catch (CoreException e) { |
| 126 | RunConfigPlugin.errorLogger(getName(),"Event Middleware Repository File", e.getMessage()); |
| 127 | } |
| 128 | try { |
| 129 | textUsage.setText(configuration.getAttribute( |
| 130 | ConstantsContainer.USAGE_FILE, ConstantsContainer.DEFAULT_USAGE_FILE)); |
| 131 | } catch (CoreException e) { |
| 132 | RunConfigPlugin.errorLogger(getName(),"Usage File", e.getMessage()); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /* (non-Javadoc) |
| 137 | * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) |
| 138 | */ |
| 139 | public void performApply(ILaunchConfigurationWorkingCopy configuration) { |
| 140 | configuration.setAttribute(ConstantsContainer.MWREPOSITORY_FILE, |
| 141 | mwtextRepository.getText()); |
| 142 | configuration.setAttribute(ConstantsContainer.EVENT_MIDDLEWARE_REPOSITORY_FILE, |
| 143 | eventMiddlewareRepository.getText()); |
| 144 | configuration.setAttribute(ConstantsContainer.ALLOCATION_FILE, |
| 145 | textAllocation.getText()); |
| 146 | configuration.setAttribute(ConstantsContainer.USAGE_FILE, textUsage |
| 147 | .getText()); |
| 148 | } |
| 149 | |
| 150 | /* (non-Javadoc) |
| 151 | * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) |
| 152 | */ |
| 153 | public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { |
| 154 | configuration.setAttribute(ConstantsContainer.MWREPOSITORY_FILE, |
| 155 | ConstantsContainer.DEFAULT_MIDDLEWARE_REPOSITORY_FILE); |
| 156 | configuration.setAttribute( |
| 157 | ConstantsContainer.EVENT_MIDDLEWARE_REPOSITORY_FILE, |
| 158 | ConstantsContainer.DEFAULT_EVENT_MIDDLEWARE_FILE); |
| 159 | } |
| 160 | |
| 161 | |
| 162 | /* (non-Javadoc) |
| 163 | * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration) |
| 164 | */ |
| 165 | @Override |
| 166 | public boolean isValid(ILaunchConfiguration launchConfig) { |
| 167 | setErrorMessage(null); |
| 168 | |
| 169 | if (!TabHelper.validateFilenameExtension(mwtextRepository.getText(), |
| 170 | ConstantsContainer.REPOSITORY_EXTENSION)) { |
| 171 | setErrorMessage("Middleware Repository is missing."); |
| 172 | return false; |
| 173 | } |
| 174 | if (!TabHelper.validateFilenameExtension(eventMiddlewareRepository.getText(), |
| 175 | ConstantsContainer.REPOSITORY_EXTENSION)) { |
| 176 | setErrorMessage("Event Middleware Repository is missing."); |
| 177 | return false; |
| 178 | } |
| 179 | if (!TabHelper.validateFilenameExtension(textAllocation.getText(), |
| 180 | ConstantsContainer.ALLOCATION_EXTENSION)) { |
| 181 | setErrorMessage("Allocation is missing."); |
| 182 | return false; |
| 183 | } |
| 184 | if (!TabHelper.validateFilenameExtension(textUsage.getText(), |
| 185 | ConstantsContainer.USAGEMODEL_EXTENSION)) { |
| 186 | setErrorMessage("Usage is missing."); |
| 187 | return false; |
| 188 | } |
| 189 | return true; |
| 190 | } |
| 191 | |
| 192 | @Override |
| 193 | public boolean canSave() { |
| 194 | return true; |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public void activated(ILaunchConfigurationWorkingCopy workingCopy) { |
| 199 | // Override this methods's super class implementation in order to |
| 200 | // prevent multiple invocation of initializeFrom() and subsequent |
| 201 | // invocations of performApply(). |
| 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {} |
| 206 | |
| 207 | /* (non-Javadoc) |
| 208 | * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#getId() |
| 209 | */ |
| 210 | @Override |
| 211 | public String getId() { |
| 212 | return "de.uka.ipd.sdq.codegen.runconfig.tabs.FileNamesInputTab"; |
| 213 | } |
| 214 | } |