1 11 package org.eclipse.ui.internal.registry; 12 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.HashMap ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 19 import org.eclipse.core.runtime.Assert; 20 import org.eclipse.core.runtime.IConfigurationElement; 21 import org.eclipse.core.runtime.IExtension; 22 import org.eclipse.core.runtime.IExtensionPoint; 23 import org.eclipse.core.runtime.Platform; 24 import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker; 25 import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler; 26 import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker; 27 import org.eclipse.ui.PlatformUI; 28 import org.eclipse.ui.dialogs.IWorkingSetPage; 29 30 33 public class WorkingSetRegistry implements IExtensionChangeHandler { 34 private static final String DEFAULT_PAGE_ID = "org.eclipse.ui.resourceWorkingSetPage"; 38 private HashMap workingSetDescriptors = new HashMap (); 39 40 43 public WorkingSetRegistry() { 44 IExtensionTracker tracker = PlatformUI.getWorkbench() 45 .getExtensionTracker(); 46 tracker.registerHandler(this, ExtensionTracker 47 .createExtensionPointFilter(getExtensionPointFilter())); 48 49 } 50 51 56 private IExtensionPoint getExtensionPointFilter() { 57 return Platform.getExtensionRegistry().getExtensionPoint( 58 PlatformUI.PLUGIN_ID, 59 IWorkbenchRegistryConstants.PL_WORKINGSETS); 60 } 61 62 68 public void addWorkingSetDescriptor(WorkingSetDescriptor descriptor) { 69 Assert.isTrue(!workingSetDescriptors.containsValue(descriptor), 70 "working set descriptor already registered"); IExtensionTracker tracker = PlatformUI.getWorkbench() 72 .getExtensionTracker(); 73 tracker.registerObject(descriptor.getConfigurationElement() 74 .getDeclaringExtension(), descriptor, 75 IExtensionTracker.REF_WEAK); 76 workingSetDescriptors.put(descriptor.getId(), descriptor); 77 } 78 79 84 public IWorkingSetPage getDefaultWorkingSetPage() { 85 WorkingSetDescriptor descriptor = (WorkingSetDescriptor) workingSetDescriptors 87 .get(DEFAULT_PAGE_ID); 88 89 if (descriptor != null) { 90 return descriptor.createWorkingSetPage(); 91 } 92 return null; 93 } 94 95 101 public WorkingSetDescriptor getWorkingSetDescriptor(String pageId) { 102 return (WorkingSetDescriptor) workingSetDescriptors.get(pageId); 103 } 104 105 110 public WorkingSetDescriptor[] getWorkingSetDescriptors() { 111 return (WorkingSetDescriptor[]) workingSetDescriptors.values().toArray( 112 new WorkingSetDescriptor[workingSetDescriptors.size()]); 113 } 114 115 122 public WorkingSetDescriptor[] getNewPageWorkingSetDescriptors() { 123 Collection descriptors= workingSetDescriptors.values(); 124 List result= new ArrayList (descriptors.size()); 125 for (Iterator iter= descriptors.iterator(); iter.hasNext();) { 126 WorkingSetDescriptor descriptor= (WorkingSetDescriptor)iter.next(); 127 if (descriptor.getPageClassName() != null) { 128 result.add(descriptor); 129 } 130 } 131 return (WorkingSetDescriptor[])result.toArray(new WorkingSetDescriptor[result.size()]); 132 } 133 134 140 public boolean hasNewPageWorkingSetDescriptor() { 141 Collection descriptors= workingSetDescriptors.values(); 142 for (Iterator iter= descriptors.iterator(); iter.hasNext();) { 143 WorkingSetDescriptor descriptor= (WorkingSetDescriptor)iter.next(); 144 if (descriptor.getPageClassName() != null) { 145 return true; 146 } 147 } 148 return false; 149 } 150 151 public WorkingSetDescriptor[] getUpdaterDescriptorsForNamespace( 152 String namespace) { 153 Collection descriptors = workingSetDescriptors.values(); 154 List result = new ArrayList (); 155 for (Iterator iter = descriptors.iterator(); iter.hasNext();) { 156 WorkingSetDescriptor descriptor = (WorkingSetDescriptor) iter 157 .next(); 158 if (namespace.equals(descriptor.getUpdaterNamespace())) { 159 result.add(descriptor); 160 } 161 } 162 return (WorkingSetDescriptor[]) result 163 .toArray(new WorkingSetDescriptor[result.size()]); 164 } 165 166 public WorkingSetDescriptor[] getElementAdapterDescriptorsForNamespace( 167 String namespace) { 168 Collection descriptors = workingSetDescriptors.values(); 169 List result = new ArrayList (); 170 for (Iterator iter = descriptors.iterator(); iter.hasNext();) { 171 WorkingSetDescriptor descriptor = (WorkingSetDescriptor) iter 172 .next(); 173 if (namespace.equals(descriptor.getDeclaringNamespace())) { 174 result.add(descriptor); 175 } 176 } 177 return (WorkingSetDescriptor[]) result 178 .toArray(new WorkingSetDescriptor[result.size()]); 179 } 180 181 187 public IWorkingSetPage getWorkingSetPage(String pageId) { 188 WorkingSetDescriptor descriptor = (WorkingSetDescriptor) workingSetDescriptors 189 .get(pageId); 190 191 if (descriptor == null) { 192 return null; 193 } 194 return descriptor.createWorkingSetPage(); 195 } 196 197 200 public void load() { 201 WorkingSetRegistryReader reader = new WorkingSetRegistryReader(); 202 reader.readWorkingSets(Platform.getExtensionRegistry(), this); 203 } 204 205 208 public void addExtension(IExtensionTracker tracker, IExtension extension) { 209 WorkingSetRegistryReader reader = new WorkingSetRegistryReader(this); 210 IConfigurationElement[] elements = extension.getConfigurationElements(); 211 for (int i = 0; i < elements.length; i++) { 212 reader.readElement(elements[i]); 213 } 214 } 215 216 219 public void removeExtension(IExtension extension, Object [] objects) { 220 for (int i = 0; i < objects.length; i++) { 221 if (objects[i] instanceof WorkingSetDescriptor) { 222 WorkingSetDescriptor desc = (WorkingSetDescriptor) objects[i]; 223 workingSetDescriptors.remove(desc.getId()); 224 } 225 } 226 } 227 } 228 | Popular Tags |