/*
 *  *
 * ProActive Parallel Suite(TM): The Java(TM) library for
 *    Parallel, Distributed, Multi-Core Computing for
 *    Enterprise Grids & Clouds
 *
 * Copyright (C) 1997-2014 INRIA/University of
 *                 Nice-Sophia Antipolis/ActiveEon
 * Contact: proactive@ow2.org or contact@activeeon.com
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License
 * as published by the Free Software Foundation; version 3 of
 * the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * If needed, contact us to obtain a release under GPL Version 2 or 3
 * or a different license than the AGPL.
 *
 *  Initial developer(s):               The ProActive Team
 *                        http://proactive.inria.fr/team_members.htm
 *  Contributor(s):
 *
 *  * $$PROACTIVE_INITIAL_DEV$$
 */

package org.ow2.proactive_grid_cloud_portal.scheduler.client.view;

import java.util.Date;

import org.ow2.proactive_grid_cloud_portal.scheduler.client.Job;
import org.ow2.proactive_grid_cloud_portal.scheduler.client.controller.TasksCentricNavigationController;

import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.RelativeDateItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.client.widgets.layout.Layout;

public class TasksCentricNavigationView extends TasksNavigationView{

    public TasksCentricNavigationView(TasksCentricNavigationController controller) {
        super(controller);
    }


    @Override
    public Layout build() {
        Layout layout = super.build();

        RelativeDateItem fromDateItem = new RelativeDateItem("fromDate", "from");
        fromDateItem.addChangedHandler(new ChangedHandler() {   
            @Override
            public void onChanged(ChangedEvent event) {
                fromDateChangedHandler(event);
            }
        });
        RelativeDateItem toDateItem = new RelativeDateItem("toDate", "to");
        toDateItem.addChangedHandler(new ChangedHandler() {
            @Override
            public void onChanged(ChangedEvent event) {
                toDateChangedHandler(event);
            }
        });

        DynamicForm form = new DynamicForm();
        form.setNumCols(4);
        form.setItems(fromDateItem, toDateItem);
        form.setStyleName("form");
        layout.addMember(form);
        
        return layout;
    }


    protected void fromDateChangedHandler(ChangedEvent event){
        Date value = (Date) event.getValue();
        long time = value.getTime();
        ((TasksCentricNavigationController) this.controller).changeFromDate(time);
    }

    protected void toDateChangedHandler(ChangedEvent event){
        Date value = (Date) event.getValue();
        long time = value.getTime();
        ((TasksCentricNavigationController) this.controller).changeToDate(time);
    }

    
    @Override
    public void jobSelected(Job job) {
    }


    @Override
    public void jobUnselected() {
    }

}

@@ -1392,16 +1392,115 @@
 .Date;%0A%0A
+import com.smartgwt.client.widgets.Canvas;%0Aimport com.smartgwt.client.widgets.layout.LayoutSpacer;%0A
 import o
@@ -2153,24 +2153,115 @@
 ler);%0A    %7D%0A
+    Canvas datesCanvas;%0A    RelativeDateItem fromDateItem;%0A    RelativeDateItem toDateItem;
 %0A%0A    @Overr
@@ -2340,33 +2340,16 @@
         
-RelativeDateItem 
 fromDate
@@ -2458,19 +2458,16 @@
 dler() %7B
-   
 %0A       
@@ -2618,33 +2618,16 @@
         
-RelativeDateItem 
 toDateIt
@@ -3002,32 +3002,34 @@
 eItem);%0A        
+//
 form.setStyleNam
@@ -3071,24 +3071,25 @@
 (form);%0A
+%0A
         
 %0A       
@@ -3076,24 +3076,242 @@
 );%0A%0A        
+datesCanvas = fromDateItem.getContainerWidget();%0A        // The far right of the canvas border isn't visible%0A        LayoutSpacer spacer = new LayoutSpacer(5,datesCanvas.getHeight());%0A        layout.addMember(spacer);%0A
 %0A        ret
@@ -3325,25 +3325,24 @@
 out;%0A    %7D%0A%0A
-%0A
     protecte
@@ -3443,35 +3443,39 @@
 );%0A        long 
-tim
+fromDat
 e = value.getTim
@@ -3491,82 +3491,228 @@
     
-((TasksCentricNavigationController) this.controller).changeFromDate(time);
+if (dateRangeIsValid()) %7B%0A            resetDatesCanvasBGColor();%0A            ((TasksCentricNavigationController) this.controller).changeFromDate(fromDate);%0A        %7D%0A        else %7B%0A            highlightDates();%0A        %7D
 %0A   
@@ -3836,18 +3836,20 @@
   long t
-im
+oDat
 e = valu
@@ -3873,87 +3873,686 @@
     
-((TasksCentricNavigationController) this.controller).changeToDate(time);%0A    %7D%0A
+if (dateRangeIsValid()) %7B%0A            resetDatesCanvasBGColor();%0A            ((TasksCentricNavigationController) this.controller).changeToDate(toDate);%0A        %7D%0A        else %7B%0A            highlightDates();%0A        %7D%0A    %7D%0A%0A    private boolean dateRangeIsValid() %7B%0A        long fromDate = RelativeDateItem.getAbsoluteDate(fromDateItem.getRelativeDate()).getTime();%0A        long toDate = RelativeDateItem.getAbsoluteDate(toDateItem.getRelativeDate()).getTime();%0A        return fromDate %3C toDate;%0A    %7D%0A%0A    private void resetDatesCanvasBGColor() %7B%0A        datesCanvas.setBorder(%22%22);%0A    %7D%0A%0A    private void highlightDates() %7B%0A        datesCanvas.setBorder(%222px solid red%22);%0A    %7D
 %0A   

Add a range check on the dates filtering in the task centric view