| /********************************************************************** |
| * Copyright (c) 2000,2002 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Common Public License v0.5 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/cpl-v05.html |
| * |
| * Contributors: |
| * IBM - Initial API and implementation |
| **********************************************************************/ |
| package org.eclipse.ant.internal.ui; |
| |
| import java.text.MessageFormat; |
| import java.util.*; |
| |
| import org.eclipse.core.runtime.*; |
| |
| public class Policy { |
| private static ResourceBundle bundle = ResourceBundle.getBundle(AntUIPlugin.PROPERTIES_MESSAGES, Locale.getDefault()); |
| |
| /** |
| * Lookup the message with the given ID in this catalog |
| */ |
| public static String bind(String id) { |
| return bind(id, (String[])null); |
| } |
| /** |
| * Lookup the message with the given ID in this catalog and bind its |
| * substitution locations with the given string. |
| */ |
| public static String bind(String id, String binding) { |
| return bind(id, new String[] {binding}); |
| } |
| /** |
| * Lookup the message with the given ID in this catalog and bind its |
| * substitution locations with the given strings. |
| */ |
| public static String bind(String id, String binding1, String binding2) { |
| return bind(id, new String[] {binding1, binding2}); |
| } |
| |
| /** |
| * Lookup the message with the given ID in this catalog and bind its |
| * substitution locations with the given string values. |
| */ |
| public static String bind(String id, String[] bindings) { |
| if (id == null) |
| return "No message available";//$NON-NLS-1$ |
| String message = null; |
| try { |
| message = bundle.getString(id); |
| } catch (MissingResourceException e) { |
| // If we got an exception looking for the message, fail gracefully by just returning |
| // the id we were looking for. In most cases this is semi-informative so is not too bad. |
| return "Missing message: " + id + "in: " + AntUIPlugin.PROPERTIES_MESSAGES;//$NON-NLS-1$ |
| } |
| if (bindings == null) |
| return message; |
| return MessageFormat.format(message, bindings); |
| } |
| public static IProgressMonitor monitorFor(IProgressMonitor monitor) { |
| if (monitor == null) |
| return new NullProgressMonitor(); |
| return monitor; |
| } |
| public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) { |
| if (monitor == null) |
| return new NullProgressMonitor(); |
| if (monitor instanceof NullProgressMonitor) |
| return monitor; |
| return new SubProgressMonitor(monitor, ticks); |
| } |
| public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks, int style) { |
| if (monitor == null) |
| return new NullProgressMonitor(); |
| if (monitor instanceof NullProgressMonitor) |
| return monitor; |
| return new SubProgressMonitor(monitor, ticks, style); |
| } |
| } |