1 11 package org.eclipse.pde.internal.ui.wizards.extension; 12 13 import java.net.URL ; 14 import java.util.ArrayList ; 15 import java.util.HashSet ; 16 import java.util.Locale ; 17 import java.util.regex.Pattern ; 18 import java.util.regex.PatternSyntaxException ; 19 20 import org.eclipse.core.resources.IProject; 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.core.runtime.IConfigurationElement; 23 import org.eclipse.core.runtime.IStatus; 24 import org.eclipse.core.runtime.NullProgressMonitor; 25 import org.eclipse.core.runtime.Status; 26 import org.eclipse.jface.dialogs.Dialog; 27 import org.eclipse.jface.dialogs.MessageDialog; 28 import org.eclipse.jface.viewers.DoubleClickEvent; 29 import org.eclipse.jface.viewers.IDoubleClickListener; 30 import org.eclipse.jface.viewers.ISelection; 31 import org.eclipse.jface.viewers.ISelectionProvider; 32 import org.eclipse.jface.viewers.IStructuredContentProvider; 33 import org.eclipse.jface.viewers.IStructuredSelection; 34 import org.eclipse.jface.viewers.ITableLabelProvider; 35 import org.eclipse.jface.viewers.LabelProvider; 36 import org.eclipse.jface.viewers.SelectionChangedEvent; 37 import org.eclipse.jface.viewers.TableViewer; 38 import org.eclipse.jface.viewers.Viewer; 39 import org.eclipse.jface.viewers.ViewerFilter; 40 import org.eclipse.jface.wizard.IWizard; 41 import org.eclipse.jface.wizard.IWizardNode; 42 import org.eclipse.osgi.util.NLS; 43 import org.eclipse.pde.core.plugin.IFragment; 44 import org.eclipse.pde.core.plugin.IPluginExtension; 45 import org.eclipse.pde.core.plugin.IPluginExtensionPoint; 46 import org.eclipse.pde.core.plugin.IPluginImport; 47 import org.eclipse.pde.core.plugin.IPluginModelBase; 48 import org.eclipse.pde.core.plugin.PluginRegistry; 49 import org.eclipse.pde.internal.core.PDECore; 50 import org.eclipse.pde.internal.core.ischema.ISchemaElement; 51 import org.eclipse.pde.internal.core.schema.Schema; 52 import org.eclipse.pde.internal.core.schema.SchemaAnnotationHandler; 53 import org.eclipse.pde.internal.core.schema.SchemaRegistry; 54 import org.eclipse.pde.internal.core.text.plugin.PluginExtensionNode; 55 import org.eclipse.pde.internal.core.text.plugin.PluginExtensionPointNode; 56 import org.eclipse.pde.internal.core.util.IdUtil; 57 import org.eclipse.pde.internal.core.util.PDEHTMLHelper; 58 import org.eclipse.pde.internal.core.util.PatternConstructor; 59 import org.eclipse.pde.internal.core.util.SchemaUtil; 60 import org.eclipse.pde.internal.core.util.XMLComponentRegistry; 61 import org.eclipse.pde.internal.ui.IHelpContextIds; 62 import org.eclipse.pde.internal.ui.PDELabelProvider; 63 import org.eclipse.pde.internal.ui.PDEPlugin; 64 import org.eclipse.pde.internal.ui.PDEPluginImages; 65 import org.eclipse.pde.internal.ui.PDEUIMessages; 66 import org.eclipse.pde.internal.ui.editor.contentassist.XMLInsertionComputer; 67 import org.eclipse.pde.internal.ui.editor.text.HTMLPrinter; 68 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; 69 import org.eclipse.pde.internal.ui.elements.ElementLabelProvider; 70 import org.eclipse.pde.internal.ui.search.ShowDescriptionAction; 71 import org.eclipse.pde.internal.ui.util.TextUtil; 72 import org.eclipse.pde.internal.ui.wizards.BaseWizardSelectionPage; 73 import org.eclipse.pde.internal.ui.wizards.ListUtil; 74 import org.eclipse.pde.internal.ui.wizards.PluginSelectionDialog; 75 import org.eclipse.pde.internal.ui.wizards.WizardCollectionElement; 76 import org.eclipse.pde.internal.ui.wizards.WizardElement; 77 import org.eclipse.pde.internal.ui.wizards.WizardNode; 78 import org.eclipse.pde.internal.ui.wizards.templates.NewExtensionTemplateWizard; 79 import org.eclipse.pde.ui.IBasePluginWizard; 80 import org.eclipse.pde.ui.IExtensionWizard; 81 import org.eclipse.pde.ui.templates.ITemplateSection; 82 import org.eclipse.swt.SWT; 83 import org.eclipse.swt.SWTError; 84 import org.eclipse.swt.browser.Browser; 85 import org.eclipse.swt.custom.SashForm; 86 import org.eclipse.swt.events.KeyEvent; 87 import org.eclipse.swt.events.KeyListener; 88 import org.eclipse.swt.events.ModifyEvent; 89 import org.eclipse.swt.events.ModifyListener; 90 import org.eclipse.swt.events.SelectionAdapter; 91 import org.eclipse.swt.events.SelectionEvent; 92 import org.eclipse.swt.graphics.Image; 93 import org.eclipse.swt.graphics.RGB; 94 import org.eclipse.swt.layout.GridData; 95 import org.eclipse.swt.layout.GridLayout; 96 import org.eclipse.swt.widgets.Button; 97 import org.eclipse.swt.widgets.Composite; 98 import org.eclipse.swt.widgets.Control; 99 import org.eclipse.swt.widgets.Label; 100 import org.eclipse.swt.widgets.Link; 101 import org.eclipse.swt.widgets.TabFolder; 102 import org.eclipse.swt.widgets.TabItem; 103 import org.eclipse.swt.widgets.TableItem; 104 import org.eclipse.swt.widgets.Text; 105 import org.eclipse.ui.PlatformUI; 106 107 public class PointSelectionPage 108 extends BaseWizardSelectionPage { 109 private TableViewer fPointListViewer; 110 private TableViewer fTemplateViewer; 111 112 private IPluginModelBase fModel; 113 private Button fFilterCheck; 114 private IPluginExtensionPoint fCurrentPoint; 115 private HashSet fAvailableImports; 116 private IProject fProject; 117 private Label fTemplateLabel; 118 private ExtensionTreeSelectionPage fWizardsPage; 119 120 private IPluginExtension fNewExtension; 121 private WizardCollectionElement fTemplateCollection; 122 private WizardCollectionElement fWizardCollection; 123 private NewExtensionWizard fWizard; 124 private Text fFilterText; 125 private WildcardFilter fWildCardFilter; 126 private Text fPointDescription; 127 private Link fDescLink; 128 private Browser fPointDescBrowser; 129 130 class PointFilter extends ViewerFilter { 131 public boolean select(Viewer viewer, Object parentElement, Object element) { 132 if (!fFilterCheck.getSelection()) 133 return true; 134 135 IPluginExtensionPoint point = (IPluginExtensionPoint) element; 136 if (point instanceof PluginExtensionPointNode) 137 return true; 138 139 return fAvailableImports.contains(point.getPluginBase().getId()); 140 } 141 } 142 class WildcardFilter extends ViewerFilter { 143 private String wMatch = "*"; protected void setMatchText(String match) { 145 if (match.indexOf("*") < 0 & match.indexOf("?") < 0 & match.indexOf(".") < 0) { match = "*" + match; } 148 wMatch = match + "*"; } 150 public boolean select(Viewer viewer, Object parentElement, Object element) { 151 String text = ((PointLabelProvider)fPointListViewer.getLabelProvider()).getColumnText(element, 0); 152 Pattern pattern = null; 153 try { 154 pattern = PatternConstructor.createPattern(wMatch, false); 155 } catch (PatternSyntaxException e) { 156 return false; 157 } 158 return pattern != null && pattern.matcher(text.subSequence(0, text.length())).matches(); 159 } 160 } 161 162 class TemplateContentProvider extends DefaultContentProvider implements IStructuredContentProvider{ 163 public Object [] getElements(Object inputElement) { 164 if (inputElement instanceof IPluginExtensionPoint){ 165 IPluginExtensionPoint point = (IPluginExtensionPoint)inputElement; 166 String pointID = IdUtil.getFullId(point, fModel); 167 ArrayList result = new ArrayList (); 168 if (fTemplateCollection.getWizards() != null) { 169 Object [] wizards = fTemplateCollection.getWizards().getChildren(); 170 for (int i = 0; i<wizards.length; i++){ 171 String wizardContributorId = ((WizardElement)wizards[i]).getContributingId(); 172 if (wizardContributorId == null || pointID == null) 173 continue; 174 if (wizards[i] instanceof WizardElement && wizardContributorId.equals(pointID)) 175 result.add(wizards[i]); 176 } 177 return result.toArray(); 178 } 179 } 180 return new Object [0]; 181 } 182 } 183 184 class PointContentProvider 185 extends DefaultContentProvider 186 implements IStructuredContentProvider { 187 public Object [] getElements(Object parent) { 188 ArrayList extPoints = new ArrayList (); 189 IPluginModelBase[] plugins = PluginRegistry.getActiveModels(); 190 for (int i = 0; i < plugins.length; i++) { 191 IPluginExtensionPoint[] points = plugins[i].getPluginBase().getExtensionPoints(); 192 String id = plugins[i].getPluginBase().getId(); 193 if (id.equals(fModel.getPluginBase().getId())) 194 continue; 195 for (int j = 0; j < points.length; j++) 196 extPoints.add(points[j]); 197 } 198 199 IPluginExtensionPoint[] points = fModel.getPluginBase().getExtensionPoints(); 200 for (int i = 0; i < points.length; i++) 201 extPoints.add(points[i]); 202 203 return extPoints.toArray(); 204 } 205 } 206 207 class PointLabelProvider 208 extends LabelProvider 209 implements ITableLabelProvider { 210 public String getText(Object obj) { 211 return getColumnText(obj, 0); 212 } 213 public String getColumnText(Object obj, int index) { 214 IPluginExtensionPoint extPoint = (IPluginExtensionPoint)obj; 215 PDELabelProvider provider = PDEPlugin.getDefault().getLabelProvider(); 216 if (provider.isFullNameModeEnabled()) 217 return provider.getText(extPoint); 218 219 return IdUtil.getFullId(extPoint, fModel); 220 } 221 222 public Image getImage(Object obj) { 223 return getColumnImage(obj, 0); 224 } 225 226 public Image getColumnImage(Object obj, int index) { 227 IPluginExtensionPoint exp = (IPluginExtensionPoint) obj; 228 229 if (((TemplateContentProvider)fTemplateViewer.getContentProvider()).getElements(exp).length >0) 230 { return PDEPlugin.getDefault().getLabelProvider().get( 231 PDEPluginImages.DESC_NEWEXP_WIZ_TOOL, 0); 232 } 233 234 return PDEPlugin.getDefault().getLabelProvider().get( 235 PDEPluginImages.DESC_EXT_POINT_OBJ, 0); 236 } 237 } 238 239 public PointSelectionPage(IProject project, IPluginModelBase model, WizardCollectionElement element, WizardCollectionElement templates, NewExtensionWizard wizard) { 240 super("pointSelectionPage", PDEUIMessages.NewExtensionWizard_PointSelectionPage_title); this.fModel = model; 242 this.fWizardCollection = element; 243 this.fTemplateCollection = templates; 244 this.fWizard= wizard; 245 this.fProject=project; 246 fWildCardFilter = new WildcardFilter(); 247 fAvailableImports = PluginSelectionDialog.getExistingImports(model, true); 248 setTitle(PDEUIMessages.NewExtensionWizard_PointSelectionPage_title); 249 setDescription(PDEUIMessages.NewExtensionWizard_PointSelectionPage_desc); 250 } 251 252 public void createControl(Composite parent) { 253 final TabFolder tabFolder = new TabFolder(parent, SWT.FLAT); 255 TabItem firstTab = new TabItem(tabFolder, SWT.NULL); 256 firstTab.setText(PDEUIMessages.PointSelectionPage_tab1); 257 TabItem secondTab = new TabItem(tabFolder, SWT.NULL); 258 secondTab.setText(PDEUIMessages.PointSelectionPage_tab2); 259 secondTab.setControl(createWizardsPage(tabFolder)); 260 tabFolder.addSelectionListener(new SelectionAdapter() { 261 public void widgetSelected(SelectionEvent e) { 262 updateTabSelection(tabFolder.getSelectionIndex()); 263 } 264 }); 265 Composite outerContainer = new Composite(tabFolder, SWT.NONE); 267 firstTab.setControl(outerContainer); 268 GridLayout layout = new GridLayout(); 269 outerContainer.setLayout(layout); 270 GridData gd = new GridData(GridData.FILL_BOTH); 271 outerContainer.setLayoutData(gd); 272 273 Composite pointContainer = new Composite(outerContainer, SWT.NONE); 274 layout = new GridLayout(); 275 layout.marginHeight = layout.marginWidth = 0; 276 pointContainer.setLayout(layout); 277 gd = new GridData(GridData.FILL_BOTH); 278 pointContainer.setLayoutData(gd); 279 280 Composite labelContainer = new Composite(pointContainer, SWT.NONE); 281 layout = new GridLayout(2, false); 282 layout.marginHeight = layout.marginWidth = 0; 283 labelContainer.setLayout(layout); 284 labelContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 285 286 Label filterLabel = new Label(labelContainer, SWT.NONE); 287 filterLabel.setText(PDEUIMessages.NewExtensionWizard_PointSelectionPage_availExtPoints_label); 288 gd = new GridData(); 289 gd.verticalAlignment = GridData.CENTER; 290 filterLabel.setLayoutData(gd); 291 fFilterText = new Text(labelContainer, SWT.BORDER); 292 fFilterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 293 fFilterText.addModifyListener(new ModifyListener() { 294 public void modifyText(ModifyEvent e) { 295 fWildCardFilter.setMatchText(fFilterText.getText()); 296 fPointListViewer.refresh(); 297 } 298 }); 299 fFilterText.addKeyListener(new KeyListener() { 300 public void keyPressed(KeyEvent e) { 301 if (e.keyCode == SWT.ARROW_DOWN) fPointListViewer.getControl().setFocus(); 302 } 303 public void keyReleased(KeyEvent e) {} 304 }); 305 306 fFilterCheck = new Button(outerContainer, SWT.CHECK); 307 fFilterCheck.setText(PDEUIMessages.NewExtensionWizard_PointSelectionPage_filterCheck); 308 gd = new GridData(GridData.FILL_HORIZONTAL); 309 fFilterCheck.setLayoutData(gd); 310 fFilterCheck.setSelection(true); 311 fFilterCheck.addSelectionListener(new SelectionAdapter() { 312 public void widgetSelected(SelectionEvent e) { 313 fPointListViewer.refresh(); 314 } 315 }); 316 317 fPointListViewer = 318 new TableViewer( 319 pointContainer, 320 SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); 321 fPointListViewer.setContentProvider(new PointContentProvider()); 322 fPointListViewer.setLabelProvider(new PointLabelProvider()); 323 fPointListViewer.addSelectionChangedListener(this); 324 fPointListViewer.addDoubleClickListener(new IDoubleClickListener(){ 325 public void doubleClick(DoubleClickEvent event) { 326 if (canFinish()){ 327 fWizard.performFinish(); 328 fWizard.getShell().close(); 329 fWizard.dispose(); 330 fWizard.setContainer(null); 331 } 332 } 333 }); 334 fPointListViewer.addFilter(fWildCardFilter); 335 fPointListViewer.setComparator(ListUtil.NAME_COMPARATOR); 336 gd = new GridData(GridData.FILL_BOTH); 337 gd.heightHint = 150; 338 fPointListViewer.getTable().setLayoutData(gd); 339 340 Composite templateComposite = new Composite(outerContainer, SWT.NONE); 341 layout = new GridLayout(); 342 layout.marginHeight = 4; 343 layout.marginWidth = 0; 344 templateComposite.setLayout(layout); 345 gd = new GridData(GridData.FILL_HORIZONTAL); 346 templateComposite.setLayoutData(gd); 347 348 fDescLink = new Link(templateComposite, SWT.NONE); 349 fDescLink.setText(NLS.bind(PDEUIMessages.PointSelectionPage_extPointDesc, "")); fDescLink.addSelectionListener(new SelectionAdapter() { 351 public void widgetSelected(SelectionEvent e) { 352 if (fCurrentPoint != null) 353 new ShowDescriptionAction(fCurrentPoint, true).run(); 354 } 355 }); 356 fDescLink.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 357 358 Control c = null; 359 Composite comp = new Composite(templateComposite, SWT.BORDER); 360 layout = new GridLayout(); 361 layout.marginHeight = layout.marginWidth = 0; 362 comp.setLayout(layout); 363 comp.setLayoutData(new GridData(GridData.FILL_BOTH)); 364 try { 365 c = fPointDescBrowser = new Browser(comp, SWT.NONE); 366 } catch (SWTError e) {} 367 if (c == null) 368 c = fPointDescription = new Text(comp, SWT.WRAP | SWT.MULTI | SWT.V_SCROLL | SWT.READ_ONLY); 369 370 setPointDescriptionText(PDEUIMessages.NewExtensionWizard_PointSelectionPage_extPointDescription); 371 gd = new GridData(GridData.FILL_HORIZONTAL); 372 gd.heightHint = 80; 373 c.setLayoutData(gd); 374 375 fTemplateLabel = new Label(templateComposite, SWT.NONE | SWT.WRAP); 376 fTemplateLabel.setText(PDEUIMessages.NewExtensionWizard_PointSelectionPage_contributedTemplates_title); 377 gd = new GridData(GridData.FILL_HORIZONTAL); 378 fTemplateLabel.setLayoutData(gd); 379 380 SashForm templateSashForm = new SashForm(templateComposite, SWT.HORIZONTAL); 381 templateSashForm.setLayout(new GridLayout()); 382 gd = new GridData(GridData.FILL_BOTH); 383 gd.heightHint = 80; 384 templateSashForm.setLayoutData(gd); 385 386 Composite wizardComposite = 387 new Composite(templateSashForm, SWT.NONE); 388 layout = new GridLayout(); 389 layout.marginHeight = 0; 390 layout.marginWidth = 0; 391 wizardComposite.setLayout(layout); 392 gd = 393 new GridData( 394 GridData.FILL_BOTH | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); 395 wizardComposite.setLayoutData(gd); 396 fTemplateViewer = new TableViewer(wizardComposite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); 397 fTemplateViewer.setContentProvider(new TemplateContentProvider()); 398 fTemplateViewer.setLabelProvider(ElementLabelProvider.INSTANCE); 399 fTemplateViewer.setComparator(ListUtil.NAME_COMPARATOR); 400 fTemplateViewer.addSelectionChangedListener(this); 401 gd = new GridData(GridData.FILL_BOTH); 402 403 fTemplateViewer.getTable().setLayoutData(gd); 404 TableItem[] selection = fPointListViewer.getTable().getSelection(); 405 if (selection != null && selection.length > 0) 406 fTemplateViewer.setInput(selection[0]); 407 fTemplateViewer.addDoubleClickListener(new IDoubleClickListener(){ 408 public void doubleClick(DoubleClickEvent event) { 409 if (canFlipToNextPage()){ 410 advanceToNextPage(); 411 } 412 } 413 }); 414 415 Composite descriptionComposite = 416 new Composite(templateSashForm, SWT.NONE); 417 layout = new GridLayout(); 418 layout.marginHeight = 0; 419 layout.marginWidth = 0; 420 descriptionComposite.setLayout(layout); 421 gd = new GridData(GridData.FILL_BOTH | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); 422 descriptionComposite.setLayoutData(gd); 423 createDescriptionIn(descriptionComposite); 424 425 getContainer().getShell().setSize(500, 500); 426 initialize(); 427 setControl(tabFolder); 428 Dialog.applyDialogFont(outerContainer); 429 PlatformUI.getWorkbench().getHelpSystem().setHelp( 430 outerContainer, 431 IHelpContextIds.ADD_EXTENSIONS_SCHEMA_BASED); 432 } 433 private Control createWizardsPage(Composite parent) { 434 fWizardsPage = new ExtensionTreeSelectionPage(fWizardCollection, null, PDEUIMessages.PointSelectionPage_categories); 435 fWizardsPage.createControl(parent); 436 fWizardsPage.setWizard(fWizard); 437 fWizardsPage.getSelectionProvider().addSelectionChangedListener(this); 438 fWizardsPage.init(fProject, fModel.getPluginBase()); 439 return fWizardsPage.getControl(); 440 } 441 442 public void advanceToNextPage() { 443 getContainer().showPage(getNextPage()); 444 } 445 446 public boolean canFlipToNextPage() { 447 return getNextPage() != null; 448 } 449 450 public boolean canFinish() { 451 if (fTemplateViewer != null) { 452 ISelection selection = fTemplateViewer.getSelection(); 453 if (selection instanceof IStructuredSelection){ 454 IStructuredSelection ssel = (IStructuredSelection)selection; 455 if (!ssel.isEmpty()) 456 return false; 457 } 458 } 459 if (fPointListViewer != null) { 460 ISelection selection = fPointListViewer.getSelection(); 461 if (selection instanceof IStructuredSelection) { 462 IStructuredSelection ssel = (IStructuredSelection) selection; 463 if (ssel.isEmpty() == false) 464 return true; 465 } 466 } 467 return false; 468 } 469 470 public void dispose() { 471 fWizardsPage.dispose(); 472 super.dispose(); 473 } 474 475 public boolean finish() { 476 String point = IdUtil.getFullId(fCurrentPoint, fModel); 477 478 try { 479 IPluginExtension extension = 480 fModel.getFactory().createExtension(); 481 extension.setPoint(point); 484 fModel.getPluginBase().add(extension); 485 486 ISchemaElement schemaElement = null; 489 Object object = extension.getSchema(); 491 if ((object != null) && 492 (object instanceof Schema)) { 493 Schema schema = (Schema)object; 494 if (extension instanceof PluginExtensionNode) { 495 String elementName = 497 ((PluginExtensionNode)extension).getXMLTagName(); 498 schemaElement = schema.findElement(elementName); 500 } 501 if (schemaElement != null) { 503 XMLInsertionComputer.computeInsertion(schemaElement, extension); 504 } 505 } 506 507 String pluginID = fCurrentPoint.getPluginBase().getId(); 508 if (!(fCurrentPoint instanceof PluginExtensionPointNode) 509 && !fAvailableImports.contains(pluginID) 510 && !(fCurrentPoint.getPluginBase() instanceof IFragment)) { 511 if (MessageDialog.openQuestion( 512 getShell(), PDEUIMessages.NewExtensionWizard_PointSelectionPage_dependencyTitle, 513 NLS.bind( 514 PDEUIMessages.NewExtensionWizard_PointSelectionPage_dependencyMessage, 515 new String [] { pluginID, fCurrentPoint.getId() }))) { 516 IPluginImport importNode = fModel.getPluginFactory().createImport(); 517 importNode.setId(pluginID); 518 fModel.getPluginBase().add(importNode); 519 } 520 } 521 } catch (CoreException e) { 522 PDEPlugin.logException(e); 523 } 524 return true; 525 } 526 527 public IPluginExtension getNewExtension() { 528 return fNewExtension; 529 } 530 531 protected void initialize() { 532 fPointListViewer.addFilter(new PointFilter()); 533 fPointListViewer.setInput(PDECore.getDefault().getModelManager()); 534 fPointListViewer.getTable().setFocus(); 535 } 536 537 public void selectionChanged(SelectionChangedEvent event) { 538 ISelection selection = event.getSelection(); 539 if (selection instanceof IStructuredSelection) { 540 IStructuredSelection ssel = (IStructuredSelection) selection; 541 if (ssel != null && !ssel.isEmpty()) { 542 Object element = ssel.getFirstElement(); 543 if (element instanceof WizardElement) 544 handleTemplateSelection((WizardElement)element); 545 else if (element instanceof IPluginExtensionPoint) 546 handlePointSelection((IPluginExtensionPoint)element); 547 } else { 548 setDescription(""); setDescriptionText(""); fTemplateLabel.setText(PDEUIMessages.NewExtensionWizard_PointSelectionPage_contributedTemplates_title); 551 setPointDescriptionText(PDEUIMessages.PointSelectionPage_noDescAvailable); 552 fDescLink.setText(NLS.bind(PDEUIMessages.PointSelectionPage_extPointDesc, "")); setSelectedNode(null); 554 setPageComplete(false); 555 } 556 getContainer().updateButtons(); 557 } 558 } 559 560 private void handleTemplateSelection(WizardElement element) { 561 setSelectedNode(createWizardNode(element)); 562 setDescriptionText(element.getDescription()); 563 setDescription(NLS.bind(PDEUIMessages.NewExtensionWizard_PointSelectionPage_templateDescription, element.getLabel())); 564 setPageComplete(false); 565 } 566 567 private void handlePointSelection(IPluginExtensionPoint element) { 568 fCurrentPoint = element; 569 fTemplateViewer.setInput(fCurrentPoint); 570 String fullPointID = IdUtil.getFullId(fCurrentPoint, fModel); 571 572 String description = 573 XMLComponentRegistry.Instance().getDescription(fullPointID, XMLComponentRegistry.F_SCHEMA_COMPONENT); 574 String name = 575 XMLComponentRegistry.Instance().getName(fullPointID, XMLComponentRegistry.F_SCHEMA_COMPONENT); 576 URL url = null; 577 if ((description == null) || 578 (name == null)) { 579 url = SchemaRegistry.getSchemaURL(fCurrentPoint, fModel); 580 } 581 if (url != null) { 582 SchemaAnnotationHandler handler = new SchemaAnnotationHandler(); 583 SchemaUtil.parseURL(url, handler); 584 description = handler.getDescription(); 585 name = handler.getName(); 586 } 587 if (description == null) { 588 setPointDescriptionText(PDEUIMessages.PointSelectionPage_noDescAvailable); 589 } else { 590 setPointDescriptionText(description); 591 } 592 if (name == null) { 593 name = fullPointID; 594 } 595 setDescription(NLS.bind(PDEUIMessages.NewExtensionWizard_PointSelectionPage_pluginDescription, name)); 596 setDescriptionText(""); fTemplateLabel.setText(NLS.bind(PDEUIMessages.NewExtensionWizard_PointSelectionPage_contributedTemplates_label, name.toLowerCase(Locale.ENGLISH))); 598 fDescLink.setText(NLS.bind(PDEUIMessages.PointSelectionPage_extPointDesc, name)); 599 setSelectedNode(null); 600 setPageComplete(true); 601 602 XMLComponentRegistry.Instance().putDescription(fullPointID, description, XMLComponentRegistry.F_SCHEMA_COMPONENT); 603 XMLComponentRegistry.Instance().putName(fullPointID, name, XMLComponentRegistry.F_SCHEMA_COMPONENT); 604 } 605 606 private void updateTabSelection(int index) { 607 if (index == 0) { 608 ISelection selection = fTemplateViewer.getSelection(); 610 if (selection.isEmpty()==false) 611 selectionChanged(new SelectionChangedEvent(fTemplateViewer, selection)); 612 else 613 selectionChanged(new SelectionChangedEvent(fPointListViewer, fPointListViewer.getSelection())); 614 fFilterText.setFocus(); 615 } else { 616 ISelectionProvider provider = fWizardsPage.getSelectionProvider(); 618 selectionChanged(new SelectionChangedEvent(provider, provider.getSelection())); 619 } 620 } 621 622 625 protected IWizardNode createWizardNode(WizardElement element) { 626 return new WizardNode(this, element) { 627 public IBasePluginWizard createWizard() throws CoreException { 628 IExtensionWizard wizard = createWizard(wizardElement); 629 if (wizard == null) 630 throw new CoreException(new Status(IStatus.ERROR, wizardElement.getConfigurationElement().getNamespaceIdentifier(), PDEUIMessages.PointSelectionPage_cannotFindTemplate)); 631 wizard.init(fProject, fModel); 632 return wizard; 633 } 634 protected IExtensionWizard createWizard(WizardElement element) 635 throws CoreException { 636 if (element.isTemplate()) { 637 IConfigurationElement template = element.getTemplateElement(); 638 if (template==null) return null; 639 ITemplateSection section = 640 (ITemplateSection) template.createExecutableExtension("class"); return new NewExtensionTemplateWizard(section); 642 } 643 return (IExtensionWizard) element.createExecutableExtension(); 644 } 645 }; 646 } 647 648 public void checkModel() { 649 IWizardNode node = getSelectedNode(); 650 if (node == null) 651 return; 652 IWizard wizard = node.getWizard(); 653 if (wizard instanceof NewExtensionTemplateWizard) { 654 if (((NewExtensionTemplateWizard) wizard).updatedDependencies()) { 655 if (MessageDialog.openQuestion(getShell(), 656 PDEUIMessages.PointSelectionPage_newDepFound, 657 PDEUIMessages.PointSelectionPage_newDepMessage)) { 658 fWizard.getEditor().doSave(new NullProgressMonitor()); 659 } 660 } 661 } 662 } 663 664 public void setVisible(boolean visible) { 665 if (visible) 666 fFilterText.setFocus(); 667 super.setVisible(visible); 668 } 669 670 private void setPointDescriptionText(String text) { 671 if (fPointDescBrowser != null) { 672 StringBuffer desc = new StringBuffer (); 673 HTMLPrinter.insertPageProlog(desc, 0, new RGB(255,255,255), TextUtil.getJavaDocStyleSheerURL()); 674 desc.append(text); 675 HTMLPrinter.addPageEpilog(desc); 676 fPointDescBrowser.setText(desc.toString()); 677 } else 678 fPointDescription.setText(PDEHTMLHelper.stripTags(text)); 679 } 680 } 681 | Popular Tags |