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.IJavaClassType; 16 import org.eclipse.jdt.debug.core.IJavaType; 17 import org.eclipse.jdt.debug.core.IJavaValue; 18 import org.eclipse.jdt.debug.core.IJavaVariable; 19 import org.eclipse.jdt.internal.debug.ui.DetailFormatter; 20 import org.eclipse.jdt.internal.debug.ui.DetailFormatterDialog; 21 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 22 import org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager; 23 import org.eclipse.jdt.internal.debug.ui.display.JavaInspectExpression; 24 import org.eclipse.jface.action.IAction; 25 import org.eclipse.jface.viewers.IStructuredSelection; 26 import org.eclipse.jface.window.Window; 27 28 public class EditDetailFormatterAction extends ObjectActionDelegate { 29 30 33 public void run(IAction action) { 34 IStructuredSelection selection = getCurrentSelection(); 35 if(selection != null && selection.size() == 1) { 36 Object element = selection.getFirstElement(); 37 IJavaType type; 38 try { 39 IJavaValue value; 40 if (element instanceof IJavaVariable) { 41 value = ((IJavaValue)((IJavaVariable) element).getValue()); 42 } else if (element instanceof JavaInspectExpression) { 43 value = ((IJavaValue)((JavaInspectExpression) element).getValue()); 44 } else { 45 return; 46 } 47 type= value.getJavaType(); 48 } catch (DebugException e) { 49 return; 50 } 51 JavaDetailFormattersManager fm = JavaDetailFormattersManager.getDefault(); 52 DetailFormatter formatter = fm.getAssociatedDetailFormatter(type); 53 if(formatter == null & type instanceof IJavaClassType) { 54 formatter = fm.getDetailFormatterFromInterface((IJavaClassType) type); 55 if(formatter == null) { 56 formatter = fm.getDetailFormatterFromSuperclass((IJavaClassType) type); 57 } 58 } 59 if (new DetailFormatterDialog(JDIDebugUIPlugin.getActivePage().getWorkbenchWindow().getShell(), formatter, null, false, true).open() == Window.OK) { 60 fm.setAssociatedDetailFormatter(formatter); 61 } 62 } 63 } 64 65 } 66 | Popular Tags |