diff options
author | Susan Franklin | 2010-05-26 16:18:22 +0000 |
---|---|---|
committer | Susan Franklin | 2010-05-26 16:18:22 +0000 |
commit | 05cd92f15e1e9e2249a35adc5553caa51de8d74c (patch) | |
tree | bcf8e53651fe68c00f510949cde489686c05cab4 /examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2 | |
parent | 1c09231497945057ea7cbeb9122921727ff5f065 (diff) | |
download | rt.equinox.p2-05cd92f15e1e9e2249a35adc5553caa51de8d74c.tar.gz rt.equinox.p2-05cd92f15e1e9e2249a35adc5553caa51de8d74c.tar.xz rt.equinox.p2-05cd92f15e1e9e2249a35adc5553caa51de8d74c.zip |
Bug 282333 - [examples] prestartup example should provide a UI-safe progress monitor to P2Utilv20100604
Diffstat (limited to 'examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2')
2 files changed, 91 insertions, 65 deletions
diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchAdvisor.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchAdvisor.java index ee686a763..64ddfc625 100644 --- a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchAdvisor.java +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchAdvisor.java @@ -1,20 +1,5 @@ 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; @@ -35,41 +20,6 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor { * * @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; diff --git a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchWindowAdvisor.java b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchWindowAdvisor.java index 2bb795ccd..0896291f3 100644 --- a/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchWindowAdvisor.java +++ b/examples/org.eclipse.equinox.p2.examples.rcp.prestartupdate/src/org/eclipse/equinox/p2/examples/rcp/prestartupdate/ApplicationWorkbenchWindowAdvisor.java @@ -1,26 +1,102 @@ 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.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.UpdateOperation; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.graphics.Point; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.application.ActionBarAdvisor; import org.eclipse.ui.application.IActionBarConfigurer; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchWindowAdvisor; public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { + + private static final String JUSTUPDATED = "justUpdated"; + + public ApplicationWorkbenchWindowAdvisor( + IWorkbenchWindowConfigurer configurer) { + super(configurer); + } + + public ActionBarAdvisor createActionBarAdvisor( + IActionBarConfigurer configurer) { + return new ApplicationActionBarAdvisor(configurer); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#preWindowOpen() + */ + public void preWindowOpen() { + IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); + configurer.setInitialSize(new Point(600, 400)); + configurer.setShowCoolBar(true); + configurer.setShowStatusLine(false); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowOpen() + */ + public void postWindowOpen() { + 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 if we're restarting after updating, don't check again. + final IPreferenceStore prefStore = Activator.getDefault().getPreferenceStore(); + if (prefStore.getBoolean(JUSTUPDATED)) { + prefStore.setValue(JUSTUPDATED, false); + return; + } + + // 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"); + } + }); + } else if (updateStatus.getSeverity() != IStatus.ERROR) { + prefStore.setValue(JUSTUPDATED, true); + PlatformUI.getWorkbench().restart(); + } else { + LogHelper.log(updateStatus); + } + } + }; + try { + new ProgressMonitorDialog(null).run(true, true, runnable); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + } + + } - public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { - super(configurer); - } - - public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) { - return new ApplicationActionBarAdvisor(configurer); - } - - public void preWindowOpen() { - IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); - configurer.setInitialSize(new Point(600, 400)); - configurer.setShowCoolBar(true); - configurer.setShowStatusLine(false); - } - } |