KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > elements > adapters > MemoryBlockLabelAdapter


1 /*******************************************************************************
2  * Copyright (c) 2005, 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
12 package org.eclipse.debug.internal.ui.elements.adapters;
13
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.debug.core.model.IMemoryBlock;
16 import org.eclipse.debug.core.model.IMemoryBlockExtension;
17 import org.eclipse.debug.internal.ui.DebugPluginImages;
18 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
19 import org.eclipse.debug.ui.IDebugUIConstants;
20 import org.eclipse.jface.resource.ImageDescriptor;
21
22 public class MemoryBlockLabelAdapter extends AsynchronousDebugLabelAdapter {
23     
24     protected ImageDescriptor[] getImageDescriptors(Object JavaDoc element, IPresentationContext context) throws CoreException {
25         if (element instanceof IMemoryBlock)
26             return new ImageDescriptor[]{DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_OBJS_VARIABLE)};
27         
28         return new ImageDescriptor[0];
29     }
30
31     /**
32      * @param memoryBlockLabel
33      * @return
34      */

35     private String JavaDoc getLabel(IMemoryBlock memoryBlock) {
36         
37         String JavaDoc memoryBlockLabel = " "; //$NON-NLS-1$
38
if (memoryBlock instanceof IMemoryBlockExtension)
39         {
40             // simply return the expression without the address
41
// do not want to keep track of changes in the address
42
if (((IMemoryBlockExtension)memoryBlock).getExpression() != null)
43             {
44                 memoryBlockLabel += ((IMemoryBlockExtension)memoryBlock).getExpression();
45             }
46         }
47         else
48         {
49             long address = memoryBlock.getStartAddress();
50             memoryBlockLabel = Long.toHexString(address);
51         }
52         return memoryBlockLabel;
53     }
54
55     protected String JavaDoc[] getLabels(Object JavaDoc element, IPresentationContext context) throws CoreException {
56         if (element instanceof IMemoryBlock)
57             return new String JavaDoc[]{getLabel((IMemoryBlock)element)};
58         return super.getLabels(element, context);
59     }
60 }
61
Popular Tags