// Path: example-app/example-app-ui/src/main/java/com/github/mcollovati/vaadin/exampleapp/MyUI.java
// @Viewport("user-scalable=no,initial-scale=1.0")
// @Theme("mytheme")
// @Widgetset("com.github.mcollovati.vaadin.exampleapp.MyAppWidgetset")
// @Push
// public class MyUI extends UI {
// 
//     private AccessControl accessControl = new BasicAccessControl();
// 
//     @Override
//     protected void init(VaadinRequest vaadinRequest) {
//         setPushConnection(new SockJSPushConnection(this));
//         Responsive.makeResponsive(this);
//         setLocale(vaadinRequest.getLocale());
//         getPage().setTitle("My");
//         if (!accessControl.isUserSignedIn()) {
//             setContent(new LoginScreen(accessControl, new LoginListener() {
//                 @Override
//                 public void loginSuccessful() {
//                     showMainView();
//                 }
//             }));
//         } else {
//             showMainView();
//         }
//     }
// 
// 
//     /* Only for serialization debug purpose
//     private void readObject(ObjectInputStream in)
//         throws IOException, ClassNotFoundException {
//         in.defaultReadObject();
//         System.out.println("============= MyUI::readObject syncid " + getConnectorTracker().getCurrentSyncId());
//     }
// 
//     private void writeObject(ObjectOutputStream out) throws IOException {
//         System.out.println("============= MyUI::writeObject syncid " + getConnectorTracker().getCurrentSyncId());
//         out.defaultWriteObject();
//     }
//     */
// 
//     @Override
//     public void attach() {
//         super.attach();
//         /*
//         UIProxy proxy = new UIProxy(this);
// 
//         proxy.runLater(() -> {
//             UI safe = UI.getCurrent();
//             safe.getPage().setTitle("Changed with safeUI");
//         }, 15, TimeUnit.SECONDS);
//         */
// 
//     }
// 
//     protected void showMainView() {
//         addStyleName(ValoTheme.UI_WITH_MENU);
//         setContent(new MainScreen(MyUI.this));
//         getNavigator().navigateTo(getNavigator().getState());
//     }
// 
//     public AccessControl getAccessControl() {
//         return accessControl;
//     }
// 
//     public static MyUI get() {
//         return (MyUI) UI.getCurrent();
//     }
// 
//     @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
//     public static class ExampleUIVerticle extends VaadinVerticle {
//     }
// 
// 
// }
// 
// Path: example-app/example-app-backend/src/main/java/com/github/mcollovati/vaadin/exampleapp/samples/backend/DataService.java
// public abstract class DataService implements Serializable {
// 
//     public abstract Collection<Product> getAllProducts();
// 
//     public abstract Collection<Category> getAllCategories();
// 
//     public abstract void updateProduct(Product p);
// 
//     public abstract void deleteProduct(int productId);
// 
//     public abstract Product getProductById(int productId);
// 
//     public static DataService get() {
//         return MockDataService.getInstance();
//     }
// 
// }
// 
// Path: example-app/example-app-backend/src/main/java/com/github/mcollovati/vaadin/exampleapp/samples/backend/data/Product.java
// public class Product implements Serializable {
// 
//     @NotNull
//     private int id = -1;
//     @NotNull
//     @Size(min = 2, message = "Product name must have at least two characters")
//     private String productName = "";
//     @Min(0)
//     private BigDecimal price = BigDecimal.ZERO;
//     private Set<Category> category;
//     @Min(value = 0, message = "Can't have negative amount in stock")
//     private int stockCount = 0;
//     @NotNull
//     private Availability availability = Availability.COMING;
// 
//     public int getId() {
//         return id;
//     }
// 
//     public void setId(int id) {
//         this.id = id;
//     }
// 
//     public String getProductName() {
//         return productName;
//     }
// 
//     public void setProductName(String productName) {
//         this.productName = productName;
//     }
// 
//     public BigDecimal getPrice() {
//         return price;
//     }
// 
//     public void setPrice(BigDecimal price) {
//         this.price = price;
//     }
// 
//     public Set<Category> getCategory() {
//         return category;
//     }
// 
//     public void setCategory(Set<Category> category) {
//         this.category = category;
//     }
// 
//     public int getStockCount() {
//         return stockCount;
//     }
// 
//     public void setStockCount(int stockCount) {
//         this.stockCount = stockCount;
//     }
// 
//     public Availability getAvailability() {
//         return availability;
//     }
// 
//     public void setAvailability(Availability availability) {
//         this.availability = availability;
//     }
// 
// }


import com.github.mcollovati.vaadin.exampleapp.MyUI;
import com.github.mcollovati.vaadin.exampleapp.samples.backend.DataService;
import com.github.mcollovati.vaadin.exampleapp.samples.backend.data.Product;
import java.io.Serializable;
import com.vaadin.server.Page;
package com.github.mcollovati.vaadin.exampleapp.samples.crud;



/**
 * This class provides an interface for the logical operations between the CRUD
 * view, its parts like the product editor form and the data source, including
 * fetching and saving products.
 *
 * Having this separate from the view makes it easier to test various parts of
 * the system separately, and to e.g. provide alternative views for the same
 * data.
 */
public class SampleCrudLogic implements Serializable {

    private SampleCrudView view;

    public SampleCrudLogic(SampleCrudView simpleCrudView) {
        view = simpleCrudView;
    }

    public void init() {
        editProduct(null);
        // Hide and disable if not admin
// Path: example-app/example-app-ui/src/main/java/com/github/mcollovati/vaadin/exampleapp/MyUI.java
// @Viewport("user-scalable=no,initial-scale=1.0")
// @Theme("mytheme")
// @Widgetset("com.github.mcollovati.vaadin.exampleapp.MyAppWidgetset")
// @Push
// public class MyUI extends UI {
// 
//     private AccessControl accessControl = new BasicAccessControl();
// 
//     @Override
//     protected void init(VaadinRequest vaadinRequest) {
//         setPushConnection(new SockJSPushConnection(this));
//         Responsive.makeResponsive(this);
//         setLocale(vaadinRequest.getLocale());
//         getPage().setTitle("My");
//         if (!accessControl.isUserSignedIn()) {
//             setContent(new LoginScreen(accessControl, new LoginListener() {
//                 @Override
//                 public void loginSuccessful() {
//                     showMainView();
//                 }
//             }));
//         } else {
//             showMainView();
//         }
//     }
// 
// 
//     /* Only for serialization debug purpose
//     private void readObject(ObjectInputStream in)
//         throws IOException, ClassNotFoundException {
//         in.defaultReadObject();
//         System.out.println("============= MyUI::readObject syncid " + getConnectorTracker().getCurrentSyncId());
//     }
// 
//     private void writeObject(ObjectOutputStream out) throws IOException {
//         System.out.println("============= MyUI::writeObject syncid " + getConnectorTracker().getCurrentSyncId());
//         out.defaultWriteObject();
//     }
//     */
// 
//     @Override
//     public void attach() {
//         super.attach();
//         /*
//         UIProxy proxy = new UIProxy(this);
// 
//         proxy.runLater(() -> {
//             UI safe = UI.getCurrent();
//             safe.getPage().setTitle("Changed with safeUI");
//         }, 15, TimeUnit.SECONDS);
//         */
// 
//     }
// 
//     protected void showMainView() {
//         addStyleName(ValoTheme.UI_WITH_MENU);
//         setContent(new MainScreen(MyUI.this));
//         getNavigator().navigateTo(getNavigator().getState());
//     }
// 
//     public AccessControl getAccessControl() {
//         return accessControl;
//     }
// 
//     public static MyUI get() {
//         return (MyUI) UI.getCurrent();
//     }
// 
//     @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
//     public static class ExampleUIVerticle extends VaadinVerticle {
//     }
// 
// 
// }
// 
// Path: example-app/example-app-backend/src/main/java/com/github/mcollovati/vaadin/exampleapp/samples/backend/DataService.java
// public abstract class DataService implements Serializable {
// 
//     public abstract Collection<Product> getAllProducts();
// 
//     public abstract Collection<Category> getAllCategories();
// 
//     public abstract void updateProduct(Product p);
// 
//     public abstract void deleteProduct(int productId);
// 
//     public abstract Product getProductById(int productId);
// 
//     public static DataService get() {
//         return MockDataService.getInstance();
//     }
// 
// }
// 
// Path: example-app/example-app-backend/src/main/java/com/github/mcollovati/vaadin/exampleapp/samples/backend/data/Product.java
// public class Product implements Serializable {
// 
//     @NotNull
//     private int id = -1;
//     @NotNull
//     @Size(min = 2, message = "Product name must have at least two characters")
//     private String productName = "";
//     @Min(0)
//     private BigDecimal price = BigDecimal.ZERO;
//     private Set<Category> category;
//     @Min(value = 0, message = "Can't have negative amount in stock")
//     private int stockCount = 0;
//     @NotNull
//     private Availability availability = Availability.COMING;
// 
//     public int getId() {
//         return id;
//     }
// 
//     public void setId(int id) {
//         this.id = id;
//     }
// 
//     public String getProductName() {
//         return productName;
//     }
// 
//     public void setProductName(String productName) {
//         this.productName = productName;
//     }
// 
//     public BigDecimal getPrice() {
//         return price;
//     }
// 
//     public void setPrice(BigDecimal price) {
//         this.price = price;
//     }
// 
//     public Set<Category> getCategory() {
//         return category;
//     }
// 
//     public void setCategory(Set<Category> category) {
//         this.category = category;
//     }
// 
//     public int getStockCount() {
//         return stockCount;
//     }
// 
//     public void setStockCount(int stockCount) {
//         this.stockCount = stockCount;
//     }
// 
//     public Availability getAvailability() {
//         return availability;
//     }
// 
//     public void setAvailability(Availability availability) {
//         this.availability = availability;
//     }
// 
// }


// Path: example-app/example-app-ui/src/main/java/com/github/mcollovati/vaadin/exampleapp/samples/crud/SampleCrudLogic.java
import com.github.mcollovati.vaadin.exampleapp.MyUI;
import com.github.mcollovati.vaadin.exampleapp.samples.backend.DataService;
import com.github.mcollovati.vaadin.exampleapp.samples.backend.data.Product;
import java.io.Serializable;
import com.vaadin.server.Page;

package com.github.mcollovati.vaadin.exampleapp.samples.crud;



/**
 * This class provides an interface for the logical operations between the CRUD
 * view, its parts like the product editor form and the data source, including
 * fetching and saving products.
 *
 * Having this separate from the view makes it easier to test various parts of
 * the system separately, and to e.g. provide alternative views for the same
 * data.
 */
public class SampleCrudLogic implements Serializable {

    private SampleCrudView view;

    public SampleCrudLogic(SampleCrudView simpleCrudView) {
        view = simpleCrudView;
    }

    public void init() {
        editProduct(null);
        // Hide and disable if not admin
        if (!MyUI.get().getAccessControl().isUserInRole("admin")) {