1 11 package org.eclipse.ui.internal.actions; 12 13 import org.eclipse.jface.action.Action; 14 import org.eclipse.swt.custom.BusyIndicator; 15 import org.eclipse.ui.IWorkbenchPreferenceConstants; 16 import org.eclipse.ui.IWorkbenchWindow; 17 import org.eclipse.ui.PlatformUI; 18 import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; 19 import org.eclipse.ui.internal.IWorkbenchHelpContextIds; 20 import org.eclipse.ui.internal.WorkbenchMessages; 21 import org.eclipse.ui.internal.util.PrefUtil; 22 23 28 public class DynamicHelpAction extends Action implements IWorkbenchAction { 29 33 private IWorkbenchWindow workbenchWindow; 34 35 38 public DynamicHelpAction() { 39 this(PlatformUI.getWorkbench().getActiveWorkbenchWindow()); 40 } 41 42 48 public DynamicHelpAction(IWorkbenchWindow window) { 49 if (window == null) { 50 throw new IllegalArgumentException (); 51 } 52 this.workbenchWindow = window; 53 setActionDefinitionId("org.eclipse.ui.help.dynamicHelp"); 55 String overrideText = PrefUtil.getAPIPreferenceStore().getString( 57 IWorkbenchPreferenceConstants.DYNAMIC_HELP_ACTION_TEXT); 58 if ("".equals(overrideText)) { setText(appendAccelerator(WorkbenchMessages.DynamicHelpAction_text)); 60 setToolTipText(WorkbenchMessages.DynamicHelpAction_toolTip); 61 } else { 62 setText(appendAccelerator(overrideText)); 63 setToolTipText(Action.removeMnemonics(overrideText)); 64 } 65 window.getWorkbench().getHelpSystem().setHelp(this, 66 IWorkbenchHelpContextIds.DYNAMIC_HELP_ACTION); 67 } 68 69 private String appendAccelerator(String text) { 70 76 return text; 79 } 80 81 84 public void run() { 85 if (workbenchWindow == null) { 86 return; 88 } 89 BusyIndicator.showWhile(null, new Runnable () { 91 public void run() { 92 workbenchWindow.getWorkbench().getHelpSystem() 93 .displayDynamicHelp(); 94 } 95 }); 96 } 97 98 101 public void dispose() { 102 workbenchWindow = null; 103 } 104 105 } 106 | Popular Tags |