1 11 package org.eclipse.jdt.internal.debug.ui.actions; 12 13 14 import org.eclipse.debug.ui.IDebugModelPresentation; 15 import org.eclipse.debug.ui.IDebugView; 16 import org.eclipse.jdt.debug.core.JDIDebugModel; 17 import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants; 18 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 19 import org.eclipse.jdt.internal.debug.ui.JDIModelPresentation; 20 import org.eclipse.jface.action.IAction; 21 import org.eclipse.jface.dialogs.Dialog; 22 import org.eclipse.jface.preference.IPreferenceStore; 23 import org.eclipse.jface.viewers.ISelection; 24 import org.eclipse.jface.viewers.Viewer; 25 import org.eclipse.jface.window.Window; 26 import org.eclipse.swt.custom.BusyIndicator; 27 import org.eclipse.swt.widgets.Event; 28 import org.eclipse.ui.IActionDelegate2; 29 import org.eclipse.ui.IViewActionDelegate; 30 import org.eclipse.ui.IViewPart; 31 import org.eclipse.ui.IViewSite; 32 33 36 public class PrimitiveOptionsAction implements IViewActionDelegate, IActionDelegate2 { 37 38 private static String [][] fgPreferenceInfo= new String [][] { 39 {IJDIPreferencesConstants.PREF_SHOW_HEX, JDIModelPresentation.SHOW_HEX_VALUES}, 40 {IJDIPreferencesConstants.PREF_SHOW_CHAR, JDIModelPresentation.SHOW_CHAR_VALUES}, 41 {IJDIPreferencesConstants.PREF_SHOW_UNSIGNED, JDIModelPresentation.SHOW_UNSIGNED_VALUES}, 42 }; 43 44 protected IViewPart fView; 45 46 49 public void init(IViewPart view) { 50 fView = view; 51 applyPreferences(); 52 } 53 54 protected void applyPreferences() { 55 IDebugView view = (IDebugView)getView().getAdapter(IDebugView.class); 56 if (view != null) { 57 IDebugModelPresentation presentation = view.getPresentation(JDIDebugModel.getPluginIdentifier()); 58 if (presentation != null) { 59 for (int i = 0; i < fgPreferenceInfo.length; i++) { 60 applyPreference(fgPreferenceInfo[i][0], fgPreferenceInfo[i][1], presentation); 61 } 62 } 63 } 64 } 65 66 protected void applyPreference(String preference, String attribute, IDebugModelPresentation presentation) { 67 boolean on = getBooleanPreferenceValue(getView().getSite().getId(), preference); 68 presentation.setAttribute(attribute, (on ? Boolean.TRUE : Boolean.FALSE)); 69 } 70 71 74 protected Dialog getDialog() { 75 IViewSite viewSite = getView().getViewSite(); 76 return new PrimitiveOptionsDialog(viewSite.getShell(), viewSite.getId()); 77 } 78 79 protected IViewPart getView() { 80 return fView; 81 } 82 83 86 public void runWithEvent(IAction action, Event event) { 87 run(action); 88 } 89 90 93 public void run(IAction action) { 94 int res = getDialog().open(); 96 if (res == Window.OK) { 97 final Viewer viewer = getViewer(); 98 BusyIndicator.showWhile(viewer.getControl().getDisplay(), new Runnable () { 99 public void run() { 100 applyPreferences(); 101 viewer.refresh(); 102 JDIDebugUIPlugin.getDefault().savePluginPreferences(); 103 } 104 }); 105 } 106 } 107 108 protected Viewer getViewer() { 109 IDebugView view = (IDebugView)getView().getAdapter(IDebugView.class); 110 if (view != null) { 111 return view.getViewer(); 112 } 113 return null; 114 } 115 116 123 public static boolean getBooleanPreferenceValue(String id, String preference) { 124 String compositeKey = id + "." + preference; IPreferenceStore store = JDIDebugUIPlugin.getDefault().getPreferenceStore(); 126 boolean value = false; 127 if (store.contains(compositeKey)) { 128 value = store.getBoolean(compositeKey); 129 } else { 130 value = store.getBoolean(preference); 131 } 132 return value; 133 } 134 135 138 public void init(IAction action) { 139 } 140 141 144 public void dispose() { 145 } 146 147 150 public void selectionChanged(IAction action, ISelection selection) { 151 } 152 } 153 | Popular Tags |