1 11 package org.eclipse.debug.internal.ui.views.variables; 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.IExpression; 17 import org.eclipse.debug.core.model.IValue; 18 import org.eclipse.debug.core.model.IVariable; 19 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 20 import org.eclipse.jface.action.Action; 21 import org.eclipse.jface.action.ActionContributionItem; 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.widgets.Control; 26 import org.eclipse.swt.widgets.Menu; 27 import org.eclipse.ui.PlatformUI; 28 29 33 public class AvailableLogicalStructuresAction extends Action implements IMenuCreator { 34 35 private VariablesView fView; 36 private Menu fMenu; 37 private IValue fValue; 38 private ILogicalStructureType[] fTypes; 39 40 public AvailableLogicalStructuresAction(VariablesView view) { 41 setView(view); 42 setToolTipText(VariablesViewMessages.AvailableLogicalStructuresAction_0); 43 setText(VariablesViewMessages.AvailableLogicalStructuresAction_1); 44 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.VARIABLES_SELECT_LOGICAL_STRUCTURE); 45 setEnabled(false); 46 setMenuCreator(this); 47 init(); 48 } 49 50 53 public void run() { 54 } 55 56 protected VariablesView getView() { 57 return fView; 58 } 59 60 protected void setView(VariablesView view) { 61 fView = view; 62 } 63 64 67 public void dispose() { 68 if (fMenu != null) { 69 fMenu.dispose(); 70 } 71 fView= null; 72 fValue = null; 73 fTypes = null; 74 } 75 76 79 public Menu getMenu(Control parent) { 80 return null; 81 } 82 83 protected void addActionToMenu(Menu parent, Action action) { 84 ActionContributionItem item= new ActionContributionItem(action); 85 item.fill(parent, -1); 86 } 87 88 91 public Menu getMenu(Menu parent) { 92 if (fMenu != null) { 93 fMenu.dispose(); 94 } 95 96 fMenu= new Menu(parent); 97 ILogicalStructureType[] types = getTypes(); 98 ILogicalStructureType enabledType = DebugPlugin.getDefaultStructureType(types); 99 if (types != null && types.length > 0) { 100 for (int i = 0; i < types.length; i++) { 101 ILogicalStructureType type= types[i]; 102 Action action = new SelectLogicalStructureAction(getView(), type, getValue(), types); 103 action.setChecked(enabledType == type); 104 StringBuffer label= new StringBuffer (); 105 if (i < 9) { 107 label.append('&'); 108 label.append(i + 1); 109 label.append(' '); 110 } 111 label.append(action.getText()); 112 action.setText(label.toString()); 113 addActionToMenu(fMenu, action); 114 } 115 } 116 return fMenu; 117 } 118 119 122 public void init() { 123 setValue(null); 124 setTypes(null); 125 if (getView().isShowLogicalStructure()) { 126 ISelection s = getView().getViewer().getSelection(); 127 if (s instanceof IStructuredSelection) { 128 IStructuredSelection selection = (IStructuredSelection) s; 129 if (selection.size() == 1) { 130 Object obj = selection.getFirstElement(); 131 IValue value = null; 132 if (obj instanceof IVariable) { 133 IVariable var = (IVariable) obj; 134 try { 135 value = var.getValue(); 136 } catch (DebugException e) { 137 } 138 } else if (obj instanceof IExpression) { 139 IExpression expression = (IExpression)obj; 140 value = expression.getValue(); 141 } 142 if (value != null) { 143 ILogicalStructureType[] types = DebugPlugin.getLogicalStructureTypes(value); 144 if (types.length > 0) { 145 setTypes(types); 146 setValue(value); 147 setEnabled(true); 148 return; 149 } 150 } 151 } 152 } 153 } 154 setEnabled(false); 155 } 156 157 protected ILogicalStructureType[] getTypes() { 158 return fTypes; 159 } 160 161 private void setTypes(ILogicalStructureType[] types) { 162 fTypes = types; 163 } 164 165 protected IValue getValue() { 166 return fValue; 167 } 168 169 private void setValue(IValue value) { 170 fValue = value; 171 } 172 } 173 | Popular Tags |