1 11 package org.eclipse.jdt.internal.debug.ui.actions; 12 13 import org.eclipse.debug.core.DebugEvent; 14 import org.eclipse.debug.core.DebugException; 15 import org.eclipse.debug.core.DebugPlugin; 16 import org.eclipse.debug.core.model.IStackFrame; 17 import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupManager; 18 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 19 import org.eclipse.jdt.debug.core.IJavaReferenceType; 20 import org.eclipse.jdt.debug.core.IJavaStackFrame; 21 import org.eclipse.jface.action.IAction; 22 import org.eclipse.jface.action.IMenuCreator; 23 import org.eclipse.jface.viewers.ISelection; 24 import org.eclipse.jface.viewers.IStructuredSelection; 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.events.MenuAdapter; 27 import org.eclipse.swt.events.MenuEvent; 28 import org.eclipse.swt.events.SelectionAdapter; 29 import org.eclipse.swt.events.SelectionEvent; 30 import org.eclipse.swt.widgets.Control; 31 import org.eclipse.swt.widgets.Menu; 32 import org.eclipse.swt.widgets.MenuItem; 33 import org.eclipse.ui.IObjectActionDelegate; 34 import org.eclipse.ui.IWorkbenchPart; 35 36 39 public class ShowStratumAction implements IObjectActionDelegate, IMenuCreator { 40 41 private IStructuredSelection fSelection; 42 private IWorkbenchPart fPart; 43 44 47 public void setActivePart(IAction action, IWorkbenchPart targetPart) { 48 fPart = targetPart; 49 } 50 51 54 public void run(IAction action) { 55 } 56 57 60 public void selectionChanged(IAction action, ISelection selection) { 61 if (selection instanceof IStructuredSelection) { 62 fSelection = (IStructuredSelection) selection; 63 action.setMenuCreator(this); 64 } else { 65 action.setMenuCreator(null); 66 } 67 } 68 69 72 public Menu getMenu(Control parent) { 73 return null; 74 } 75 76 79 public Menu getMenu(Menu parent) { 80 Menu menu = new Menu(parent); 82 menu.addMenuListener(new MenuAdapter() { 83 public void menuShown(MenuEvent e) { 84 Menu m = (Menu)e.widget; 85 MenuItem[] items = m.getItems(); 86 for (int i=0; i < items.length; i++) { 87 items[i].dispose(); 88 } 89 fillMenu(m); 90 } 91 }); 92 return menu; 93 } 94 95 100 private void fillMenu(Menu m) { 101 IStackFrame frame = (IStackFrame) fSelection.getFirstElement(); 102 final IJavaStackFrame javaStackFrame = (IJavaStackFrame) frame.getAdapter(IJavaStackFrame.class); 103 try { 104 IJavaReferenceType declaringType = javaStackFrame.getReferenceType(); 105 final IJavaDebugTarget target = (IJavaDebugTarget) javaStackFrame.getDebugTarget(); 106 String currentStratum = target.getDefaultStratum(); 107 String [] strata = declaringType.getAvailableStrata(); 108 for (int i = 0; i < strata.length; i++) { 109 final String stratum = strata[i]; 110 MenuItem item = createMenuItem(m, stratum, javaStackFrame, target); 111 item.setSelection(stratum.equals(currentStratum)); 112 } 113 MenuItem item = createMenuItem(m, null, javaStackFrame, target); 114 item.setSelection(currentStratum == null); 115 } catch (DebugException e) { 116 } 117 } 118 119 private MenuItem createMenuItem(Menu m, final String stratum, final IJavaStackFrame frame, final IJavaDebugTarget target) { 120 MenuItem item = new MenuItem(m, SWT.CHECK); 121 if (stratum == null) { 122 item.setText(ActionMessages.ShowStratumAction_0); 123 } else { 124 item.setText(stratum); 125 } 126 item.addSelectionListener(new SelectionAdapter() { 127 public void widgetSelected(SelectionEvent e) { 128 if (((MenuItem)e.getSource()).getSelection()) { 129 target.setDefaultStratum(stratum); 130 } else { 131 target.setDefaultStratum(null); 132 } 133 DebugEvent event = new DebugEvent(frame, DebugEvent.CHANGE, DebugEvent.CONTENT); 134 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[]{event}); 135 SourceLookupManager.getDefault().displaySource(frame, fPart.getSite().getPage(), true); 137 } 138 }); 139 return item; 140 } 141 142 145 public void dispose() { 146 } 147 148 149 } 150 | Popular Tags |