1 11 12 package org.eclipse.pde.internal.ui.wizards.feature; 13 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.core.runtime.PluginVersionIdentifier; 16 import org.eclipse.jface.dialogs.Dialog; 17 import org.eclipse.jface.window.Window; 18 import org.eclipse.jface.wizard.WizardPage; 19 import org.eclipse.pde.internal.core.PDECore; 20 import org.eclipse.pde.internal.core.ifeature.IFeatureModel; 21 import org.eclipse.pde.internal.core.util.IdUtil; 22 import org.eclipse.pde.internal.ui.PDEUIMessages; 23 import org.eclipse.pde.internal.ui.util.SWTUtil; 24 import org.eclipse.pde.internal.ui.wizards.FeatureSelectionDialog; 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.events.ModifyEvent; 27 import org.eclipse.swt.events.ModifyListener; 28 import org.eclipse.swt.events.SelectionAdapter; 29 import org.eclipse.swt.events.SelectionEvent; 30 import org.eclipse.swt.layout.GridData; 31 import org.eclipse.swt.layout.GridLayout; 32 import org.eclipse.swt.widgets.Button; 33 import org.eclipse.swt.widgets.Composite; 34 import org.eclipse.swt.widgets.Group; 35 import org.eclipse.swt.widgets.Label; 36 import org.eclipse.swt.widgets.Text; 37 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; 38 39 public abstract class BaseFeatureSpecPage extends WizardPage { 40 41 private boolean isPatch; 42 protected WizardNewProjectCreationPage mainPage; 43 protected Text featureIdText; 44 protected Text featureNameText; 45 protected Text featureVersionText; 46 protected Text featureProviderText; 47 protected Text patchIdText; 48 protected Text patchNameText; 49 protected Text patchProviderText; 50 protected Text libraryText; 51 protected Button browseButton; 52 protected Button customChoice; 53 protected String initialId; 54 protected String initialName; 55 protected Label libraryLabel; 56 protected boolean isInitialized = false; 57 protected IFeatureModel fFeatureToPatch; 58 59 public BaseFeatureSpecPage(WizardNewProjectCreationPage mainPage, 60 boolean isPatch) { 61 super("specPage"); this.isPatch = isPatch; 63 this.mainPage = mainPage; 64 } 65 66 public void createControl(Composite parent) { 67 Composite container = new Composite(parent, SWT.NULL); 68 GridLayout layout = new GridLayout(); 69 layout.numColumns = 2; 70 layout.verticalSpacing = 12; 71 layout.horizontalSpacing = 9; 72 container.setLayout(layout); 73 74 ModifyListener listener = new ModifyListener() { 75 public void modifyText(ModifyEvent e) { 76 verifyComplete(); 77 } 78 }; 79 80 if (isPatch()) { 81 Group patchPropertiesGroup = new Group(container, SWT.NULL); 82 layout = new GridLayout(2, false); 83 patchPropertiesGroup.setLayout(layout); 84 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 85 gd.horizontalSpan = 2; 86 patchPropertiesGroup.setLayoutData(gd); 87 patchPropertiesGroup.setText(PDEUIMessages.NewFeatureWizard_SpecPage_patchProperties); Label label = new Label(patchPropertiesGroup, SWT.NULL); 89 label.setText(PDEUIMessages.NewFeaturePatch_SpecPage_id); 90 patchIdText = new Text(patchPropertiesGroup, SWT.BORDER); 91 gd = new GridData(GridData.FILL_HORIZONTAL); 92 patchIdText.setLayoutData(gd); 93 if (initialId != null) 94 patchIdText.setText(initialId); 95 patchIdText.addModifyListener(listener); 96 97 label = new Label(patchPropertiesGroup, SWT.NULL); 98 label.setText(PDEUIMessages.NewFeaturePatch_SpecPage_name); 99 patchNameText = new Text(patchPropertiesGroup, SWT.BORDER); 100 gd = new GridData(GridData.FILL_HORIZONTAL); 101 patchNameText.setLayoutData(gd); 102 if (initialName != null) 103 patchNameText.setText(initialName); 104 patchNameText.addModifyListener(listener); 105 106 label = new Label(patchPropertiesGroup, SWT.NULL); 107 label.setText(PDEUIMessages.NewFeaturePatch_SpecPage_provider); 108 patchProviderText = new Text(patchPropertiesGroup, SWT.BORDER); 109 gd = new GridData(GridData.FILL_HORIZONTAL); 110 patchProviderText.setLayoutData(gd); 111 patchProviderText.addModifyListener(listener); 112 } 113 addFeatureProperties(container, listener); 114 addCustomInstallHandlerSection(container, listener); 115 116 setControl(container); 117 Dialog.applyDialogFont(container); 118 } 119 private void addCustomInstallHandlerSection(Composite parent, ModifyListener listener) { 120 Group customHandlerGroup = new Group(parent, SWT.NONE); 121 GridLayout layout = new GridLayout(); 122 layout.numColumns = 2; 123 customHandlerGroup.setLayout(layout); 124 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 125 gd.horizontalSpan = 2; 126 customHandlerGroup.setLayoutData(gd); 127 customHandlerGroup.setText(PDEUIMessages.BaseFeatureSpecPage_customGroup); 129 customChoice = new Button(customHandlerGroup, SWT.CHECK); 130 if (!isPatch()) 131 customChoice.setText(PDEUIMessages.NewFeatureWizard_SpecPage_customProject); 132 else 133 customChoice.setText(PDEUIMessages.NewFeatureWizard_SpecPage_patch_customProject); 134 customChoice.addSelectionListener(new SelectionAdapter() { 135 public void widgetSelected(SelectionEvent e) { 136 boolean isSelected = ((Button) e.widget).getSelection(); 137 libraryText.setEnabled(isSelected); 138 libraryLabel.setEnabled(isSelected); 139 verifyComplete(); 140 } 141 }); 142 gd = new GridData(GridData.FILL_HORIZONTAL); 143 gd.horizontalSpan = 2; 144 customChoice.setLayoutData(gd); 145 146 libraryLabel = new Label(customHandlerGroup, SWT.NULL); 147 libraryLabel.setText( 148 PDEUIMessages.NewFeatureWizard_SpecPage_library); 149 gd = new GridData(); 150 gd.horizontalIndent = 22; 151 libraryLabel.setLayoutData(gd); 152 libraryText = new Text(customHandlerGroup, SWT.SINGLE | SWT.BORDER); 153 libraryText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 154 libraryText.addModifyListener(listener); 155 156 } 157 public boolean isPatch() { 158 return isPatch; 159 } 160 161 protected abstract void verifyComplete(); 162 165 public String getInitialName() { 166 return initialName; 167 } 168 169 173 public void setInitialName(String initialName) { 174 this.initialName = initialName; 175 } 176 177 181 public void setInitialId(String initialId) { 182 this.initialId = initialId; 183 } 184 185 188 public String getInitialId() { 189 return initialId; 190 } 191 192 protected void initialize(){ 193 customChoice.setSelection(false); 194 libraryText.setEnabled(false); 195 libraryLabel.setEnabled(false); 196 } 197 198 private void addFeatureProperties(Composite container, ModifyListener listener){ 199 Group featurePropertiesGroup = new Group(container, SWT.NULL); 200 GridLayout layout = new GridLayout(2, false); 201 featurePropertiesGroup.setLayout(layout); 202 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 203 gd.horizontalSpan = 2; 204 featurePropertiesGroup.setLayoutData(gd); 205 206 if (isPatch()){ 207 featurePropertiesGroup.setText(PDEUIMessages.BaseFeatureSpecPage_patchGroup_title); 209 Label label = new Label(featurePropertiesGroup, SWT.NULL); 210 label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_id); 211 212 Composite patchcontainer = new Composite(featurePropertiesGroup, SWT.NULL); 213 layout = new GridLayout(2, false); 214 layout.marginHeight = layout.marginWidth =0; 215 layout.horizontalSpacing = 5; 216 patchcontainer.setLayout(layout); 217 gd = new GridData(GridData.FILL_HORIZONTAL); 218 gd.horizontalSpan = 1; 219 patchcontainer.setLayoutData(gd); 220 221 featureIdText = new Text(patchcontainer, SWT.BORDER); 222 gd = new GridData(GridData.FILL_HORIZONTAL); 223 featureIdText.setLayoutData(gd); 224 if (initialId != null) 225 featureIdText.setText(initialId); 226 featureIdText.addModifyListener(listener); 227 228 browseButton = new Button(patchcontainer, SWT.PUSH); 229 browseButton.setText(PDEUIMessages.BaseFeatureSpecPage_browse); gd = new GridData(GridData.HORIZONTAL_ALIGN_END); 231 browseButton.setLayoutData(gd); 232 browseButton.addSelectionListener(new SelectionAdapter() { 233 234 public void widgetSelected(SelectionEvent e) { 235 FeatureSelectionDialog dialog = new FeatureSelectionDialog( 236 getShell(), PDECore.getDefault() 237 .getFeatureModelManager().getModels(), 238 false); 239 dialog.create(); 240 if (dialog.open() == Window.OK) { 241 Object [] result = dialog.getResult(); 242 IFeatureModel selectedModel = (IFeatureModel) result[0]; 243 featureIdText.setText(selectedModel.getFeature().getId()); 244 featureNameText.setText(selectedModel.getFeature().getLabel()); 245 featureVersionText.setText(selectedModel.getFeature().getVersion()); 246 fFeatureToPatch = selectedModel; 247 } 248 } 249 }); 250 SWTUtil.setButtonDimensionHint(browseButton); 251 } else { 252 featurePropertiesGroup.setText(PDEUIMessages.BaseFeatureSpecPage_featurePropertiesGroup_title); 254 Label label = new Label(featurePropertiesGroup, SWT.NULL); 255 label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_id); 256 featureIdText = new Text(featurePropertiesGroup, SWT.BORDER); 257 gd = new GridData(GridData.FILL_HORIZONTAL); 258 featureIdText.setLayoutData(gd); 259 if (initialId != null) 260 featureIdText.setText(initialId); 261 featureIdText.addModifyListener(listener); 262 263 } 264 265 Label label = new Label(featurePropertiesGroup, SWT.NULL); 266 label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_name); 267 featureNameText = new Text(featurePropertiesGroup, SWT.BORDER); 268 gd = new GridData(GridData.FILL_HORIZONTAL); 269 featureNameText.setLayoutData(gd); 270 if (initialName != null) 271 featureNameText.setText(initialName); 272 featureNameText.addModifyListener(listener); 273 274 label = new Label(featurePropertiesGroup, SWT.NULL); 275 label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_version); 276 featureVersionText = new Text(featurePropertiesGroup, SWT.BORDER); 277 gd = new GridData(GridData.FILL_HORIZONTAL); 278 featureVersionText.setLayoutData(gd); 279 featureVersionText.addModifyListener(listener); 280 if (!isPatch()) { 281 label = new Label(featurePropertiesGroup, SWT.NULL); 282 label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_provider); 283 featureProviderText = new Text(featurePropertiesGroup, SWT.BORDER); 284 gd = new GridData(GridData.FILL_HORIZONTAL); 285 featureProviderText.setLayoutData(gd); 286 featureProviderText.addModifyListener(listener); 287 } 288 } 289 protected String computeInitialId(String projectName) { 290 return projectName.replaceAll("[^a-zA-Z0-9\\._]", "_"); } 292 293 protected String verifyVersion() { 294 String problemText = PDEUIMessages.NewFeatureWizard_SpecPage_versionFormat; 295 String value = featureVersionText.getText(); 296 if (PluginVersionIdentifier.validateVersion(value).getSeverity() != IStatus.OK) 297 return problemText; 298 return null; 299 } 300 301 protected String verifyIdRules() { 302 String id = featureIdText.getText(); 303 if (id == null || id.length() == 0) 304 return PDEUIMessages.NewFeatureWizard_SpecPage_missing; 305 if (!IdUtil.isValidPluginId(id)) { 306 return PDEUIMessages.NewFeatureWizard_SpecPage_invalidId; 307 } 308 return null; 309 } 310 311 public IFeatureModel getFeatureToPatch(){ 312 return fFeatureToPatch; 313 } 314 315 protected String getInstallHandlerLibrary() { 316 if (!customChoice.getSelection()) 317 return null; 318 String library = libraryText.getText(); 319 if (!library.endsWith(".jar") && !library.endsWith("/") && !library.equals(".")) library += "/"; return library; 322 } 323 } 324 | Popular Tags |