001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.location.internal;
018:
019: import java.lang.reflect.Field;
020:
021: import net.refractions.udig.location.LocationUIPlugin;
022:
023: import org.eclipse.jface.action.IAction;
024: import org.eclipse.jface.resource.ImageDescriptor;
025: import org.eclipse.osgi.util.NLS;
026:
027: public class Messages extends NLS {
028: private static final String BUNDLE_NAME = "net.refractions.udig.location.internal.messages"; //$NON-NLS-1$
029: public static String action_show_image;
030: public static String action_show_tooltip;
031: public static String action_show_label;
032: public static String LocationView_no_results;
033: public static String LocationView_searching;
034: public static String LocationView_keywords;
035: public static String LocationView_notFound;
036: public static String LocationView_name;
037: public static String LocationView_title;
038: public static String LocationView_wait;
039: public static String LocationView_searching_for;
040: public static String LocationView_instructions;
041: public static String LocationView_description;
042: public static String LocationView_bboxTooltip;
043: public static String LocationView_bbox;
044: public static String LocationView_server;
045: public static String LocationView_prompt;
046: public static String LocationView_default;
047: static {
048: // initialize resource bundle
049: NLS.initializeMessages(BUNDLE_NAME, Messages.class);
050: }
051:
052: private Messages() {
053: }
054:
055: /**
056: * Initialize the given Action from a ResourceBundle.
057: * <p>
058: * Makes use of the following keys:
059: * <ul>
060: * <li>prefix.label
061: * <li>prefix.tooltip
062: * <li>prefix.image
063: * <li>prefix.description
064: * </p>
065: * <p>
066: * Note: The use of a single image value is mapped to images for both the enabled and distabled
067: * state of the IAction. the Local toolbar (elcl16/ and dlcl16/) is assumed if a path has not
068: * been provided.
069: *
070: * <pre><code>
071: * add_co.gif (prefix.image)
072: * enabled: elcl16/add_co.gif
073: * disabled: dlcl/remove_co.gif
074: * tool16/discovery_wiz.16 (prefix.image)
075: * enabled: etool16/discovery_wiz.16
076: * disabled: etool16/discovery_wiz.16
077: * </code></pre>
078: *
079: * </p>
080: *
081: * @param a action
082: * @param id used for binding (id.label, id.tooltip, ...)
083: */
084: public static void initAction(IAction a, String id) {
085: String labelKey = "_label"; //$NON-NLS-1$
086: String tooltipKey = "_tooltip"; //$NON-NLS-1$
087: String imageKey = "_image"; //$NON-NLS-1$
088: String descriptionKey = "_description"; //$NON-NLS-1$
089: if (id != null && id.length() > 0) {
090: labelKey = id + labelKey;
091: tooltipKey = id + tooltipKey;
092: imageKey = id + imageKey;
093: descriptionKey = id + descriptionKey;
094: }
095: String s = bind(labelKey);
096: if (s != null)
097: a.setText(s);
098: s = bind(tooltipKey);
099: if (s != null)
100: a.setToolTipText(s);
101: s = bind(descriptionKey);
102: if (s != null)
103: a.setDescription(s);
104: String relPath = bind(imageKey);
105: if (relPath != null && !relPath.equals(imageKey)
106: && relPath.trim().length() > 0) {
107: String dPath;
108: String ePath;
109: if (relPath.indexOf("/") >= 0) { //$NON-NLS-1$
110: String path = relPath.substring(1);
111: dPath = 'd' + path;
112: ePath = 'e' + path;
113: } else {
114: dPath = "dlcl16/" + relPath; //$NON-NLS-1$
115: ePath = "elcl16/" + relPath; //$NON-NLS-1$
116: }
117: ImageDescriptor image;
118:
119: image = Images.getDescriptor(ePath);
120: if (id != null) {
121: LocationUIPlugin.trace(id
122: + ": '" + ePath + "' found " + id); //$NON-NLS-1$ //$NON-NLS-2$
123: a.setImageDescriptor(image);
124: }
125: image = Images.getDescriptor(dPath);
126: if (id != null) {
127: LocationUIPlugin.trace(id
128: + ": '" + dPath + "' found " + id); //$NON-NLS-1$ //$NON-NLS-2$
129: a.setDisabledImageDescriptor(image);
130: }
131: }
132: }
133:
134: private static String bind(String fieldName) {
135: Field field;
136: try {
137: field = Messages.class.getDeclaredField(fieldName);
138: return (String) field.get(null);
139: } catch (Exception e) {
140: LocationUIPlugin.log("Error loading key " + fieldName, e); //$NON-NLS-1$
141: }
142: return null;
143: }
144: }
|