1 11 package org.eclipse.debug.internal.ui.views.memory.renderings; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IProgressMonitor; 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.core.runtime.Status; 17 import org.eclipse.core.runtime.jobs.Job; 18 import org.eclipse.debug.core.DebugException; 19 import org.eclipse.debug.core.model.IDebugElement; 20 import org.eclipse.debug.core.model.IDebugTarget; 21 import org.eclipse.debug.core.model.IMemoryBlock; 22 import org.eclipse.debug.core.model.IMemoryBlockRetrieval; 23 import org.eclipse.debug.internal.ui.DebugUIMessages; 24 import org.eclipse.debug.internal.ui.DebugUIPlugin; 25 import org.eclipse.debug.internal.ui.views.memory.MemoryViewUtil; 26 import org.eclipse.debug.ui.DebugUITools; 27 import org.eclipse.debug.ui.memory.AbstractMemoryRendering; 28 import org.eclipse.debug.ui.memory.IMemoryRendering; 29 import org.eclipse.debug.ui.memory.IMemoryRenderingBindingsListener; 30 import org.eclipse.debug.ui.memory.IMemoryRenderingContainer; 31 import org.eclipse.debug.ui.memory.IMemoryRenderingType; 32 import org.eclipse.jface.util.PropertyChangeEvent; 33 import org.eclipse.jface.viewers.DoubleClickEvent; 34 import org.eclipse.jface.viewers.IBasicPropertyConstants; 35 import org.eclipse.jface.viewers.IDoubleClickListener; 36 import org.eclipse.jface.viewers.ILabelProvider; 37 import org.eclipse.jface.viewers.ILabelProviderListener; 38 import org.eclipse.jface.viewers.ISelection; 39 import org.eclipse.jface.viewers.IStructuredContentProvider; 40 import org.eclipse.jface.viewers.IStructuredSelection; 41 import org.eclipse.jface.viewers.ListViewer; 42 import org.eclipse.jface.viewers.Viewer; 43 import org.eclipse.swt.SWT; 44 import org.eclipse.swt.events.SelectionEvent; 45 import org.eclipse.swt.events.SelectionListener; 46 import org.eclipse.swt.graphics.Image; 47 import org.eclipse.swt.layout.GridData; 48 import org.eclipse.swt.layout.GridLayout; 49 import org.eclipse.swt.widgets.Button; 50 import org.eclipse.swt.widgets.Composite; 51 import org.eclipse.swt.widgets.Control; 52 import org.eclipse.swt.widgets.Label; 53 import org.eclipse.ui.progress.WorkbenchJob; 54 55 59 public class CreateRendering extends AbstractMemoryRendering implements IMemoryRenderingBindingsListener { 60 61 private ListViewer fViewer; 62 private Label fMemoryBlockLabel; 63 private IMemoryRenderingContainer fContainer; 64 private Composite fCanvas; 65 private String fLabel; 66 67 public CreateRendering(IMemoryRenderingContainer container) 68 { 69 super("org.eclipse.debug.internal.ui.views.createrendering"); fContainer = container; 71 } 72 73 class MemoryRenderingLabelProvider implements ILabelProvider 74 { 75 76 79 public Image getImage(Object element) { 80 return null; 81 } 82 83 86 public String getText(Object element) { 87 if (element instanceof IMemoryRenderingType) 88 { 89 String label = ((IMemoryRenderingType)element).getLabel(); 90 return label; 91 } 92 return element.toString(); 93 } 94 95 98 public void addListener(ILabelProviderListener listener) { 99 } 100 101 104 public void dispose() { 105 } 106 107 110 public boolean isLabelProperty(Object element, String property) { 111 return false; 112 } 113 114 117 public void removeListener(ILabelProviderListener listener) { 118 } 119 120 } 121 122 class MemoryRenderingContentProvider implements IStructuredContentProvider 123 { 124 125 128 public Object [] getElements(Object inputElement) { 129 IMemoryRenderingType[] renderings = DebugUITools.getMemoryRenderingManager().getRenderingTypes((IMemoryBlock)inputElement); 130 return renderings; 131 } 132 133 136 public void dispose() { 137 138 } 139 140 143 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 144 } 145 146 } 147 148 151 public Control createControl(Composite parent) { 152 fCanvas = new Composite(parent, SWT.NONE); 153 GridLayout compositeLayout = new GridLayout(); 154 compositeLayout.numColumns = 2; 155 compositeLayout.makeColumnsEqualWidth = false; 156 fCanvas.setLayout(compositeLayout); 157 158 GridData comositeSpec= new GridData(); 159 comositeSpec.grabExcessVerticalSpace= true; 160 comositeSpec.grabExcessHorizontalSpace= true; 161 comositeSpec.horizontalAlignment= GridData.FILL; 162 comositeSpec.verticalAlignment= GridData.CENTER; 163 fCanvas.setLayoutData(comositeSpec); 164 165 fMemoryBlockLabel = new Label(fCanvas, SWT.BORDER); 166 167 String memoryBlockLabel = " "; memoryBlockLabel = getLabel(); 169 170 fMemoryBlockLabel.setText(" " + DebugUIMessages.CreateRenderingTab_Memory_monitor + memoryBlockLabel + " "); GridData textLayout = new GridData(); 172 textLayout.verticalAlignment=GridData.CENTER; 173 textLayout.horizontalAlignment=GridData.BEGINNING; 174 fMemoryBlockLabel.setLayoutData(textLayout); 175 176 Label renderingLabel = new Label(fCanvas, SWT.NONE); 177 renderingLabel.setText(DebugUIMessages.CreateRenderingTab_Select_renderings_to_create); 178 GridData renderingLayout = new GridData(); 179 renderingLayout.horizontalAlignment = GridData.BEGINNING; 180 renderingLayout.verticalAlignment = GridData.CENTER; 181 renderingLayout.horizontalSpan = 2; 182 renderingLabel.setLayoutData(renderingLayout); 183 184 fViewer = new ListViewer(fCanvas); 185 fViewer.setContentProvider(new MemoryRenderingContentProvider()); 186 fViewer.setLabelProvider(new MemoryRenderingLabelProvider()); 187 fViewer.setInput(getMemoryBlock()); 188 189 if (fViewer.getElementAt(0) != null) 190 { 191 fViewer.getList().select(0); 192 } 193 194 GridData listLayout = new GridData(GridData.FILL_BOTH); 195 listLayout.horizontalSpan = 1; 196 fViewer.getControl().setLayoutData(listLayout); 197 198 fViewer.addDoubleClickListener(new IDoubleClickListener (){ 199 200 public void doubleClick(DoubleClickEvent event) { 201 addRenderings(); 202 }}); 203 204 Button addButton = new Button(fCanvas, SWT.NONE); 205 addButton.setText(DebugUIMessages.CreateRenderingTab_Add_renderings); 206 GridData buttonLayout = new GridData(); 207 buttonLayout.horizontalAlignment = GridData.BEGINNING; 208 buttonLayout.verticalAlignment = GridData.BEGINNING; 209 addButton.setLayoutData(buttonLayout); 210 211 addButton.addSelectionListener(new SelectionListener() { 212 213 public void widgetSelected(SelectionEvent e) { 214 addRenderings(); 215 } 216 217 public void widgetDefaultSelected(SelectionEvent e) { 218 addRenderings(); 219 }}); 220 221 DebugUITools.getMemoryRenderingManager().addListener(this); 222 223 return fCanvas; 224 } 225 226 private void addRenderings() 227 { 228 ISelection selection = fViewer.getSelection(); 229 Object [] renderings = null; 230 231 if (selection instanceof IStructuredSelection) 232 { 233 IStructuredSelection strucSelection = (IStructuredSelection)selection; 234 235 renderings = strucSelection.toArray(); 236 } 237 238 if (renderings == null) 239 { 240 Status stat = new Status( 241 IStatus.ERROR,DebugUIPlugin.getUniqueIdentifier(), 242 DebugException.INTERNAL_ERROR, DebugUIMessages.CreateRenderingTab_0, null); 243 DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), DebugUIMessages.CreateRenderingTab_1, DebugUIMessages.CreateRenderingTab_2, stat); return; 245 } 246 247 IDebugTarget debugTarget = ((IDebugElement)getMemoryBlock()).getDebugTarget(); 249 IMemoryBlockRetrieval standardMemRetrieval = (IMemoryBlockRetrieval)((IDebugElement)getMemoryBlock()).getAdapter(IMemoryBlockRetrieval.class); 250 251 if (standardMemRetrieval == null) 252 { 253 standardMemRetrieval = debugTarget; 254 } 255 256 if (standardMemRetrieval == null) 257 return; 258 259 260 IMemoryRenderingContainer container = fContainer; 262 for (int i=0; i<renderings.length; i++) 264 { 265 if (renderings[i] instanceof IMemoryRenderingType) 266 { 267 try { 268 IMemoryRendering rendering = ((IMemoryRenderingType)renderings[i]).createRendering(); 269 if (rendering != null) 270 { 271 rendering.init(container, getMemoryBlock()); 272 container.addMemoryRendering(rendering); 273 } 274 } catch (CoreException e) { 275 276 MemoryViewUtil.openError(DebugUIMessages.CreateRendering_0, DebugUIMessages.CreateRendering_1, e); } 278 } 279 } 280 } 281 282 285 public void dispose() { 286 fViewer = null; 287 fCanvas = null; 288 fContainer = null; 289 fMemoryBlockLabel = null; 290 DebugUITools.getMemoryRenderingManager().removeListener(this); 291 } 292 293 296 public Control getControl() { 297 return fCanvas; 298 } 299 public void memoryRenderingBindingsChanged() { 300 if (fViewer != null) 301 fViewer.refresh(); 302 } 303 304 public String getLabel() { 305 if (fLabel == null) 306 { 307 fLabel = DebugUIMessages.CreateRendering_2; 308 updateRenderingLabel(); 309 } 310 311 return fLabel; 312 } 313 314 protected void updateRenderingLabel() 315 { 316 Job job = new Job("Update Rendering Label"){ 318 protected IStatus run(IProgressMonitor monitor) { 319 fLabel = CreateRendering.super.getLabel(); 320 firePropertyChangedEvent(new PropertyChangeEvent(CreateRendering.this, IBasicPropertyConstants.P_TEXT, null, fLabel)); 321 322 WorkbenchJob wbJob = new WorkbenchJob("Create Rendering Update Label"){ 324 public IStatus runInUIThread(IProgressMonitor wbMonitor) { 325 if (fMemoryBlockLabel != null) 326 { 327 fMemoryBlockLabel.setText(" " + DebugUIMessages.CreateRenderingTab_Memory_monitor + fLabel + " "); fMemoryBlockLabel.getParent().layout(); 329 } 330 return Status.OK_STATUS; 331 }}; 332 wbJob.setSystem(true); 333 wbJob.schedule(); 334 return Status.OK_STATUS; 335 }}; 336 job.setSystem(true); 337 job.schedule(); 338 } 339 } 340 | Popular Tags |