KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > memory > MemoryRenderingManager


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.memory;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Collection JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.List JavaDoc;
18 import java.util.Map JavaDoc;
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 /**
34  * The memory rendering manager.
35  *
36  * @see org.eclipse.debug.ui.memory.IMemoryRenderingManager
37  * @since 3.1
38  */

39 public class MemoryRenderingManager extends AbstractMemoryRenderingBindingsProvider implements IMemoryRenderingManager {
40     
41     // map of rendering type ids to valid rendering types
42
private Map JavaDoc fRenderingTypes = new HashMap JavaDoc();
43     
44     // list of renderingBindings
45
private List JavaDoc fBindings = new ArrayList JavaDoc();
46         
47     // singleton manager
48
private static MemoryRenderingManager fgDefault;
49     
50     // elements in the memory renderings extension point
51
public static final String JavaDoc ELEMENT_MEMORY_RENDERING_TYPE = "renderingType"; //$NON-NLS-1$
52
public static final String JavaDoc ELEMENT_RENDERING_BINDINGS = "renderingBindings"; //$NON-NLS-1$
53

54     /**
55      * Returns the memory rendering manager.
56      *
57      * @return the memory rendering manager
58      */

59     public static IMemoryRenderingManager getDefault() {
60         if (fgDefault == null) {
61             fgDefault = new MemoryRenderingManager();
62         }
63         return fgDefault;
64     }
65     /**
66      * Construts a new memory rendering manager. Only to be called by DebugUIPlugin.
67      */

68     private MemoryRenderingManager() {
69         initializeRenderings();
70     }
71
72     /* (non-Javadoc)
73      * @see org.eclipse.debug.ui.memory.IMemoryRenderingManager#createRendering(java.lang.String)
74      */

75     public IMemoryRendering createRendering(String JavaDoc id) throws CoreException {
76         IMemoryRenderingType type = getRenderingType(id);
77         if (type != null) {
78             return type.createRendering();
79         }
80         return null;
81     }
82
83     /* (non-Javadoc)
84      * @see org.eclipse.debug.ui.memory.IMemoryRenderingManager#getRenderingTypes()
85      */

86     public IMemoryRenderingType[] getRenderingTypes() {
87         Collection JavaDoc types = fRenderingTypes.values();
88         return (IMemoryRenderingType[]) types.toArray(new IMemoryRenderingType[types.size()]);
89     }
90
91     /* (non-Javadoc)
92      * @see org.eclipse.debug.ui.memory.IMemoryRenderingManager#getRenderingType(java.lang.String)
93      */

94     public IMemoryRenderingType getRenderingType(String JavaDoc id) {
95         return (IMemoryRenderingType) fRenderingTypes.get(id);
96     }
97
98     /* (non-Javadoc)
99      * @see org.eclipse.debug.ui.memory.IMemoryRenderingBindingsProvider#getDefaultRenderingTypes(org.eclipse.debug.core.model.IMemoryBlock)
100      */

101     public IMemoryRenderingType[] getDefaultRenderingTypes(IMemoryBlock block) {
102         List JavaDoc allTypes = new ArrayList JavaDoc();
103         Iterator JavaDoc 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     /* (non-Javadoc)
118      * @see org.eclipse.debug.ui.memory.IMemoryRenderingBindingsProvider#getPrimaryRenderingType(org.eclipse.debug.core.model.IMemoryBlock)
119      */

120     public IMemoryRenderingType getPrimaryRenderingType(IMemoryBlock block) {
121         Iterator JavaDoc 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     /* (non-Javadoc)
133      * @see org.eclipse.debug.ui.memory.IMemoryRenderingBindingsProvider#getRenderingTypes(org.eclipse.debug.core.model.IMemoryBlock)
134      */

135     public IMemoryRenderingType[] getRenderingTypes(IMemoryBlock block) {
136         List JavaDoc allTypes = new ArrayList JavaDoc();
137         Iterator JavaDoc 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     /**
152      * Processes memory rendering contributions.
153      */

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 JavaDoc 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