KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 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.core.runtime.PlatformObject;
16 import org.eclipse.debug.core.DebugException;
17 import org.eclipse.debug.core.model.IMemoryBlock;
18 import org.eclipse.debug.core.model.IMemoryBlockExtension;
19 import org.eclipse.debug.internal.ui.memory.provisional.AbstractAsyncTableRendering;
20 import org.eclipse.debug.ui.memory.AbstractTableRendering;
21 import org.eclipse.debug.ui.memory.IMemoryRendering;
22
23 /**
24  * This is an internal class for storing information about the content
25  * in the table viewer.
26  */

27 public class TableRenderingContentInput extends PlatformObject {
28
29     private IMemoryRendering fRendering;
30     private int fPreBuffer; // number of lines before the top visible line
31
private int fPostBuffer; // number of lines after thes last visible line
32
private BigInteger JavaDoc fLoadAddress; // Top address to load at the table
33
private int fNumLines; // number of visible lines
34
private boolean fUpdateDelta; // should the content provider calculate delta info
35
private BigInteger JavaDoc fMemoryBlockBaseAddress; // base address of the memory block when this input is set
36
private BigInteger JavaDoc fStartAddress;
37     private BigInteger JavaDoc fEndAddress;
38     
39     public TableRenderingContentInput(IMemoryRendering rendering, int preBuffer, int postBuffer, BigInteger JavaDoc loadAddress, int numOfLines, boolean updateDelta, BigInteger JavaDoc contentBaseAddress)
40     {
41         fRendering = rendering;
42         fPreBuffer = preBuffer;
43         fPostBuffer = postBuffer;
44         fLoadAddress = loadAddress;
45         fNumLines = numOfLines;
46         fUpdateDelta = updateDelta;
47
48         if (contentBaseAddress == null)
49         {
50             try {
51                 updateContentBaseAddress();
52             } catch (DebugException e) {
53             }
54         }
55         else
56         {
57             fMemoryBlockBaseAddress = contentBaseAddress;
58         }
59     }
60
61     public int getPostBuffer() {
62         return fPostBuffer;
63     }
64     public int getPreBuffer() {
65         return fPreBuffer;
66     }
67     public BigInteger JavaDoc getLoadAddress() {
68         return fLoadAddress;
69     }
70     
71     public IMemoryBlock getMemoryBlock()
72     {
73         return fRendering.getMemoryBlock();
74     }
75     public void setPostBuffer(int postBuffer) {
76         fPostBuffer = postBuffer;
77     }
78     public void setPreBuffer(int preBuffer) {
79         fPreBuffer = preBuffer;
80     }
81     public boolean isUpdateDelta() {
82         return fUpdateDelta;
83     }
84     public void setUpdateDelta(boolean updateDelta) {
85         fUpdateDelta = updateDelta;
86     }
87
88     public void setLoadAddress(BigInteger JavaDoc address)
89     {
90         fLoadAddress = address;
91     }
92     public BigInteger JavaDoc getContentBaseAddress() {
93         
94         if (fMemoryBlockBaseAddress == null)
95         {
96             try {
97                 updateContentBaseAddress();
98             } catch (DebugException e) {
99                 fMemoryBlockBaseAddress = new BigInteger JavaDoc("0"); //$NON-NLS-1$
100
}
101         }
102         
103         return fMemoryBlockBaseAddress;
104     }
105     
106     public void updateContentBaseAddress() throws DebugException {
107         IMemoryBlock memoryBlock = fRendering.getMemoryBlock();
108         if (memoryBlock instanceof IMemoryBlockExtension)
109             fMemoryBlockBaseAddress = ((IMemoryBlockExtension)memoryBlock).getBigBaseAddress();
110         else
111             fMemoryBlockBaseAddress = BigInteger.valueOf(memoryBlock.getStartAddress());
112     }
113     
114     /**
115      * @return start address of the memory block
116      */

117     public BigInteger JavaDoc getStartAddress()
118     {
119         if (fStartAddress == null)
120         {
121             try {
122                 IMemoryBlock memoryBlock = fRendering.getMemoryBlock();
123                 if(memoryBlock instanceof IMemoryBlockExtension)
124                 {
125                     BigInteger JavaDoc startAddress = ((IMemoryBlockExtension)memoryBlock).getMemoryBlockStartAddress();
126                     if (startAddress != null)
127                         fStartAddress = startAddress;
128                 }
129             } catch (DebugException e) {
130                 // default to 0 if we have trouble getting the start address
131
fStartAddress = BigInteger.valueOf(0);
132             }
133             
134             if (fStartAddress == null)
135                 fStartAddress = BigInteger.valueOf(0);
136         }
137         return fStartAddress;
138     }
139     
140     /**
141      * @return end address of the memory block
142      */

143     public BigInteger JavaDoc getEndAddress()
144     {
145         if (fEndAddress == null)
146         {
147             IMemoryBlock memoryBlock = fRendering.getMemoryBlock();
148             if(memoryBlock instanceof IMemoryBlockExtension)
149             {
150                 BigInteger JavaDoc endAddress;
151                 try {
152                     endAddress = ((IMemoryBlockExtension)memoryBlock).getMemoryBlockEndAddress();
153                     if (endAddress != null)
154                         fEndAddress = endAddress;
155                 } catch (DebugException e) {
156                     fEndAddress = null;
157                 }
158                 
159                 if (fEndAddress == null)
160                 {
161                     int addressSize;
162                     try {
163                         addressSize = ((IMemoryBlockExtension)memoryBlock).getAddressSize();
164                     } catch (DebugException e) {
165                         addressSize = 4;
166                     }
167                     
168                     endAddress = BigInteger.valueOf(2);
169                     endAddress = endAddress.pow(addressSize*8);
170                     endAddress = endAddress.subtract(BigInteger.valueOf(1));
171                     fEndAddress = endAddress;
172                 }
173             }
174             
175             if (fEndAddress == null)
176                 fEndAddress = BigInteger.valueOf(Integer.MAX_VALUE);
177         }
178         return fEndAddress;
179     }
180     
181     public int getNumLines()
182     {
183         return fNumLines;
184     }
185     
186     public void setNumLines(int numLines)
187     {
188         fNumLines = numLines;
189     }
190     
191     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
192         if (adapter == AbstractTableRendering.class)
193         {
194             if (fRendering instanceof AbstractTableRendering)
195                 return fRendering;
196         }
197         if (adapter == AbstractAsyncTableRendering.class)
198         {
199             if (fRendering instanceof AbstractAsyncTableRendering)
200                 return fRendering;
201         }
202         
203         return super.getAdapter(adapter);
204     }
205 }
206
Popular Tags