1 11 package org.eclipse.update.internal.scheduler; 12 13 import java.lang.reflect.*; 14 import java.util.MissingResourceException ; 15 import java.util.ResourceBundle ; 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 28 public class UpdateSchedulerPlugin extends AbstractUIPlugin{ 29 public static final String P_ENABLED = "enabled"; public static final String P_SCHEDULE = "schedule"; public static final String VALUE_ON_STARTUP = "on-startup"; public static final String VALUE_ON_SCHEDULE = "on-schedule"; public static final String P_DOWNLOAD = "download"; 36 private static UpdateSchedulerPlugin plugin; 38 private ResourceBundle resourceBundle; 40 41 private static SchedulerStartup scheduler; 43 44 47 public UpdateSchedulerPlugin() { 48 plugin = this; 49 } 50 51 52 public ResourceBundle getResourceBundle() { 53 if (resourceBundle == null) 54 try { 55 resourceBundle = ResourceBundle.getBundle("org.eclipse.update.internal.scheduler.UpdateSchedulerResources"); } catch (MissingResourceException x) { 57 resourceBundle = null; 58 } 59 return resourceBundle; 60 } 61 62 65 public static UpdateSchedulerPlugin getDefault() { 66 return plugin; 67 } 68 69 public static String getPluginId() { 70 return getDefault().getBundle().getSymbolicName(); 71 } 72 73 public static void logException(Throwable e) { 74 logException(e, true); 75 } 76 77 public static void logException(Throwable 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 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 Bundle bundle = Platform.getBundle("org.eclipse.update.scheduler"); 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 141 public void start(BundleContext context) throws Exception { 142 super.start(context); 143 } 144 145 public static SchedulerStartup getScheduler() { 146 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 |