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.IPluginExtensionPoint;
015: import org.eclipse.pde.internal.core.text.IDocumentAttributeNode;
016: import org.eclipse.pde.internal.core.text.IDocumentRange;
017: import org.eclipse.pde.internal.ui.IHelpContextIds;
018: import org.eclipse.pde.internal.ui.IPDEUIConstants;
019: import org.eclipse.pde.internal.ui.PDEPlugin;
020: import org.eclipse.pde.internal.ui.PDEPluginImages;
021: import org.eclipse.pde.internal.ui.PDEUIMessages;
022: import org.eclipse.pde.internal.ui.editor.PDEFormPage;
023: import org.eclipse.pde.internal.ui.editor.PDEMasterDetailsBlock;
024: import org.eclipse.pde.internal.ui.editor.PDESection;
025: import org.eclipse.swt.custom.StyledText;
026: import org.eclipse.swt.widgets.Composite;
027: import org.eclipse.ui.PlatformUI;
028: import org.eclipse.ui.forms.DetailsPart;
029: import org.eclipse.ui.forms.IDetailsPage;
030: import org.eclipse.ui.forms.IDetailsPageProvider;
031: import org.eclipse.ui.forms.IManagedForm;
032: import org.eclipse.ui.forms.editor.FormEditor;
033: import org.eclipse.ui.forms.editor.IFormPage;
034: import org.eclipse.ui.forms.widgets.ScrolledForm;
035:
036: public class ExtensionPointsPage extends PDEFormPage {
037:
038: public static final String PAGE_ID = "ex-points"; //$NON-NLS-1$
039:
040: private ExtensionPointsSection fExtensionPointsSection;
041: private ExtensionPointsBlock fBlock;
042:
043: public class ExtensionPointsBlock extends PDEMasterDetailsBlock {
044:
045: public ExtensionPointsBlock() {
046: super (ExtensionPointsPage.this );
047: }
048:
049: protected PDESection createMasterSection(
050: IManagedForm managedForm, Composite parent) {
051: fExtensionPointsSection = new ExtensionPointsSection(
052: getPage(), parent);
053: return fExtensionPointsSection;
054: }
055:
056: protected void registerPages(DetailsPart detailsPart) {
057: detailsPart.setPageProvider(new IDetailsPageProvider() {
058: public Object getPageKey(Object object) {
059: if (object instanceof IPluginExtensionPoint)
060: return IPluginExtensionPoint.class;
061: return object.getClass();
062: }
063:
064: public IDetailsPage getPage(Object key) {
065: if (key.equals(IPluginExtensionPoint.class))
066: return new ExtensionPointDetails();
067: return null;
068: }
069: });
070: }
071: }
072:
073: public ExtensionPointsPage(FormEditor editor) {
074: super (editor, PAGE_ID,
075: PDEUIMessages.ExtensionPointsPage_tabName);
076: fBlock = new ExtensionPointsBlock();
077: }
078:
079: /* (non-Javadoc)
080: * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
081: */
082: protected String getHelpResource() {
083: return IPDEUIConstants.PLUGIN_DOC_ROOT
084: + "guide/tools/editors/manifest_editor/extension_points.htm"; //$NON-NLS-1$
085: }
086:
087: protected void createFormContent(IManagedForm managedForm) {
088: super .createFormContent(managedForm);
089: ScrolledForm form = managedForm.getForm();
090: form.setImage(PDEPlugin.getDefault().getLabelProvider().get(
091: PDEPluginImages.DESC_EXT_POINTS_OBJ));
092: form.setText(PDEUIMessages.ExtensionPointsPage_title);
093: fBlock.createContent(managedForm);
094: fExtensionPointsSection.fireSelection();
095: PlatformUI.getWorkbench().getHelpSystem().setHelp(
096: form.getBody(),
097: IHelpContextIds.MANIFEST_PLUGIN_EXT_POINTS);
098: }
099:
100: public void updateFormSelection() {
101: super .updateFormSelection();
102: IFormPage page = getPDEEditor().findPage(
103: PluginInputContext.CONTEXT_ID);
104: if (page instanceof ManifestSourcePage) {
105: ISourceViewer viewer = ((ManifestSourcePage) page)
106: .getViewer();
107: if (viewer == null)
108: return;
109: StyledText text = viewer.getTextWidget();
110: if (text == null)
111: return;
112: int offset = text.getCaretOffset();
113: if (offset < 0)
114: return;
115:
116: IDocumentRange range = ((ManifestSourcePage) page)
117: .getRangeElement(offset, true);
118: if (range instanceof IDocumentAttributeNode)
119: range = ((IDocumentAttributeNode) range)
120: .getEnclosingElement();
121: if (range instanceof IPluginExtensionPoint)
122: fExtensionPointsSection
123: .selectExtensionPoint(new StructuredSelection(
124: range));
125: }
126: }
127: }
|