/*
 * Copyright 2015 Ryan Gilera.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.daytron.revworks.ui.dashboard;

import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.server.FontAwesome;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.RichTextArea;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ValoTheme;
import java.util.Date;

/**
 *
 * @author Ryan Gilera
 */
public class HomeView extends VerticalLayout implements View {

    public static final String VIEW_NAME = "Home";

    public HomeView() {
        setSizeFull();
        setMargin(true);
        setSpacing(true);

        Label whatsNewLabel = new Label();

    }

    private Component createAnnouncementPanel(
            final String title,
            final RichTextArea announcementTextArea,
            Date dateSubmitted,
            String authorSubmitted) {
        final CssLayout wrapperItem = new CssLayout();
        wrapperItem.setWidth("100%");
        wrapperItem.setStyleName(ValoTheme.LAYOUT_CARD);

        wrapperItem.addComponent(createPanelHeader(title));
        wrapperItem.addComponent(announcementTextArea);

        return wrapperItem;
    }

    private HorizontalLayout createPanelHeader(String title) {
        final HorizontalLayout layoutHeader = new HorizontalLayout();
        layoutHeader.addStyleName("v-panel-caption");
        layoutHeader.setWidth("100%");

        Label titleLabel = new Label(title);
        layoutHeader.addComponent(titleLabel);
        layoutHeader.setExpandRatio(titleLabel, 1);

        Button expandButton = new Button();
        expandButton.setIcon(FontAwesome.EXPAND);
        expandButton.addStyleName("borderless-colored");
        expandButton.addStyleName("small");
        expandButton.addStyleName("icon-only");
        layoutHeader.addComponent(expandButton);

        return layoutHeader;
    }

    @Override
    public void enter(ViewChangeListener.ViewChangeEvent event) {

//        if (!initialized) {
//            initalizeLayouts();
//        }
//
//        if (!isDataUpToDate) {
//            updateData();
//        }
    }

}

@@ -641,16 +641,178 @@
 board;%0A%0A
+import com.github.daytron.revworks.event.AppEvent;%0Aimport com.github.daytron.revworks.event.AppEventBus;%0Aimport com.github.daytron.revworks.service.DataProvider;%0A
 import c
@@ -1210,17 +1210,95 @@
 ava.
-util.Date
+sql.ResultSet;%0Aimport java.util.ArrayList;%0Aimport java.util.Date;%0Aimport java.util.List
 ;%0A%0A/
@@ -1454,146 +1454,221 @@
     
-public HomeView() %7B%0A        setSizeFull();%0A        setMargin(true);%0A        setSpacing(true)
+// Flags%0A    private boolean initialised = false;%0A    private boolean isDataLoaded = false;%0A%0A    private static final String viewTitle = %22What's New%22;%0A%0A    private ResultSet dataContainer
 ;%0A%0A    
- 
-   Label whatsNewLabel = new Label();%0A
+public HomeView() %7B
 %0A   
@@ -2958,18 +2958,16 @@
 ent) %7B%0A%0A
-//
         
@@ -2983,17 +2983,210 @@
 iali
-z
+s
 ed) %7B%0A
-//
+            AppEventBus.post(new AppEvent.LoadHomeViewDataEvent());%0A            this.dataContainer = DataProvider.get().getAnnouncementsContainer();%0A%0A            if (dataContainer != null) %7B%0A    
     
@@ -3201,111 +3201,657 @@
 init
+i
 ali
-z
+s
 eLayout
-s();%0A//        %7D%0A//%0A//
+();%0A                %0A                AppEventBus.post(new AppEvent.CloseSQLStatementAndConnectionEvent());%0A            %7D%0A%0A        %7D%0A
     
+%7D%0A%0A
     
-if (!isDataUpToDate) %7B%0A//            updateData();%0A//        %7D
+private void initialiseLayout() %7B%0A        setSizeFull();%0A        setMargin(true);%0A        setSpacing(true);%0A%0A        Label whatsNewLabel = new Label(viewTitle);%0A        VerticalLayout contentLayout = new VerticalLayout();%0A        contentLayout.setSizeFull();%0A        %0A        // TODO logic for creating panel news from resultset object (dataContainer)%0A        %0A        %0A        addComponent(whatsNewLabel);%0A        addComponent(contentLayout);%0A        %0A        setExpandRatio(contentLayout, 1);
 %0A   

Apply dataprovider