1 11 12 package org.eclipse.debug.internal.ui.views.memory; 13 14 import org.eclipse.debug.core.model.IMemoryBlock; 15 import org.eclipse.debug.internal.ui.DebugUIPlugin; 16 import org.eclipse.debug.ui.IDebugUIConstants; 17 import org.eclipse.debug.ui.memory.IMemoryRendering; 18 import org.eclipse.jface.action.IAction; 19 import org.eclipse.jface.viewers.ISelection; 20 import org.eclipse.jface.viewers.IStructuredSelection; 21 import org.eclipse.jface.viewers.StructuredSelection; 22 import org.eclipse.ui.IViewActionDelegate; 23 import org.eclipse.ui.IViewPart; 24 import org.eclipse.ui.IWorkbenchPage; 25 import org.eclipse.ui.PartInitException; 26 27 30 public class NewMemoryViewAction implements IViewActionDelegate { 31 32 private MemoryView fView; 33 public void init(IViewPart view) { 34 if (view instanceof MemoryView) 35 fView = (MemoryView)view; 36 } 37 38 public void run(IAction action) { 39 40 String secondaryId = MemoryViewIdRegistry.getUniqueSecondaryId(IDebugUIConstants.ID_MEMORY_VIEW); 41 try { 42 IWorkbenchPage page = DebugUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(); 43 IViewPart newView = page.showView(IDebugUIConstants.ID_MEMORY_VIEW, secondaryId, IWorkbenchPage.VIEW_ACTIVATE); 44 45 setInitialSelection(newView); 47 setInitialViewSettings(newView); 48 49 } catch (PartInitException e) { 50 DebugUIPlugin.log(e); 52 } 53 } 54 55 private void setInitialSelection(IViewPart newView) { 56 ISelection selection = fView.getSite().getSelectionProvider().getSelection(); 57 if (selection instanceof IStructuredSelection) 58 { 59 IStructuredSelection strucSel = (IStructuredSelection)selection; 60 61 if (strucSel.isEmpty()) 63 return; 64 65 Object obj = strucSel.getFirstElement(); 66 67 if (obj == null) 68 return; 69 70 if (obj instanceof IMemoryRendering) 71 { 72 IMemoryBlock memBlock = ((IMemoryRendering)obj).getMemoryBlock(); 73 strucSel = new StructuredSelection(memBlock); 74 newView.getSite().getSelectionProvider().setSelection(strucSel); 75 } 76 else if (obj instanceof IMemoryBlock) 77 { 78 newView.getSite().getSelectionProvider().setSelection(strucSel); 79 } 80 } 81 } 82 83 private void setInitialViewSettings(IViewPart newView) { 84 if (fView != null && newView instanceof MemoryView) 85 { 86 MemoryView newMView = (MemoryView)newView; 87 IMemoryViewPane[] viewPanes = fView.getViewPanes(); 88 int orientation = fView.getViewPanesOrientation(); 89 for (int i=0; i<viewPanes.length; i++) 90 { 91 newMView.showViewPane(fView.isViewPaneVisible(viewPanes[i].getId()), viewPanes[i].getId()); 93 } 94 95 98 newMView.setViewPanesOrientation(orientation); 100 } 101 } 102 103 public void selectionChanged(IAction action, ISelection selection) { 104 105 } 106 107 } 108 | Popular Tags |