KickJava   Java API By Example, From Geeks To Geeks.

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


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.views.memory.renderings;
13
14 import org.eclipse.debug.core.model.MemoryByte;
15 import org.eclipse.debug.internal.ui.DebugUIMessages;
16 import org.eclipse.debug.ui.IDebugUIConstants;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.Label;
23 import org.eclipse.ui.IWorkbenchPropertyPage;
24 import org.eclipse.ui.PlatformUI;
25 import org.eclipse.ui.dialogs.PropertyPage;
26
27 public class TableRenderingPropertiesPage extends PropertyPage implements
28         IWorkbenchPropertyPage {
29
30     public TableRenderingPropertiesPage() {
31         super();
32     }
33
34     protected Control createContents(Composite parent) {
35         PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IDebugUIConstants.PLUGIN_ID + ".TableRenderingPropertiesPage_context"); //$NON-NLS-1$
36
noDefaultAndApplyButton();
37         Composite composite = new Composite(parent, SWT.NONE);
38         if (getElement() instanceof AbstractBaseTableRendering)
39         {
40             AbstractBaseTableRendering rendering = (AbstractBaseTableRendering)getElement();
41             GridLayout compositeLayout = new GridLayout();
42             compositeLayout.numColumns = 2;
43             compositeLayout.makeColumnsEqualWidth = false;
44             composite.setLayout(compositeLayout);
45             
46             GridData comositeSpec= new GridData();
47             comositeSpec.grabExcessVerticalSpace= true;
48             comositeSpec.grabExcessHorizontalSpace= true;
49             comositeSpec.horizontalAlignment= GridData.FILL;
50             comositeSpec.verticalAlignment= GridData.CENTER;
51             composite.setLayoutData(comositeSpec);
52             
53             String JavaDoc label = rendering.getLabel();
54             if (label.startsWith("&&")) //$NON-NLS-1$
55
label = label.replaceFirst("&&", "&"); //$NON-NLS-1$//$NON-NLS-2$
56
addProperty(composite, DebugUIMessages.TableRenderingPropertiesPage_1, label);
57                         
58             MemoryByte[] bytes = rendering.getSelectedAsBytes();
59             if (bytes.length > 0) {
60                 
61                 if (rendering.getSelectedAddress() != null)
62                 {
63                     String JavaDoc selectedAddress = "0x" + rendering.getSelectedAddress().toString(16).toUpperCase(); //$NON-NLS-1$
64
StringBuffer JavaDoc content = new StringBuffer JavaDoc(selectedAddress);
65                     addProperty(composite, DebugUIMessages.TableRenderingPropertiesPage_2, content.toString());
66                 }
67                 
68                 String JavaDoc length = String.valueOf(rendering.getAddressableUnitPerColumn()) + " " + DebugUIMessages.TableRenderingPropertiesPage_3; //$NON-NLS-1$
69
addProperty(composite, DebugUIMessages.TableRenderingPropertiesPage_4, length);
70                 
71                 String JavaDoc selectedContent = rendering.getSelectedAsString();
72                 addProperty(composite, DebugUIMessages.TableRenderingPropertiesPage_5, selectedContent);
73                 
74                 int addressableSize = rendering.getAddressableSize() * 8;
75                 addProperty(composite, DebugUIMessages.TableRenderingPropertiesPage_6, String.valueOf(addressableSize) + " " + DebugUIMessages.TableRenderingPropertiesPage_8); //$NON-NLS-1$
76

77                 boolean endianessKnown = bytes[0].isEndianessKnown();
78                 int endianess = RenderingsUtil.ENDIANESS_UNKNOWN;
79                 if (endianessKnown)
80                     endianess = bytes[0].isBigEndian()?RenderingsUtil.BIG_ENDIAN:RenderingsUtil.LITTLE_ENDIAN;
81                 
82                 boolean allBytesKnown = bytes[0].isHistoryKnown();
83                 boolean allBytesUnchanged = bytes[0].isChanged()?false:true;
84                 
85                 boolean allBytesReadable = bytes[0].isReadable();
86                 boolean allBytesWritable = bytes[0].isWritable();
87                 
88                 if (bytes.length > 1)
89                 {
90                     for (int i=1; i<bytes.length; i++)
91                     {
92                         if (endianessKnown)
93                         {
94                             int byteEndianess = bytes[i].isBigEndian()?RenderingsUtil.BIG_ENDIAN:RenderingsUtil.LITTLE_ENDIAN;
95                             if (endianess != RenderingsUtil.ENDIANESS_UNKNOWN && endianess != byteEndianess)
96                                 endianess = RenderingsUtil.ENDIANESS_UNKNOWN;
97                         }
98                         
99                         if (!bytes[i].isHistoryKnown())
100                             allBytesKnown = false;
101                         if (bytes[i].isChanged())
102                             allBytesUnchanged = false;
103                         
104                         if (!bytes[i].isReadable())
105                             allBytesReadable = false;
106                         
107                         if (!bytes[i].isWritable())
108                             allBytesWritable = false;
109                     }
110                 }
111                 
112                 boolean isChanged = allBytesKnown && !allBytesUnchanged;
113                 if (allBytesKnown)
114                     addProperty(composite, DebugUIMessages.TableRenderingPropertiesPage_9, String.valueOf(isChanged));
115                 else
116                     addProperty(composite, DebugUIMessages.TableRenderingPropertiesPage_10, DebugUIMessages.TableRenderingPropertiesPage_11);
117                 
118                 String JavaDoc dataEndian = DebugUIMessages.TableRenderingPropertiesPage_12;
119                 if (endianessKnown)
120                 {
121                     if (endianess == RenderingsUtil.BIG_ENDIAN)
122                         dataEndian = DebugUIMessages.TableRenderingPropertiesPage_13;
123                     else if (endianess == RenderingsUtil.LITTLE_ENDIAN)
124                         dataEndian = DebugUIMessages.TableRenderingPropertiesPage_14;
125                     else
126                         dataEndian = DebugUIMessages.TableRenderingPropertiesPage_15;
127                 }
128                 addProperty(composite, DebugUIMessages.TableRenderingPropertiesPage_16, dataEndian);
129                 
130                 
131                 if (rendering instanceof AbstractIntegerRendering)
132                 {
133                     
134                     AbstractIntegerRendering intRendering = (AbstractIntegerRendering)rendering;
135                     String JavaDoc displayEndian = DebugUIMessages.TableRenderingPropertiesPage_17;
136                     endianess = intRendering.getDisplayEndianess();
137                     
138                     if (endianess == RenderingsUtil.BIG_ENDIAN)
139                         displayEndian = DebugUIMessages.TableRenderingPropertiesPage_18;
140                     else if (endianess == RenderingsUtil.LITTLE_ENDIAN)
141                         displayEndian = DebugUIMessages.TableRenderingPropertiesPage_19;
142                     else
143                     {
144                         if (endianessKnown)
145                             displayEndian = dataEndian;
146                         else
147                             displayEndian = DebugUIMessages.TableRenderingPropertiesPage_20;
148                     }
149                     addProperty(composite, DebugUIMessages.TableRenderingPropertiesPage_21, displayEndian);
150                 }
151                 addProperty(composite, DebugUIMessages.TableRenderingPropertiesPage_22, String.valueOf(allBytesReadable));
152                 addProperty(composite, DebugUIMessages.TableRenderingPropertiesPage_23, String.valueOf(allBytesWritable));
153             }
154             else
155             {
156                 String JavaDoc selectedAddress = "0x" + rendering.getSelectedAddress().toString(16).toUpperCase(); //$NON-NLS-1$
157
addProperty(composite, DebugUIMessages.TableRenderingPropertiesPage_25, selectedAddress);
158                 
159                 int unitsPerLine = rendering.getAddressableUnitPerLine();
160                 addProperty(composite, DebugUIMessages.TableRenderingPropertiesPage_26, String.valueOf(unitsPerLine));
161             }
162         }
163         
164         return composite;
165     }
166     
167     private void addProperty(Composite composite, String JavaDoc labelStr, String JavaDoc contentStr)
168     {
169         Label label = new Label(composite, SWT.NONE);
170         label.setText(labelStr);
171         Label text = new Label(composite, SWT.WRAP );
172         text.setText(contentStr);
173     }
174
175 }
176
Popular Tags