1 11 package org.eclipse.jdt.internal.debug.ui.actions; 12 13 14 import org.eclipse.debug.core.DebugException; 15 import org.eclipse.jdt.debug.core.IJavaType; 16 import org.eclipse.jdt.debug.core.IJavaValue; 17 import org.eclipse.jdt.debug.core.IJavaVariable; 18 import org.eclipse.jdt.internal.debug.ui.DetailFormatter; 19 import org.eclipse.jdt.internal.debug.ui.DetailFormatterDialog; 20 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 21 import org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager; 22 import org.eclipse.jdt.internal.debug.ui.display.JavaInspectExpression; 23 import org.eclipse.jface.action.IAction; 24 import org.eclipse.jface.viewers.IStructuredSelection; 25 import org.eclipse.jface.window.Window; 26 27 public class NewDetailFormatterAction extends ObjectActionDelegate { 28 29 32 public void run(IAction action) { 33 IStructuredSelection selection= getCurrentSelection(); 34 if (selection == null || selection.size() != 1) { 35 return; 36 } 37 Object element= selection.getFirstElement(); 38 String typeName; 39 try { 40 IJavaType type; 41 if (element instanceof IJavaVariable) { 42 type = ((IJavaValue)((IJavaVariable) element).getValue()).getJavaType(); 43 } else if (element instanceof JavaInspectExpression) { 44 type = ((IJavaValue)((JavaInspectExpression) element).getValue()).getJavaType(); 45 } else { 46 return; 47 } 48 if (type == null) { 49 return; 50 } 51 typeName= type.getName(); 52 } catch (DebugException e) { 53 return; 54 } 55 JavaDetailFormattersManager detailFormattersManager= JavaDetailFormattersManager.getDefault(); 56 DetailFormatter detailFormatter= new DetailFormatter(typeName, "", true); if (new DetailFormatterDialog(JDIDebugUIPlugin.getActivePage().getWorkbenchWindow().getShell(), detailFormatter, null, true, false).open() == Window.OK) { 58 detailFormattersManager.setAssociatedDetailFormatter(detailFormatter); 59 } 60 } 61 62 } 63 | Popular Tags |