1 11 package org.eclipse.debug.internal.ui.views.memory; 12 13 14 import java.util.Enumeration ; 15 import java.util.Hashtable ; 16 17 import org.eclipse.debug.core.IMemoryBlockListener; 18 import org.eclipse.debug.core.model.IMemoryBlock; 19 import org.eclipse.debug.core.model.IMemoryBlockRetrieval; 20 import org.eclipse.debug.internal.ui.DebugUIPlugin; 21 import org.eclipse.debug.ui.DebugUITools; 22 import org.eclipse.debug.ui.contexts.IDebugContextListener; 23 import org.eclipse.jface.action.IAction; 24 import org.eclipse.jface.viewers.ISelection; 25 import org.eclipse.jface.viewers.ISelectionChangedListener; 26 import org.eclipse.jface.viewers.ISelectionProvider; 27 import org.eclipse.jface.viewers.SelectionChangedEvent; 28 import org.eclipse.jface.viewers.StructuredSelection; 29 import org.eclipse.swt.SWT; 30 import org.eclipse.swt.custom.StackLayout; 31 import org.eclipse.swt.events.SelectionListener; 32 import org.eclipse.swt.layout.GridData; 33 import org.eclipse.swt.layout.GridLayout; 34 import org.eclipse.swt.widgets.Composite; 35 import org.eclipse.swt.widgets.Control; 36 import org.eclipse.swt.widgets.TabFolder; 37 import org.eclipse.swt.widgets.TabItem; 38 import org.eclipse.ui.ISelectionListener; 39 import org.eclipse.ui.IViewPart; 40 import org.eclipse.ui.IWorkbenchPart; 41 42 public abstract class AbstractMemoryViewPane implements IMemoryBlockListener, ISelectionListener, SelectionListener, IMemoryView, ISelectionChangedListener, IMemoryViewPane, IDebugContextListener{ 43 44 public static final String BEGINNING_POPUP = "popUpBegin"; protected static final StructuredSelection EMPTY = new StructuredSelection(); 46 47 protected Composite fViewPaneCanvas; 48 protected StackLayout fStackLayout; 49 protected ViewTabEnablementManager fViewTabEnablementManager; 50 protected TabFolder fEmptyTabFolder; 51 protected Hashtable fTabFolderForDebugView = new Hashtable (); 52 protected boolean fVisible; 53 protected Hashtable fRenderingInfoTable; 54 protected IMemoryBlockRetrieval fKey; protected ViewPaneSelectionProvider fSelectionProvider; 56 protected IViewPart fParent; 57 protected String fPaneId; 58 private Composite fCanvas; 59 protected String fLabel; 60 61 public AbstractMemoryViewPane(IViewPart parent) 62 { 63 super(); 64 fParent = parent; 65 fSelectionProvider = new ViewPaneSelectionProvider(); 66 } 67 68 73 public Control createViewPane(Composite parent, String paneId, String label) 74 { 75 fPaneId = paneId; 76 fLabel = label; 77 fCanvas = new Composite(parent, SWT.NONE); 78 GridLayout layout = new GridLayout(); 79 layout.makeColumnsEqualWidth = false; 80 layout.numColumns = 1; 81 layout.marginHeight = 0; 82 layout.marginWidth = 0; 83 GridData data = new GridData(); 84 data.grabExcessHorizontalSpace = true; 85 data.grabExcessVerticalSpace = true; 86 data.verticalAlignment = SWT.BEGINNING; 87 data.horizontalAlignment = SWT.BEGINNING; 88 fCanvas.setLayout(layout); 89 fCanvas.setLayoutData(data); 90 91 Composite memoryViewAreaParent = fCanvas; 93 Composite subCanvas = new Composite(memoryViewAreaParent, SWT.NONE); 94 fViewPaneCanvas = subCanvas; 95 fStackLayout = new StackLayout(); 96 GridData memoryAreaData = new GridData(); 97 memoryAreaData.grabExcessHorizontalSpace = true; 98 memoryAreaData.grabExcessVerticalSpace = true; 99 memoryAreaData.verticalAlignment = SWT.FILL; 100 memoryAreaData.horizontalAlignment = SWT.FILL; 101 fViewPaneCanvas.setLayout(fStackLayout); 102 fViewPaneCanvas.setLayoutData(memoryAreaData); 103 104 fViewTabEnablementManager = new ViewTabEnablementManager(); 105 106 fEmptyTabFolder = new TabFolder(fViewPaneCanvas, SWT.NULL); 107 setTabFolder(fEmptyTabFolder); 108 109 addListeners(); 110 111 Object context = DebugUITools.getDebugContext(); 112 if (context != null) 113 { 114 IMemoryBlockRetrieval retrieval = MemoryViewUtil.getMemoryBlockRetrieval(context); 115 if (retrieval != null) 116 createFolder(retrieval); 117 } 118 119 fVisible = true; 120 121 return fCanvas; 122 } 123 124 protected void addListeners() 125 { 126 MemoryViewUtil.getMemoryBlockManager().addListener(this); 127 fParent.getViewSite().getPage().addSelectionListener(this); 128 DebugUITools.getDebugContextManager().getContextService(fParent.getSite().getWorkbenchWindow()).addDebugContextListener(this); 129 } 130 131 protected void removeListeners() 132 { 133 MemoryViewUtil.getMemoryBlockManager().removeListener(this); 134 fParent.getViewSite().getPage().removeSelectionListener(this); 135 DebugUITools.getDebugContextManager().getContextService(fParent.getSite().getWorkbenchWindow()).removeDebugContextListener(this); 136 137 if (fStackLayout.topControl != null) 138 { 139 TabFolder old = (TabFolder)fStackLayout.topControl; 140 141 if (!old.isDisposed()) 142 { 143 old.removeSelectionListener(this); 144 old.removeSelectionListener(fViewTabEnablementManager); 145 } 146 } 147 } 148 149 protected void setTabFolder(TabFolder folder) 150 { 151 if (fStackLayout.topControl != null) 152 { 153 TabFolder old = (TabFolder)fStackLayout.topControl; 154 155 if (!old.isDisposed()) 156 { 157 old.removeSelectionListener(this); 158 old.removeSelectionListener(fViewTabEnablementManager); 159 } 160 } 161 162 fStackLayout.topControl = folder; 163 164 if (folder.getItemCount() > 0) 165 { 166 TabItem[] selectedItem = folder.getSelection(); 167 168 if (selectedItem.length > 0) 169 { 170 Object selected = getCurrentSelection(); 171 if (selected != null) 172 { 173 fSelectionProvider.setSelection(new StructuredSelection(selected)); 174 } 175 else 176 { 177 fSelectionProvider.setSelection(AbstractMemoryViewPane.EMPTY); 178 } 179 } 180 } 181 else 182 { 183 fSelectionProvider.setSelection(AbstractMemoryViewPane.EMPTY); 184 } 185 186 folder.addSelectionListener(this); 187 folder.addSelectionListener(fViewTabEnablementManager); 188 } 189 190 191 private void createFolder(IMemoryBlockRetrieval memRetrieval) 192 { 193 if (fTabFolderForDebugView.containsKey(memRetrieval)) { 195 if (fStackLayout.topControl != (TabFolder)fTabFolderForDebugView.get(memRetrieval)) { 196 setTabFolder((TabFolder)fTabFolderForDebugView.get(memRetrieval)); 197 fViewPaneCanvas.layout(); 198 } 199 } else { fTabFolderForDebugView.put(memRetrieval, new TabFolder(fViewPaneCanvas, SWT.NULL)); 201 setTabFolder((TabFolder)fTabFolderForDebugView.get(memRetrieval)); 202 fViewPaneCanvas.layout(); 203 } 204 } 205 206 public IMemoryViewTab getTopMemoryTab() { 207 208 if (fStackLayout.topControl instanceof TabFolder) 209 { 210 TabFolder folder = (TabFolder)fStackLayout.topControl; 211 if (!folder.isDisposed()) 212 { 213 int index = folder.getSelectionIndex(); 214 if (index >= 0) { 215 TabItem tab = folder.getItem(index); 216 return (IMemoryViewTab)tab.getData(); 217 } 218 } 219 } 220 return null; 221 } 222 223 protected void disposeTab(TabItem tabItem) 224 { 225 if (tabItem == null) 226 return; 227 228 if (!tabItem.isDisposed()) 231 { 232 tabItem.dispose(); 233 } 234 } 235 236 protected void emptyFolder() 237 { 238 setTabFolder(fEmptyTabFolder); 239 if (!fViewPaneCanvas.isDisposed()) { 240 fViewPaneCanvas.layout(); 241 } 242 } 243 244 public void addSelectionListener(ISelectionChangedListener listener) 245 { 246 if (fSelectionProvider == null) 247 fSelectionProvider = new ViewPaneSelectionProvider(); 248 249 fSelectionProvider.addSelectionChangedListener(listener); 250 } 251 252 public void removeSelctionListener(ISelectionChangedListener listener) 253 { 254 if (fSelectionProvider == null) 255 return; 256 257 fSelectionProvider.removeSelectionChangedListener(listener); 258 } 259 260 public ISelectionProvider getSelectionProvider() 261 { 262 return fSelectionProvider; 263 } 264 265 public void dispose() 266 { 267 removeListeners(); 268 269 fEmptyTabFolder.dispose(); 271 272 try { 274 275 if (fTabFolderForDebugView != null) { 276 Enumeration enumeration = fTabFolderForDebugView.elements(); 277 278 while (enumeration.hasMoreElements()) 279 { 280 TabFolder tabFolder = (TabFolder)enumeration.nextElement(); 281 282 if (tabFolder.isDisposed()) 283 continue; 284 285 TabItem[] tabs = tabFolder.getItems(); 287 288 for (int i=0; i<tabs.length; i++) 289 { 290 disposeTab(tabs[i]); 291 } 292 293 tabFolder.dispose(); 294 } 295 296 fTabFolderForDebugView.clear(); 298 fTabFolderForDebugView = null; 299 } 300 } catch (Exception e) { 301 302 DebugUIPlugin.logErrorMessage("Exception occurred when the Memory View is disposed."); } 304 } 305 306 public void setVisible(boolean visible) 307 { 308 fVisible = visible; 309 310 IMemoryViewTab currentTab = getTopMemoryTab(); 311 if (currentTab != null) 312 currentTab.setEnabled(visible); 313 } 314 315 public void selectionChanged(SelectionChangedEvent event) { 316 ISelection selection = event.getSelection(); 317 selectionChanged(fParent,selection); 318 319 fSelectionProvider.setSelection(selection); 320 } 321 322 325 public String getPaneId() 326 { 327 return fPaneId; 328 } 329 330 331 334 public Control getControl() { 335 return fCanvas; 336 } 337 338 public boolean isVisible() 339 { 340 return fVisible; 341 } 342 343 public String getLabel() 344 { 345 return fLabel; 346 } 347 348 351 abstract public void memoryBlocksAdded(IMemoryBlock[] memoryBlocks); 352 353 356 abstract public void memoryBlocksRemoved(final IMemoryBlock[] memoryBlocks); 357 358 361 abstract public void selectionChanged(IWorkbenchPart part, ISelection selection); 362 363 366 abstract public Object getCurrentSelection(); 367 368 372 abstract public void restoreViewPane(); 373 374 377 abstract public IAction[] getActions(); 378 379 } 380 | Popular Tags |