KickJava   Java API By Example, From Geeks To Geeks.

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


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.internal.ui.DebugUIPlugin;
16 import org.eclipse.debug.ui.IDebugUIConstants;
17 import org.eclipse.debug.ui.memory.AbstractTableRendering;
18 import org.eclipse.debug.ui.memory.IMemoryBlockTablePresentation;
19 import org.eclipse.jface.viewers.IColorProvider;
20 import org.eclipse.swt.graphics.Color;
21
22 /**
23  * @since 3.0
24  */

25 public class TableRenderingLabelProvider extends AbstractTableRenderingLabelProvider implements IColorProvider {
26     
27     private IMemoryBlockTablePresentation fTablePresentation;
28
29     /**
30      * Constructor for MemoryViewLabelProvider
31      */

32     public TableRenderingLabelProvider() {
33         super();
34     }
35     
36     public TableRenderingLabelProvider(AbstractTableRendering rendering){
37         super(rendering);
38         fTablePresentation = (IMemoryBlockTablePresentation)rendering.getAdapter(IMemoryBlockTablePresentation.class);
39     }
40     
41     
42     /* (non-Javadoc)
43      * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
44      */

45     public void dispose() {
46         if (fTablePresentation != null) {
47             fTablePresentation.dispose();
48             fTablePresentation = null;
49         }
50         super.dispose();
51     }
52
53     /* (non-Javadoc)
54      * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
55      */

56     public Color getForeground(Object JavaDoc element) {
57         if (element instanceof TableRenderingLine)
58         {
59             TableRenderingLine line = (TableRenderingLine)element;
60             
61             if (line.isMonitored) {
62                 return DebugUIPlugin.getPreferenceColor(IDebugUIConstants.PREF_MEMORY_HISTORY_KNOWN_COLOR);
63             }
64             return DebugUIPlugin.getPreferenceColor(IDebugUIConstants.PREF_MEMORY_HISTORY_UNKNOWN_COLOR);
65         }
66         return DebugUIPlugin.getPreferenceColor(IDebugUIConstants.PREF_MEMORY_HISTORY_KNOWN_COLOR);
67     }
68
69     /* (non-Javadoc)
70      * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
71      */

72     public Color getBackground(Object JavaDoc element) {
73         
74         return null;
75     }
76     
77     /* (non-Javadoc)
78      * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
79      */

80     public String JavaDoc getColumnText(Object JavaDoc element, int columnIndex) {
81         
82         String JavaDoc label = super.getColumnText(element, columnIndex);
83         
84         // consult model presentation for address presentation
85
if (columnIndex == 0)
86         {
87             if (fTablePresentation != null)
88             {
89                 String JavaDoc address = ((TableRenderingLine)element).getAddress();
90                 
91                 // get address presentation
92
String JavaDoc tempLabel = fTablePresentation.getRowLabel(fRendering.getMemoryBlock(), new BigInteger JavaDoc(address, 16));
93                 
94                 if (tempLabel != null)
95                     return tempLabel;
96             }
97             return label;
98         }
99         return label;
100     }
101 }
102
Popular Tags