KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > runtime > internal > adaptor > DefaultStartupMonitor


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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  * Andrew Niefer - IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.runtime.internal.adaptor;
12
13 import java.lang.reflect.Method JavaDoc;
14 import org.eclipse.core.runtime.adaptor.EclipseStarter;
15 import org.eclipse.core.runtime.internal.stats.StatsManager;
16 import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
17 import org.eclipse.osgi.service.runnable.StartupMonitor;
18
19 public class DefaultStartupMonitor implements StartupMonitor {
20
21     private Method JavaDoc updateMethod = null;
22     private Runnable JavaDoc splashHandler = null;
23
24     /**
25      * Create a new startup monitor using the given splash handler. The splash handle must
26      * have an updateSplash method.
27      *
28      * @param splashHandler
29      * @throws IllegalStateException
30      */

31     public DefaultStartupMonitor(Runnable JavaDoc splashHandler) throws IllegalStateException JavaDoc {
32         this.splashHandler = splashHandler;
33
34         try {
35             updateMethod = splashHandler.getClass().getMethod("updateSplash", null); //$NON-NLS-1$
36
} catch (SecurityException JavaDoc e) {
37             throw new IllegalStateException JavaDoc(e.getMessage());
38         } catch (NoSuchMethodException JavaDoc e) {
39             //TODO maybe we could do something else in the update method in this case, like print something to the console?
40
throw new IllegalStateException JavaDoc(e.getMessage());
41         }
42     }
43
44     /* (non-Javadoc)
45      * @see org.eclipse.core.runtime.adaptor.StartupMonitor#update()
46      */

47     public void update() {
48         if (updateMethod != null) {
49             try {
50                 updateMethod.invoke(splashHandler, null);
51             } catch (Throwable JavaDoc e) {
52                 // ignore, this is best effort
53
}
54         } else {
55             //TODO maybe we could print something interesting to the console?
56
}
57     }
58
59     public void applicationRunning() {
60         if (EclipseStarter.debug) {
61             String JavaDoc timeString = FrameworkProperties.getProperty("eclipse.startTime"); //$NON-NLS-1$
62
long time = timeString == null ? 0L : Long.parseLong(timeString);
63             System.out.println("Application Started: " + (System.currentTimeMillis() - time)); //$NON-NLS-1$
64
}
65         StatsManager.doneBooting();
66         splashHandler.run();
67     }
68 }
69
Popular Tags