1 11 package org.eclipse.debug.internal.ui.memory; 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 import java.util.Map ; 19 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.runtime.IConfigurationElement; 22 import org.eclipse.core.runtime.IExtensionPoint; 23 import org.eclipse.core.runtime.Platform; 24 import org.eclipse.debug.core.model.IMemoryBlock; 25 import org.eclipse.debug.internal.ui.DebugUIPlugin; 26 import org.eclipse.debug.ui.IDebugUIConstants; 27 import org.eclipse.debug.ui.memory.AbstractMemoryRenderingBindingsProvider; 28 import org.eclipse.debug.ui.memory.IMemoryRendering; 29 import org.eclipse.debug.ui.memory.IMemoryRenderingBindingsListener; 30 import org.eclipse.debug.ui.memory.IMemoryRenderingManager; 31 import org.eclipse.debug.ui.memory.IMemoryRenderingType; 32 33 39 public class MemoryRenderingManager extends AbstractMemoryRenderingBindingsProvider implements IMemoryRenderingManager { 40 41 private Map fRenderingTypes = new HashMap (); 43 44 private List fBindings = new ArrayList (); 46 47 private static MemoryRenderingManager fgDefault; 49 50 public static final String ELEMENT_MEMORY_RENDERING_TYPE = "renderingType"; public static final String ELEMENT_RENDERING_BINDINGS = "renderingBindings"; 54 59 public static IMemoryRenderingManager getDefault() { 60 if (fgDefault == null) { 61 fgDefault = new MemoryRenderingManager(); 62 } 63 return fgDefault; 64 } 65 68 private MemoryRenderingManager() { 69 initializeRenderings(); 70 } 71 72 75 public IMemoryRendering createRendering(String id) throws CoreException { 76 IMemoryRenderingType type = getRenderingType(id); 77 if (type != null) { 78 return type.createRendering(); 79 } 80 return null; 81 } 82 83 86 public IMemoryRenderingType[] getRenderingTypes() { 87 Collection types = fRenderingTypes.values(); 88 return (IMemoryRenderingType[]) types.toArray(new IMemoryRenderingType[types.size()]); 89 } 90 91 94 public IMemoryRenderingType getRenderingType(String id) { 95 return (IMemoryRenderingType) fRenderingTypes.get(id); 96 } 97 98 101 public IMemoryRenderingType[] getDefaultRenderingTypes(IMemoryBlock block) { 102 List allTypes = new ArrayList (); 103 Iterator iterator = fBindings.iterator(); 104 while (iterator.hasNext()) { 105 RenderingBindings binding = (RenderingBindings)iterator.next(); 106 IMemoryRenderingType[] renderingTypes = binding.getDefaultRenderingTypes(block); 107 for (int i = 0; i < renderingTypes.length; i++) { 108 IMemoryRenderingType type = renderingTypes[i]; 109 if (!allTypes.contains(type)) { 110 allTypes.add(type); 111 } 112 } 113 } 114 return (IMemoryRenderingType[]) allTypes.toArray(new IMemoryRenderingType[allTypes.size()]); 115 } 116 117 120 public IMemoryRenderingType getPrimaryRenderingType(IMemoryBlock block) { 121 Iterator iterator = fBindings.iterator(); 122 while (iterator.hasNext()) { 123 RenderingBindings binding = (RenderingBindings)iterator.next(); 124 IMemoryRenderingType renderingType = binding.getPrimaryRenderingType(block); 125 if (renderingType != null) { 126 return renderingType; 127 } 128 } 129 return null; 130 } 131 132 135 public IMemoryRenderingType[] getRenderingTypes(IMemoryBlock block) { 136 List allTypes = new ArrayList (); 137 Iterator iterator = fBindings.iterator(); 138 while (iterator.hasNext()) { 139 RenderingBindings binding = (RenderingBindings)iterator.next(); 140 IMemoryRenderingType[] renderingTypes = binding.getRenderingTypes(block); 141 for (int i = 0; i < renderingTypes.length; i++) { 142 IMemoryRenderingType type = renderingTypes[i]; 143 if (!allTypes.contains(type)) { 144 allTypes.add(type); 145 } 146 } 147 } 148 return (IMemoryRenderingType[]) allTypes.toArray(new IMemoryRenderingType[allTypes.size()]); 149 } 150 151 154 private void initializeRenderings() { 155 IExtensionPoint extensionPoint= Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.EXTENSION_POINT_MEMORY_RENDERIGNS); 156 IConfigurationElement[] configurationElements = extensionPoint.getConfigurationElements(); 157 for (int i = 0; i < configurationElements.length; i++) { 158 IConfigurationElement element= configurationElements[i]; 159 String name = element.getName(); 160 if (name.equals(ELEMENT_MEMORY_RENDERING_TYPE)) { 161 MemoryRenderingType type = new MemoryRenderingType(element); 162 try { 163 type.validate(); 164 fRenderingTypes.put(type.getId(), type); 165 } catch (CoreException e) { 166 DebugUIPlugin.log(e); 167 } 168 } else if (name.equals(ELEMENT_RENDERING_BINDINGS)) { 169 RenderingBindings bindings = new RenderingBindings(element); 170 try { 171 bindings.validate(); 172 fBindings.add(bindings); 173 bindings.addListener(new IMemoryRenderingBindingsListener() { 174 public void memoryRenderingBindingsChanged() { 175 fireBindingsChanged(); 176 }}); 177 } catch (CoreException e) { 178 DebugUIPlugin.log(e); 179 } 180 } 181 } 182 } 183 } 184 | Popular Tags |