// Path: emailclient-tutorial-data/src/main/java/org/vaadin/example/backend/MessageFacade.java
// @Stateless
// public class MessageFacade {
// 
//     public static final String FOLDER_INBOX = "inbox";
//     public static final String FOLDER_DRAFTS = "drafts";
//     public static final String FOLDER_SENT = "sent";
//     public static final String FOLDER_JUNK = "junk";
//     public static final String FOLDER_TRASH = "trash";
//     public static final String FOLDER_FLAGGED = "flagged";
//     public static final List<String> FOLDERS = Arrays.asList(FOLDER_INBOX,
//             FOLDER_DRAFTS, FOLDER_SENT, FOLDER_JUNK, FOLDER_TRASH,
//             FOLDER_FLAGGED);
// 
//     @Inject
//     private MessageRepository repository;
// 
//     public List<Message> getFolderMessages(String folder) {
//         if (FOLDERS.contains(folder)) {
//             if (folder.equals(FOLDER_INBOX)) {
//                 return repository.findAll();
//             } else if (folder.equals(FOLDER_FLAGGED)) {
//                 return repository.findByFlagIsNotNullAndTrashed(false);
//             }
//         }
//         return new ArrayList<>();
//     }
// 
//     public long countAllUnread() {
//         return repository.findByRead(false).count();
// 
//     }
// 
//     public long countFlaggedUnread() {
//         return repository.findByFlagIsNotNullAndRead(false).count();
//     }
// 
//     public void save(Message message) {
//         repository.saveAndFlush(message);
//     }
// }
// 
// Path: emailclient-tutorial-data/src/main/java/org/vaadin/example/ui/themes/mytheme/MyTheme.java
// public class MyTheme {
//     public static final String INDICATOR_STAR_RED = "indicator-star-red";
//     public static final String INDICATOR_CIRCLE = "indicator-circle";
//     public static final String SELECTED = "selected";
// 
//     public static final List<String> MESSAGE_STYLES = Collections
//             .unmodifiableList(Arrays.asList(MyTheme.INDICATOR_CIRCLE,
//                     MyTheme.INDICATOR_STAR_RED));
// }


import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;
import javax.annotation.PostConstruct;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import org.vaadin.example.backend.MessageFacade;
import org.vaadin.example.ui.themes.mytheme.MyTheme;
import com.vaadin.cdi.UIScoped;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.UI;
                } else {
                    component.setCaption(
                            String.format(captionFormat, folder, badgeText));
                }
            }
        }
    }

    // Map button click to a navigation method.
    // Map button to a folder name to allow setting selected style when folder
    // is navigated without clicking the button.
    // Map button to a Supplier method, that provides count for unread items
    private void mapButton(Button button, String folderName,
            Optional<Supplier<Long>> badgeSupplier) {
        button.addClickListener(event -> navigateToFolder(folderName));
        button.setData(folderName);
        if (badgeSupplier.isPresent()) {
            badgeSuppliers.put(folderName, badgeSupplier.get());
        }
    }

    private void mapButton(Button button, String folderName) {
        mapButton(button, folderName, Optional.empty());
    }

    // Checks if a given Component has a given folder name as data, and adds or
    // removes selected style appropriately
    private void adjustStyleByData(Component component, Object data) {
        if (component instanceof Button) {
            if (data != null && data.equals(((Button) component).getData())) {
// Path: emailclient-tutorial-data/src/main/java/org/vaadin/example/backend/MessageFacade.java
// @Stateless
// public class MessageFacade {
// 
//     public static final String FOLDER_INBOX = "inbox";
//     public static final String FOLDER_DRAFTS = "drafts";
//     public static final String FOLDER_SENT = "sent";
//     public static final String FOLDER_JUNK = "junk";
//     public static final String FOLDER_TRASH = "trash";
//     public static final String FOLDER_FLAGGED = "flagged";
//     public static final List<String> FOLDERS = Arrays.asList(FOLDER_INBOX,
//             FOLDER_DRAFTS, FOLDER_SENT, FOLDER_JUNK, FOLDER_TRASH,
//             FOLDER_FLAGGED);
// 
//     @Inject
//     private MessageRepository repository;
// 
//     public List<Message> getFolderMessages(String folder) {
//         if (FOLDERS.contains(folder)) {
//             if (folder.equals(FOLDER_INBOX)) {
//                 return repository.findAll();
//             } else if (folder.equals(FOLDER_FLAGGED)) {
//                 return repository.findByFlagIsNotNullAndTrashed(false);
//             }
//         }
//         return new ArrayList<>();
//     }
// 
//     public long countAllUnread() {
//         return repository.findByRead(false).count();
// 
//     }
// 
//     public long countFlaggedUnread() {
//         return repository.findByFlagIsNotNullAndRead(false).count();
//     }
// 
//     public void save(Message message) {
//         repository.saveAndFlush(message);
//     }
// }
// 
// Path: emailclient-tutorial-data/src/main/java/org/vaadin/example/ui/themes/mytheme/MyTheme.java
// public class MyTheme {
//     public static final String INDICATOR_STAR_RED = "indicator-star-red";
//     public static final String INDICATOR_CIRCLE = "indicator-circle";
//     public static final String SELECTED = "selected";
// 
//     public static final List<String> MESSAGE_STYLES = Collections
//             .unmodifiableList(Arrays.asList(MyTheme.INDICATOR_CIRCLE,
//                     MyTheme.INDICATOR_STAR_RED));
// }


// Path: emailclient-tutorial-data/src/main/java/org/vaadin/example/ui/MainLayout.java
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;
import javax.annotation.PostConstruct;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import org.vaadin.example.backend.MessageFacade;
import org.vaadin.example.ui.themes.mytheme.MyTheme;
import com.vaadin.cdi.UIScoped;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.UI;

                } else {
                    component.setCaption(
                            String.format(captionFormat, folder, badgeText));
                }
            }
        }
    }

    // Map button click to a navigation method.
    // Map button to a folder name to allow setting selected style when folder
    // is navigated without clicking the button.
    // Map button to a Supplier method, that provides count for unread items
    private void mapButton(Button button, String folderName,
            Optional<Supplier<Long>> badgeSupplier) {
        button.addClickListener(event -> navigateToFolder(folderName));
        button.setData(folderName);
        if (badgeSupplier.isPresent()) {
            badgeSuppliers.put(folderName, badgeSupplier.get());
        }
    }

    private void mapButton(Button button, String folderName) {
        mapButton(button, folderName, Optional.empty());
    }

    // Checks if a given Component has a given folder name as data, and adds or
    // removes selected style appropriately
    private void adjustStyleByData(Component component, Object data) {
        if (component instanceof Button) {
            if (data != null && data.equals(((Button) component).getData())) {
                component.addStyleName(MyTheme.SELECTED);