blob: 9fcab756334acdc564c17f38e4f3f09891d7f3fd [file] [log] [blame]
/******************************************************************************
* Copyright (c) David Orme and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* David Orme - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.app.skeleton;
import org.eclipse.e4.core.deeplink.DeepLinkManager;
import org.eclipse.e4.enterprise.installer.BundleUpdaterConfig;
import org.eclipse.e4.enterprise.installer.InstallError;
import org.eclipse.e4.enterprise.installer.ui.swt.BundleUpdaterHelper;
import org.eclipse.e4.enterprise.installer.ui.swt.BundleUpdaterHelper.UpdateStatus;
import org.eclipse.e4.ui.swtdialogs.Dialogs;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
/**
* This class controls all aspects of the application's life cycle. This
* example is intended to be deployed in the following configuration:
* <p> <ul>
* <li>With just RCP, the configuration plugin, and the installer plugin
* <li>This plugin uses the installer to download the rest:
* <ul>
* <li>The default perspective factory
* <li>Any other perspectives
* <li>Views, editors, actions, Commands, etc.
* <li>Any other dependencies
* </ul></ul>
* The installer then runs at the beginning of each execution and keeps the
* application up to date with the plugins that are deployed in the remote
* plugin repository.
*/
public class Application implements IApplication {
private Thread updateThread;
/* (non-Javadoc)
* @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
*/
public Object start(IApplicationContext context) throws Exception {
Display display = PlatformUI.createDisplay();
// Use this if your application needs to log into some sort of server infrastructure
if (!login()) {
return IApplication.EXIT_OK;
}
// If we are configured to use the installer, try to update...
if( isUpdateSiteConfigPropertySet() )
{
UpdateStatus status = updateBundles();
switch(status.result) {
case SUCCESS_RESTART_REQUIRED:
return IApplication.EXIT_RESTART;
case FAILURE_USER_CANCELLED:
return IApplication.EXIT_OK;
case FAILURE_INSTALL_ERROR:
Dialogs.errorDialogMessage("Install Error" + ": " + status.failureException.getMessage());
return IApplication.EXIT_OK;
}
}
// Include the following code and add org.eclipse.e4.core.deeplink
// as a dependency if you intend to support deep linking
DeepLinkManager deepLinkManager = new DeepLinkManager(true, Activator.getDefault().getLog());
deepLinkManager.startServer();
deepLinkManager.processCommandLineArguments(context);
try {
int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART)
return IApplication.EXIT_RESTART;
else
return IApplication.EXIT_OK;
} finally {
display.dispose();
}
}
/* (non-Javadoc)
* @see org.eclipse.equinox.app.IApplication#stop()
*/
public void stop() {
final IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench == null)
return;
final Display display = workbench.getDisplay();
display.syncExec(new Runnable() {
public void run() {
if (!display.isDisposed())
workbench.close();
}
});
if (updateThread != null) {
updateThread.interrupt();
}
}
/**
* A stub indicating where to put your own system login or single sign-on
* code if you have it.
*
* @return true if the user is successfully authenticated; false otherwise.
*/
private boolean login() {
// Insert your own login code here...
return true;
}
/**
* Run the installer and update our configuration to match what is stored
* on the remote server.
*
* @return true if the installer told us we need to restart; false otherwise.
* @throws InstallError If something bad happened.
*/
private UpdateStatus updateBundles() throws InstallError {
UpdateStatus result = new BundleUpdaterHelper().updateWithProgressDialog();
return result;
}
/**
* Return if the update site configuration property is set. As a side
* effect, this method reads the configuration and caches the value of
* the property if it exists.
*
* @return true if the update site config property is set; false otherwise
*/
private boolean isUpdateSiteConfigPropertySet() {
String updateSite =
Activator.getDefault().getConfiguration().getProperties().getProperty(BundleUpdaterConfig.UPDATE_SITE_KEY);
if (updateSite == null || updateSite.trim().equals("")) {
return false;
} else {
return true;
}
}
}