KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > plugin > ExtensionsPage


1 /*******************************************************************************
2  * Copyright (c) 2003, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.editor.plugin;
12 import org.eclipse.jface.text.source.ISourceViewer;
13 import org.eclipse.jface.viewers.StructuredSelection;
14 import org.eclipse.pde.core.plugin.IPluginElement;
15 import org.eclipse.pde.core.plugin.IPluginExtension;
16 import org.eclipse.pde.core.plugin.IPluginParent;
17 import org.eclipse.pde.internal.core.ischema.ISchemaElement;
18 import org.eclipse.pde.internal.core.ischema.ISchemaSimpleType;
19 import org.eclipse.pde.internal.core.text.IDocumentAttribute;
20 import org.eclipse.pde.internal.core.text.IDocumentRange;
21 import org.eclipse.pde.internal.core.text.IDocumentTextNode;
22 import org.eclipse.pde.internal.ui.IHelpContextIds;
23 import org.eclipse.pde.internal.ui.IPDEUIConstants;
24 import org.eclipse.pde.internal.ui.PDEPlugin;
25 import org.eclipse.pde.internal.ui.PDEPluginImages;
26 import org.eclipse.pde.internal.ui.PDEUIMessages;
27 import org.eclipse.pde.internal.ui.editor.PDEFormPage;
28 import org.eclipse.pde.internal.ui.editor.PDEMasterDetailsBlock;
29 import org.eclipse.pde.internal.ui.editor.PDESection;
30 import org.eclipse.swt.custom.StyledText;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.ui.PlatformUI;
33 import org.eclipse.ui.forms.DetailsPart;
34 import org.eclipse.ui.forms.IDetailsPage;
35 import org.eclipse.ui.forms.IDetailsPageProvider;
36 import org.eclipse.ui.forms.IManagedForm;
37 import org.eclipse.ui.forms.editor.FormEditor;
38 import org.eclipse.ui.forms.editor.IFormPage;
39 import org.eclipse.ui.forms.widgets.ScrolledForm;
40
41 public class ExtensionsPage extends PDEFormPage {
42     public static final String JavaDoc PAGE_ID = "extensions"; //$NON-NLS-1$
43

44     private ExtensionsSection fSection;
45     private ExtensionsBlock fBlock;
46     
47     public class ExtensionsBlock extends PDEMasterDetailsBlock implements IDetailsPageProvider {
48         
49         private ExtensionElementBodyTextDetails fBodyTextDetails;
50         
51         public ExtensionsBlock() {
52             super(ExtensionsPage.this);
53         }
54         protected PDESection createMasterSection(IManagedForm managedForm,
55                 Composite parent) {
56             fSection = new ExtensionsSection(getPage(), parent);
57             return fSection;
58         }
59         protected void registerPages(DetailsPart detailsPart) {
60             detailsPart.setPageLimit(10);
61             // register static page for the extensions
62
detailsPart.registerPage(IPluginExtension.class,
63                     new ExtensionDetails(fSection));
64             // Register a static page for the extension elements that contain
65
// only body text (no child elements or attributes)
66
// (e.g. schema simple type)
67
fBodyTextDetails = new ExtensionElementBodyTextDetails(fSection);
68             detailsPart.registerPage(ExtensionElementBodyTextDetails.class,
69                     fBodyTextDetails);
70             // register a dynamic provider for elements
71
detailsPart.setPageProvider(this);
72         }
73         public Object JavaDoc getPageKey(Object JavaDoc object) {
74             if (object instanceof IPluginExtension)
75                 return IPluginExtension.class;
76             if (object instanceof IPluginElement) {
77                 ISchemaElement element = ExtensionsSection.getSchemaElement((IPluginElement)object);
78                 // Extension point schema exists
79
if (element != null) {
80                     // Use the body text page if the element has no child
81
// elements or attributes
82
if (element.getType() instanceof ISchemaSimpleType) {
83                         // Set the schema element (to provide hover text
84
// content)
85
fBodyTextDetails.setSchemaElement(element);
86                         return ExtensionElementBodyTextDetails.class;
87                     }
88                     return element;
89                 }
90                 // No Extension point schema
91
// no element - construct one
92
IPluginElement pelement = (IPluginElement)object;
93                 // Use the body text page if the element has no child
94
// elements or attributes
95
if ((pelement.getAttributeCount() == 0) &&
96                         (pelement.getChildCount() == 0)) {
97                     // Unset the previous schema element (no hover text
98
// content)
99
fBodyTextDetails.setSchemaElement(null);
100                     return ExtensionElementBodyTextDetails.class;
101                 }
102                 String JavaDoc ename = pelement.getName();
103                 IPluginExtension extension = ExtensionsSection.getExtension((IPluginParent)pelement.getParent());
104                 return extension.getPoint()+"/"+ename; //$NON-NLS-1$
105
}
106             return object.getClass();
107         }
108         public IDetailsPage getPage(Object JavaDoc object) {
109             if (object instanceof ISchemaElement)
110                 return new ExtensionElementDetails(fSection, (ISchemaElement)object);
111             if (object instanceof String JavaDoc)
112                 return new ExtensionElementDetails(fSection, null);
113             return null;
114         }
115     }
116     
117     /**
118      * @param editor
119      * @param id
120      * @param title
121      */

122     public ExtensionsPage(FormEditor editor) {
123         super(editor, PAGE_ID, PDEUIMessages.ExtensionsPage_tabName);
124         fBlock = new ExtensionsBlock();
125     }
126     
127     /* (non-Javadoc)
128      * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
129      */

130     protected String JavaDoc getHelpResource() {
131         return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/manifest_editor/extensions.htm"; //$NON-NLS-1$
132
}
133     
134     protected void createFormContent(IManagedForm managedForm) {
135         ScrolledForm form = managedForm.getForm();
136         form.setText(PDEUIMessages.ExtensionsPage_title);
137         form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_EXTENSIONS_OBJ));
138         fBlock.createContent(managedForm);
139         //refire selection
140
fSection.fireSelection();
141         PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.MANIFEST_PLUGIN_EXTENSIONS);
142         super.createFormContent(managedForm);
143     }
144     
145     public void updateFormSelection() {
146         super.updateFormSelection();
147         IFormPage page = getPDEEditor().findPage(PluginInputContext.CONTEXT_ID);
148         if (page instanceof ManifestSourcePage) {
149             ISourceViewer viewer = ((ManifestSourcePage)page).getViewer();
150             if (viewer == null)
151                 return;
152             StyledText text = viewer.getTextWidget();
153             if (text == null)
154                 return;
155             int offset = text.getCaretOffset();
156             if (offset < 0)
157                 return;
158             
159             IDocumentRange range = ((ManifestSourcePage)page).getRangeElement(offset, true);
160             if (range instanceof IDocumentAttribute)
161                 range = ((IDocumentAttribute)range).getEnclosingElement();
162             else if (range instanceof IDocumentTextNode)
163                 range = ((IDocumentTextNode)range).getEnclosingElement();
164             if ((range instanceof IPluginExtension) ||
165                     (range instanceof IPluginElement)) {
166                 fSection.selectExtensionElement(new StructuredSelection(range));
167             }
168         }
169     }
170 }
171
Popular Tags