1 11 package org.eclipse.jdt.internal.debug.ui.actions; 12 13 import org.eclipse.debug.core.DebugException; 14 import org.eclipse.debug.core.DebugPlugin; 15 import org.eclipse.debug.core.ILogicalStructureType; 16 import org.eclipse.debug.core.model.IValue; 17 import org.eclipse.jdt.debug.core.IJavaVariable; 18 import org.eclipse.jdt.internal.debug.core.logicalstructures.JavaLogicalStructure; 19 import org.eclipse.jdt.internal.debug.core.logicalstructures.JavaLogicalStructures; 20 import org.eclipse.jdt.internal.debug.core.logicalstructures.JavaStructureErrorValue; 21 import org.eclipse.jdt.internal.debug.ui.EditLogicalStructureDialog; 22 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 23 import org.eclipse.jface.action.IAction; 24 import org.eclipse.jface.viewers.ISelection; 25 import org.eclipse.jface.viewers.IStructuredSelection; 26 import org.eclipse.jface.window.Window; 27 import org.eclipse.swt.widgets.Shell; 28 import org.eclipse.ui.IObjectActionDelegate; 29 import org.eclipse.ui.IWorkbenchPart; 30 import org.eclipse.ui.actions.ActionDelegate; 31 32 36 public class EditVariableLogicalStructureAction extends ActionDelegate implements IObjectActionDelegate { 37 38 42 private JavaLogicalStructure fStructure= null; 43 44 47 public void setActivePart(IAction action, IWorkbenchPart targetPart) { 48 } 49 50 54 public void run(IAction action) { 55 if (fStructure == null) { 56 return; 57 } 58 Shell shell= JDIDebugUIPlugin.getActiveWorkbenchShell(); 59 if (shell != null) { 60 EditLogicalStructureDialog dialog= new EditLogicalStructureDialog(shell, fStructure); 61 if (dialog.open() == Window.OK) { 62 JavaLogicalStructures.saveUserDefinedJavaLogicalStructures(); 63 } 64 } 65 } 66 67 70 public void selectionChanged(IAction action, ISelection selection) { 71 fStructure= null; 72 Object element = ((IStructuredSelection) selection).getFirstElement(); 73 if (element instanceof IJavaVariable) { 74 try { 75 IValue value= ((IJavaVariable) element).getValue(); 76 if (value instanceof JavaStructureErrorValue) { 77 value= ((JavaStructureErrorValue) value).getParentValue(); 78 } 79 ILogicalStructureType type= getLogicalStructure(value); 80 if (type instanceof JavaLogicalStructure) { 81 JavaLogicalStructure javaStructure= (JavaLogicalStructure) type; 82 if (!javaStructure.isContributed()) { 83 fStructure= javaStructure; 84 } 85 } 86 } catch (DebugException e) { 87 JDIDebugUIPlugin.log(e.getStatus()); 88 } 89 } 90 action.setEnabled(fStructure != null); 91 } 92 93 100 public static ILogicalStructureType getLogicalStructure(IValue value) { 101 ILogicalStructureType type = null; 103 ILogicalStructureType[] types = DebugPlugin.getLogicalStructureTypes(value); 104 if (types.length > 0) { 105 type= DebugPlugin.getDefaultStructureType(types); 106 } 107 return type; 108 } 109 } 110 | Popular Tags |