comparison dwtx/jface/internal/text/link/contentassist/ContentAssistMessages.d @ 129:eb30df5ca28b

Added JFace Text sources
author Frank Benoit <benoit@tionex.de>
date Sat, 23 Aug 2008 19:10:48 +0200
parents
children c4fb132a086c
comparison
equal deleted inserted replaced
128:8df1d4193877 129:eb30df5ca28b
1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13
14 module dwtx.jface.internal.text.link.contentassist.ContentAssistMessages;
15
16 import dwt.dwthelper.utils;
17
18 import java.util.MissingResourceException;
19 import java.util.ResourceBundle;
20
21 import com.ibm.icu.text.MessageFormat;
22
23
24 /**
25 * Helper class to get NLSed messages.
26 *
27 * @since 3.0
28 */
29 class ContentAssistMessages {
30
31 private static final String RESOURCE_BUNDLE= ContentAssistMessages.class.getName();
32
33 private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
34
35 private ContentAssistMessages() {
36 }
37
38 /**
39 * Gets a string from the resource bundle.
40 *
41 * @param key the string used to get the bundle value, must not be null
42 * @return the string from the resource bundle
43 */
44 public static String getString(String key) {
45 try {
46 return fgResourceBundle.getString(key);
47 } catch (MissingResourceException e) {
48 return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
49 }
50 }
51
52 /**
53 * Gets a string from the resource bundle and formats it with the given arguments.
54 *
55 * @param key the string used to get the bundle value, must not be null
56 * @param args the arguments used to format the string
57 * @return the formatted string
58 */
59 public static String getFormattedString(String key, Object[] args) {
60 String format= null;
61 try {
62 format= fgResourceBundle.getString(key);
63 } catch (MissingResourceException e) {
64 return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
65 }
66 return MessageFormat.format(format, args);
67 }
68
69 /**
70 * Gets a string from the resource bundle and formats it with the given argument.
71 *
72 * @param key the string used to get the bundle value, must not be null
73 * @param arg the argument used to format the string
74 * @return the formatted string
75 */
76 public static String getFormattedString(String key, Object arg) {
77 String format= null;
78 try {
79 format= fgResourceBundle.getString(key);
80 } catch (MissingResourceException e) {
81 return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
82 }
83 if (arg is null)
84 arg= ""; //$NON-NLS-1$
85 return MessageFormat.format(format, new Object[] { arg });
86 }
87 }