package com.thingtrack.konekti.view.module.product.internal;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.springframework.beans.factory.annotation.Autowired;
import com.thingtrack.konekti.knowledge.service.api.ProductKnowledgeService;
import com.thingtrack.konekti.service.api.ProductService;
import com.thingtrack.konekti.service.api.ProductTypeService;
import com.thingtrack.konekti.service.api.ProductUnitService;
import com.thingtrack.konekti.service.api.SupplierService;
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 ProductViewContainer extends AbstractViewContainer {
@AutoGenerated
private VerticalLayout mainLayout;
@AutoGenerated
private SliderView sliderView;
/** Views **/
private ProductView productView;
/** Business services **/
@Autowired
private ProductService productService;
@Autowired
private ProductTypeService productTypeService;
@Autowired
private ProductUnitService productUnitService;
@Autowired
private SupplierService supplierService;
@Autowired
private ProductKnowledgeService productKnowledgeService;
private IWorkbenchContext context;
// Thread Local Bundle Business Services
private static ThreadLocal<ProductService> threadProductService= new ThreadLocal<ProductService>();
private static ThreadLocal<ProductTypeService> threadProductTypeService = new ThreadLocal<ProductTypeService>();
private static ThreadLocal<ProductUnitService> threadProductUnitService = new ThreadLocal<ProductUnitService>();
private static ThreadLocal<SupplierService> threadSupplierService = new ThreadLocal<SupplierService>();
private static ThreadLocal<ProductKnowledgeService> threadProductKnowledgeService = new ThreadLocal<ProductKnowledgeService>();
/*- 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 ProductViewContainer(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
threadProductService.set(productService);
threadProductTypeService.set(productTypeService);
threadSupplierService.set(supplierService);
threadProductKnowledgeService.set(productKnowledgeService);
threadProductUnitService.set(productUnitService);
// add all views controlled by SliderView Component
productView = new ProductView(context, this);
sliderView.addView(productView);
views.put(0, productView);
}
@SuppressWarnings("unused")
@PreDestroy
private void destroyViews() {
// destroy thread local bundle services
threadProductService.set(null);
threadProductTypeService.set(null);
threadSupplierService.set(null);
threadProductKnowledgeService.set(null);
threadProductUnitService.set(null);
}
public static ProductService getProductService() {
return threadProductService.get();
}
public static ProductTypeService getProductTypeService() {
return threadProductTypeService.get();
}
public static ProductUnitService getProductUnitService() {
return threadProductUnitService.get();
}
public static SupplierService getSupplierService() {
return threadSupplierService.get();
}
public static ProductKnowledgeService getProductKnowledgeService() {
return threadProductKnowledgeService.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;
}
}