blob: b21e88964d3c3a3852fcfab48208edb53d803921 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2012 Rushan R. Gilmullin and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Rushan R. Gilmullin - initial API and implementation
*******************************************************************************/
package org.eclipse.osbp.vaaclipse.presentation.engine;
import java.net.URI;
import javax.annotation.PostConstruct;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.contributions.IContributionFactory;
import org.eclipse.e4.ui.model.application.MApplicationElement;
import org.eclipse.e4.ui.workbench.IPresentationEngine;
import org.eclipse.osbp.vaaclipse.api.VaadinExecutorService;
import org.eclipse.osbp.vaaclipse.presentation.fastview.FastViewManager;
import org.eclipse.osbp.vaaclipse.publicapi.events.PublicEvents;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@SuppressWarnings("restriction")
public class VaadinPresentationEngine extends GenericPresentationEngine {
public VaadinPresentationEngine() {
}
@Override
public Object run(final MApplicationElement uiRoot,
IEclipseContext appContext) {
ContextInjectionFactory.make(FastViewManager.class, appContext);
super.run(uiRoot, appContext);
return "";
}
@Override
@PostConstruct
public void postConstruct(IEclipseContext context) {
super.postConstruct(context);
// Add the presentation engine to the context
context.set(IPresentationEngine.class.getName(), this);
// TODO use parameter or registry
IContributionFactory contribFactory = context
.get(IContributionFactory.class);
try {
rendererFactory = (RendererFactory) contribFactory
.create("bundleclass://org.eclipse.osbp.vaaclipse.presentation/org.eclipse.osbp.vaaclipse.presentation.renderers.VaadinRendererFactory",
context);
} catch (Exception e) {
logger.warn(e, "Could not create rendering factory");
}
}
@Override
public void stop() {
eventBroker.send(PublicEvents.EXIT_WORKBENCH, null);
super.stop();
VaadinExecutorService executor = theApp.getContext().get(
VaadinExecutorService.class);
executor.removeAllAlwaysRunnables();
final UI ui = theApp.getContext().get(UI.class);
Runnable runnable = new Runnable() {
@Override
public void run() {
ui.setContent(new VerticalLayout());
URI appUri = ui.getPage().getLocation();
ui.close();
ui.getPage().setLocation(appUri);
}
};
if (UI.getCurrent() == null) {
ui.access(runnable);
} else {
runnable.run();
}
}
}