001: /*******************************************************************************
002: * Copyright (c) 2003, 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.editor.plugin;
011:
012: import org.eclipse.jface.text.source.ISourceViewer;
013: import org.eclipse.jface.viewers.StructuredSelection;
014: import org.eclipse.pde.core.plugin.IPluginElement;
015: import org.eclipse.pde.core.plugin.IPluginExtension;
016: import org.eclipse.pde.core.plugin.IPluginParent;
017: import org.eclipse.pde.internal.core.ischema.ISchemaElement;
018: import org.eclipse.pde.internal.core.ischema.ISchemaSimpleType;
019: import org.eclipse.pde.internal.core.text.IDocumentAttributeNode;
020: import org.eclipse.pde.internal.core.text.IDocumentRange;
021: import org.eclipse.pde.internal.core.text.IDocumentTextNode;
022: import org.eclipse.pde.internal.ui.IHelpContextIds;
023: import org.eclipse.pde.internal.ui.IPDEUIConstants;
024: import org.eclipse.pde.internal.ui.PDEPlugin;
025: import org.eclipse.pde.internal.ui.PDEPluginImages;
026: import org.eclipse.pde.internal.ui.PDEUIMessages;
027: import org.eclipse.pde.internal.ui.editor.PDEFormPage;
028: import org.eclipse.pde.internal.ui.editor.PDEMasterDetailsBlock;
029: import org.eclipse.pde.internal.ui.editor.PDESection;
030: import org.eclipse.swt.custom.StyledText;
031: import org.eclipse.swt.widgets.Composite;
032: import org.eclipse.ui.PlatformUI;
033: import org.eclipse.ui.forms.DetailsPart;
034: import org.eclipse.ui.forms.IDetailsPage;
035: import org.eclipse.ui.forms.IDetailsPageProvider;
036: import org.eclipse.ui.forms.IManagedForm;
037: import org.eclipse.ui.forms.editor.FormEditor;
038: import org.eclipse.ui.forms.editor.IFormPage;
039: import org.eclipse.ui.forms.widgets.ScrolledForm;
040:
041: public class ExtensionsPage extends PDEFormPage {
042: public static final String PAGE_ID = "extensions"; //$NON-NLS-1$
043:
044: private ExtensionsSection fSection;
045: private ExtensionsBlock fBlock;
046:
047: public class ExtensionsBlock extends PDEMasterDetailsBlock
048: implements IDetailsPageProvider {
049:
050: private ExtensionElementBodyTextDetails fBodyTextDetails;
051:
052: public ExtensionsBlock() {
053: super (ExtensionsPage.this );
054: }
055:
056: protected PDESection createMasterSection(
057: IManagedForm managedForm, Composite parent) {
058: fSection = new ExtensionsSection(getPage(), parent);
059: return fSection;
060: }
061:
062: protected void registerPages(DetailsPart detailsPart) {
063: detailsPart.setPageLimit(10);
064: // register static page for the extensions
065: detailsPart.registerPage(IPluginExtension.class,
066: new ExtensionDetails(fSection));
067: // Register a static page for the extension elements that contain
068: // only body text (no child elements or attributes)
069: // (e.g. schema simple type)
070: fBodyTextDetails = new ExtensionElementBodyTextDetails(
071: fSection);
072: detailsPart.registerPage(
073: ExtensionElementBodyTextDetails.class,
074: fBodyTextDetails);
075: // register a dynamic provider for elements
076: detailsPart.setPageProvider(this );
077: }
078:
079: public Object getPageKey(Object object) {
080: if (object instanceof IPluginExtension)
081: return IPluginExtension.class;
082: if (object instanceof IPluginElement) {
083: ISchemaElement element = ExtensionsSection
084: .getSchemaElement((IPluginElement) object);
085: // Extension point schema exists
086: if (element != null) {
087: // Use the body text page if the element has no child
088: // elements or attributes
089: if (element.getType() instanceof ISchemaSimpleType) {
090: // Set the schema element (to provide hover text
091: // content)
092: fBodyTextDetails.setSchemaElement(element);
093: return ExtensionElementBodyTextDetails.class;
094: }
095: return element;
096: }
097: // No Extension point schema
098: // no element - construct one
099: IPluginElement pelement = (IPluginElement) object;
100: // Use the body text page if the element has no child
101: // elements or attributes
102: if ((pelement.getAttributeCount() == 0)
103: && (pelement.getChildCount() == 0)) {
104: // Unset the previous schema element (no hover text
105: // content)
106: fBodyTextDetails.setSchemaElement(null);
107: return ExtensionElementBodyTextDetails.class;
108: }
109: String ename = pelement.getName();
110: IPluginExtension extension = ExtensionsSection
111: .getExtension((IPluginParent) pelement
112: .getParent());
113: return extension.getPoint() + "/" + ename; //$NON-NLS-1$
114: }
115: return object.getClass();
116: }
117:
118: public IDetailsPage getPage(Object object) {
119: if (object instanceof ISchemaElement)
120: return new ExtensionElementDetails(fSection,
121: (ISchemaElement) object);
122: if (object instanceof String)
123: return new ExtensionElementDetails(fSection, null);
124: return null;
125: }
126: }
127:
128: /**
129: * @param editor
130: * @param id
131: * @param title
132: */
133: public ExtensionsPage(FormEditor editor) {
134: super (editor, PAGE_ID, PDEUIMessages.ExtensionsPage_tabName);
135: fBlock = new ExtensionsBlock();
136: }
137:
138: /* (non-Javadoc)
139: * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
140: */
141: protected String getHelpResource() {
142: return IPDEUIConstants.PLUGIN_DOC_ROOT
143: + "guide/tools/editors/manifest_editor/extensions.htm"; //$NON-NLS-1$
144: }
145:
146: protected void createFormContent(IManagedForm managedForm) {
147: ScrolledForm form = managedForm.getForm();
148: form.setText(PDEUIMessages.ExtensionsPage_title);
149: form.setImage(PDEPlugin.getDefault().getLabelProvider().get(
150: PDEPluginImages.DESC_EXTENSIONS_OBJ));
151: fBlock.createContent(managedForm);
152: //refire selection
153: fSection.fireSelection();
154: PlatformUI.getWorkbench().getHelpSystem().setHelp(
155: form.getBody(),
156: IHelpContextIds.MANIFEST_PLUGIN_EXTENSIONS);
157: super .createFormContent(managedForm);
158: }
159:
160: public void updateFormSelection() {
161: super .updateFormSelection();
162: IFormPage page = getPDEEditor().findPage(
163: PluginInputContext.CONTEXT_ID);
164: if (page instanceof ManifestSourcePage) {
165: ISourceViewer viewer = ((ManifestSourcePage) page)
166: .getViewer();
167: if (viewer == null)
168: return;
169: StyledText text = viewer.getTextWidget();
170: if (text == null)
171: return;
172: int offset = text.getCaretOffset();
173: if (offset < 0)
174: return;
175:
176: IDocumentRange range = ((ManifestSourcePage) page)
177: .getRangeElement(offset, true);
178: if (range instanceof IDocumentAttributeNode)
179: range = ((IDocumentAttributeNode) range)
180: .getEnclosingElement();
181: else if (range instanceof IDocumentTextNode)
182: range = ((IDocumentTextNode) range)
183: .getEnclosingElement();
184: if ((range instanceof IPluginExtension)
185: || (range instanceof IPluginElement)) {
186: fSection
187: .selectExtensionElement(new StructuredSelection(
188: range));
189: }
190: }
191: }
192: }
|