Source Code Cross Referenced for PointSelectionPage.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » ui » wizards » extension » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » Eclipse plug in development » org.eclipse.pde.internal.ui.wizards.extension 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.extension;
011:
012:        import java.net.URL;
013:        import java.util.ArrayList;
014:        import java.util.HashSet;
015:        import java.util.Locale;
016:        import java.util.regex.Pattern;
017:        import java.util.regex.PatternSyntaxException;
018:
019:        import org.eclipse.core.resources.IProject;
020:        import org.eclipse.core.runtime.CoreException;
021:        import org.eclipse.core.runtime.IConfigurationElement;
022:        import org.eclipse.core.runtime.IStatus;
023:        import org.eclipse.core.runtime.NullProgressMonitor;
024:        import org.eclipse.core.runtime.Status;
025:        import org.eclipse.jface.dialogs.Dialog;
026:        import org.eclipse.jface.dialogs.MessageDialog;
027:        import org.eclipse.jface.viewers.DoubleClickEvent;
028:        import org.eclipse.jface.viewers.IDoubleClickListener;
029:        import org.eclipse.jface.viewers.ISelection;
030:        import org.eclipse.jface.viewers.ISelectionProvider;
031:        import org.eclipse.jface.viewers.IStructuredContentProvider;
032:        import org.eclipse.jface.viewers.IStructuredSelection;
033:        import org.eclipse.jface.viewers.ITableLabelProvider;
034:        import org.eclipse.jface.viewers.LabelProvider;
035:        import org.eclipse.jface.viewers.SelectionChangedEvent;
036:        import org.eclipse.jface.viewers.TableViewer;
037:        import org.eclipse.jface.viewers.Viewer;
038:        import org.eclipse.jface.viewers.ViewerFilter;
039:        import org.eclipse.jface.wizard.IWizard;
040:        import org.eclipse.jface.wizard.IWizardNode;
041:        import org.eclipse.osgi.util.NLS;
042:        import org.eclipse.pde.core.plugin.IFragment;
043:        import org.eclipse.pde.core.plugin.IPluginExtension;
044:        import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
045:        import org.eclipse.pde.core.plugin.IPluginImport;
046:        import org.eclipse.pde.core.plugin.IPluginModelBase;
047:        import org.eclipse.pde.core.plugin.PluginRegistry;
048:        import org.eclipse.pde.internal.core.PDECore;
049:        import org.eclipse.pde.internal.core.ischema.ISchemaElement;
050:        import org.eclipse.pde.internal.core.schema.Schema;
051:        import org.eclipse.pde.internal.core.schema.SchemaAnnotationHandler;
052:        import org.eclipse.pde.internal.core.schema.SchemaRegistry;
053:        import org.eclipse.pde.internal.core.text.plugin.PluginExtensionNode;
054:        import org.eclipse.pde.internal.core.text.plugin.PluginExtensionPointNode;
055:        import org.eclipse.pde.internal.core.util.IdUtil;
056:        import org.eclipse.pde.internal.core.util.PDEHTMLHelper;
057:        import org.eclipse.pde.internal.core.util.PatternConstructor;
058:        import org.eclipse.pde.internal.core.util.SchemaUtil;
059:        import org.eclipse.pde.internal.core.util.XMLComponentRegistry;
060:        import org.eclipse.pde.internal.ui.IHelpContextIds;
061:        import org.eclipse.pde.internal.ui.PDELabelProvider;
062:        import org.eclipse.pde.internal.ui.PDEPlugin;
063:        import org.eclipse.pde.internal.ui.PDEPluginImages;
064:        import org.eclipse.pde.internal.ui.PDEUIMessages;
065:        import org.eclipse.pde.internal.ui.editor.contentassist.XMLInsertionComputer;
066:        import org.eclipse.pde.internal.ui.editor.text.HTMLPrinter;
067:        import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
068:        import org.eclipse.pde.internal.ui.elements.ElementLabelProvider;
069:        import org.eclipse.pde.internal.ui.search.ShowDescriptionAction;
070:        import org.eclipse.pde.internal.ui.util.TextUtil;
071:        import org.eclipse.pde.internal.ui.wizards.BaseWizardSelectionPage;
072:        import org.eclipse.pde.internal.ui.wizards.ListUtil;
073:        import org.eclipse.pde.internal.ui.wizards.PluginSelectionDialog;
074:        import org.eclipse.pde.internal.ui.wizards.WizardCollectionElement;
075:        import org.eclipse.pde.internal.ui.wizards.WizardElement;
076:        import org.eclipse.pde.internal.ui.wizards.WizardNode;
077:        import org.eclipse.pde.internal.ui.wizards.templates.NewExtensionTemplateWizard;
078:        import org.eclipse.pde.ui.IBasePluginWizard;
079:        import org.eclipse.pde.ui.IExtensionWizard;
080:        import org.eclipse.pde.ui.templates.ITemplateSection;
081:        import org.eclipse.swt.SWT;
082:        import org.eclipse.swt.SWTError;
083:        import org.eclipse.swt.browser.Browser;
084:        import org.eclipse.swt.custom.SashForm;
085:        import org.eclipse.swt.events.KeyEvent;
086:        import org.eclipse.swt.events.KeyListener;
087:        import org.eclipse.swt.events.ModifyEvent;
088:        import org.eclipse.swt.events.ModifyListener;
089:        import org.eclipse.swt.events.SelectionAdapter;
090:        import org.eclipse.swt.events.SelectionEvent;
091:        import org.eclipse.swt.graphics.Image;
092:        import org.eclipse.swt.graphics.RGB;
093:        import org.eclipse.swt.layout.GridData;
094:        import org.eclipse.swt.layout.GridLayout;
095:        import org.eclipse.swt.widgets.Button;
096:        import org.eclipse.swt.widgets.Composite;
097:        import org.eclipse.swt.widgets.Control;
098:        import org.eclipse.swt.widgets.Label;
099:        import org.eclipse.swt.widgets.Link;
100:        import org.eclipse.swt.widgets.TabFolder;
101:        import org.eclipse.swt.widgets.TabItem;
102:        import org.eclipse.swt.widgets.TableItem;
103:        import org.eclipse.swt.widgets.Text;
104:        import org.eclipse.ui.PlatformUI;
105:
106:        public class PointSelectionPage extends BaseWizardSelectionPage {
107:            private TableViewer fPointListViewer;
108:            private TableViewer fTemplateViewer;
109:
110:            private IPluginModelBase fModel;
111:            private Button fFilterCheck;
112:            private IPluginExtensionPoint fCurrentPoint;
113:            private HashSet fAvailableImports;
114:            private IProject fProject;
115:            private Label fTemplateLabel;
116:            private ExtensionTreeSelectionPage fWizardsPage;
117:
118:            private IPluginExtension fNewExtension;
119:            private WizardCollectionElement fTemplateCollection;
120:            private WizardCollectionElement fWizardCollection;
121:            private NewExtensionWizard fWizard;
122:            private Text fFilterText;
123:            private WildcardFilter fWildCardFilter;
124:            private Text fPointDescription;
125:            private Link fDescLink;
126:            private Browser fPointDescBrowser;
127:
128:            class PointFilter extends ViewerFilter {
129:                public boolean select(Viewer viewer, Object parentElement,
130:                        Object element) {
131:                    if (!fFilterCheck.getSelection())
132:                        return true;
133:
134:                    IPluginExtensionPoint point = (IPluginExtensionPoint) element;
135:                    if (point instanceof  PluginExtensionPointNode)
136:                        return true;
137:
138:                    return fAvailableImports.contains(point.getPluginBase()
139:                            .getId());
140:                }
141:            }
142:
143:            class WildcardFilter extends ViewerFilter {
144:                private String wMatch = "*"; //$NON-NLS-1$
145:
146:                protected void setMatchText(String match) {
147:                    if (match.indexOf("*") < 0 & match.indexOf("?") < 0 & match.indexOf(".") < 0) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
148:                        match = "*" + match; //$NON-NLS-1$
149:                    }
150:                    wMatch = match + "*"; //$NON-NLS-1$
151:                }
152:
153:                public boolean select(Viewer viewer, Object parentElement,
154:                        Object element) {
155:                    String text = ((PointLabelProvider) fPointListViewer
156:                            .getLabelProvider()).getColumnText(element, 0);
157:                    Pattern pattern = null;
158:                    try {
159:                        pattern = PatternConstructor.createPattern(wMatch,
160:                                false);
161:                    } catch (PatternSyntaxException e) {
162:                        return false;
163:                    }
164:                    return pattern != null
165:                            && pattern.matcher(
166:                                    text.subSequence(0, text.length()))
167:                                    .matches();
168:                }
169:            }
170:
171:            class TemplateContentProvider extends DefaultContentProvider
172:                    implements  IStructuredContentProvider {
173:                public Object[] getElements(Object inputElement) {
174:                    if (inputElement instanceof  IPluginExtensionPoint) {
175:                        IPluginExtensionPoint point = (IPluginExtensionPoint) inputElement;
176:                        String pointID = IdUtil.getFullId(point, fModel);
177:                        ArrayList result = new ArrayList();
178:                        if (fTemplateCollection.getWizards() != null) {
179:                            Object[] wizards = fTemplateCollection.getWizards()
180:                                    .getChildren();
181:                            for (int i = 0; i < wizards.length; i++) {
182:                                String wizardContributorId = ((WizardElement) wizards[i])
183:                                        .getContributingId();
184:                                if (wizardContributorId == null
185:                                        || pointID == null)
186:                                    continue;
187:                                if (wizards[i] instanceof  WizardElement
188:                                        && wizardContributorId.equals(pointID))
189:                                    result.add(wizards[i]);
190:                            }
191:                            return result.toArray();
192:                        }
193:                    }
194:                    return new Object[0];
195:                }
196:            }
197:
198:            class PointContentProvider extends DefaultContentProvider implements 
199:                    IStructuredContentProvider {
200:                public Object[] getElements(Object parent) {
201:                    ArrayList extPoints = new ArrayList();
202:                    IPluginModelBase[] plugins = PluginRegistry
203:                            .getActiveModels();
204:                    for (int i = 0; i < plugins.length; i++) {
205:                        IPluginExtensionPoint[] points = plugins[i]
206:                                .getPluginBase().getExtensionPoints();
207:                        String id = plugins[i].getPluginBase().getId();
208:                        if (id.equals(fModel.getPluginBase().getId()))
209:                            continue;
210:                        for (int j = 0; j < points.length; j++)
211:                            extPoints.add(points[j]);
212:                    }
213:
214:                    IPluginExtensionPoint[] points = fModel.getPluginBase()
215:                            .getExtensionPoints();
216:                    for (int i = 0; i < points.length; i++)
217:                        extPoints.add(points[i]);
218:
219:                    return extPoints.toArray();
220:                }
221:            }
222:
223:            class PointLabelProvider extends LabelProvider implements 
224:                    ITableLabelProvider {
225:                public String getText(Object obj) {
226:                    return getColumnText(obj, 0);
227:                }
228:
229:                public String getColumnText(Object obj, int index) {
230:                    IPluginExtensionPoint extPoint = (IPluginExtensionPoint) obj;
231:                    PDELabelProvider provider = PDEPlugin.getDefault()
232:                            .getLabelProvider();
233:                    if (provider.isFullNameModeEnabled())
234:                        return provider.getText(extPoint);
235:
236:                    return IdUtil.getFullId(extPoint, fModel);
237:                }
238:
239:                public Image getImage(Object obj) {
240:                    return getColumnImage(obj, 0);
241:                }
242:
243:                public Image getColumnImage(Object obj, int index) {
244:                    IPluginExtensionPoint exp = (IPluginExtensionPoint) obj;
245:
246:                    if (((TemplateContentProvider) fTemplateViewer
247:                            .getContentProvider()).getElements(exp).length > 0) {
248:                        return PDEPlugin.getDefault().getLabelProvider().get(
249:                                PDEPluginImages.DESC_NEWEXP_WIZ_TOOL, 0);
250:                    }
251:
252:                    return PDEPlugin.getDefault().getLabelProvider().get(
253:                            PDEPluginImages.DESC_EXT_POINT_OBJ, 0);
254:                }
255:            }
256:
257:            public PointSelectionPage(IProject project, IPluginModelBase model,
258:                    WizardCollectionElement element,
259:                    WizardCollectionElement templates, NewExtensionWizard wizard) {
260:                super (
261:                        "pointSelectionPage", PDEUIMessages.NewExtensionWizard_PointSelectionPage_title); //$NON-NLS-1$ 
262:                this .fModel = model;
263:                this .fWizardCollection = element;
264:                this .fTemplateCollection = templates;
265:                this .fWizard = wizard;
266:                this .fProject = project;
267:                fWildCardFilter = new WildcardFilter();
268:                fAvailableImports = PluginSelectionDialog.getExistingImports(
269:                        model, true);
270:                setTitle(PDEUIMessages.NewExtensionWizard_PointSelectionPage_title);
271:                setDescription(PDEUIMessages.NewExtensionWizard_PointSelectionPage_desc);
272:            }
273:
274:            public void createControl(Composite parent) {
275:                // tab folder
276:                final TabFolder tabFolder = new TabFolder(parent, SWT.FLAT);
277:                TabItem firstTab = new TabItem(tabFolder, SWT.NULL);
278:                firstTab.setText(PDEUIMessages.PointSelectionPage_tab1);
279:                TabItem secondTab = new TabItem(tabFolder, SWT.NULL);
280:                secondTab.setText(PDEUIMessages.PointSelectionPage_tab2);
281:                secondTab.setControl(createWizardsPage(tabFolder));
282:                tabFolder.addSelectionListener(new SelectionAdapter() {
283:                    public void widgetSelected(SelectionEvent e) {
284:                        updateTabSelection(tabFolder.getSelectionIndex());
285:                    }
286:                });
287:                // top level group
288:                Composite outerContainer = new Composite(tabFolder, SWT.NONE);
289:                firstTab.setControl(outerContainer);
290:                GridLayout layout = new GridLayout();
291:                outerContainer.setLayout(layout);
292:                GridData gd = new GridData(GridData.FILL_BOTH);
293:                outerContainer.setLayoutData(gd);
294:
295:                Composite pointContainer = new Composite(outerContainer,
296:                        SWT.NONE);
297:                layout = new GridLayout();
298:                layout.marginHeight = layout.marginWidth = 0;
299:                pointContainer.setLayout(layout);
300:                gd = new GridData(GridData.FILL_BOTH);
301:                pointContainer.setLayoutData(gd);
302:
303:                Composite labelContainer = new Composite(pointContainer,
304:                        SWT.NONE);
305:                layout = new GridLayout(2, false);
306:                layout.marginHeight = layout.marginWidth = 0;
307:                labelContainer.setLayout(layout);
308:                labelContainer.setLayoutData(new GridData(
309:                        GridData.FILL_HORIZONTAL));
310:
311:                Label filterLabel = new Label(labelContainer, SWT.NONE);
312:                filterLabel
313:                        .setText(PDEUIMessages.NewExtensionWizard_PointSelectionPage_availExtPoints_label);
314:                gd = new GridData();
315:                gd.verticalAlignment = GridData.CENTER;
316:                filterLabel.setLayoutData(gd);
317:                fFilterText = new Text(labelContainer, SWT.BORDER);
318:                fFilterText
319:                        .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
320:                fFilterText.addModifyListener(new ModifyListener() {
321:                    public void modifyText(ModifyEvent e) {
322:                        fWildCardFilter.setMatchText(fFilterText.getText());
323:                        fPointListViewer.refresh();
324:                    }
325:                });
326:                fFilterText.addKeyListener(new KeyListener() {
327:                    public void keyPressed(KeyEvent e) {
328:                        if (e.keyCode == SWT.ARROW_DOWN)
329:                            fPointListViewer.getControl().setFocus();
330:                    }
331:
332:                    public void keyReleased(KeyEvent e) {
333:                    }
334:                });
335:
336:                fFilterCheck = new Button(outerContainer, SWT.CHECK);
337:                fFilterCheck
338:                        .setText(PDEUIMessages.NewExtensionWizard_PointSelectionPage_filterCheck);
339:                gd = new GridData(GridData.FILL_HORIZONTAL);
340:                fFilterCheck.setLayoutData(gd);
341:                fFilterCheck.setSelection(true);
342:                fFilterCheck.addSelectionListener(new SelectionAdapter() {
343:                    public void widgetSelected(SelectionEvent e) {
344:                        fPointListViewer.refresh();
345:                    }
346:                });
347:
348:                fPointListViewer = new TableViewer(pointContainer, SWT.V_SCROLL
349:                        | SWT.H_SCROLL | SWT.BORDER);
350:                fPointListViewer.setContentProvider(new PointContentProvider());
351:                fPointListViewer.setLabelProvider(new PointLabelProvider());
352:                fPointListViewer.addSelectionChangedListener(this );
353:                fPointListViewer
354:                        .addDoubleClickListener(new IDoubleClickListener() {
355:                            public void doubleClick(DoubleClickEvent event) {
356:                                if (canFinish()) {
357:                                    fWizard.performFinish();
358:                                    fWizard.getShell().close();
359:                                    fWizard.dispose();
360:                                    fWizard.setContainer(null);
361:                                }
362:                            }
363:                        });
364:                fPointListViewer.addFilter(fWildCardFilter);
365:                fPointListViewer.setComparator(ListUtil.NAME_COMPARATOR);
366:                gd = new GridData(GridData.FILL_BOTH);
367:                gd.heightHint = 150;
368:                fPointListViewer.getTable().setLayoutData(gd);
369:
370:                Composite templateComposite = new Composite(outerContainer,
371:                        SWT.NONE);
372:                layout = new GridLayout();
373:                layout.marginHeight = 4;
374:                layout.marginWidth = 0;
375:                templateComposite.setLayout(layout);
376:                gd = new GridData(GridData.FILL_HORIZONTAL);
377:                templateComposite.setLayoutData(gd);
378:
379:                fDescLink = new Link(templateComposite, SWT.NONE);
380:                fDescLink.setText(NLS.bind(
381:                        PDEUIMessages.PointSelectionPage_extPointDesc, "")); //$NON-NLS-1$
382:                fDescLink.addSelectionListener(new SelectionAdapter() {
383:                    public void widgetSelected(SelectionEvent e) {
384:                        if (fCurrentPoint != null)
385:                            new ShowDescriptionAction(fCurrentPoint, true)
386:                                    .run();
387:                    }
388:                });
389:                fDescLink.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
390:
391:                Control c = null;
392:                Composite comp = new Composite(templateComposite, SWT.BORDER);
393:                layout = new GridLayout();
394:                layout.marginHeight = layout.marginWidth = 0;
395:                comp.setLayout(layout);
396:                comp.setLayoutData(new GridData(GridData.FILL_BOTH));
397:                try {
398:                    c = fPointDescBrowser = new Browser(comp, SWT.NONE);
399:                } catch (SWTError e) {
400:                }
401:                if (c == null)
402:                    c = fPointDescription = new Text(comp, SWT.WRAP | SWT.MULTI
403:                            | SWT.V_SCROLL | SWT.READ_ONLY);
404:
405:                setPointDescriptionText(PDEUIMessages.NewExtensionWizard_PointSelectionPage_extPointDescription);
406:                gd = new GridData(GridData.FILL_HORIZONTAL);
407:                gd.heightHint = 80;
408:                c.setLayoutData(gd);
409:
410:                fTemplateLabel = new Label(templateComposite, SWT.NONE
411:                        | SWT.WRAP);
412:                fTemplateLabel
413:                        .setText(PDEUIMessages.NewExtensionWizard_PointSelectionPage_contributedTemplates_title);
414:                gd = new GridData(GridData.FILL_HORIZONTAL);
415:                fTemplateLabel.setLayoutData(gd);
416:
417:                SashForm templateSashForm = new SashForm(templateComposite,
418:                        SWT.HORIZONTAL);
419:                templateSashForm.setLayout(new GridLayout());
420:                gd = new GridData(GridData.FILL_BOTH);
421:                gd.heightHint = 80;
422:                templateSashForm.setLayoutData(gd);
423:
424:                Composite wizardComposite = new Composite(templateSashForm,
425:                        SWT.NONE);
426:                layout = new GridLayout();
427:                layout.marginHeight = 0;
428:                layout.marginWidth = 0;
429:                wizardComposite.setLayout(layout);
430:                gd = new GridData(GridData.FILL_BOTH
431:                        | GridData.HORIZONTAL_ALIGN_FILL
432:                        | GridData.GRAB_HORIZONTAL);
433:                wizardComposite.setLayoutData(gd);
434:                fTemplateViewer = new TableViewer(wizardComposite, SWT.V_SCROLL
435:                        | SWT.H_SCROLL | SWT.BORDER);
436:                fTemplateViewer
437:                        .setContentProvider(new TemplateContentProvider());
438:                fTemplateViewer.setLabelProvider(ElementLabelProvider.INSTANCE);
439:                fTemplateViewer.setComparator(ListUtil.NAME_COMPARATOR);
440:                fTemplateViewer.addSelectionChangedListener(this );
441:                gd = new GridData(GridData.FILL_BOTH);
442:
443:                fTemplateViewer.getTable().setLayoutData(gd);
444:                TableItem[] selection = fPointListViewer.getTable()
445:                        .getSelection();
446:                if (selection != null && selection.length > 0)
447:                    fTemplateViewer.setInput(selection[0]);
448:                fTemplateViewer
449:                        .addDoubleClickListener(new IDoubleClickListener() {
450:                            public void doubleClick(DoubleClickEvent event) {
451:                                if (canFlipToNextPage()) {
452:                                    advanceToNextPage();
453:                                }
454:                            }
455:                        });
456:
457:                Composite descriptionComposite = new Composite(
458:                        templateSashForm, SWT.NONE);
459:                layout = new GridLayout();
460:                layout.marginHeight = 0;
461:                layout.marginWidth = 0;
462:                descriptionComposite.setLayout(layout);
463:                gd = new GridData(GridData.FILL_BOTH
464:                        | GridData.HORIZONTAL_ALIGN_FILL
465:                        | GridData.GRAB_HORIZONTAL);
466:                descriptionComposite.setLayoutData(gd);
467:                createDescriptionIn(descriptionComposite);
468:
469:                getContainer().getShell().setSize(500, 500);
470:                initialize();
471:                setControl(tabFolder);
472:                Dialog.applyDialogFont(outerContainer);
473:                PlatformUI.getWorkbench().getHelpSystem().setHelp(
474:                        outerContainer,
475:                        IHelpContextIds.ADD_EXTENSIONS_SCHEMA_BASED);
476:            }
477:
478:            private Control createWizardsPage(Composite parent) {
479:                fWizardsPage = new ExtensionTreeSelectionPage(
480:                        fWizardCollection, null,
481:                        PDEUIMessages.PointSelectionPage_categories);
482:                fWizardsPage.createControl(parent);
483:                fWizardsPage.setWizard(fWizard);
484:                fWizardsPage.getSelectionProvider()
485:                        .addSelectionChangedListener(this );
486:                fWizardsPage.init(fProject, fModel.getPluginBase());
487:                return fWizardsPage.getControl();
488:            }
489:
490:            public void advanceToNextPage() {
491:                getContainer().showPage(getNextPage());
492:            }
493:
494:            public boolean canFlipToNextPage() {
495:                return getNextPage() != null;
496:            }
497:
498:            public boolean canFinish() {
499:                if (fTemplateViewer != null) {
500:                    ISelection selection = fTemplateViewer.getSelection();
501:                    if (selection instanceof  IStructuredSelection) {
502:                        IStructuredSelection ssel = (IStructuredSelection) selection;
503:                        if (!ssel.isEmpty())
504:                            return false;
505:                    }
506:                }
507:                if (fPointListViewer != null) {
508:                    ISelection selection = fPointListViewer.getSelection();
509:                    if (selection instanceof  IStructuredSelection) {
510:                        IStructuredSelection ssel = (IStructuredSelection) selection;
511:                        if (ssel.isEmpty() == false)
512:                            return true;
513:                    }
514:                }
515:                return false;
516:            }
517:
518:            public void dispose() {
519:                fWizardsPage.dispose();
520:                super .dispose();
521:            }
522:
523:            public boolean finish() {
524:                String point = IdUtil.getFullId(fCurrentPoint, fModel);
525:
526:                try {
527:                    IPluginExtension extension = fModel.getFactory()
528:                            .createExtension();
529:                    // Set the point attribute
530:                    // The point value overrides an auto-generated value
531:                    extension.setPoint(point);
532:                    fModel.getPluginBase().add(extension);
533:
534:                    // Recursively auto-insert required child elements and attributes 
535:                    // respecting multiplicity
536:                    ISchemaElement schemaElement = null;
537:                    // Get the extension's schema
538:                    Object object = extension.getSchema();
539:                    if ((object != null) && (object instanceof  Schema)) {
540:                        Schema schema = (Schema) object;
541:                        if (extension instanceof  PluginExtensionNode) {
542:                            // Get the extension's XML element name
543:                            String elementName = ((PluginExtensionNode) extension)
544:                                    .getXMLTagName();
545:                            // Find the extension's corresponding schema element
546:                            schemaElement = schema.findElement(elementName);
547:                        }
548:                        // If there is an associated schema, do the auto-insert
549:                        if (schemaElement != null) {
550:                            XMLInsertionComputer.computeInsertion(
551:                                    schemaElement, extension);
552:                        }
553:                    }
554:
555:                    String pluginID = fCurrentPoint.getPluginBase().getId();
556:                    if (!(fCurrentPoint instanceof  PluginExtensionPointNode)
557:                            && !fAvailableImports.contains(pluginID)
558:                            && !(fCurrentPoint.getPluginBase() instanceof  IFragment)) {
559:                        if (MessageDialog
560:                                .openQuestion(
561:                                        getShell(),
562:                                        PDEUIMessages.NewExtensionWizard_PointSelectionPage_dependencyTitle,
563:                                        NLS
564:                                                .bind(
565:                                                        PDEUIMessages.NewExtensionWizard_PointSelectionPage_dependencyMessage,
566:                                                        new String[] {
567:                                                                pluginID,
568:                                                                fCurrentPoint
569:                                                                        .getId() }))) {
570:                            IPluginImport importNode = fModel
571:                                    .getPluginFactory().createImport();
572:                            importNode.setId(pluginID);
573:                            fModel.getPluginBase().add(importNode);
574:                        }
575:                    }
576:                } catch (CoreException e) {
577:                    PDEPlugin.logException(e);
578:                }
579:                return true;
580:            }
581:
582:            public IPluginExtension getNewExtension() {
583:                return fNewExtension;
584:            }
585:
586:            protected void initialize() {
587:                fPointListViewer.addFilter(new PointFilter());
588:                fPointListViewer.setInput(PDECore.getDefault()
589:                        .getModelManager());
590:                fPointListViewer.getTable().setFocus();
591:            }
592:
593:            public void selectionChanged(SelectionChangedEvent event) {
594:                ISelection selection = event.getSelection();
595:                if (selection instanceof  IStructuredSelection) {
596:                    IStructuredSelection ssel = (IStructuredSelection) selection;
597:                    if (ssel != null && !ssel.isEmpty()) {
598:                        Object element = ssel.getFirstElement();
599:                        if (element instanceof  WizardElement)
600:                            handleTemplateSelection((WizardElement) element);
601:                        else if (element instanceof  IPluginExtensionPoint)
602:                            handlePointSelection((IPluginExtensionPoint) element);
603:                    } else {
604:                        setDescription(""); //$NON-NLS-1$
605:                        setDescriptionText(""); //$NON-NLS-1$
606:                        fTemplateLabel
607:                                .setText(PDEUIMessages.NewExtensionWizard_PointSelectionPage_contributedTemplates_title);
608:                        setPointDescriptionText(PDEUIMessages.PointSelectionPage_noDescAvailable);
609:                        fDescLink.setText(NLS.bind(
610:                                PDEUIMessages.PointSelectionPage_extPointDesc,
611:                                "")); //$NON-NLS-1$
612:                        setSelectedNode(null);
613:                        setPageComplete(false);
614:                    }
615:                    getContainer().updateButtons();
616:                }
617:            }
618:
619:            private void handleTemplateSelection(WizardElement element) {
620:                setSelectedNode(createWizardNode(element));
621:                setDescriptionText(element.getDescription());
622:                setDescription(NLS
623:                        .bind(
624:                                PDEUIMessages.NewExtensionWizard_PointSelectionPage_templateDescription,
625:                                element.getLabel()));
626:                setPageComplete(false);
627:            }
628:
629:            private void handlePointSelection(IPluginExtensionPoint element) {
630:                fCurrentPoint = element;
631:                fTemplateViewer.setInput(fCurrentPoint);
632:                String fullPointID = IdUtil.getFullId(fCurrentPoint, fModel);
633:
634:                String description = XMLComponentRegistry.Instance()
635:                        .getDescription(fullPointID,
636:                                XMLComponentRegistry.F_SCHEMA_COMPONENT);
637:                String name = XMLComponentRegistry.Instance().getName(
638:                        fullPointID, XMLComponentRegistry.F_SCHEMA_COMPONENT);
639:                URL url = null;
640:                if ((description == null) || (name == null)) {
641:                    url = SchemaRegistry.getSchemaURL(fCurrentPoint, fModel);
642:                }
643:                if (url != null) {
644:                    SchemaAnnotationHandler handler = new SchemaAnnotationHandler();
645:                    SchemaUtil.parseURL(url, handler);
646:                    description = handler.getDescription();
647:                    name = handler.getName();
648:                }
649:                if (description == null) {
650:                    setPointDescriptionText(PDEUIMessages.PointSelectionPage_noDescAvailable);
651:                } else {
652:                    setPointDescriptionText(description);
653:                }
654:                if (name == null) {
655:                    name = fullPointID;
656:                }
657:                setDescription(NLS
658:                        .bind(
659:                                PDEUIMessages.NewExtensionWizard_PointSelectionPage_pluginDescription,
660:                                name));
661:                setDescriptionText(""); //$NON-NLS-1$
662:                fTemplateLabel
663:                        .setText(NLS
664:                                .bind(
665:                                        PDEUIMessages.NewExtensionWizard_PointSelectionPage_contributedTemplates_label,
666:                                        name.toLowerCase(Locale.ENGLISH)));
667:                fDescLink.setText(NLS.bind(
668:                        PDEUIMessages.PointSelectionPage_extPointDesc, name));
669:                setSelectedNode(null);
670:                setPageComplete(true);
671:
672:                XMLComponentRegistry.Instance().putDescription(fullPointID,
673:                        description, XMLComponentRegistry.F_SCHEMA_COMPONENT);
674:                XMLComponentRegistry.Instance().putName(fullPointID, name,
675:                        XMLComponentRegistry.F_SCHEMA_COMPONENT);
676:            }
677:
678:            private void updateTabSelection(int index) {
679:                if (index == 0) {
680:                    // extension point page
681:                    ISelection selection = fTemplateViewer.getSelection();
682:                    if (selection.isEmpty() == false)
683:                        selectionChanged(new SelectionChangedEvent(
684:                                fTemplateViewer, selection));
685:                    else
686:                        selectionChanged(new SelectionChangedEvent(
687:                                fPointListViewer, fPointListViewer
688:                                        .getSelection()));
689:                    fFilterText.setFocus();
690:                } else {
691:                    // wizard page
692:                    ISelectionProvider provider = fWizardsPage
693:                            .getSelectionProvider();
694:                    selectionChanged(new SelectionChangedEvent(provider,
695:                            provider.getSelection()));
696:                }
697:            }
698:
699:            /* (non-Javadoc)
700:             * @see org.eclipse.pde.internal.ui.wizards.BaseWizardSelectionPage#createWizardNode(org.eclipse.pde.internal.ui.wizards.WizardElement)
701:             */
702:            protected IWizardNode createWizardNode(WizardElement element) {
703:                return new WizardNode(this , element) {
704:                    public IBasePluginWizard createWizard()
705:                            throws CoreException {
706:                        IExtensionWizard wizard = createWizard(wizardElement);
707:                        if (wizard == null)
708:                            throw new CoreException(
709:                                    new Status(
710:                                            IStatus.ERROR,
711:                                            wizardElement
712:                                                    .getConfigurationElement()
713:                                                    .getNamespaceIdentifier(),
714:                                            PDEUIMessages.PointSelectionPage_cannotFindTemplate));
715:                        wizard.init(fProject, fModel);
716:                        return wizard;
717:                    }
718:
719:                    protected IExtensionWizard createWizard(
720:                            WizardElement element) throws CoreException {
721:                        if (element.isTemplate()) {
722:                            IConfigurationElement template = element
723:                                    .getTemplateElement();
724:                            if (template == null)
725:                                return null;
726:                            ITemplateSection section = (ITemplateSection) template
727:                                    .createExecutableExtension("class"); //$NON-NLS-1$
728:                            return new NewExtensionTemplateWizard(section);
729:                        }
730:                        return (IExtensionWizard) element
731:                                .createExecutableExtension();
732:                    }
733:                };
734:            }
735:
736:            public void checkModel() {
737:                IWizardNode node = getSelectedNode();
738:                if (node == null)
739:                    return;
740:                IWizard wizard = node.getWizard();
741:                if (wizard instanceof  NewExtensionTemplateWizard) {
742:                    if (((NewExtensionTemplateWizard) wizard)
743:                            .updatedDependencies()) {
744:                        if (MessageDialog.openQuestion(getShell(),
745:                                PDEUIMessages.PointSelectionPage_newDepFound,
746:                                PDEUIMessages.PointSelectionPage_newDepMessage)) {
747:                            fWizard.getEditor().doSave(
748:                                    new NullProgressMonitor());
749:                        }
750:                    }
751:                }
752:            }
753:
754:            public void setVisible(boolean visible) {
755:                if (visible)
756:                    fFilterText.setFocus();
757:                super .setVisible(visible);
758:            }
759:
760:            private void setPointDescriptionText(String text) {
761:                if (fPointDescBrowser != null) {
762:                    StringBuffer desc = new StringBuffer();
763:                    HTMLPrinter.insertPageProlog(desc, 0,
764:                            new RGB(255, 255, 255), TextUtil
765:                                    .getJavaDocStyleSheerURL());
766:                    desc.append(text);
767:                    HTMLPrinter.addPageEpilog(desc);
768:                    fPointDescBrowser.setText(desc.toString());
769:                } else
770:                    fPointDescription.setText(PDEHTMLHelper.stripTags(text));
771:            }
772:        }
w__w_w_.j___a___va___2_s___.c__o_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.