KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IConfigurationElement;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.debug.internal.ui.DebugUIPlugin;
18 import org.eclipse.debug.ui.IDebugUIConstants;
19 import org.eclipse.debug.ui.memory.IMemoryRendering;
20 import org.eclipse.debug.ui.memory.IMemoryRenderingType;
21 import org.eclipse.debug.ui.memory.IMemoryRenderingTypeDelegate;
22
23 /**
24  * A contributed memory rendering type.
25  *
26  * @since 3.1
27  */

28 class MemoryRenderingType implements IMemoryRenderingType {
29     
30     private IConfigurationElement fConfigurationElement;
31     private IMemoryRenderingTypeDelegate fDelegate;
32     
33     // attributes for a memoryRenderingType
34
static final String JavaDoc ATTR_MEM_RENDERING_TYPE_NAME = "name"; //$NON-NLS-1$
35
static final String JavaDoc ATTR_MEM_RENDERING_TYPE_ID = "id"; //$NON-NLS-1$
36
static final String JavaDoc ATTR_MEM_RENDERING_TYPE_DELEGATE = "class"; //$NON-NLS-1$
37

38     /**
39      * Constructs a rendering type from a contribution.
40      */

41     MemoryRenderingType(IConfigurationElement element) {
42         fConfigurationElement = element;
43     }
44
45     /* (non-Javadoc)
46      * @see org.eclipse.debug.ui.memory.IMemoryRenderingType#getLabel()
47      */

48     public String JavaDoc getLabel() {
49         return fConfigurationElement.getAttribute(ATTR_MEM_RENDERING_TYPE_NAME);
50     }
51
52     /* (non-Javadoc)
53      * @see org.eclipse.debug.ui.memory.IMemoryRenderingType#getId()
54      */

55     public String JavaDoc getId() {
56         return fConfigurationElement.getAttribute(ATTR_MEM_RENDERING_TYPE_ID);
57     }
58
59     /* (non-Javadoc)
60      * @see org.eclipse.debug.ui.memory.IMemoryRenderingType#createRendering()
61      */

62     public IMemoryRendering createRendering() throws CoreException {
63         if (fDelegate == null) {
64             fDelegate = (IMemoryRenderingTypeDelegate) fConfigurationElement.createExecutableExtension(ATTR_MEM_RENDERING_TYPE_DELEGATE);
65         }
66         return fDelegate.createRendering(getId());
67     }
68
69     /**
70      * Validates this contribution.
71      *
72      * @exception CoreException if invalid
73      */

74     void validate() throws CoreException {
75         verifyPresent(ATTR_MEM_RENDERING_TYPE_ID);
76         verifyPresent(ATTR_MEM_RENDERING_TYPE_NAME);
77         verifyPresent(ATTR_MEM_RENDERING_TYPE_DELEGATE);
78     }
79     
80     private void verifyPresent(String JavaDoc attrName) throws CoreException {
81         if (fConfigurationElement.getAttribute(attrName) == null) {
82             Status status = new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.INTERNAL_ERROR,
83                     "<memoryRenderingType> element missing required attribute: " + attrName, null); //$NON-NLS-1$
84
throw new CoreException(status);
85         }
86     }
87 }
88
Popular Tags