blob: 89b73265db45e0fc45f00ede72be1cfa6c45bf18 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* 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:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*
*/
package org.eclipse.osbp.utils.vaadin.bpmn;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.impl.UIElementImpl;
import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.osbp.bpm.api.IBPMEngine;
import org.eclipse.osbp.bpm.api.IBlipBPMFunctionProvider;
import org.slf4j.Logger;
import com.vaadin.server.Page;
import com.vaadin.server.Page.BrowserWindowResizeEvent;
import com.vaadin.server.Page.BrowserWindowResizeListener;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@SuppressWarnings("all")
public class BpmnView {
private static Logger log = org.slf4j.LoggerFactory
.getLogger(BpmnView.class);
private HorizontalLayout lowerArea;
@Inject
@Optional
private IBPMEngine bpmEngine;
@Inject
@Named("Blip")
private IBlipBPMFunctionProvider blip;
private VerticalLayout workArea;
private BpmnRenderer bpmnRenderer;
private String processId;
private VerticalLayout parent;
private IEclipseContext eclipseContext;
@Inject
public BpmnView(final VerticalLayout parent, final IEclipseContext context,
final MApplication app) {
this.parent = parent;
this.eclipseContext = context;
}
@PostConstruct
public void createView(final VerticalLayout parent) {
parent.setPrimaryStyleName("osbp");
bpmnRenderer = new BpmnRenderer(bpmEngine, blip, eclipseContext);
VerticalLayout inner = new VerticalLayout();
inner.setMargin(false);
inner.setSizeFull();
inner.setPrimaryStyleName("osbp");
inner.addComponent(bpmnRenderer);
// to resize the chart according to browser
Page.getCurrent().addBrowserWindowResizeListener(new BrowserWindowResizeListener() {
@Override
public void browserWindowResized(BrowserWindowResizeEvent event) {
log.debug("browserWindowResized - redraw bpmn");
showBpmn(processId);
}
});
// to resize the chart according to split positions of partsashcontainer - setContainerData is tracked
MPart part = eclipseContext.get(MPart.class);
((EObject)part).eAdapters().add(new AdapterImpl() {
public void notifyChanged(Notification notification) {
if (notification.getEventType()==Notification.SET &&
notification.getFeatureID(UIElementImpl.class) == UiPackageImpl.UI_ELEMENT__CONTAINER_DATA)
{
log.debug("split position changed - redraw bpmn");
showBpmn(processId);
}
}
});
}
public void showBpmn(String processId) {
this.processId = processId;
UI.getCurrent().access(new Runnable() {
@Override
public void run() {
bpmnRenderer.drawBpmn(processId);
}
});
}
public void selectTask(String taskName) {
bpmnRenderer.setSelectedCell(taskName);
}
}