1 11 package org.eclipse.pde.internal.ui.wizards.product; 12 13 import java.util.TreeSet ; 14 15 import org.eclipse.core.resources.IProject; 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.core.plugin.IPluginElement; 20 import org.eclipse.pde.core.plugin.IPluginExtension; 21 import org.eclipse.pde.core.plugin.IPluginExtensionPoint; 22 import org.eclipse.pde.core.plugin.IPluginModelBase; 23 import org.eclipse.pde.core.plugin.IPluginObject; 24 import org.eclipse.pde.core.plugin.PluginRegistry; 25 import org.eclipse.pde.internal.core.PDEStateHelper; 26 import org.eclipse.pde.internal.core.iproduct.IProduct; 27 import org.eclipse.pde.internal.ui.IHelpContextIds; 28 import org.eclipse.pde.internal.ui.PDEUIMessages; 29 import org.eclipse.pde.internal.ui.search.ShowDescriptionAction; 30 import org.eclipse.pde.internal.ui.util.SWTUtil; 31 import org.eclipse.pde.internal.ui.wizards.PluginSelectionDialog; 32 import org.eclipse.swt.SWT; 33 import org.eclipse.swt.events.ModifyEvent; 34 import org.eclipse.swt.events.ModifyListener; 35 import org.eclipse.swt.events.SelectionAdapter; 36 import org.eclipse.swt.events.SelectionEvent; 37 import org.eclipse.swt.layout.GridData; 38 import org.eclipse.swt.layout.GridLayout; 39 import org.eclipse.swt.widgets.Button; 40 import org.eclipse.swt.widgets.Composite; 41 import org.eclipse.swt.widgets.Group; 42 import org.eclipse.swt.widgets.Label; 43 import org.eclipse.swt.widgets.Text; 44 import org.eclipse.ui.PlatformUI; 45 import org.eclipse.ui.forms.events.HyperlinkEvent; 46 import org.eclipse.ui.forms.events.IHyperlinkListener; 47 import org.eclipse.ui.forms.widgets.FormText; 48 import org.eclipse.ui.forms.widgets.FormToolkit; 49 50 public class ProductIntroWizardPage extends WizardPage implements IHyperlinkListener { 51 52 private Text fPluginText; 53 private Text fIntroIdText; 54 private TreeSet fIntroIds; 55 private IProduct fProduct; 56 57 private ModifyListener fListener = new ModifyListener() { 58 public void modifyText(ModifyEvent e) { 59 validatePage(); 60 } 61 }; 62 63 public ProductIntroWizardPage(String pageName, IProduct product) { 64 super(pageName); 65 setTitle(PDEUIMessages.ProductIntroWizardPage_title); 66 setDescription(PDEUIMessages.ProductIntroWizardPage_description); 67 fIntroIds = getCurrentIntroIds(); 68 fProduct = product; 69 } 70 71 public void createControl(Composite parent) { 72 Composite comp = new Composite(parent, SWT.NONE); 73 GridLayout layout = new GridLayout(); 74 layout.verticalSpacing = 20; 75 comp.setLayout(layout); 76 77 createProductGroup(comp); 78 79 setControl(comp); 80 setPageComplete(getPluginId() != null); 81 Dialog.applyDialogFont(comp); 82 PlatformUI.getWorkbench().getHelpSystem().setHelp(comp, IHelpContextIds.PRODUCT_DEFINITIONS_WIZARD); 83 } 84 85 private void createProductGroup(Composite comp) { 86 Group group = new Group(comp, SWT.NONE); 87 group.setText(PDEUIMessages.ProductIntroWizardPage_groupText); 88 group.setLayout(new GridLayout(3, false)); 89 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 90 91 FormToolkit toolkit = new FormToolkit(group.getDisplay()); 92 FormText text = toolkit.createFormText(group, false); 93 text.setText(PDEUIMessages.ProductIntroWizardPage_formText, true, false); 94 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 95 gd.horizontalSpan = 3; 96 gd.widthHint = 400; 97 text.setLayoutData(gd); 98 text.setBackground(null); 99 text.addHyperlinkListener(this); 100 101 Label label = new Label(group, SWT.NONE); 102 label.setText(PDEUIMessages.ProductIntroWizardPage_targetLabel); 103 104 fPluginText = new Text(group, SWT.SINGLE|SWT.BORDER); 105 fPluginText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 106 107 Button button = new Button(group, SWT.PUSH); 108 button.setText(PDEUIMessages.ProductIntroWizardPage_browse); 109 SWTUtil.setButtonDimensionHint(button); 110 button.addSelectionListener(new SelectionAdapter() { 111 public void widgetSelected(SelectionEvent e) { 112 handleBrowse(); 113 } 114 }); 115 116 label = new Label(group, SWT.NONE); 117 label.setText(PDEUIMessages.ProductIntroWizardPage_introLabel); 118 119 fIntroIdText = new Text(group, SWT.SINGLE|SWT.BORDER); 120 gd = new GridData(GridData.FILL_HORIZONTAL); 121 gd.horizontalSpan = 2; 122 fIntroIdText.setLayoutData(gd); 123 124 String pluginId = getPluginId(); 125 if (pluginId != null) { 126 fPluginText.setText(pluginId); 127 fIntroIdText.setText(getAvailableIntroId(pluginId)); 128 } 129 fPluginText.addModifyListener(fListener); 130 fIntroIdText.addModifyListener(fListener); 131 } 132 133 134 public void setVisible(boolean visible) { 135 super.setVisible(visible); 136 if (visible) { 137 fPluginText.setVisible(visible); 138 fPluginText.setFocus(); 139 } 140 } 141 142 private void validatePage() { 143 String error = null; 144 String pluginId = getDefiningPlugin(); 145 IPluginModelBase model = PluginRegistry.findModel(pluginId); 146 if (model == null){ 147 error = PDEUIMessages.ProductDefinitonWizardPage_noPlugin; 148 } else if (model.getUnderlyingResource() == null) { 149 error = PDEUIMessages.ProductDefinitonWizardPage_notInWorkspace; 150 } else if (pluginId.length() == 0) { 151 error = PDEUIMessages.ProductIntroWizardPage_targetNotSet; 152 } 153 validateId(error); 154 155 } 156 157 private void validateId(String error) { 158 if (error == null) { 159 String id = fIntroIdText.getText().trim(); 160 161 if (id.length() == 0) 162 error = PDEUIMessages.ProductIntroWizardPage_introNotSet; 163 164 if (error == null) 165 for (int i = 0; i < id.length(); i++) 166 if (!id.substring(i,i+1).matches("[a-zA-Z0-9.]")) error = PDEUIMessages.ProductIntroWizardPage_invalidIntroId; 168 169 if (error == null && fIntroIds.contains(id)) 170 error = PDEUIMessages.ProductIntroWizardPage_introIdExists; 171 } 172 setErrorMessage(error); 173 setPageComplete(error == null); 174 } 175 176 private void handleBrowse() { 177 PluginSelectionDialog dialog = new PluginSelectionDialog(getShell(), PluginRegistry.getWorkspaceModels(), false); 178 if (dialog.open() == Window.OK) { 179 IPluginModelBase model = (IPluginModelBase)dialog.getFirstResult(); 180 String id = model.getPluginBase().getId(); 181 fPluginText.setText(id); 182 fIntroIdText.setText(getAvailableIntroId(id)); 183 } 184 } 185 186 187 private String getAvailableIntroId(String id) { 188 String introId = "intro"; String numString = ""; int idNum = 1; 191 while (fIntroIds.contains(id + "." + introId + numString)) { numString = Integer.toString(idNum++); 193 } 194 return id + "." + introId + numString; } 196 197 private TreeSet getCurrentIntroIds() { 198 String introId; 199 TreeSet result = new TreeSet (); 200 IPluginModelBase[] plugins = PluginRegistry.getActiveModels(); 201 for (int i = 0; i < plugins.length; i++) { 202 IPluginExtension[] extensions = plugins[i].getPluginBase().getExtensions(); 203 for (int j = 0; j < extensions.length; j++) { 204 String point = extensions[j].getPoint(); 205 if (point != null && point.equals("org.eclipse.ui.intro")) { IPluginObject[] children = extensions[j].getChildren(); 207 for (int k = 0; k < children.length; k++) { 208 IPluginElement element = (IPluginElement)children[k]; 209 if ("intro".equals(element.getName())) { introId = element.getAttribute("id").getValue(); if (introId != null) 212 result.add(introId); 213 } 214 } 215 } 216 } 217 } 218 return result; 219 } 220 221 222 public String getDefiningPlugin() { 223 return fPluginText.getText().trim(); 224 } 225 226 public String getIntroId() { 227 return fIntroIdText.getText().trim(); 228 } 229 230 private String getPluginId() { 231 IProject project = fProduct.getModel().getUnderlyingResource().getProject(); 232 IPluginModelBase model = PluginRegistry.findModel(project); 233 return (model == null) ? null : model.getPluginBase().getId(); 234 } 235 236 public void linkEntered(HyperlinkEvent e) { 237 } 238 239 public void linkExited(HyperlinkEvent e) { 240 } 241 242 public void linkActivated(HyperlinkEvent e) { 243 String extPoint = "org.eclipse.ui." + e.getHref().toString(); IPluginExtensionPoint point = PDEStateHelper.findExtensionPoint(extPoint); 245 if (point != null) 246 new ShowDescriptionAction(point, true).run(); 247 248 } 249 } 250 | Popular Tags |