KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > model > elements > MemoryBlockLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2006 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.model.elements;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.debug.core.model.IMemoryBlock;
15 import org.eclipse.debug.core.model.IMemoryBlockExtension;
16 import org.eclipse.debug.internal.ui.DebugPluginImages;
17 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
18 import org.eclipse.debug.ui.IDebugUIConstants;
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.jface.viewers.TreePath;
21
22 public class MemoryBlockLabelProvider extends DebugElementLabelProvider {
23     
24     protected String JavaDoc getLabel(TreePath elementPath,
25             IPresentationContext presentationContext, String JavaDoc columnId)
26             throws CoreException {
27         Object JavaDoc element = elementPath.getLastSegment();
28         
29         if (element instanceof IMemoryBlock)
30             return getLabel((IMemoryBlock)element);
31         
32         return super.getLabel(elementPath, presentationContext, columnId);
33     }
34     
35     protected ImageDescriptor getImageDescriptor(TreePath elementPath,
36             IPresentationContext presentationContext, String JavaDoc columnId)
37             throws CoreException {
38         
39         Object JavaDoc element = elementPath.getLastSegment();
40         
41         if (element instanceof IMemoryBlock)
42             return DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_OBJS_VARIABLE);
43         
44         return super.getImageDescriptor(elementPath, presentationContext, columnId);
45     }
46     
47     /**
48      * @param memoryBlockLabel
49      * @return
50      */

51     private String JavaDoc getLabel(IMemoryBlock memoryBlock) {
52         
53         String JavaDoc memoryBlockLabel = " "; //$NON-NLS-1$
54
if (memoryBlock instanceof IMemoryBlockExtension)
55         {
56             // simply return the expression without the address
57
// do not want to keep track of changes in the address
58
if (((IMemoryBlockExtension)memoryBlock).getExpression() != null)
59             {
60                 memoryBlockLabel += ((IMemoryBlockExtension)memoryBlock).getExpression();
61             }
62         }
63         else
64         {
65             long address = memoryBlock.getStartAddress();
66             memoryBlockLabel = Long.toHexString(address);
67         }
68         return memoryBlockLabel;
69     }
70
71 }
72
Popular Tags