package com.thingtrack.konekti.view.module.organization.internal;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.springframework.beans.factory.annotation.Autowired;
import com.thingtrack.konekti.service.api.AreaService;
import com.thingtrack.konekti.service.api.LocationService;
import com.thingtrack.konekti.service.api.OrganizationService;
import com.thingtrack.konekti.view.addon.ui.AbstractViewContainer;
import com.thingtrack.konekti.view.addon.ui.SliderView;
import com.thingtrack.konekti.view.kernel.IModule;
import com.thingtrack.konekti.view.kernel.IWorkbenchContext;
import com.thingtrack.konekti.view.kernel.ui.layout.ISliderView;
import com.thingtrack.konekti.view.kernel.ui.layout.IViewChangeListener;
import com.thingtrack.konekti.view.kernel.ui.layout.IView;
import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.VerticalLayout;
@SuppressWarnings("serial")
public class OrganizationViewContainer extends AbstractViewContainer {
@AutoGenerated
private VerticalLayout mainLayout;
@AutoGenerated
private SliderView sliderView;
/** Views **/
private OrganizationView organizationView;
/** Business services **/
@Autowired
private OrganizationService organizationService;
@Autowired
private LocationService locationService;
@Autowired
private AreaService areaService;
private IWorkbenchContext context;
// Thread Local Bundle Business Services
private static ThreadLocal<OrganizationService> threadOrganizationService = new ThreadLocal<OrganizationService>();
private static ThreadLocal<LocationService> threadLocationService = new ThreadLocal<LocationService>();
private static ThreadLocal<AreaService> threadAreaService = new ThreadLocal<AreaService>();
/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
/**
* The constructor should first build the main layout, set the
* composition root and then do any custom initialization.
*
* The constructor will not be automatically regenerated by the
* visual editor.
*/
public OrganizationViewContainer(IWorkbenchContext context, IModule module) {
buildMainLayout();
setCompositionRoot(mainLayout);
// TODO add user code here
this.context = context;
this.module = module;
}
@SuppressWarnings("unused")
@PostConstruct
private void createViews() {
// initialize thread local bundle services
threadOrganizationService.set(organizationService);
threadLocationService.set(locationService);
threadAreaService.set(areaService);
// add all views controlled by SliderView Component
organizationView = new OrganizationView(context, this);
sliderView.addView(organizationView);
views.put(0, organizationView);
}
@SuppressWarnings("unused")
@PreDestroy
private void destroyViews() {
// destroy thread local bundle services
threadOrganizationService.set(null);
threadLocationService.set(null);
threadAreaService.set(null);
}
public static OrganizationService getOrganizationService() {
return threadOrganizationService.get();
}
public static LocationService getLocationService() {
return threadLocationService.get();
}
public static AreaService getAreaService() {
return threadAreaService.get();
}
@Override
public ISliderView getSliderView() {
return sliderView;
}
@Override
public IView getSelectedView() {
return sliderView.getSelectedView();
}
@Override
public void addListener(IViewChangeListener listener) {
sliderView.addListener(listener);
}
@AutoGenerated
private VerticalLayout buildMainLayout() {
// common part: create layout
mainLayout = new VerticalLayout();
mainLayout.setImmediate(false);
mainLayout.setWidth("100%");
mainLayout.setHeight("100%");
mainLayout.setMargin(false);
// top-level component properties
setWidth("100.0%");
setHeight("100.0%");
// sliderView
sliderView = new SliderView();
sliderView.setImmediate(false);
sliderView.setWidth("100.0%");
sliderView.setHeight("100.0%");
mainLayout.addComponent(sliderView);
mainLayout.setExpandRatio(sliderView, 1.0f);
return mainLayout;
}
}