You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by da...@apache.org on 2006/10/07 06:59:29 UTC

svn commit: r453845 [2/2] - in /db/derby/code/trunk/java/demo/localcal: ./ lib/ src/ src/images/

Added: db/derby/code/trunk/java/demo/localcal/src/UpdateEventRequest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/demo/localcal/src/UpdateEventRequest.java?view=auto&rev=453845
==============================================================================
--- db/derby/code/trunk/java/demo/localcal/src/UpdateEventRequest.java (added)
+++ db/derby/code/trunk/java/demo/localcal/src/UpdateEventRequest.java Fri Oct  6 21:59:28 2006
@@ -0,0 +1,64 @@
+/*
+ 
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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.
+ 
+ */
+
+/**
+ * Captures a request to update an event
+ */
+public class UpdateEventRequest extends GCalendarRequest {  
+    private String eventId;
+    private String title;
+            
+    /** Creates a new instance of AddEventRequest */
+    protected UpdateEventRequest(int requestId, String eventId, String title) {
+        super(requestId);
+        this.setEventId(eventId);
+        this.setTitle(title);
+    }
+        
+    public String toString() {
+        return "Request # " + getId() + " to update event id " + getEventId() +
+                " with title '" + getTitle() + "'";
+    }
+    
+    public void submit(GCalendar calendar) throws Exception {
+        CalEvent event = EventManager.getEvent(getEventId());
+        if ( event == null ) {
+            throw new Exception("Event " + getEventId() + " does not " +
+               "appear to be in the database; unable to submit update request");
+        }
+        event.setTitle(getTitle());
+        calendar.updateEvent(event);
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getEventId() {
+        return eventId;
+    }
+
+    public void setEventId(String eventId) {
+        this.eventId = eventId;
+    }    
+}

Propchange: db/derby/code/trunk/java/demo/localcal/src/UpdateEventRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/demo/localcal/src/images/delete.gif
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/demo/localcal/src/images/delete.gif?view=auto&rev=453845
==============================================================================
Binary file - no diff available.

Propchange: db/derby/code/trunk/java/demo/localcal/src/images/delete.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: db/derby/code/trunk/java/demo/localcal/src/index.html
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/demo/localcal/src/index.html?view=auto&rev=453845
==============================================================================
--- db/derby/code/trunk/java/demo/localcal/src/index.html (added)
+++ db/derby/code/trunk/java/demo/localcal/src/index.html Fri Oct  6 21:59:28 2006
@@ -0,0 +1,174 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to you 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.
+-->
+
+<html>
+<head>
+  <title>LocalCalendar</title>
+  <style type="text/css">
+      body { 
+        background  :   #ccffff;
+      }
+      
+      .day-header {
+        font-size   :   22px;
+        font-weight :   bold;
+      }
+      div.login {
+        background  :   transparent;
+        visibility  :   visible;
+      }
+      div.main {
+        visibility  :   hidden;
+      }
+      
+      .input-box {
+        background  :   transparent;
+        border      :   0px;
+      }
+      
+      .input-box:hover {
+        background  :   #ffffff;
+      }
+      
+      .input-box:focus {
+        background  :   #ffffff;
+      }
+  </style>
+  <applet code="CalendarController" 
+      archive="localcal.jar,gdata-calendar-1.0.jar,gdata-client-1.0.jar,derby.jar"
+      height="1" width="1"
+      id="calapplet"></applet>
+  <script type="text/javascript" src="localcal.js"></script>
+
+</head>
+<body id="body">
+  <div id="login-div" class="login">
+  <h1 id="loginHeader">My Week of Events</h1>
+  <h3>Please login to Google Calendar</h3>
+  <form class="login-form" name="loginForm" >
+      <table>
+          <tr>
+              <td><strong>Google Id: </strong></td>
+              <td><input type="text" name="user" size="40"/></td>
+              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
+              <td><strong>Password: </strong></td>
+              <td><input type="password" name="password"/></td>
+              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
+              <td><input type="button" onclick="derbycal.login()" 
+              value="Login"</td>
+          </tr>
+          <tr><td>&nbsp;</td></tr>
+          <tr>
+              <td id="loggingIn" style="{visibility : hidden;}">
+                    <strong>Logging In...</strong>
+             </td>
+         </tr>
+             <td><input type="button" value="Work Offline" 
+                  onclick="derbycal.startOffline(); return false;"
+                  id="workOfflineButton"/>
+             </td>
+          </tr>
+      </table>
+  </form>
+  </div>
+  <div id="main-div" class="main">
+      <h1>My Week of Events</h1>
+      <hr>
+      <table>
+          <tr>
+              <form name="offlineForm">
+                  <td><input type="button" value="Go Offline" 
+                      onclick="derbycal.goOffline(); return false;"
+                  name="offlineButton"/></td>
+                  <td><input type="button" value="Go Online" disabled="true" 
+                      onclick="derbycal.goOnline(); return false;"
+                  name="onlineButton" id="onlineButton"/></td>
+                  <td id="goingOnline" style="{visibility : hidden}">
+                      <strong>&nbsp;&nbsp;&nbsp;Resynchronizing with Google Calendar...</strong>
+                  </td>
+              </form>
+          </tr>
+      </table>
+      <hr>
+                
+      <form class="new-event-form" name="newEventForm">
+          <table>
+              <tr>
+                  <td>
+                      <select name="eventDay" value="Sunday">
+                          <option value="Sunday">Sunday</option>
+                          <option value="Monday">Monday</option>
+                          <option value="Tuesday">Tuesday</option>
+                          <option value="Wednesday">Wednesday</option>
+                          <option value="Thursday">Thursday</option>
+                          <option value="Friday">Friday</option>
+                          <option value="Saturday">Saturday</option>                  
+                      </select>
+                  </td>
+                  <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>What:</strong></td>
+                  <td><input type="text" size="70" name="eventTitle"></input></td>
+                  <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
+                  <td><input type="button" 
+                      onclick="derbycal.postNewEvent(); return false;"
+                      value="Add Event"
+                  </td>
+                  <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
+                  <td>
+                      <input type="reset" value="Clear"/>
+                  </td>
+              </tr>
+              <tr><td><br>&nbsp;</td></tr>
+              <tr>
+                  <td><input type="button" onclick="derbycal.refreshCalendar();return false;"
+                  value="Refresh Calendar"</input></td>
+              </tr>
+          </table> 
+      </form>
+      <hr>
+      <table id="Sunday" class="day-table">
+          <tr><td class="day-header">Sunday</td></tr>
+      </table>
+      <hr>
+      <table id="Monday" class="day-table">
+          <tr><td class="day-header">Monday</td></tr>
+      </table>
+      <hr>
+      <table id="Tuesday" class="day-table">
+          <tr><td class="day-header">Tuesday</td></tr>
+      </table>
+      <hr>
+      <table id="Wednesday" class="day-table">
+          <tr><td class="day-header">Wednesday</td></tr>
+      </table>
+      <hr>
+      <table id="Thursday" class="day-table">
+          <tr><td class="day-header">Thursday</td></tr>
+      </table>
+      <hr>
+      <table id="Friday" class="day-table">
+          <tr><td class="day-header">Friday</td></tr>
+      </table>
+      <hr>
+      <table id="Saturday" class="day-table">
+          <tr><td class="day-header">Saturday</td></tr>
+      </table>
+      <hr>
+    </div>
+</body>
+</html>

Propchange: db/derby/code/trunk/java/demo/localcal/src/index.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/demo/localcal/src/localcal.js
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/demo/localcal/src/localcal.js?view=auto&rev=453845
==============================================================================
--- db/derby/code/trunk/java/demo/localcal/src/localcal.js (added)
+++ db/derby/code/trunk/java/demo/localcal/src/localcal.js Fri Oct  6 21:59:28 2006
@@ -0,0 +1,337 @@
+/*
+ 
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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.
+ 
+ */
+
+var derbycal = {};
+
+// This is the Google Calendar id for the shared calendar for this
+// application
+derbycal.calid = "olj8s6vvk5pu2b7oib47t57pps@group.calendar.google.com";
+
+// The offset from GMT for this calendar.  Change this if you want to change
+// time zones for the calendar.  Right now set to CST (Austin).
+derbycal.gmtOffset = "-08:00";
+
+derbycal.onlineColor = "#66FF66";
+derbycal.offlineColor = "#ccFFFF";
+
+/** 
+** You need to change the dates if you want a different week showing
+** on the calendar.  Yes, I could calculate this, but I have bigger
+** fish to fry...
+*/
+derbycal.days = [ 
+    ["Sunday",      "2006-10-01"],
+    ["Monday",      "2006-10-02"],
+    ["Tuesday",     "2006-10-03"],
+    ["Wednesday",   "2006-10-04"],
+    ["Thursday",    "2006-10-05"],
+    ["Friday",      "2006-10-06"],
+    ["Saturday",    "2006-10-07"],
+    ["Sunday",      "2006-10-08"]
+];
+
+derbycal.startDate = derbycal.days[0][1];
+derbycal.endDate   = derbycal.days[6][1];
+
+derbycal.offline   = false;
+
+/** 
+ * Log in to Google Calendar
+ */
+derbycal.login = function() {
+    var statusText = document.getElementById("loggingIn");
+    statusText.style.visibility = "visible";
+
+    var loginForm = document.loginForm;
+    derbycal.user = loginForm.user.value;
+    derbycal.password = loginForm.password.value;
+
+    try {
+        // Get the events list from  Google Calendar
+        calapplet.login(derbycal.calid, derbycal.gmtOffset, 
+            derbycal.user, derbycal.password,
+            derbycal.startDate, derbycal.endDate, false);
+
+
+    } catch ( e ) {
+        alert("Error logging in to calendar : " + 
+            derbycal.getExceptionMessage(e));
+        return;
+    }
+
+    var loginDiv = document.getElementById("login-div");
+    loginDiv.style.display = "none";
+
+    var mainDiv = document.getElementById("main-div");
+    mainDiv.style.visibility = "visible";
+    
+    derbycal.refreshCalendar();
+
+    derbycal.setPageOffline(false);
+}
+
+// Start working offline without logging in
+derbycal.startOffline = function () {
+    derbycal.goOffline();
+    var mainDiv = document.getElementById("main-div");
+    mainDiv.style.visibility = "visible";
+    derbycal.refreshCalendar();
+
+    document.getElementById("workOfflineButton").style.visibility = "hidden";
+    document.getElementById("loginHeader").style.visibility = "hidden";
+    document.getElementById("onlineButton").disabled = true;
+}
+
+derbycal.goOffline = function() {
+    calapplet.goOffline();
+    derbycal.setPageOffline(true);
+}
+
+derbycal.setPageOffline = function(offline) {
+    derbycal.offline = offline;
+    document.offlineForm.offlineButton.disabled = offline;
+    document.offlineForm.onlineButton.disabled  = !offline;
+
+    var bodyElement = document.getElementById("body");
+    if ( offline ) {
+        bodyElement.style.background = derbycal.offlineColor;    
+    } else {
+        bodyElement.style.background = derbycal.onlineColor;    
+    }
+}
+
+derbycal.goOnline = function() {
+    var status = document.getElementById("goingOnline");
+    // This isn't working right... status.style.visibility = "visible";
+    try {
+        calapplet.goOnline();
+    } catch ( e ) {
+        alert("Error going online: " + derbycal.getExceptionMessage(e));
+    }
+    status.style.visibility = "hidden";    
+    derbycal.setPageOffline(false);
+
+    var conflicts = calapplet.getConflicts();
+    if ( conflicts != null ) {
+        alert(conflicts);
+    }
+
+    derbycal.checkOffline();
+    derbycal.refreshCalendar();
+}
+
+// Check to see if we're offline, and if so fix the page to indicate this
+// Should do this after each invocation to derbycal
+derbycal.checkOffline = function() {
+    if ( derbycal.offline ) {
+        return;
+    }
+
+    if ( ! calapplet.isOnline() ) {
+        derbycal.setPageOffline(true);
+        alert("Unable to communicate with Google Calendar; " +
+            "going offline.");
+    }
+}
+
+
+// Get the events from the Google Calendar
+derbycal.refreshCalendar = function() {
+
+    // Get the list of events from Google Calendar
+    var eventStr = calapplet.refresh();
+
+    derbycal.loadEvents(eventStr);
+    derbycal.checkOffline();
+}
+
+//
+// Load events onto the page from a JSON array containing
+// the events
+//
+derbycal.loadEvents = function(eventStr) {
+    var events = eval('(' + eventStr + ')');
+
+    // First, clear the calendar on the web page
+    derbycal.clearCalendarOnPage();
+
+    var i = 0;
+    while ( events != null  &&  i < events.length ) {
+        var event = events[i++];
+        derbycal.addEventToPage(event.eventid, event.day, event.title);
+    }
+}
+derbycal.clearCalendarOnPage = function() {
+    var i = 0;
+    var days = "";
+    while ( i < derbycal.days.length ) {
+        var day = derbycal.days[i++][0];
+  
+        var dayrow = document.getElementById(day);
+  
+        var j = dayrow.childNodes.length - 1;
+        while ( j > 1 ) {
+            dayrow.removeChild(dayrow.childNodes[j--]);
+        }
+    }
+}
+  
+
+derbycal.postNewEvent = function() {
+    // Get the form data
+    var day     = document.newEventForm.eventDay.value;
+    var title   = document.newEventForm.eventTitle.value;
+
+    // Generate a unique id for it
+    var id = derbycal.getUniqueId();
+
+    var date = derbycal.getDateForDay(day);
+
+    // Tell our applet to save this
+    try {
+
+        var eventJSON = calapplet.addEvent(id, date, title);
+        var event = eval( "(" + eventJSON + ")" );
+        id = event.eventid;
+
+        // Update the HTML
+        derbycal.addEventToPage(id, day, title);
+    } catch ( e ) {
+        alert("Unable to add event: " + derbycal.getExceptionMessage(e));
+    }
+    derbycal.checkOffline();
+}
+
+derbycal.getDateForDay = function(day) {
+    var i = 0;
+    while ( i < derbycal.days.length ) {
+        if ( derbycal.days[i][0] == day )
+            return derbycal.days[i][1];
+        else
+            i++;
+    }
+
+    throw "The day specified, " + day + " is not one I recognize";
+}
+
+derbycal.addEventToPage = function(id, day, title) {
+    // Get the table for the specified day
+    var table = document.getElementById(day);
+
+    if ( table == null ) {
+        alert("Can't find the HTML element for day " + day);
+        return;
+    }
+
+    var tr = document.createElement("tr");
+    // tr.class        = "event";
+    tr.className    = "event";  // for IE
+    tr.id           = id;
+
+    tr.innerHTML =  
+        '<td><input type="image" src="images/delete.gif" ' +
+        'onclick="derbycal.deleteEvent(this); return false;"</td>' +
+        '<td>&nbsp;&nbsp;&nbsp;</td>' +
+        '<td><input type="text" size="70" ' +
+        'class="input-box"' + 
+        'onchange="derbycal.updateEvent(this); return false;" ' + 
+        'value="' + title + '"></input></td>';
+
+    table.appendChild(tr);
+}
+
+/**
+ * Update the event
+ * 
+ *  element - the DOM element for the input box for this event.
+ *      This is used to get to the enclosing row, which has the id for this
+ *      event.
+ */
+derbycal.updateEvent = function(element) {
+    var id = element.parentNode.id;
+
+    // tell our applet to update this
+    try {
+        calapplet.updateEvent(id, element.value);
+    } catch (e) {
+        alert("Unable to update event: " + derbycal.getExceptionMessage(e));
+
+        // Simple Big Hammer approach to fixing things.  Can get more
+        // refined if you want to by remembering the old value and resetting
+        // it...
+        derbycal.refreshCalendar();
+    }
+    derbycal.checkOffline();
+}
+
+/**
+ * Delete the event
+ *
+ *  element - the DOM element for the Delete button.  This is used
+ *      to get the parent and delete the whole row
+ */
+derbycal.deleteEvent = function(element) {
+    var row = element.parentNode;
+    var id = row.id;
+
+    // now tell our applet to delete this
+    try {
+        calapplet.deleteEvent(id);
+    } catch (e) {
+        alert("Unable to delete event from Google Calendar: " + 
+            derbycal.getExceptionMessage(e));
+        return;
+    }
+            
+    row.parentNode.removeChild(row);
+    derbycal.checkOffline();
+}
+
+/**
+ * Get a temporary unique id.  This isn't perfect, but it will do for our purposes.
+ * If you have a better algorithm, please feel free to use it!
+ *
+ * This one was scraped from the web at
+ *
+ * http://www.sitepoint.com/forums/showthread.php?t=318819
+ */
+derbycal.getUniqueId = function() {
+	return Math.random() * Math.pow(10, 17) + Math.random() * 
+            Math.pow(10, 17) + Math.random() * Math.pow(10, 17) + 
+            Math.random() * Math.pow(10, 17);
+}
+
+derbycal.getExceptionMessage = function(e) {
+    // Java exceptions (at least in Firefox) are stacked underneath
+    // a PrivilegedActionException and then an InvocationTargetException,
+    // so we have to dig deep to get the real message.  
+    //
+    // I suspect other browsers do this differently so your mileage may
+    // vary, and I can see this turning into a very "rich" function
+    //
+    if ( e.getException ) {
+        var exc = e.getException().getCause().getCause();
+        return exc.getClass().getName() + ": " + exc.getMessage() + ".  Please " +
+            "see the Java Console for more information";
+    } else if ( e.getMessage ) {
+        return e.getMessage + ". Please see the Java Console for more information.";
+    } else {
+        return e;
+    }
+}

Propchange: db/derby/code/trunk/java/demo/localcal/src/localcal.js
------------------------------------------------------------------------------
    svn:eol-style = native