1 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 PAGE_ID = "extensions"; 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 detailsPart.registerPage(IPluginExtension.class, 63 new ExtensionDetails(fSection)); 64 fBodyTextDetails = new ExtensionElementBodyTextDetails(fSection); 68 detailsPart.registerPage(ExtensionElementBodyTextDetails.class, 69 fBodyTextDetails); 70 detailsPart.setPageProvider(this); 72 } 73 public Object getPageKey(Object object) { 74 if (object instanceof IPluginExtension) 75 return IPluginExtension.class; 76 if (object instanceof IPluginElement) { 77 ISchemaElement element = ExtensionsSection.getSchemaElement((IPluginElement)object); 78 if (element != null) { 80 if (element.getType() instanceof ISchemaSimpleType) { 83 fBodyTextDetails.setSchemaElement(element); 86 return ExtensionElementBodyTextDetails.class; 87 } 88 return element; 89 } 90 IPluginElement pelement = (IPluginElement)object; 93 if ((pelement.getAttributeCount() == 0) && 96 (pelement.getChildCount() == 0)) { 97 fBodyTextDetails.setSchemaElement(null); 100 return ExtensionElementBodyTextDetails.class; 101 } 102 String ename = pelement.getName(); 103 IPluginExtension extension = ExtensionsSection.getExtension((IPluginParent)pelement.getParent()); 104 return extension.getPoint()+"/"+ename; } 106 return object.getClass(); 107 } 108 public IDetailsPage getPage(Object object) { 109 if (object instanceof ISchemaElement) 110 return new ExtensionElementDetails(fSection, (ISchemaElement)object); 111 if (object instanceof String ) 112 return new ExtensionElementDetails(fSection, null); 113 return null; 114 } 115 } 116 117 122 public ExtensionsPage(FormEditor editor) { 123 super(editor, PAGE_ID, PDEUIMessages.ExtensionsPage_tabName); 124 fBlock = new ExtensionsBlock(); 125 } 126 127 130 protected String getHelpResource() { 131 return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/manifest_editor/extensions.htm"; } 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 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 |