1 11 package org.eclipse.core.internal.plugins; 12 13 import java.util.*; 14 import org.eclipse.core.runtime.*; 15 import org.eclipse.osgi.util.NLS; 16 17 public class Policy { 18 private static String bundleName = "org.eclipse.core.internal.plugins.messages"; private static ResourceBundle bundle; 20 21 24 private static ResourceBundle getResourceBundle() { 25 ResourceBundle tmpBundle = bundle; 27 if (tmpBundle != null) 28 return tmpBundle; 29 return bundle = ResourceBundle.getBundle(bundleName, Locale.getDefault()); 32 } 33 34 37 public static String bind(String id) { 38 return bind(id, (String []) null); 39 } 40 41 45 public static String bind(String id, String binding) { 46 return bind(id, new String [] {binding}); 47 } 48 49 53 public static String bind(String id, String binding1, String binding2) { 54 return bind(id, new String [] {binding1, binding2}); 55 } 56 57 61 public static String bind(String id, String [] bindings) { 62 if (id == null) 63 return "No message available"; String message = null; 65 try { 66 message = getResourceBundle().getString(id); 67 } catch (MissingResourceException e) { 68 return "Missing message: " + id + " in: " + bundleName; } 72 if (bindings == null) 73 return message; 74 return NLS.bind(message, bindings); 75 } 76 77 public static IProgressMonitor monitorFor(IProgressMonitor monitor) { 78 if (monitor == null) 79 return new NullProgressMonitor(); 80 return monitor; 81 } 82 83 public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) { 84 if (monitor == null) 85 return new NullProgressMonitor(); 86 if (monitor instanceof NullProgressMonitor) 87 return monitor; 88 return new SubProgressMonitor(monitor, ticks); 89 } 90 91 public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks, int style) { 92 if (monitor == null) 93 return new NullProgressMonitor(); 94 if (monitor instanceof NullProgressMonitor) 95 return monitor; 96 return new SubProgressMonitor(monitor, ticks, style); 97 } 98 99 103 public static void debug(boolean includeDate, String message) { 104 if (includeDate) 105 message = new Date(System.currentTimeMillis()) + " - " + message; System.out.println(message); 107 } 108 } 109 | Popular Tags |