KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > scheduler > UpdateSchedulerPlugin


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  *******************************************************************************/

11 package org.eclipse.update.internal.scheduler;
12
13 import java.lang.reflect.*;
14 import java.util.MissingResourceException JavaDoc;
15 import java.util.ResourceBundle JavaDoc;
16
17 import org.eclipse.core.runtime.*;
18 import org.eclipse.jface.dialogs.*;
19 import org.eclipse.swt.widgets.*;
20 import org.eclipse.ui.*;
21 import org.eclipse.ui.plugin.*;
22 import org.osgi.framework.*;
23
24 /**
25  * This plug-in is loaded on startup to fork a job that
26  * searches for new plug-ins.
27  */

28 public class UpdateSchedulerPlugin extends AbstractUIPlugin{
29     // Preferences
30
public static final String JavaDoc P_ENABLED = "enabled"; //$NON-NLS-1$
31
public static final String JavaDoc P_SCHEDULE = "schedule"; //$NON-NLS-1$
32
public static final String JavaDoc VALUE_ON_STARTUP = "on-startup"; //$NON-NLS-1$
33
public static final String JavaDoc VALUE_ON_SCHEDULE = "on-schedule"; //$NON-NLS-1$
34
public static final String JavaDoc P_DOWNLOAD = "download"; // value is true or false, default is false //$NON-NLS-1$
35

36     //The shared instance.
37
private static UpdateSchedulerPlugin plugin;
38     //Resource bundle.
39
private ResourceBundle JavaDoc resourceBundle;
40     
41     // singleton
42
private static SchedulerStartup scheduler;
43
44     /**
45      * The constructor.
46      */

47     public UpdateSchedulerPlugin() {
48         plugin = this;
49     }
50
51
52     public ResourceBundle JavaDoc getResourceBundle() {
53         if (resourceBundle == null)
54             try {
55                 resourceBundle = ResourceBundle.getBundle("org.eclipse.update.internal.scheduler.UpdateSchedulerResources"); //$NON-NLS-1$
56
} catch (MissingResourceException JavaDoc x) {
57                 resourceBundle = null;
58             }
59         return resourceBundle;
60     }
61
62     /**
63      * Returns the shared instance.
64      */

65     public static UpdateSchedulerPlugin getDefault() {
66         return plugin;
67     }
68
69     public static String JavaDoc getPluginId() {
70         return getDefault().getBundle().getSymbolicName();
71     }
72
73     public static void logException(Throwable JavaDoc e) {
74         logException(e, true);
75     }
76
77     public static void logException(Throwable JavaDoc e, boolean showErrorDialog) {
78         if (e instanceof InvocationTargetException) {
79             e = ((InvocationTargetException) e).getTargetException();
80         }
81
82         IStatus status = null;
83         if (e instanceof CoreException) {
84             status = ((CoreException) e).getStatus();
85         } else {
86             String JavaDoc message = e.getMessage();
87             if (message == null)
88                 message = e.toString();
89             status =
90                 new Status(
91                     IStatus.ERROR,
92                     getPluginId(),
93                     IStatus.OK,
94                     message,
95                     e);
96         }
97         log(status, showErrorDialog);
98     }
99
100     public static void log(IStatus status, boolean showErrorDialog) {
101         if (status.getSeverity() != IStatus.INFO) {
102             if (showErrorDialog)
103                 ErrorDialog.openError(
104                     getActiveWorkbenchShell(),
105                     null,
106                     null,
107                     status);
108 // Should log on the update plugin's log
109
// Platform.getPlugin("org.eclipse.core.runtime").getLog().log(status); //$NON-NLS-1$
110
Bundle JavaDoc bundle = Platform.getBundle("org.eclipse.update.scheduler"); //$NON-NLS-1$
111
Platform.getLog(bundle).log(status);
112         } else {
113             MessageDialog.openInformation(
114                 getActiveWorkbenchShell(),
115                 null,
116                 status.getMessage());
117         }
118     }
119
120     public static IWorkbenchPage getActivePage() {
121         UpdateSchedulerPlugin plugin = getDefault();
122         IWorkbenchWindow window =
123             plugin.getWorkbench().getActiveWorkbenchWindow();
124         if (window != null)
125             return window.getActivePage();
126         return null;
127     }
128
129     public static Shell getActiveWorkbenchShell() {
130         IWorkbenchWindow window = getActiveWorkbenchWindow();
131         return window != null ? window.getShell() : null;
132     }
133
134     public static IWorkbenchWindow getActiveWorkbenchWindow() {
135         return getDefault().getWorkbench().getActiveWorkbenchWindow();
136     }
137
138     /* (non-Javadoc)
139      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
140      */

141     public void start(BundleContext context) throws Exception JavaDoc {
142         super.start(context);
143     }
144     
145     public static SchedulerStartup getScheduler() {
146         // If the scheduler was disabled, it does not get initialized
147
if (scheduler == null)
148             scheduler = new SchedulerStartup();
149         return scheduler;
150     }
151     
152     static void setScheduler(SchedulerStartup scheduler) {
153         UpdateSchedulerPlugin.scheduler = scheduler;
154     }
155 }
156
Popular Tags