1 11 package org.eclipse.ui.texteditor; 12 13 14 15 import java.util.MissingResourceException ; 16 import java.util.ResourceBundle ; 17 18 import org.eclipse.jface.action.Action; 19 import org.eclipse.jface.resource.ImageDescriptor; 20 21 import org.eclipse.ui.PlatformUI; 22 23 24 33 public abstract class ResourceAction extends Action { 34 35 46 protected static String getString(ResourceBundle bundle, String key, String defaultValue) { 47 48 String value= defaultValue; 49 try { 50 value= bundle.getString(key); 51 } catch (MissingResourceException x) { 52 } 53 54 return value; 55 } 56 57 84 public ResourceAction(ResourceBundle bundle, String prefix, int style) { 85 super(null, style); 86 initialize(bundle, prefix); 87 } 88 89 107 public ResourceAction(ResourceBundle bundle, String prefix) { 108 super(); 109 initialize(bundle, prefix); 110 } 111 112 117 public final void setHelpContextId(String contextId) { 118 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, contextId); 119 } 120 121 128 protected void initialize(ResourceBundle bundle, String prefix) { 129 String labelKey= "label"; String tooltipKey= "tooltip"; String imageKey= "image"; String descriptionKey= "description"; 134 if (prefix != null && prefix.length() > 0) { 135 labelKey= prefix + labelKey; 136 tooltipKey= prefix + tooltipKey; 137 imageKey= prefix + imageKey; 138 descriptionKey= prefix + descriptionKey; 139 } 140 141 setText(getString(bundle, labelKey, labelKey)); 142 setToolTipText(getString(bundle, tooltipKey, null)); 143 setDescription(getString(bundle, descriptionKey, null)); 144 145 String file= getString(bundle, imageKey, null); 146 if (file != null && file.trim().length() > 0) 147 setImageDescriptor(ImageDescriptor.createFromFile(getClass(), file)); 148 } 149 } 150 | Popular Tags |