1 11 12 package org.eclipse.pde.internal.ui.wizards.feature; 13 14 import org.eclipse.jface.dialogs.IMessageProvider; 15 import org.eclipse.jface.window.Window; 16 import org.eclipse.jface.wizard.IWizardPage; 17 import org.eclipse.osgi.util.NLS; 18 import org.eclipse.pde.internal.core.PDECore; 19 import org.eclipse.pde.internal.core.ifeature.IFeatureModel; 20 import org.eclipse.pde.internal.core.util.IdUtil; 21 import org.eclipse.pde.internal.ui.IHelpContextIds; 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.ModifyListener; 27 import org.eclipse.swt.events.SelectionAdapter; 28 import org.eclipse.swt.events.SelectionEvent; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.layout.GridLayout; 31 import org.eclipse.swt.widgets.Button; 32 import org.eclipse.swt.widgets.Composite; 33 import org.eclipse.swt.widgets.Group; 34 import org.eclipse.swt.widgets.Label; 35 import org.eclipse.swt.widgets.Text; 36 37 public class PatchSpecPage extends AbstractFeatureSpecPage { 38 39 private Text fPatchProviderText; 40 private Button fBrowseButton; 41 private Text fPatchIdText; 42 private Text fPatchNameText; 43 private Text fFeatureIdText; 44 45 public PatchSpecPage() { 46 super(); 47 setTitle(PDEUIMessages.PatchSpec_title); 48 setDescription(PDEUIMessages.NewFeatureWizard_SpecPage_desc); 49 } 50 51 protected void initialize() { 52 String projectName = getProjectName(); 53 if (fInitialId == null) 54 fPatchIdText.setText(IdUtil.getValidId(projectName)); 55 if (fInitialName == null) 56 fPatchNameText.setText(projectName); 57 setMessage(PDEUIMessages.FeaturePatch_MainPage_desc); 58 } 59 60 protected String validateContent() { 61 fFeatureToPatch = PDECore.getDefault().getFeatureModelManager().findFeatureModel( 62 fFeatureIdText.getText(), fFeatureVersionText.getText()); 63 if (fFeatureToPatch != null) { 64 setMessage(null); 65 return null; 66 } 67 68 setMessage(NLS.bind(PDEUIMessages.NewFeaturePatch_SpecPage_notFound, 69 fFeatureIdText.getText(), fFeatureVersionText.getText()), 70 IMessageProvider.WARNING); 71 getContainer().updateButtons(); 72 return null; 73 } 74 75 78 public IWizardPage getNextPage() { 79 if (fFeatureToPatch == null) 80 return null; 81 return super.getNextPage(); 82 } 83 84 private String getPatchId() { 85 if (fPatchIdText == null) 86 return ""; return fPatchIdText.getText(); 88 } 89 90 private String getPatchName() { 91 if (fPatchNameText == null) 92 return ""; return fPatchNameText.getText(); 94 } 95 96 private String getPatchProvider() { 97 if (fPatchProviderText == null) 98 return ""; return fPatchProviderText.getText(); 100 } 101 102 public FeatureData getFeatureData() { 103 FeatureData data = new FeatureData(); 104 data.id = getPatchId(); 105 data.version = "1.0.0"; data.provider = getPatchProvider(); 107 data.name = getPatchName(); 108 data.library = getInstallHandlerLibrary(); 109 data.isPatch = true; 110 data.featureToPatchId = fFeatureIdText.getText(); 111 data.featureToPatchVersion = fFeatureVersionText.getText(); 112 return data; 113 } 114 115 protected String verifyIdRules() { 116 String id = fPatchIdText.getText(); 117 if (id == null || id.length() == 0) 118 return PDEUIMessages.NewFeatureWizard_SpecPage_pmissing; 119 if (!IdUtil.isValidCompositeID(id)) { 120 return PDEUIMessages.NewFeatureWizard_SpecPage_invalidId; 121 } 122 return super.verifyIdRules(); 123 } 124 125 126 protected String getHelpId() { 127 return IHelpContextIds.NEW_PATCH_REQUIRED_DATA; 128 } 129 130 protected void createTopGroup(Composite container) { 131 Group patchGroup = new Group(container, SWT.NULL); 132 patchGroup.setLayout(new GridLayout(2, false)); 133 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 134 gd.verticalIndent = 10; 135 patchGroup.setLayoutData(gd); 136 patchGroup.setText(PDEUIMessages.NewFeatureWizard_SpecPage_patchProperties); 137 Label label = new Label(patchGroup, SWT.NULL); 138 label.setText(PDEUIMessages.NewFeaturePatch_SpecPage_id); 139 fPatchIdText = new Text(patchGroup, SWT.BORDER); 140 fPatchIdText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 141 142 label = new Label(patchGroup, SWT.NULL); 143 label.setText(PDEUIMessages.NewFeaturePatch_SpecPage_name); 144 fPatchNameText = new Text(patchGroup, SWT.BORDER); 145 fPatchNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 146 147 label = new Label(patchGroup, SWT.NULL); 148 label.setText(PDEUIMessages.NewFeaturePatch_SpecPage_provider); 149 fPatchProviderText = new Text(patchGroup, SWT.BORDER); 150 fPatchProviderText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 151 152 createInstallHandlerText(patchGroup); 153 } 154 155 protected void createContents(Composite container) { 156 157 createTopGroup(container); 158 159 Group group = new Group(container, SWT.NULL); 160 group.setLayout(new GridLayout(2, false)); 161 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 162 gd.verticalIndent = 10; 163 group.setLayoutData(gd); 164 group.setText(PDEUIMessages.BaseFeatureSpecPage_patchGroup_title); 165 166 Label label = new Label(group, SWT.NULL); 167 label.setText(PDEUIMessages.NewFeatureWizard_SpecPage_id); 168 169 Composite patchcontainer = new Composite(group, SWT.NULL); 170 GridLayout layout = new GridLayout(2, false); 171 layout.marginHeight = layout.marginWidth = 0; 172 layout.horizontalSpacing = 5; 173 patchcontainer.setLayout(layout); 174 patchcontainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 175 176 fFeatureIdText = new Text(patchcontainer, SWT.BORDER); 177 fFeatureIdText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 178 179 fBrowseButton = new Button(patchcontainer, SWT.PUSH); 180 fBrowseButton.setText(PDEUIMessages.BaseFeatureSpecPage_browse); 181 fBrowseButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); 182 fBrowseButton.addSelectionListener(new SelectionAdapter() { 183 184 public void widgetSelected(SelectionEvent e) { 185 FeatureSelectionDialog dialog = new FeatureSelectionDialog( 186 getShell(), PDECore.getDefault().getFeatureModelManager().getModels(), false); 187 dialog.create(); 188 if (dialog.open() == Window.OK) { 189 Object [] result = dialog.getResult(); 190 IFeatureModel selectedModel = (IFeatureModel) result[0]; 191 192 fSelfModification = true; 194 fFeatureIdText.setText(selectedModel.getFeature().getId()); 195 fFeatureNameText.setText(selectedModel.getFeature().getLabel()); 196 fSelfModification = false; 197 fFeatureVersionText.setText(selectedModel.getFeature().getVersion()); 198 199 fFeatureToPatch = selectedModel; 200 } 201 } 202 }); 203 SWTUtil.setButtonDimensionHint(fBrowseButton); 204 205 createCommonInput(group); 206 } 207 208 protected void attachListeners(ModifyListener listener) { 209 fPatchIdText.addModifyListener(listener); 210 fPatchNameText.addModifyListener(listener); 211 fPatchProviderText.addModifyListener(listener); 212 fFeatureIdText.addModifyListener(listener); 213 } 214 215 protected String getFeatureId() { 216 return fFeatureIdText.getText(); 217 } 218 219 protected void updateNameRelativeFields() { 220 if (fPatchIdText == null || fPatchNameText == null) 221 return; 222 fSelfModification = true; 223 String id = IdUtil.getValidId(getProjectName()); 224 fPatchIdText.setText(id); 225 fPatchNameText.setText(IdUtil.getValidName(id, PDEUIMessages.PatchSpecPage_feature)); 226 fPatchProviderText.setText(IdUtil.getValidProvider(id)); 227 fSelfModification = false; 228 } 229 } 230 | Popular Tags |