| package org.eclipse.equinox.p2.examples.rcp.prestartupdate; |
| |
| import java.lang.reflect.InvocationTargetException; |
| |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.OperationCanceledException; |
| import org.eclipse.core.runtime.Status; |
| import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; |
| import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; |
| import org.eclipse.equinox.p2.core.IProvisioningAgent; |
| import org.eclipse.equinox.p2.operations.ProvisioningSession; |
| import org.eclipse.equinox.p2.operations.UpdateOperation; |
| import org.eclipse.jface.dialogs.MessageDialog; |
| import org.eclipse.jface.dialogs.ProgressMonitorDialog; |
| import org.eclipse.jface.operation.IRunnableWithProgress; |
| import org.eclipse.ui.PlatformUI; |
| import org.eclipse.ui.application.IWorkbenchWindowConfigurer; |
| import org.eclipse.ui.application.WorkbenchAdvisor; |
| import org.eclipse.ui.application.WorkbenchWindowAdvisor; |
| |
| /** |
| * This workbench advisor creates the window advisor, and specifies the |
| * perspective id for the initial window. |
| */ |
| public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor { |
| |
| public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor( |
| IWorkbenchWindowConfigurer configurer) { |
| return new ApplicationWorkbenchWindowAdvisor(configurer); |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.ui.application.WorkbenchAdvisor#preStartup() |
| */ |
| public void preStartup() { |
| final IProvisioningAgent agent = (IProvisioningAgent) ServiceHelper |
| .getService(Activator.bundleContext, |
| IProvisioningAgent.SERVICE_NAME); |
| if (agent == null) { |
| LogHelper.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "No provisioning agent found. This application is not set up for updates.")); |
| } |
| |
| // XXX check for updates before starting up. |
| // If an update is performed, restart. Otherwise log |
| // the status. |
| IRunnableWithProgress runnable = new IRunnableWithProgress() { |
| public void run(IProgressMonitor monitor) |
| throws InvocationTargetException, InterruptedException { |
| IStatus updateStatus = P2Util.checkForUpdates(agent, monitor); |
| if (updateStatus.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) { |
| PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { |
| public void run() { |
| MessageDialog.openInformation(null, "Updates", "No updates were found"); |
| } |
| }); |
| } |
| if (updateStatus.getSeverity() != IStatus.ERROR) |
| PlatformUI.getWorkbench().restart(); |
| else |
| LogHelper.log(updateStatus); |
| } |
| }; |
| try { |
| new ProgressMonitorDialog(null).run(true, true, runnable); |
| } catch (InvocationTargetException e) { |
| e.printStackTrace(); |
| } catch (InterruptedException e) { |
| } |
| } |
| |
| public String getInitialWindowPerspectiveId() { |
| return Perspective.ID; |
| } |
| |
| } |