KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > memory > renderings > AbstractTableRenderingLabelProvider


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.views.memory.renderings;
12
13 import java.math.BigInteger JavaDoc;
14
15 import org.eclipse.debug.core.model.MemoryByte;
16 import org.eclipse.debug.internal.ui.DebugPluginImages;
17 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
18 import org.eclipse.debug.ui.memory.AbstractTableRendering;
19 import org.eclipse.jface.viewers.ITableLabelProvider;
20 import org.eclipse.jface.viewers.LabelProvider;
21 import org.eclipse.swt.graphics.Image;
22
23 /**
24  * Abstract label provider for an ITableMemoryViewTab
25  *
26  * @since 3.0
27  */

28 abstract public class AbstractTableRenderingLabelProvider extends LabelProvider implements ITableLabelProvider{
29
30     protected AbstractTableRendering fRendering;
31     
32     /**
33      *
34      * Constructor for MemoryViewLabelProvider
35      */

36     public AbstractTableRenderingLabelProvider() {
37         super();
38     }
39     
40     public AbstractTableRenderingLabelProvider(AbstractTableRendering rendering){
41         fRendering = rendering;
42     }
43
44     /* (non-Javadoc)
45      * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
46      */

47     public void dispose() {
48         fRendering = null;
49         super.dispose();
50     }
51
52     /**
53      * @see ITableLabelProvider#getColumnImage(Object, int)
54      */

55     public Image getColumnImage(Object JavaDoc element, int columnIndex) {
56         
57         if (columnIndex == 0)
58         {
59             return DebugPluginImages.getImage(IInternalDebugUIConstants.IMG_OBJECT_MEMORY);
60         }
61         else if (columnIndex > (fRendering.getBytesPerLine()/fRendering.getBytesPerColumn()))
62         {
63             return DebugPluginImages.getImage(IInternalDebugUIConstants.IMG_OBJECT_MEMORY);
64         }
65         else
66         {
67             // if memory in the range has changed, return delta icon
68
int startOffset = (columnIndex-1)*fRendering.getBytesPerColumn();
69             int endOffset = startOffset + fRendering.getBytesPerColumn() - 1;
70             if (((TableRenderingLine)element).isRangeChange(startOffset, endOffset)) {
71                 return DebugPluginImages.getImage(IInternalDebugUIConstants.IMG_OBJECT_MEMORY_CHANGED);
72             }
73             return DebugPluginImages.getImage(IInternalDebugUIConstants.IMG_OBJECT_MEMORY);
74         }
75     }
76     
77     
78     /* (non-Javadoc)
79      * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
80      */

81     public String JavaDoc getColumnText(Object JavaDoc element, int columnIndex) {
82         String JavaDoc columnLabel = null;
83
84         if (columnIndex == 0)
85         {
86             columnLabel = ((TableRenderingLine)element).getAddress();
87             
88             // consult model presentation for address presentation
89
}
90         else if (columnIndex > (fRendering.getBytesPerLine()/fRendering.getBytesPerColumn()))
91         {
92             columnLabel = " "; //$NON-NLS-1$
93
}
94         else
95         {
96             int start = (columnIndex-1)*fRendering.getBytesPerColumn();
97             int end = start + fRendering.getBytesPerColumn();
98
99             MemoryByte[] bytes = ((TableRenderingLine)element).getBytes(start, end);
100             BigInteger JavaDoc address = new BigInteger JavaDoc(((TableRenderingLine)element).getAddress(), 16);
101             address = address.add(BigInteger.valueOf(start));
102             
103             columnLabel = fRendering.getString(fRendering.getRenderingId(), address, bytes);
104         }
105         return columnLabel;
106     }
107 }
108
Popular Tags