Change cookie expiration time to a day; that also solves the numeric overflow problem that would happen in java, since the expiration time in milliseconds for a year cannot fit into an int.

Guard against IndexOutOfBoundsException that can occur when user hits the "Delete" button and there are no cookies to delete.

Patch by: rdayal
Review by: jat

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2927 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/samples/showcase/src/com/google/gwt/sample/showcase/client/content/other/CwCookies.java b/samples/showcase/src/com/google/gwt/sample/showcase/client/content/other/CwCookies.java
index 6ce4aff..2cd0cc1 100644
--- a/samples/showcase/src/com/google/gwt/sample/showcase/client/content/other/CwCookies.java
+++ b/samples/showcase/src/com/google/gwt/sample/showcase/client/content/other/CwCookies.java
@@ -62,10 +62,10 @@
   }
 
   /**
-   * The timeout before a cookie expires, in milliseconds. Current one year.
+   * The timeout before a cookie expires, in milliseconds. Current one day.
    */
   @ShowcaseData
-  private static final int COOKIE_TIMOUT = 1000 * 60 * 60 * 24 * 365;
+  private static final int COOKIE_TIMEOUT = 1000 * 60 * 60 * 24;
 
   /**
    * An instance of the constants.
@@ -150,7 +150,7 @@
       public void onClick(Widget sender) {
         String name = cookieNameBox.getText();
         String value = cookieValueBox.getText();
-        Date expires = new Date((new Date()).getTime() + COOKIE_TIMOUT);
+        Date expires = new Date((new Date()).getTime() + COOKIE_TIMEOUT);
 
         // Verify the name is valid
         if (name.length() < 1) {
@@ -175,10 +175,12 @@
     deleteCookieButton.addClickListener(new ClickListener() {
       public void onClick(Widget sender) {
         int selectedIndex = existingCookiesBox.getSelectedIndex();
-        String cookieName = existingCookiesBox.getValue(selectedIndex);
-        Cookies.removeCookie(cookieName);
-        existingCookiesBox.removeItem(selectedIndex);
-        updateExstingCookie();
+        if (selectedIndex > -1 && selectedIndex < existingCookiesBox.getItemCount()) {
+          String cookieName = existingCookiesBox.getValue(selectedIndex);
+          Cookies.removeCookie(cookieName);
+          existingCookiesBox.removeItem(selectedIndex);
+          updateExstingCookie();
+        }
       }
     });