Search in sources :

Example 1 with AbstractSplashHandler

use of org.eclipse.ui.splash.AbstractSplashHandler in project eclipse.platform.ui by eclipse-platform.

the class Workbench method createAndRunWorkbench.

/**
 * Creates the workbench and associates it with the the given display and
 * workbench advisor, and runs the workbench UI. This entails processing and
 * dispatching events until the workbench is closed or restarted.
 * <p>
 * This method is intended to be called by <code>PlatformUI</code>. Fails if the
 * workbench UI has already been created.
 * </p>
 * <p>
 * The display passed in must be the default display.
 * </p>
 *
 * @param display the display to be used for all UI interactions with the
 *                workbench
 * @param advisor the application-specific advisor that configures and
 *                specializes the workbench
 * @return return code {@link PlatformUI#RETURN_OK RETURN_OK}for normal exit;
 *         {@link PlatformUI#RETURN_RESTART RETURN_RESTART}if the workbench was
 *         terminated with a call to {@link IWorkbench#restart
 *         IWorkbench.restart}; other values reserved for future use
 */
public static int createAndRunWorkbench(final Display display, final WorkbenchAdvisor advisor) {
    final int[] returnCode = new int[1];
    Realm.runWithDefault(DisplayRealm.getRealm(display), () -> {
        boolean showProgress = PrefUtil.getAPIPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_PROGRESS_ON_STARTUP);
        final String nlExtensions = Platform.getNLExtensions();
        if (nlExtensions.length() > 0) {
            ULocale.setDefault(Category.FORMAT, new ULocale(ULocale.getDefault(Category.FORMAT).getBaseName() + nlExtensions));
        }
        System.setProperty(org.eclipse.e4.ui.workbench.IWorkbench.XMI_URI_ARG, // $NON-NLS-1$
        "org.eclipse.ui.workbench/LegacyIDE.e4xmi");
        Object obj = getApplication(Platform.getCommandLineArgs());
        IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore();
        if (!store.isDefault(IPreferenceConstants.LAYOUT_DIRECTION)) {
            int orientation = store.getInt(IPreferenceConstants.LAYOUT_DIRECTION);
            Window.setDefaultOrientation(orientation);
        }
        if (obj instanceof E4Application) {
            E4Application e4app = (E4Application) obj;
            E4Workbench e4Workbench = e4app.createE4Workbench(getApplicationContext(), display);
            MApplication appModel = e4Workbench.getApplication();
            IEclipseContext context = e4Workbench.getContext();
            // create the workbench instance
            Workbench workbench = new Workbench(display, advisor, appModel, context);
            Dictionary<String, Object> properties = new Hashtable<>();
            properties.put(Constants.SERVICE_RANKING, Integer.valueOf(Integer.MAX_VALUE - 1));
            ServiceRegistration<?>[] registration = new ServiceRegistration[1];
            StartupMonitor startupMonitor = new StartupMonitor() {

                @Override
                public void applicationRunning() {
                    // unregister ourself
                    registration[0].unregister();
                    // fire part visibility events now that we're up
                    for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) {
                        IWorkbenchPage page = window.getActivePage();
                        if (page != null) {
                            ((WorkbenchPage) page).fireInitialPartVisibilityEvents();
                        }
                    }
                }

                @Override
                public void update() {
                // do nothing - we come into the picture far too late
                // for this to be relevant
                }
            };
            registration[0] = FrameworkUtil.getBundle(WorkbenchPlugin.class).getBundleContext().registerService(StartupMonitor.class.getName(), startupMonitor, properties);
            // listener for updating the splash screen
            SynchronousBundleListener bundleListener = null;
            createSplash = WorkbenchPlugin.isSplashHandleSpecified();
            if (createSplash) {
                // prime the splash nice and early
                workbench.createSplashWrapper();
                // Bug 539376, 427393, 455162: show the splash screen after
                // the image is loaded. See IDEApplication#checkInstanceLocation
                // where the splash shell got hidden to avoid empty shell
                AbstractSplashHandler handler = getSplash();
                if (handler != null) {
                    Shell splashShell = handler.getSplash();
                    if (splashShell != null && !splashShell.isDisposed()) {
                        splashShell.setVisible(true);
                        splashShell.forceActive();
                    }
                }
                spinEventQueueToUpdateSplash(display);
                if (handler != null && showProgress) {
                    IProgressMonitor progressMonitor = SubMonitor.convert(handler.getBundleProgressMonitor());
                    bundleListener = new Workbench.StartupProgressBundleListener(progressMonitor, display);
                    WorkbenchPlugin.getDefault().addBundleListener(bundleListener);
                }
            }
            setSearchContribution(appModel, true);
            // run the legacy workbench once
            returnCode[0] = workbench.runUI();
            if (returnCode[0] == PlatformUI.RETURN_OK) {
                // run the e4 event loop and instantiate ... well, stuff
                if (bundleListener != null) {
                    WorkbenchPlugin.getDefault().removeBundleListener(bundleListener);
                }
                e4Workbench.createAndRunUI(e4Workbench.getApplication());
            }
            if (returnCode[0] != PlatformUI.RETURN_UNSTARTABLE) {
                setSearchContribution(appModel, false);
                e4app.saveModel();
            }
            // code needs to be set appropriately
            if (e4Workbench.isRestart()) {
                returnCode[0] = PlatformUI.RETURN_RESTART;
            } else {
                e4Workbench.close();
                returnCode[0] = workbench.returnCode;
            }
        }
    });
    return returnCode[0];
}
Also used : E4Workbench(org.eclipse.e4.ui.internal.workbench.E4Workbench) IWorkbench(org.eclipse.ui.IWorkbench) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) E4Workbench(org.eclipse.e4.ui.internal.workbench.E4Workbench) StartupMonitor(org.eclipse.osgi.service.runnable.StartupMonitor) ServiceRegistration(org.osgi.framework.ServiceRegistration) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ULocale(com.ibm.icu.util.ULocale) Hashtable(java.util.Hashtable) Point(org.eclipse.swt.graphics.Point) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) AbstractSplashHandler(org.eclipse.ui.splash.AbstractSplashHandler) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) E4Application(org.eclipse.e4.ui.internal.workbench.swt.E4Application) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) EObject(org.eclipse.emf.ecore.EObject) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) SynchronousBundleListener(org.osgi.framework.SynchronousBundleListener) MApplication(org.eclipse.e4.ui.model.application.MApplication)

Example 2 with AbstractSplashHandler

use of org.eclipse.ui.splash.AbstractSplashHandler in project eclipse.platform.ui by eclipse-platform.

the class SplashHandlerFactory method findSplashHandlerFor.

/**
 * Find the splash handler for the given product or <code>null</code> if it
 * cannot be found.
 *
 * @param product the product
 * @return the splash or <code>null</code>
 */
public static AbstractSplashHandler findSplashHandlerFor(IProduct product) {
    if (product == null)
        return null;
    IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(PlatformUI.PLUGIN_ID, IWorkbenchRegistryConstants.PL_SPLASH_HANDLERS);
    if (point == null)
        return null;
    IExtension[] extensions = point.getExtensions();
    // String->ConfigurationElement
    Map idToSplash = new HashMap();
    String[] targetId = new String[1];
    for (IExtension extension : extensions) {
        IConfigurationElement[] children = extension.getConfigurationElements();
        for (IConfigurationElement element : children) {
            AbstractSplashHandler handler = processElement(element, idToSplash, targetId, product);
            if (handler != null)
                return handler;
        }
    }
    return null;
}
Also used : AbstractSplashHandler(org.eclipse.ui.splash.AbstractSplashHandler) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) HashMap(java.util.HashMap) IExtension(org.eclipse.core.runtime.IExtension) HashMap(java.util.HashMap) Map(java.util.Map) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 3 with AbstractSplashHandler

use of org.eclipse.ui.splash.AbstractSplashHandler in project eclipse.platform.ui by eclipse-platform.

the class Workbench method runStartupWithProgress.

private void runStartupWithProgress(final Runnable runnable) {
    AbstractSplashHandler handler = getSplash();
    IProgressMonitor progressMonitor = null;
    if (handler != null) {
        progressMonitor = handler.getBundleProgressMonitor();
    }
    if (progressMonitor == null) {
        // cannot report progress (e.g. if the splash screen is not showing)
        // fall back to starting without showing progress.
        runnable.run();
    } else {
        SynchronousBundleListener bundleListener = new StartupProgressBundleListener(progressMonitor, display);
        WorkbenchPlugin.getDefault().addBundleListener(bundleListener);
        try {
            runnable.run();
        } finally {
            WorkbenchPlugin.getDefault().removeBundleListener(bundleListener);
        }
    }
}
Also used : AbstractSplashHandler(org.eclipse.ui.splash.AbstractSplashHandler) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SynchronousBundleListener(org.osgi.framework.SynchronousBundleListener)

Example 4 with AbstractSplashHandler

use of org.eclipse.ui.splash.AbstractSplashHandler in project eclipse.platform.ui by eclipse-platform.

the class SplashHandlerFactory method create.

/**
 * Create the splash implementation.
 *
 * @param splashElement the element to create from
 * @return the element or <code>null</code> if it couldn't be created
 */
private static AbstractSplashHandler create(final IConfigurationElement splashElement) {
    final AbstractSplashHandler[] handler = new AbstractSplashHandler[1];
    SafeRunner.run(new SafeRunnable() {

        @Override
        public void run() throws Exception {
            handler[0] = (AbstractSplashHandler) WorkbenchPlugin.createExtension(splashElement, IWorkbenchRegistryConstants.ATT_CLASS);
        }

        @Override
        public void handleException(Throwable e) {
            // $NON-NLS-1$
            WorkbenchPlugin.log("Problem creating splash implementation", e);
        }
    });
    return handler[0];
}
Also used : AbstractSplashHandler(org.eclipse.ui.splash.AbstractSplashHandler) SafeRunnable(org.eclipse.jface.util.SafeRunnable)

Aggregations

AbstractSplashHandler (org.eclipse.ui.splash.AbstractSplashHandler)4 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 SynchronousBundleListener (org.osgi.framework.SynchronousBundleListener)2 ULocale (com.ibm.icu.util.ULocale)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtension (org.eclipse.core.runtime.IExtension)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 E4Workbench (org.eclipse.e4.ui.internal.workbench.E4Workbench)1 E4Application (org.eclipse.e4.ui.internal.workbench.swt.E4Application)1 MApplication (org.eclipse.e4.ui.model.application.MApplication)1 EObject (org.eclipse.emf.ecore.EObject)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 SafeRunnable (org.eclipse.jface.util.SafeRunnable)1 StartupMonitor (org.eclipse.osgi.service.runnable.StartupMonitor)1 Point (org.eclipse.swt.graphics.Point)1 Shell (org.eclipse.swt.widgets.Shell)1