001: //package statement
002: package com.salmonllc.examples.example19;
003:
004: //The Salmon Open Framework for Internet Applications (SOFIA)
005: //Copyright (C) 1999 - 2002, Salmon LLC
006: //
007: //This program is free software; you can redistribute it and/or
008: //modify it under the terms of the GNU General Public License version 2
009: //as published by the Free Software Foundation;
010: //
011: //This program is distributed in the hope that it will be useful,
012: //but WITHOUT ANY WARRANTY; without even the implied warranty of
013: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: //GNU General Public License for more details.
015: //
016: //You should have received a copy of the GNU General Public License
017: //along with this program; if not, write to the Free Software
018: //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: //
020: //For more information please visit http://www.salmonllc.com
021:
022: //Salmon import statements
023: import java.text.ParseException;
024: import java.text.SimpleDateFormat;
025: import java.util.Date;
026: import java.util.GregorianCalendar;
027:
028: import com.salmonllc.jsp.*;
029: import com.salmonllc.html.HtmlLookUpComponent;
030: import com.salmonllc.html.HtmlScriptGenerator;
031: import com.salmonllc.html.events.*;
032:
033: /**
034: * This controller is for the calendar popup window. It is used to set the current date of the
035: * calendar to the one specified in the lookup component
036: */
037: public class CalendarLookupController extends JspController implements
038: PageListener, SubmitListener {
039:
040: //Visual Components
041: public com.salmonllc.html.HtmlCalendar _calendar1;
042: public com.salmonllc.jsp.JspLink _cancel;
043: public com.salmonllc.jsp.JspLink _today;
044:
045: /**
046: * Initialize the page. Set up listeners and perform other initialization activities.
047: */
048: public void initialize() {
049: addPageListener(this );
050: _today.addSubmitListener(this );
051: }
052:
053: /**
054: * Set the month and year from the selected month and year in the calendar
055: * @param event the page event to be processed
056: */
057: public void pageRequested(PageEvent event) {
058: if (!isReferredByCurrentPage()) {
059:
060: //set the appropriate script for the cancel button
061: HtmlScriptGenerator gen = new HtmlScriptGenerator(this );
062: _cancel.setHref("javascript:"
063: + gen.generateCancelLookupScript());
064:
065: //set the month and year
066: String val = HtmlLookUpComponent.getParentLookupValue(this );
067: if (val != null) {
068: String format = HtmlLookUpComponent
069: .getParentLookupFormat(this );
070: SimpleDateFormat df = new SimpleDateFormat(format);
071: try {
072: Date d = df.parse(val);
073: GregorianCalendar cal = new GregorianCalendar();
074: cal.setTime(d);
075: _calendar1.setCalendarYear(cal
076: .get(GregorianCalendar.YEAR));
077: _calendar1.setCalendarMonth(cal
078: .get(GregorianCalendar.MONTH));
079: } catch (ParseException e) {
080: }
081: }
082: }
083: }
084:
085: public void pageRequestEnd(PageEvent event) {
086: }
087:
088: public void pageSubmitEnd(PageEvent event) {
089: }
090:
091: public void pageSubmitted(PageEvent event) {
092: }
093:
094: public boolean submitPerformed(SubmitEvent e) throws Exception {
095: HtmlLookUpComponent comp = getPopupLookupComponent();
096: String lookupFormat = comp.getEditField().getDisplayFormat();
097: HtmlScriptGenerator gen = new HtmlScriptGenerator(this );
098: String dtString = null;
099: Date d = new Date(System.currentTimeMillis());
100: if (lookupFormat != null) {
101: SimpleDateFormat df = new SimpleDateFormat(lookupFormat);
102: dtString = df.format(d);
103: } else {
104: dtString = d.toString();
105: }
106: writeScript(gen.generateReturnValueToLookupScript(dtString, ""));
107: return true;
108: }
109:
110: }
|