KickJava   Java API By Example, From Geeks To Geeks.

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


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

11 package org.eclipse.debug.internal.ui.views.memory;
12
13 import java.math.BigInteger JavaDoc;
14 import org.eclipse.debug.internal.core.memory.MemoryByte;
15 import org.eclipse.debug.internal.ui.DebugPluginImages;
16 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
17 import org.eclipse.jface.viewers.ITableLabelProvider;
18 import org.eclipse.jface.viewers.LabelProvider;
19 import org.eclipse.swt.graphics.Image;
20
21 /**
22  * Abstract label provider for an ITableMemoryViewTab
23  *
24  * @since 3.0
25  */

26 abstract public class AbstractTableViewTabLabelProvider extends LabelProvider implements ITableLabelProvider{
27
28     protected ITableMemoryViewTab fViewTab;
29     protected AbstractMemoryRenderer fRenderer;
30     
31     /**
32      *
33      * Constructor for MemoryViewLabelProvider
34      */

35     public AbstractTableViewTabLabelProvider() {
36         super();
37     }
38     
39     public AbstractTableViewTabLabelProvider(ITableMemoryViewTab viewTab, AbstractMemoryRenderer renderer){
40         fViewTab = viewTab;
41         setRenderer(renderer);
42     }
43     
44     public void setViewTab(ITableMemoryViewTab viewTab){
45         fViewTab = viewTab;
46     }
47     
48     public void setRenderer(AbstractMemoryRenderer renderer){
49         fRenderer = renderer;
50         renderer.setViewTab(fViewTab);
51     }
52     
53     public AbstractMemoryRenderer getRenderer()
54     {
55         return fRenderer;
56     }
57
58     /**
59      * @see ITableLabelProvider#getColumnImage(Object, int)
60      */

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

87     public String JavaDoc getColumnText(Object JavaDoc element, int columnIndex) {
88         String JavaDoc columnLabel = null;
89
90         if (columnIndex == 0)
91         {
92             columnLabel = ((MemoryViewLine)element).getAddress();
93             
94             // consult model presentation for address presentation
95
}
96         else if (columnIndex > (fViewTab.getBytesPerLine()/fViewTab.getColumnSize()))
97         {
98             columnLabel = " "; //$NON-NLS-1$
99
}
100         else
101         {
102             int start = (columnIndex-1)*fViewTab.getColumnSize();
103             int end = start + fViewTab.getColumnSize();
104             MemoryViewLine line = (MemoryViewLine)element;
105
106             MemoryByte[] bytes = ((MemoryViewLine)element).getBytes(start, end);
107             BigInteger JavaDoc address = new BigInteger JavaDoc(((MemoryViewLine)element).getAddress(), 16);
108             address = address.add(BigInteger.valueOf(start));
109             
110             columnLabel = fRenderer.getString(fViewTab.getRenderingId(), address, bytes, line.getPaddedString());
111         }
112         return columnLabel;
113     }
114 }
115
Popular Tags