01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM - Initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.build;
11:
12: import java.util.*;
13: import org.eclipse.core.runtime.*;
14:
15: /**
16: * Utility class used to help with NLS'ing messages, creating progress monitors, etc.
17: */
18: public class Policy {
19:
20: /**
21: * Return a progress monitor for the given monitor. Ensures that the resulting
22: * monitor is not <code>null</code>.
23: *
24: * @param monitor the monitor to wrap, or <code>null</code>
25: * @return IProgressMonitor
26: */
27: public static IProgressMonitor monitorFor(IProgressMonitor monitor) {
28: if (monitor == null)
29: return new NullProgressMonitor();
30: return monitor;
31: }
32:
33: /**
34: * Create a sub progress monitor with the given units of work, for the given monitor.
35: *
36: * @param monitor the parent monitor, or <code>null</code>
37: * @param ticks the number of units of work
38: * @return IProgressMonitor
39: */
40: public static IProgressMonitor subMonitorFor(
41: IProgressMonitor monitor, int ticks) {
42: if (monitor == null)
43: return new NullProgressMonitor();
44: if (monitor instanceof NullProgressMonitor)
45: return monitor;
46: return new SubProgressMonitor(monitor, ticks);
47: }
48:
49: /**
50: * Create a sub progress monitor with the given number of units of work and in the
51: * given style, for the specified parent monitor.
52: *
53: * @param monitor the parent monitor, or <code>null</code>
54: * @param ticks the number of units of work
55: * @param style the style of the sub progress monitor
56: * @return IProgressMonitor
57: */
58: public static IProgressMonitor subMonitorFor(
59: IProgressMonitor monitor, int ticks, int style) {
60: if (monitor == null)
61: return new NullProgressMonitor();
62: if (monitor instanceof NullProgressMonitor)
63: return monitor;
64: return new SubProgressMonitor(monitor, ticks, style);
65: }
66:
67: /**
68: * Print a debug message to the console. If the given boolean is
69: * <code>true</code> then pre-pend the message with the current date.
70: */
71: public static void debug(boolean includeDate, String message) {
72: if (includeDate)
73: message = new Date(System.currentTimeMillis()).toString()
74: + " - " + message; //$NON-NLS-1$
75: System.out.println(message);
76: }
77: }
|