1 11 package org.eclipse.jdt.internal.ui.wizards.buildpaths; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.core.runtime.IExtensionPoint; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.core.runtime.Platform; 20 import org.eclipse.core.runtime.Status; 21 22 import org.eclipse.jdt.core.IClasspathEntry; 23 24 import org.eclipse.jdt.ui.JavaUI; 25 import org.eclipse.jdt.ui.wizards.IClasspathContainerPage; 26 27 import org.eclipse.jdt.internal.ui.JavaPlugin; 28 import org.eclipse.jdt.internal.ui.util.CoreUtility; 29 30 32 public class ClasspathContainerDescriptor { 33 34 private IConfigurationElement fConfigElement; 35 private IClasspathContainerPage fPage; 36 37 private static final String ATT_EXTENSION = "classpathContainerPage"; 39 private static final String ATT_ID = "id"; private static final String ATT_NAME = "name"; private static final String ATT_PAGE_CLASS = "class"; 43 public ClasspathContainerDescriptor(IConfigurationElement configElement) throws CoreException { 44 super(); 45 fConfigElement = configElement; 46 fPage= null; 47 48 String id = fConfigElement.getAttribute(ATT_ID); 49 String name = configElement.getAttribute(ATT_NAME); 50 String pageClassName = configElement.getAttribute(ATT_PAGE_CLASS); 51 52 if (name == null) { 53 throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, 0, "Invalid extension (missing name): " + id, null)); } 55 if (pageClassName == null) { 56 throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, 0, "Invalid extension (missing page class name): " + id, null)); } 58 } 59 60 public IClasspathContainerPage createPage() throws CoreException { 61 if (fPage == null) { 62 Object elem= CoreUtility.createExtension(fConfigElement, ATT_PAGE_CLASS); 63 if (elem instanceof IClasspathContainerPage) { 64 fPage= (IClasspathContainerPage) elem; 65 } else { 66 String id= fConfigElement.getAttribute(ATT_ID); 67 throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, 0, "Invalid extension (page not of type IClasspathContainerPage): " + id, null)); } 69 } 70 return fPage; 71 } 72 73 public IClasspathContainerPage getPage() { 74 return fPage; 75 } 76 77 public void setPage(IClasspathContainerPage page) { 78 fPage= page; 79 } 80 81 public void dispose() { 82 if (fPage != null) { 83 fPage.dispose(); 84 fPage= null; 85 } 86 } 87 88 public String getName() { 89 return fConfigElement.getAttribute(ATT_NAME); 90 } 91 92 public String getPageClass() { 93 return fConfigElement.getAttribute(ATT_PAGE_CLASS); 94 } 95 96 public boolean canEdit(IClasspathEntry entry) { 97 String id = fConfigElement.getAttribute(ATT_ID); 98 if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { 99 String type = entry.getPath().segment(0); 100 return id.equals(type); 101 } 102 return false; 103 } 104 105 public static ClasspathContainerDescriptor[] getDescriptors() { 106 ArrayList containers= new ArrayList (); 107 108 IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(JavaUI.ID_PLUGIN, ATT_EXTENSION); 109 if (extensionPoint != null) { 110 ClasspathContainerDescriptor defaultPage= null; 111 String defaultPageName= ClasspathContainerDefaultPage.class.getName(); 112 113 IConfigurationElement[] elements = extensionPoint.getConfigurationElements(); 114 for (int i = 0; i < elements.length; i++) { 115 try { 116 ClasspathContainerDescriptor curr= new ClasspathContainerDescriptor(elements[i]); 117 if (defaultPageName.equals(curr.getPageClass())) { 118 defaultPage= curr; 119 } else { 120 containers.add(curr); 121 } 122 } catch (CoreException e) { 123 JavaPlugin.log(e); 124 } 125 } 126 if (defaultPageName != null && containers.isEmpty()) { 127 containers.add(defaultPage); 129 } 130 } 131 return (ClasspathContainerDescriptor[]) containers.toArray(new ClasspathContainerDescriptor[containers.size()]); 132 } 133 134 } 135 | Popular Tags |