From: Marc Englund Date: Fri, 17 Aug 2007 08:01:06 +0000 (+0000) Subject: Calendar component added + demo and refactoring. X-Git-Tag: 6.7.0.beta1~6091 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2f77bbabb6c4b04feb458f661b200e5059990588;p=vaadin-framework.git Calendar component added + demo and refactoring. svn changeset:2043/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/demo/HelloWorld.java b/src/com/itmill/toolkit/demo/HelloWorld.java index d4ab04e486..e2001a73cd 100644 --- a/src/com/itmill/toolkit/demo/HelloWorld.java +++ b/src/com/itmill/toolkit/demo/HelloWorld.java @@ -1,6 +1,13 @@ package com.itmill.toolkit.demo; -import com.itmill.toolkit.ui.*; +import java.util.Date; + +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.CalendarField; +import com.itmill.toolkit.ui.DateField; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.Window; /** * The classic "hello, world!" example for IT Mill Toolkit. The class simply @@ -19,8 +26,10 @@ public class HelloWorld extends com.itmill.toolkit.Application { * com.itmill.toolkit.service.Application class. It will be automatically * called by the framework when a user accesses the application. */ + OrderedLayout l; public void init() { + setTheme("demo"); /* * - Create new window for the application - Give the window a visible * title - Set the window to be the main window of the application @@ -28,15 +37,44 @@ public class HelloWorld extends com.itmill.toolkit.Application { Window main = new Window("Hello window"); setMainWindow(main); + main.addComponent(new DateField()); + main.addComponent(new CalendarField()); + /* * - Create a label with the classic text - Add the label to the main * window */ - main.addComponent(new Label("Hello World!")); + main.addComponent(new Label("Hello4 World!")); + + l = new OrderedLayout(); + main.addComponent(l); + l.addComponent(new Button("foo",this,"foo")); + l.addComponent(new Button("asd",this,"asd")); /* * And that's it! The framework will display the main window and its * contents when the application is accessed with the terminal. */ } + + public void foo() { + long s = new Date().getTime(); + System.out.println("> foo: " + s); + try { + Thread.currentThread().sleep(5000); + } catch (Exception e) { + + } + System.out.println("< foo: " + s); + } + public void asd() { + long s = new Date().getTime(); + System.out.println("> asd: " + s); + try { + Thread.currentThread().sleep(5000); + } catch (Exception e) { + + } + System.out.println("< asd: " + s); + } } diff --git a/src/com/itmill/toolkit/demo/util/SampleCalendarDatabase.java b/src/com/itmill/toolkit/demo/util/SampleCalendarDatabase.java new file mode 100644 index 0000000000..d27756b4f5 --- /dev/null +++ b/src/com/itmill/toolkit/demo/util/SampleCalendarDatabase.java @@ -0,0 +1,162 @@ +package com.itmill.toolkit.demo.util; + +import java.sql.Connection; +import java.sql.Date; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Timestamp; + +/** + * Creates temporary database named toolkit with sample table named employee and + * populates it with data. By default we use HSQLDB. Ensure that you have + * hsqldb.jar under WEB-INF/lib directory. Database is will be created into + * memory. + * + * @author IT Mill Ltd. + * + */ +public class SampleCalendarDatabase { + + public static final int ENTRYCOUNT = 100; + + public static final String DB_TABLE_NAME = "calendar"; + public static final String PROPERTY_ID_START = "EVENTSTART"; + public static final String PROPERTY_ID_END = "EVENTEND"; + public static final String PROPERTY_ID_TITLE = "TITLE"; + public static final String PROPERTY_ID_NOTIME = "NOTIME"; + + private Connection connection = null; + + private static final String[] titles = new String[] { "Meeting", "Dentist", + "Haircut", "Bank", "Birthday", "Library", "Rent", "Acme test", "Party" }; + + /** + * Create temporary database. + * + */ + public SampleCalendarDatabase() { + // connect to SQL database + connect(); + + // initialize SQL database + createTables(); + + // test by executing sample JDBC query + testDatabase(); + } + + /** + * Creates sample table named employee and populates it with data.Use the + * specified database connection. + * + * @param connection + */ + public SampleCalendarDatabase(Connection connection) { + // initialize SQL database + createTables(); + + // test by executing sample JDBC query + testDatabase(); + } + + /** + * Connect to SQL database. In this sample we use HSQLDB and an toolkit + * named database in implicitly created into system memory. + * + */ + private void connect() { + // use memory-Only Database + String url = "jdbc:hsqldb:mem:toolkit"; + try { + Class.forName("org.hsqldb.jdbcDriver").newInstance(); + connection = DriverManager.getConnection(url, "sa", ""); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * use for SQL commands CREATE, DROP, INSERT and UPDATE + * + * @param expression + * @throws SQLException + */ + public void update(String expression) throws SQLException { + Statement st = null; + st = connection.createStatement(); + int i = st.executeUpdate(expression); + if (i == -1) { + System.out.println("SampleDatabase error : " + expression); + } + st.close(); + } + + /** + * Create test table and few rows. Issue note: using capitalized column + * names as HSQLDB returns column names in capitalized form with this demo. + * + */ + private void createTables() { + try { + String stmt = null; + stmt = "CREATE TABLE "+DB_TABLE_NAME+" ( ID INTEGER IDENTITY, TITLE VARCHAR(100), " + + "EVENTSTART DATETIME, EVENTEND DATETIME, NOTIME BOOLEAN )"; + update(stmt); + for (int j = 0; j < ENTRYCOUNT; j++) { + Timestamp start = new Timestamp(new java.util.Date().getTime()); + start.setDate((int)((Math.random()-0.4) * 200)); + start.setMinutes(0); + start.setHours(8+(int)Math.random()*12); + Timestamp end = new Timestamp(start.getTime()); + if (Math.random()<0.7) { + long t = end.getTime(); + long hour = 60 * 60 * 1000; + t = t + hour + (long)(Math.round(Math.random() * 3 * hour)); + end.setTime(t); + } + + stmt = "INSERT INTO "+DB_TABLE_NAME+"(TITLE, EVENTSTART, EVENTEND, NOTIME) VALUES (" + + "'" + + titles[(int) (Math.round(Math.random() * (titles.length - 1)))] + + "','" + + start + + "','" + + end + + "'," + + (Math.random()>0.7) + + ")"; + update(stmt); + } + } catch (SQLException e) { + if (e.toString().indexOf("Table already exists") == -1) + throw new RuntimeException(e); + } + } + + /** + * Test database connection with simple SELECT command. + * + */ + private String testDatabase() { + String result = null; + try { + Statement stmt = connection.createStatement( + ResultSet.TYPE_SCROLL_INSENSITIVE, + ResultSet.CONCUR_UPDATABLE); + ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM "+DB_TABLE_NAME); + rs.next(); + result = "rowcount for table test is " + rs.getObject(1).toString(); + stmt.close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + return result; + } + + public Connection getConnection() { + return connection; + } + +} diff --git a/src/com/itmill/toolkit/terminal/gwt/client/DateTimeService.java b/src/com/itmill/toolkit/terminal/gwt/client/DateTimeService.java index 77429b0a04..10e2a31837 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/DateTimeService.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/DateTimeService.java @@ -2,174 +2,250 @@ package com.itmill.toolkit.terminal.gwt.client; import java.util.Date; +import com.itmill.toolkit.terminal.gwt.client.ui.IDateField; + /** - * This class provides date/time parsing services to - * all components on the client side. + * This class provides date/time parsing services to all components on the + * client side. * * @author IT Mill Ltd. - * + * */ public class DateTimeService { - - private String currentLocale; - - private static int [] maxDaysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - - /** - * Creates a new date time service with the application default locale. - */ - public DateTimeService() { - currentLocale = LocaleService.getDefaultLocale(); - } - - /** - * Creates a new date time service with a given locale. - * - * @param locale e.g. fi, en etc. - * @throws LocaleNotLoadedException - */ - public DateTimeService(String locale) throws LocaleNotLoadedException { - setLocale(locale); - } - - public void setLocale(String locale) throws LocaleNotLoadedException { - if(LocaleService.getAvailableLocales().contains(locale)) - currentLocale = locale; - else throw new LocaleNotLoadedException(locale); - } - - public String getLocale() { - return currentLocale; - } - - public String getMonth(int month) { - try { - return LocaleService.getMonthNames(currentLocale)[month]; - } catch (LocaleNotLoadedException e) { - // TODO redirect to console - System.out.println(e + ":" + e.getMessage()); - } - return null; - } - - public String getShortMonth(int month) { - try { - return LocaleService.getShortMonthNames(currentLocale)[month]; - } catch (LocaleNotLoadedException e) { - // TODO redirect to console - System.out.println(e + ":" + e.getMessage()); - } - return null; - } - - public String getDay(int day) { - try { - return LocaleService.getDayNames(currentLocale)[day]; - } catch (LocaleNotLoadedException e) { - // TODO redirect to console - System.out.println(e + ":" + e.getMessage()); - } - return null; - } - - public String getShortDay(int day) { - try { - return LocaleService.getShortDayNames(currentLocale)[day]; - } catch (LocaleNotLoadedException e) { - // TODO redirect to console - System.out.println(e + ":" + e.getMessage()); - } - return null; - } - - public int getFirstDayOfWeek() { - try { - return LocaleService.getFirstDayOfWeek(currentLocale); - } catch (LocaleNotLoadedException e) { - // TODO redirect to console - System.out.println(e + ":" + e.getMessage()); - } - return 0; - } - - public boolean isTwelveHourClock() { - try { - return LocaleService.isTwelveHourClock(currentLocale); - } catch (LocaleNotLoadedException e) { - // TODO redirect to console - System.out.println(e + ":" + e.getMessage()); - } - return false; - } - - public String getClockDelimeter() { - try { - return LocaleService.getClockDelimiter(currentLocale); - } catch (LocaleNotLoadedException e) { - // TODO redirect to console - System.out.println(e + ":" + e.getMessage()); - } - return ":"; - } - - public String[] getAmPmStrings() { - try { - return LocaleService.getAmPmStrings(currentLocale); - } catch (LocaleNotLoadedException e) { - // TODO redirect to console - System.out.println(e + ":" + e.getMessage()); - } - String[] temp = new String[2]; - temp[0] = "AM"; - temp[1] = "PM"; - return temp; - } - - public int getStartWeekDay(Date date){ - Date dateForFirstOfThisMonth = new Date(date.getYear(), date.getMonth(), 1); - int firstDay; - try { - firstDay = LocaleService.getFirstDayOfWeek(currentLocale); - } catch (LocaleNotLoadedException e) { - firstDay = 0; - // TODO redirect to console - System.out.println(e + ":" + e.getMessage()); - } - int start = dateForFirstOfThisMonth.getDay() - firstDay; - if(start < 0) start = 6; - return start; - } - - public String getDateFormat() { - try { - return LocaleService.getDateFormat(currentLocale); - } catch (LocaleNotLoadedException e) { - // TODO redirect to console - System.out.println(e + ":" + e.getMessage()); - } - return "M/d/yy"; - } - - public static int getNumberOfDaysInMonth(Date date){ - int month = date.getMonth(); - if(month == 1 && true == isLeapYear(date)) - return 29; - return maxDaysInMonth[month]; - } - - public static boolean isLeapYear(Date date){ - // Instantiate the date for 1st March of that year - Date firstMarch = new Date(date.getYear(), 2, 1); - - // Go back 1 day - long firstMarchTime = firstMarch.getTime(); - long lastDayTimeFeb = firstMarchTime - (24*60*60*1000); // NUM_MILLISECS_A_DAY - - //Instantiate new Date with this time - Date febLastDay = new Date(lastDayTimeFeb); - - // Check for date in this new instance - return (29 == febLastDay.getDate()) ? true : false; - } + public static int RESOLUTION_YEAR = 0; + public static int RESOLUTION_MONTH = 1; + public static int RESOLUTION_DAY = 2; + public static int RESOLUTION_HOUR = 3; + public static int RESOLUTION_MIN = 4; + public static int RESOLUTION_SEC = 5; + public static int RESOLUTION_MSEC = 6; + + private String currentLocale; + + private static int[] maxDaysInMonth = { 31, 28, 31, 30, 31, 30, 31, 31, 30, + 31, 30, 31 }; + + /** + * Creates a new date time service with the application default locale. + */ + public DateTimeService() { + currentLocale = LocaleService.getDefaultLocale(); + } + + /** + * Creates a new date time service with a given locale. + * + * @param locale + * e.g. fi, en etc. + * @throws LocaleNotLoadedException + */ + public DateTimeService(String locale) throws LocaleNotLoadedException { + setLocale(locale); + } + + public void setLocale(String locale) throws LocaleNotLoadedException { + if (LocaleService.getAvailableLocales().contains(locale)) + currentLocale = locale; + else + throw new LocaleNotLoadedException(locale); + } + + public String getLocale() { + return currentLocale; + } + + public String getMonth(int month) { + try { + return LocaleService.getMonthNames(currentLocale)[month]; + } catch (LocaleNotLoadedException e) { + // TODO redirect to console + System.out.println(e + ":" + e.getMessage()); + } + return null; + } + + public String getShortMonth(int month) { + try { + return LocaleService.getShortMonthNames(currentLocale)[month]; + } catch (LocaleNotLoadedException e) { + // TODO redirect to console + System.out.println(e + ":" + e.getMessage()); + } + return null; + } + + public String getDay(int day) { + try { + return LocaleService.getDayNames(currentLocale)[day]; + } catch (LocaleNotLoadedException e) { + // TODO redirect to console + System.out.println(e + ":" + e.getMessage()); + } + return null; + } + + public String getShortDay(int day) { + try { + return LocaleService.getShortDayNames(currentLocale)[day]; + } catch (LocaleNotLoadedException e) { + // TODO redirect to console + System.out.println(e + ":" + e.getMessage()); + } + return null; + } + + public int getFirstDayOfWeek() { + try { + return LocaleService.getFirstDayOfWeek(currentLocale); + } catch (LocaleNotLoadedException e) { + // TODO redirect to console + System.out.println(e + ":" + e.getMessage()); + } + return 0; + } + + public boolean isTwelveHourClock() { + try { + return LocaleService.isTwelveHourClock(currentLocale); + } catch (LocaleNotLoadedException e) { + // TODO redirect to console + System.out.println(e + ":" + e.getMessage()); + } + return false; + } + + public String getClockDelimeter() { + try { + return LocaleService.getClockDelimiter(currentLocale); + } catch (LocaleNotLoadedException e) { + // TODO redirect to console + System.out.println(e + ":" + e.getMessage()); + } + return ":"; + } + + public String[] getAmPmStrings() { + try { + return LocaleService.getAmPmStrings(currentLocale); + } catch (LocaleNotLoadedException e) { + // TODO redirect to console + System.out.println(e + ":" + e.getMessage()); + } + String[] temp = new String[2]; + temp[0] = "AM"; + temp[1] = "PM"; + return temp; + } + + public int getStartWeekDay(Date date) { + Date dateForFirstOfThisMonth = new Date(date.getYear(), + date.getMonth(), 1); + int firstDay; + try { + firstDay = LocaleService.getFirstDayOfWeek(currentLocale); + } catch (LocaleNotLoadedException e) { + firstDay = 0; + // TODO redirect to console + System.out.println(e + ":" + e.getMessage()); + } + int start = dateForFirstOfThisMonth.getDay() - firstDay; + if (start < 0) + start = 6; + return start; + } + + public String getDateFormat() { + try { + return LocaleService.getDateFormat(currentLocale); + } catch (LocaleNotLoadedException e) { + // TODO redirect to console + System.out.println(e + ":" + e.getMessage()); + } + return "M/d/yy"; + } + + public static int getNumberOfDaysInMonth(Date date) { + int month = date.getMonth(); + if (month == 1 && true == isLeapYear(date)) + return 29; + return maxDaysInMonth[month]; + } + + public static boolean isLeapYear(Date date) { + // Instantiate the date for 1st March of that year + Date firstMarch = new Date(date.getYear(), 2, 1); + + // Go back 1 day + long firstMarchTime = firstMarch.getTime(); + long lastDayTimeFeb = firstMarchTime - (24 * 60 * 60 * 1000); // NUM_MILLISECS_A_DAY + + // Instantiate new Date with this time + Date febLastDay = new Date(lastDayTimeFeb); + + // Check for date in this new instance + return (29 == febLastDay.getDate()) ? true : false; + } + + public static boolean isSameDay(Date d1, Date d2) { + return (getDayInt(d1) == getDayInt(d2)); + } + + public static boolean isInRange(Date date, Date rangeStart, Date rangeEnd, + int resolution) { + Date s; + Date e; + if (rangeStart.after(rangeEnd)) { + s = rangeEnd; + e = rangeStart; + } else { + e = rangeEnd; + s = rangeStart; + } + if (date.getYear() < s.getYear() || date.getYear() > e.getYear()) { + return false; + } else if (resolution == RESOLUTION_YEAR) { + return true; + } + if (date.getMonth() < s.getMonth() || date.getMonth() > e.getMonth()) { + return false; + } else if (resolution == RESOLUTION_MONTH) { + return true; + } + if (date.getDate() < s.getDate() || date.getDate() > e.getDate()) { + return false; + } else if (resolution == RESOLUTION_DAY) { + return true; + } + if (date.getHours() < s.getHours() || date.getHours() > e.getHours()) { + return false; + } else if (resolution == RESOLUTION_HOUR) { + return true; + } + if (date.getMinutes() < s.getMinutes() + || date.getMinutes() > e.getMinutes()) { + return false; + } else if (resolution == RESOLUTION_MIN) { + return true; + } + if (date.getSeconds() < s.getSeconds() + || date.getSeconds() > e.getSeconds()) { + return false; + } else if (resolution == RESOLUTION_SEC) { + return true; + } + if (date.getTime() < s.getTime() || date.getTime() > e.getTime()) { + return false; + } else { + return true; + } + } + + private static int getDayInt(Date date) { + int y = date.getYear(); + int m = date.getMonth(); + int d = date.getDate(); + + return ((y + 1900) * 10000 + m * 100 + d) * 1000000000; + } } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java b/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java index 10263d9dcb..7a2c7a2136 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java @@ -3,11 +3,12 @@ package com.itmill.toolkit.terminal.gwt.client; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.ui.Widget; import com.itmill.toolkit.terminal.gwt.client.ui.IButton; -import com.itmill.toolkit.terminal.gwt.client.ui.ICalendar; import com.itmill.toolkit.terminal.gwt.client.ui.ICheckBox; import com.itmill.toolkit.terminal.gwt.client.ui.IComponent; import com.itmill.toolkit.terminal.gwt.client.ui.ICustomLayout; +import com.itmill.toolkit.terminal.gwt.client.ui.IDateFieldCalendar; import com.itmill.toolkit.terminal.gwt.client.ui.IEmbedded; +import com.itmill.toolkit.terminal.gwt.client.ui.IEntryCalendar; import com.itmill.toolkit.terminal.gwt.client.ui.IForm; import com.itmill.toolkit.terminal.gwt.client.ui.IGridLayout; import com.itmill.toolkit.terminal.gwt.client.ui.ILabel; @@ -35,229 +36,199 @@ import com.itmill.toolkit.terminal.gwt.client.ui.IWindow; public class DefaultWidgetFactory implements WidgetFactory { - public Widget createWidget(UIDL uidl) { + public Widget createWidget(UIDL uidl) { - String className = resolveWidgetTypeName(uidl); + String className = resolveWidgetTypeName(uidl); - if ("com.itmill.toolkit.terminal.gwt.client.ui.ICheckBox".equals(className)) { - return new ICheckBox(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IButton".equals(className)) { - return new IButton(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IView".equals(className)) { - // TODO remove IView? - return new IView(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IWindow".equals(className)) { - return new IWindow(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutVertical".equals(className)) { - return new IOrderedLayoutVertical(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutHorizontal".equals(className)) { - return new IOrderedLayoutHorizontal(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ILabel".equals(className)) { - return new ILabel(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ILink".equals(className)) { - return new ILink(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IGridLayout".equals(className)) { - return new IGridLayout(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ITree".equals(className)) { - return new ITree(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IOptionGroup".equals(className)) { - return new IOptionGroup(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ITwinColSelect".equals(className)) { - return new ITwinColSelect(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ISelect".equals(className)) { - return new ISelect(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IPanel".equals(className)) { - return new IPanel(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IComponent".equals(className)) { - return new IComponent(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ITabsheet".equals(className)) { - return new ITabsheet(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IEmbedded".equals(className)) { - return new IEmbedded(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ICustomLayout".equals(className)) { - return new ICustomLayout(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ITextArea".equals(className)) { - return new ITextArea(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IPasswordField".equals(className)) { - return new IPasswordField(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ITextField".equals(className)) { - return new ITextField(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ITablePaging".equals(className)) { - return new ITablePaging(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IScrollTable".equals(className)) { - return new IScrollTable(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ICalendar".equals(className)) { - return new ICalendar(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ITextualDate".equals(className)) { - return new ITextualDate(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IPopupCalendar".equals(className)) { - return new IPopupCalendar(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ISlider".equals(className)) { - return new ISlider(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IForm".equals(className)) { - return new IForm(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IUpload".equals(className)) { - return new IUpload(); - } - return new IUnknownComponent(); - - /* TODO: Class based impl, use when GWT supports - return (Widget)GWT.create(resolveWidgetClass(uidl)); - */ + if ("com.itmill.toolkit.terminal.gwt.client.ui.ICheckBox" + .equals(className)) { + return new ICheckBox(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IButton" + .equals(className)) { + return new IButton(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IView" + .equals(className)) { + // TODO remove IView? + return new IView(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IWindow" + .equals(className)) { + return new IWindow(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutVertical" + .equals(className)) { + return new IOrderedLayoutVertical(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutHorizontal" + .equals(className)) { + return new IOrderedLayoutHorizontal(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ILabel" + .equals(className)) { + return new ILabel(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ILink" + .equals(className)) { + return new ILink(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IGridLayout" + .equals(className)) { + return new IGridLayout(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ITree" + .equals(className)) { + return new ITree(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IOptionGroup" + .equals(className)) { + return new IOptionGroup(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ITwinColSelect" + .equals(className)) { + return new ITwinColSelect(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ISelect" + .equals(className)) { + return new ISelect(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IPanel" + .equals(className)) { + return new IPanel(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IComponent" + .equals(className)) { + return new IComponent(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ITabsheet" + .equals(className)) { + return new ITabsheet(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IEmbedded" + .equals(className)) { + return new IEmbedded(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ICustomLayout" + .equals(className)) { + return new ICustomLayout(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ITextArea" + .equals(className)) { + return new ITextArea(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IPasswordField" + .equals(className)) { + return new IPasswordField(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ITextField" + .equals(className)) { + return new ITextField(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ITablePaging" + .equals(className)) { + return new ITablePaging(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IScrollTable" + .equals(className)) { + return new IScrollTable(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IDateFieldCalendar" + .equals(className)) { + return new IDateFieldCalendar(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IEntryCalendar" + .equals(className)) { + return new IEntryCalendar(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ITextualDate" + .equals(className)) { + return new ITextualDate(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IPopupCalendar" + .equals(className)) { + return new IPopupCalendar(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ISlider" + .equals(className)) { + return new ISlider(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IForm" + .equals(className)) { + return new IForm(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IUpload" + .equals(className)) { + return new IUpload(); } + return new IUnknownComponent(); - private String resolveWidgetTypeName(UIDL uidl) { + /* + * TODO: Class based impl, use when GWT supports return + * (Widget)GWT.create(resolveWidgetClass(uidl)); + */ + } - String tag = uidl.getTag(); - if ("button".equals(tag)) { - if ("switch".equals(uidl.getStringAttribute("type"))) { - return "com.itmill.toolkit.terminal.gwt.client.ui.ICheckBox"; - } else { - return "com.itmill.toolkit.terminal.gwt.client.ui.IButton"; - } - } else if ("window".equals(tag)) { - return "com.itmill.toolkit.terminal.gwt.client.ui.IWindow"; - } else if ("orderedlayout".equals(tag)) { - if ("horizontal".equals(uidl.getStringAttribute("orientation"))) { - return "com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutHorizontal"; - } else { - return "com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutVertical"; - } - } else if ("label".equals(tag)) { - return "com.itmill.toolkit.terminal.gwt.client.ui.ILabel"; - } else if ("link".equals(tag)) { - return "com.itmill.toolkit.terminal.gwt.client.ui.ILink"; - } else if ("gridlayout".equals(tag)) { - return "com.itmill.toolkit.terminal.gwt.client.ui.IGridLayout"; - } else if ("tree".equals(tag)) { - return "com.itmill.toolkit.terminal.gwt.client.ui.ITree"; - } else if ("select".equals(tag)) { - if ("optiongroup".equals(uidl.getStringAttribute("style"))) { - return "com.itmill.toolkit.terminal.gwt.client.ui.IOptionGroup"; - } else if ("twincol".equals(uidl.getStringAttribute("style"))) { - return "com.itmill.toolkit.terminal.gwt.client.ui.ITwinColSelect"; - } else { - return "com.itmill.toolkit.terminal.gwt.client.ui.ISelect"; - } - } else if ("panel".equals(tag)) { - return "com.itmill.toolkit.terminal.gwt.client.ui.IPanel"; - } else if ("component".equals(tag)) { - return "com.itmill.toolkit.terminal.gwt.client.ui.IComponent"; - } else if ("tabsheet".equals(tag)) { - return "com.itmill.toolkit.terminal.gwt.client.ui.ITabsheet"; - } else if ("embedded".equals(tag)) { - return "com.itmill.toolkit.terminal.gwt.client.ui.IEmbedded"; - } else if ("customlayout".equals(tag)) { - return "com.itmill.toolkit.terminal.gwt.client.ui.ICustomLayout"; - } else if ("textfield".equals(tag)) { - if (uidl.hasAttribute("multiline")) { - return "com.itmill.toolkit.terminal.gwt.client.ui.ITextArea"; - } else if (uidl.getBooleanAttribute("secret")) { - return "com.itmill.toolkit.terminal.gwt.client.ui.IPasswordField"; - } else { - return "com.itmill.toolkit.terminal.gwt.client.ui.ITextField"; - } - } else if ("table".equals(tag)) { - if (uidl.hasAttribute("style")) { - if ("paging".equals(uidl.getStringAttribute("style"))) { - return "com.itmill.toolkit.terminal.gwt.client.ui.ITablePaging"; - } - } else { - return "com.itmill.toolkit.terminal.gwt.client.ui.IScrollTable"; - } - } else if ("datefield".equals(tag)) { - if (uidl.hasAttribute("style")) { - if ("calendar".equals(uidl.getStringAttribute("style"))) { - return "com.itmill.toolkit.terminal.gwt.client.ui.ICalendar"; - } else if ("text".equals(uidl.getStringAttribute("style"))) { - return "com.itmill.toolkit.terminal.gwt.client.ui.ITextualDate"; - } - } else { - return "com.itmill.toolkit.terminal.gwt.client.ui.IPopupCalendar"; - } - } else if ("slider".equals(tag)) { - return "com.itmill.toolkit.terminal.gwt.client.ui.ISlider"; - } else if ("form".equals(tag)) { - return "com.itmill.toolkit.terminal.gwt.client.ui.IForm"; - } else if ("upload".equals(tag)) { - return "com.itmill.toolkit.terminal.gwt.client.ui.IUpload"; - } + private String resolveWidgetTypeName(UIDL uidl) { - return "com.itmill.toolkit.terminal.gwt.client.ui.IUnknownComponent"; - - /* TODO: Class based impl, use when GWT supports + String tag = uidl.getTag(); if ("button".equals(tag)) { - return IButton.class; + if ("switch".equals(uidl.getStringAttribute("type"))) { + return "com.itmill.toolkit.terminal.gwt.client.ui.ICheckBox"; + } else { + return "com.itmill.toolkit.terminal.gwt.client.ui.IButton"; + } } else if ("window".equals(tag)) { - return IView.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.IWindow"; } else if ("orderedlayout".equals(tag)) { if ("horizontal".equals(uidl.getStringAttribute("orientation"))) { - return IOrderedLayoutHorizontal.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutHorizontal"; } else { - return IOrderedLayoutVertical.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutVertical"; } } else if ("label".equals(tag)) { - return ILabel.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.ILabel"; } else if ("link".equals(tag)) { - return ILink.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.ILink"; } else if ("gridlayout".equals(tag)) { - return IGridLayout.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.IGridLayout"; } else if ("tree".equals(tag)) { - return ITree.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.ITree"; } else if ("select".equals(tag)) { if ("optiongroup".equals(uidl.getStringAttribute("style"))) { - return IOptionGroup.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.IOptionGroup"; } else if ("twincol".equals(uidl.getStringAttribute("style"))) { - return ITwinColSelect.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.ITwinColSelect"; } else { - return ISelect.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.ISelect"; } } else if ("panel".equals(tag)) { - return IPanel.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.IPanel"; } else if ("component".equals(tag)) { - return IComponent.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.IComponent"; } else if ("tabsheet".equals(tag)) { - return ITabsheet.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.ITabsheet"; } else if ("embedded".equals(tag)) { - return IEmbedded.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.IEmbedded"; } else if ("customlayout".equals(tag)) { - return ICustomLayout.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.ICustomLayout"; } else if ("textfield".equals(tag)) { if (uidl.hasAttribute("multiline")) { - return ITextArea.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.ITextArea"; } else if (uidl.getBooleanAttribute("secret")) { - return IPasswordField.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.IPasswordField"; } else { - return ITextField.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.ITextField"; } } else if ("table".equals(tag)) { if (uidl.hasAttribute("style")) { if ("paging".equals(uidl.getStringAttribute("style"))) { - return ITablePaging.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.ITablePaging"; } } else { - return IScrollTable.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.IScrollTable"; } } else if ("datefield".equals(tag)) { if (uidl.hasAttribute("style")) { if ("calendar".equals(uidl.getStringAttribute("style"))) { - return ICalendar.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.ICalendar"; } else if ("text".equals(uidl.getStringAttribute("style"))) { - return ITextualDate.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.ITextualDate"; } } else { - return IPopupCalendar.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.IPopupCalendar"; } + } else if ("calendarfield".equals(tag)) { + return "com.itmill.toolkit.terminal.gwt.client.ui.IEntryCalendar"; } else if ("slider".equals(tag)) { - return ISlider.class; + return "com.itmill.toolkit.terminal.gwt.client.ui.ISlider"; + } else if ("form".equals(tag)) { + return "com.itmill.toolkit.terminal.gwt.client.ui.IForm"; + } else if ("upload".equals(tag)) { + return "com.itmill.toolkit.terminal.gwt.client.ui.IUpload"; } - return IUnknownComponent.class; - */ - } + return "com.itmill.toolkit.terminal.gwt.client.ui.IUnknownComponent"; - public boolean isCorrectImplementation(Widget currentWidget, UIDL uidl) { - return GWT.getTypeName(currentWidget).equals(resolveWidgetTypeName(uidl)); - } + /* + * TODO: use class based impl when GWT supports it + */ + } + + public boolean isCorrectImplementation(Widget currentWidget, UIDL uidl) { + return GWT.getTypeName(currentWidget).equals( + resolveWidgetTypeName(uidl)); + } } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java deleted file mode 100644 index 6092b0cf0a..0000000000 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.itmill.toolkit.terminal.gwt.client.ui; - -import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; -import com.itmill.toolkit.terminal.gwt.client.UIDL; - -public class ICalendar extends IDateField { - - private ICalendarPanel date; - - public ICalendar() { - super(); - setStyleName(CLASSNAME+"-calendar"); - date = new ICalendarPanel(this); - add(date); - } - - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - super.updateFromUIDL(uidl, client); - date.updateCalendar(); - } - -} diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendarPanel.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendarPanel.java index 976994068c..8f3dc8a480 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendarPanel.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendarPanel.java @@ -1,6 +1,8 @@ package com.itmill.toolkit.terminal.gwt.client.ui; import java.util.Date; +import java.util.Iterator; +import java.util.List; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; @@ -15,276 +17,389 @@ import com.google.gwt.user.client.ui.TableListener; import com.google.gwt.user.client.ui.Widget; import com.itmill.toolkit.terminal.gwt.client.DateTimeService; import com.itmill.toolkit.terminal.gwt.client.LocaleService; +import com.itmill.toolkit.terminal.gwt.client.ui.calendar.ICalendarEntry; -public class ICalendarPanel extends FlexTable implements MouseListener, ClickListener { - - private IDateField datefield; - - private IEventButton prevYear; - private IEventButton nextYear; - private IEventButton prevMonth; - private IEventButton nextMonth; - - private ITime time; - - /* Needed to identify resolution changes */ - private int resolution = IDateField.RESOLUTION_YEAR; - - /* Needed to identify locale changes */ - private String locale = LocaleService.getDefaultLocale(); - - public ICalendarPanel(IDateField parent) { - datefield = parent; - setStyleName(datefield.CLASSNAME+"-calendarpanel"); - //buildCalendar(true); - addTableListener(new DateClickListener(this)); +public class ICalendarPanel extends FlexTable implements MouseListener, + ClickListener { + + private IDateField datefield; + + private IEventButton prevYear; + private IEventButton nextYear; + private IEventButton prevMonth; + private IEventButton nextMonth; + + private ITime time; + + private Date minDate = null; + private Date maxDate = null; + + private CalendarEntrySource entrySource; + + /* Needed to identify resolution changes */ + private int resolution = IDateField.RESOLUTION_YEAR; + + /* Needed to identify locale changes */ + private String locale = LocaleService.getDefaultLocale(); + + public ICalendarPanel(IDateField parent) { + datefield = parent; + setStyleName(datefield.CLASSNAME + "-calendarpanel"); + // buildCalendar(true); + addTableListener(new DateClickListener(this)); + } + + public ICalendarPanel(IDateField parent, Date min, Date max) { + datefield = parent; + setStyleName(datefield.CLASSNAME + "-calendarpanel"); + // buildCalendar(true); + addTableListener(new DateClickListener(this)); + } + + private void buildCalendar(boolean forceRedraw) { + boolean needsMonth = datefield.currentResolution > IDateField.RESOLUTION_YEAR; + boolean needsBody = datefield.currentResolution >= IDateField.RESOLUTION_DAY; + boolean needsTime = datefield.currentResolution >= IDateField.RESOLUTION_HOUR; + buildCalendarHeader(forceRedraw, needsMonth); + clearCalendarBody(!needsBody); + if (needsBody) + buildCalendarBody(); + if (needsTime) + buildTime(forceRedraw); + else if (time != null) { + remove(time); + time = null; } - - private void buildCalendar(boolean forceRedraw) { - boolean needsMonth = datefield.currentResolution > IDateField.RESOLUTION_YEAR; - boolean needsBody = datefield.currentResolution >= IDateField.RESOLUTION_DAY; - boolean needsTime = datefield.currentResolution >= IDateField.RESOLUTION_HOUR; - buildCalendarHeader(forceRedraw, needsMonth); - clearCalendarBody(!needsBody); - if(needsBody) - buildCalendarBody(); - if(needsTime) - buildTime(forceRedraw); - else if(time != null) { - remove(time); - time = null; + } + + private void clearCalendarBody(boolean remove) { + if (!remove) { + for (int row = 2; row < 8; row++) { + for (int col = 0; col < 7; col++) { + setHTML(row, col, " "); } + } + } else if (getRowCount() > 2) { + while (getRowCount() > 2) + removeRow(2); } + } - private void clearCalendarBody(boolean remove) { - if(!remove) { - for (int row = 2; row < 8; row++) { - for (int col = 0; col < 7; col++) { - setHTML(row, col, " "); - } - } - } else if(getRowCount() > 2) { - while(getRowCount() > 2) - removeRow(2); + private void buildCalendarHeader(boolean forceRedraw, boolean needsMonth) { + // Can't draw a calendar without a date :) + if (datefield.date == null) + datefield.date = new Date(); + + if (forceRedraw) { + if (prevMonth == null) { // Only do once + prevYear = new IEventButton(); + prevYear.setHTML("«"); + nextYear = new IEventButton(); + nextYear.setHTML("»"); + prevYear.addMouseListener(this); + nextYear.addMouseListener(this); + prevYear.addClickListener(this); + nextYear.addClickListener(this); + setWidget(0, 0, prevYear); + setWidget(0, 4, nextYear); + + if (needsMonth) { + prevMonth = new IEventButton(); + prevMonth.setHTML("‹"); + nextMonth = new IEventButton(); + nextMonth.setHTML("›"); + prevMonth.addMouseListener(this); + nextMonth.addMouseListener(this); + prevMonth.addClickListener(this); + nextMonth.addClickListener(this); + setWidget(0, 3, nextMonth); + setWidget(0, 1, prevMonth); } + + getFlexCellFormatter().setColSpan(0, 2, 3); + } else if (!needsMonth) { + // Remove month traverse buttons + prevMonth.removeClickListener(this); + prevMonth.removeMouseListener(this); + nextMonth.removeClickListener(this); + nextMonth.removeMouseListener(this); + remove(prevMonth); + remove(nextMonth); + prevMonth = null; + nextMonth = null; + } + + // Print weekday names + int firstDay = datefield.dts.getFirstDayOfWeek(); + for (int i = 0; i < 7; i++) { + int day = i + firstDay; + if (day > 6) + day = 0; + if (datefield.currentResolution > IDateField.RESOLUTION_MONTH) + setHTML(1, i, "" + datefield.dts.getShortDay(day) + + ""); + else + setHTML(1, i, ""); + } } - - private void buildCalendarHeader(boolean forceRedraw, boolean needsMonth) { - // Can't draw a calendar without a date :) - if(datefield.date == null) - datefield.date = new Date(); - - if(forceRedraw) { - if(prevMonth == null) { // Only do once - prevYear = new IEventButton(); prevYear.setHTML("«"); - nextYear = new IEventButton(); nextYear.setHTML("»"); - prevYear.addMouseListener(this); nextYear.addMouseListener(this); - prevYear.addClickListener(this); nextYear.addClickListener(this); - setWidget(0, 0, prevYear); - setWidget(0, 4, nextYear); - - if(needsMonth) { - prevMonth = new IEventButton(); prevMonth.setHTML("‹"); - nextMonth = new IEventButton(); nextMonth.setHTML("›"); - prevMonth.addMouseListener(this); nextMonth.addMouseListener(this); - prevMonth.addClickListener(this); nextMonth.addClickListener(this); - setWidget(0, 3, nextMonth); - setWidget(0, 1, prevMonth); + + String monthName = needsMonth ? datefield.dts.getMonth(datefield.date + .getMonth()) : ""; + int year = datefield.date.getYear() + 1900; + setHTML(0, 2, "" + monthName + " " + year + + ""); + } + + private void buildCalendarBody() { + Date date = datefield.date; + if (date == null) + date = new Date(); + int startWeekDay = datefield.dts.getStartWeekDay(date); + int numDays = DateTimeService.getNumberOfDaysInMonth(date); + int dayCount = 0; + Date today = new Date(); + Date curr = new Date(date.getTime()); + for (int row = 2; row < 8; row++) { + for (int col = 0; col < 7; col++) { + if (!(row == 2 && col < startWeekDay)) { + if (dayCount < numDays) { + int selectedDate = ++dayCount; + String title = ""; + if (this.entrySource != null) { + curr.setDate(dayCount); + List entries = this.entrySource + .getEntries(curr,IDateField.RESOLUTION_DAY); + if (entries != null) { + for (Iterator it = entries.iterator(); it.hasNext();) { + ICalendarEntry entry = (ICalendarEntry)it.next(); + title += (title.length() > 0 ? "\n" : "") + entry.getStringForDate(curr); } - - getFlexCellFormatter().setColSpan(0, 2, 3); - } else if(!needsMonth){ - // Remove month traverse buttons - prevMonth.removeClickListener(this); - prevMonth.removeMouseListener(this); - nextMonth.removeClickListener(this); - nextMonth.removeMouseListener(this); - remove(prevMonth); - remove(nextMonth); - prevMonth = null; nextMonth = null; + } } - - // Print weekday names - int firstDay = datefield.dts.getFirstDayOfWeek(); - for(int i = 0; i < 7; i++) { - int day = i + firstDay; - if(day > 6) day = 0; - if(datefield.currentResolution > IDateField.RESOLUTION_MONTH) - setHTML(1,i, "" + datefield.dts.getShortDay(day) + ""); - else - setHTML(1,i, ""); + String baseclass = datefield.CLASSNAME + + "-calendarpanel-day"; + String cssClass = baseclass; + if (!isEnabledDate(curr)) { + cssClass += " " + baseclass + "-disabled"; } - } - - String monthName = needsMonth? datefield.dts.getMonth(datefield.date.getMonth()) : ""; - int year = datefield.date.getYear()+1900; - setHTML(0, 2, "" + monthName + " " + year + ""); - } - - private void buildCalendarBody() { - Date date = datefield.date; - if(date == null) - date = new Date(); - int startWeekDay = datefield.dts.getStartWeekDay(date); - int numDays = DateTimeService.getNumberOfDaysInMonth(date); - int dayCount = 0; - Date today = new Date(); - for (int row = 2; row < 8; row++){ - for (int col = 0; col < 7; col++){ - if(!(row == 2 && col < startWeekDay)) { - if(dayCount < numDays){ - int selectedDate = ++dayCount; - if(date.getDate() == dayCount){ - setHTML(row, col, "" + selectedDate + ""); - } else if(today.getDate() == dayCount && today.getMonth() == date.getMonth() && today.getYear() == date.getYear()){ - setHTML(row, col, "" + selectedDate + ""); - } else { - setHTML(row, col, "" + selectedDate + ""); - } - } else { - break; - } - } + if (date.getDate() == dayCount) { + cssClass += " " + baseclass + "-selected"; } + if (today.getDate() == dayCount + && today.getMonth() == date.getMonth() + && today.getYear() == date.getYear()) { + cssClass += " " + baseclass + "-today"; + } + if (title.length() > 0) + cssClass += " " + baseclass + "-entry"; + setHTML(row, col, "" + + selectedDate + ""); + } else { + break; + } + } + } } - - private void buildTime(boolean forceRedraw) { - if(time == null) { - time = new ITime(datefield); - setText(8,0,""); // Add new row - getFlexCellFormatter().setColSpan(8, 0, 7); - setWidget(8, 0, time); - } - time.updateTime(forceRedraw); + } + + private void buildTime(boolean forceRedraw) { + if (time == null) { + time = new ITime(datefield); + setText(8, 0, ""); // Add new row + getFlexCellFormatter().setColSpan(8, 0, 7); + setWidget(8, 0, time); } - - /** - * - * @param forceRedraw Build all from scratch, in case of e.g. locale changes - */ - public void updateCalendar() { - // Locale and resolution changes force a complete redraw - buildCalendar(locale != datefield.currentLocale || resolution != datefield.currentResolution); - if(datefield instanceof ITextualDate) - ((ITextualDate) datefield).buildDate(); - locale = datefield.currentLocale; - resolution = datefield.currentResolution; + time.updateTime(forceRedraw); + } + + /** + * + * @param forceRedraw + * Build all from scratch, in case of e.g. locale changes + */ + public void updateCalendar() { + // Locale and resolution changes force a complete redraw + buildCalendar(locale != datefield.currentLocale + || resolution != datefield.currentResolution); + if (datefield instanceof ITextualDate) + ((ITextualDate) datefield).buildDate(); + locale = datefield.currentLocale; + resolution = datefield.currentResolution; + } + + public void onClick(Widget sender) { + processClickEvent(sender); + } + + private boolean isEnabledDate(Date date) { + if ((this.minDate != null && date.before(this.minDate)) + || (this.maxDate != null && date.after(this.maxDate))) { + return false; } + return true; + } + + private void processClickEvent(Widget sender) { + if (!datefield.enabled || datefield.readonly) + return; - public void onClick(Widget sender) { - processClickEvent(sender); + if (sender == prevYear) { + datefield.date.setYear(datefield.date.getYear() - 1); + datefield.client.updateVariable(datefield.id, "year", + datefield.date.getYear() + 1900, datefield.immediate); + updateCalendar(); + } else if (sender == nextYear) { + datefield.date.setYear(datefield.date.getYear() + 1); + datefield.client.updateVariable(datefield.id, "year", + datefield.date.getYear() + 1900, datefield.immediate); + updateCalendar(); + } else if (sender == prevMonth) { + datefield.date.setMonth(datefield.date.getMonth() - 1); + datefield.client.updateVariable(datefield.id, "month", + datefield.date.getMonth() + 1, datefield.immediate); + updateCalendar(); + } else if (sender == nextMonth) { + datefield.date.setMonth(datefield.date.getMonth() + 1); + datefield.client.updateVariable(datefield.id, "month", + datefield.date.getMonth() + 1, datefield.immediate); + updateCalendar(); } + } - private void processClickEvent(Widget sender) { - if(!datefield.enabled || datefield.readonly) - return; - if(sender == prevYear) { - datefield.date.setYear(datefield.date.getYear()-1); - datefield.client.updateVariable(datefield.id, "year", datefield.date.getYear()+1900, datefield.immediate); - updateCalendar(); - } else if(sender == nextYear) { - datefield.date.setYear(datefield.date.getYear()+1); - datefield.client.updateVariable(datefield.id, "year", datefield.date.getYear()+1900, datefield.immediate); - updateCalendar(); - } else if(sender == prevMonth) { - datefield.date.setMonth(datefield.date.getMonth()-1); - datefield.client.updateVariable(datefield.id, "month", datefield.date.getMonth()+1, datefield.immediate); - updateCalendar(); - } else if(sender == nextMonth) { - datefield.date.setMonth(datefield.date.getMonth()+1); - datefield.client.updateVariable(datefield.id, "month", datefield.date.getMonth()+1, datefield.immediate); - updateCalendar(); - } - } - - private Timer timer; + private Timer timer; - public void onMouseDown(final Widget sender, int x, int y) { - if(sender instanceof IEventButton) { - timer = new Timer() { - public void run() { - processClickEvent(sender); - } - }; - timer.scheduleRepeating(100); + public void onMouseDown(final Widget sender, int x, int y) { + if (sender instanceof IEventButton) { + timer = new Timer() { + public void run() { + processClickEvent(sender); } + }; + timer.scheduleRepeating(100); } + } + + public void onMouseEnter(Widget sender) { + } + + public void onMouseLeave(Widget sender) { + if (timer != null) + timer.cancel(); + } - public void onMouseEnter(Widget sender) {} + public void onMouseMove(Widget sender, int x, int y) { + } - public void onMouseLeave(Widget sender) { - if(timer != null) - timer.cancel(); + public void onMouseUp(Widget sender, int x, int y) { + if (timer != null) + timer.cancel(); + } + + private class IEventButton extends IButton implements SourcesMouseEvents { + + private MouseListenerCollection mouseListeners; + + public IEventButton() { + super(); + sinkEvents(Event.FOCUSEVENTS | Event.KEYEVENTS | Event.ONCLICK + | Event.MOUSEEVENTS); } - public void onMouseMove(Widget sender, int x, int y) {} + public void addMouseListener(MouseListener listener) { + if (mouseListeners == null) { + mouseListeners = new MouseListenerCollection(); + } + mouseListeners.add(listener); + } - public void onMouseUp(Widget sender, int x, int y) { - if(timer != null) - timer.cancel(); + public void removeMouseListener(MouseListener listener) { + if (mouseListeners != null) + mouseListeners.remove(listener); } - - private class IEventButton extends IButton implements SourcesMouseEvents { - - private MouseListenerCollection mouseListeners; - - public IEventButton() { - super(); - sinkEvents(Event.FOCUSEVENTS | Event.KEYEVENTS | Event.ONCLICK - | Event.MOUSEEVENTS); - } - - public void addMouseListener(MouseListener listener) { - if (mouseListeners == null) { - mouseListeners = new MouseListenerCollection(); - } - mouseListeners.add(listener); - } - public void removeMouseListener(MouseListener listener) { - if (mouseListeners != null) - mouseListeners.remove(listener); + public void onBrowserEvent(Event event) { + super.onBrowserEvent(event); + switch (DOM.eventGetType(event)) { + case Event.ONMOUSEDOWN: + case Event.ONMOUSEUP: + case Event.ONMOUSEMOVE: + case Event.ONMOUSEOVER: + case Event.ONMOUSEOUT: + if (mouseListeners != null) { + mouseListeners.fireMouseEvent(this, event); } - - public void onBrowserEvent(Event event) { - super.onBrowserEvent(event); - switch (DOM.eventGetType(event)) { - case Event.ONMOUSEDOWN: - case Event.ONMOUSEUP: - case Event.ONMOUSEMOVE: - case Event.ONMOUSEOVER: - case Event.ONMOUSEOUT: - if (mouseListeners != null) { - mouseListeners.fireMouseEvent(this, event); - } - break; - } - } + break; + } } - - private class DateClickListener implements TableListener { - - private ICalendarPanel cal; - - public DateClickListener(ICalendarPanel panel) { - cal = panel; - } + } - public void onCellClicked(SourcesTableEvents sender, int row, int col) { - if(sender != cal || row < 2 || row > 7 || !cal.datefield.enabled || cal.datefield.readonly) - return; - - String text = cal.getText(row, col); - if(text.equals(" ")) - return; - - Integer day = new Integer(text); - cal.datefield.date.setDate(day.intValue()); - cal.datefield.client.updateVariable(cal.datefield.id, "day", cal.datefield.date.getDate(), cal.datefield.immediate); - - updateCalendar(); - } - + private class DateClickListener implements TableListener { + + private ICalendarPanel cal; + + public DateClickListener(ICalendarPanel panel) { + cal = panel; + } + + public void onCellClicked(SourcesTableEvents sender, int row, int col) { + if (sender != cal || row < 2 || row > 7 || !cal.datefield.enabled + || cal.datefield.readonly) + return; + + String text = cal.getText(row, col); + if (text.equals(" ")) + return; + + Integer day = new Integer(text); + + Date newDate = new Date(cal.datefield.date.getTime()); + newDate.setDate(day.intValue()); + if (!isEnabledDate(newDate)) { + return; + } + cal.datefield.date.setTime(newDate.getTime()); + cal.datefield.client.updateVariable(cal.datefield.id, "day", + cal.datefield.date.getDate(), cal.datefield.immediate); + + updateCalendar(); + } + + } + + public void setLimits(Date min, Date max) { + if (min != null ) { + Date d = new Date(min.getTime()); + d.setHours(0); + d.setMinutes(0); + d.setSeconds(1); + this.minDate = d; + } else { + this.minDate = null; + } + if (max != null) { + Date d = new Date(max.getTime()); + d.setHours(24); + d.setMinutes(59); + d.setSeconds(59); + this.maxDate = d; + }else { + this.maxDate = null; } + } + + public void setCalendarEntrySource(CalendarEntrySource entrySource) { + this.entrySource = entrySource; + } + + public CalendarEntrySource getCalendarEntrySource() { + return this.entrySource; + } + + public interface CalendarEntrySource { + public List getEntries(Date date, int resolution); + } + } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IDateField.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IDateField.java index cb24dfeee8..fbed7063b1 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IDateField.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IDateField.java @@ -19,13 +19,13 @@ public class IDateField extends FlowPanel implements Paintable { protected boolean immediate; - protected static int RESOLUTION_YEAR = 0; - protected static int RESOLUTION_MONTH = 1; - protected static int RESOLUTION_DAY = 2; - protected static int RESOLUTION_HOUR = 3; - protected static int RESOLUTION_MIN = 4; - protected static int RESOLUTION_SEC = 5; - protected static int RESOLUTION_MSEC = 6; + static int RESOLUTION_YEAR = 0; + static int RESOLUTION_MONTH = 1; + static int RESOLUTION_DAY = 2; + static int RESOLUTION_HOUR = 3; + static int RESOLUTION_MIN = 4; + static int RESOLUTION_SEC = 5; + static int RESOLUTION_MSEC = 6; protected int currentResolution = RESOLUTION_YEAR; protected String currentLocale; diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IDateFieldCalendar.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IDateFieldCalendar.java new file mode 100644 index 0000000000..150f96c504 --- /dev/null +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IDateFieldCalendar.java @@ -0,0 +1,22 @@ +package com.itmill.toolkit.terminal.gwt.client.ui; + +import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; +import com.itmill.toolkit.terminal.gwt.client.UIDL; + +public class IDateFieldCalendar extends IDateField { + + private ICalendarPanel date; + + public IDateFieldCalendar() { + super(); + setStyleName(CLASSNAME+"-calendar"); + date = new ICalendarPanel(this); + add(date); + } + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + super.updateFromUIDL(uidl, client); + date.updateCalendar(); + } + +} diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IEntryCalendar.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IEntryCalendar.java new file mode 100644 index 0000000000..6119e8f5d0 --- /dev/null +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IEntryCalendar.java @@ -0,0 +1,163 @@ +package com.itmill.toolkit.terminal.gwt.client.ui; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +import com.google.gwt.user.client.ui.FlexTable; +import com.google.gwt.user.client.ui.SourcesTableEvents; +import com.google.gwt.user.client.ui.TableListener; +import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; +import com.itmill.toolkit.terminal.gwt.client.DateTimeService; +import com.itmill.toolkit.terminal.gwt.client.UIDL; +import com.itmill.toolkit.terminal.gwt.client.ui.calendar.ICalendarEntry; + +public class IEntryCalendar extends IDateField { + + private ICalendarPanel calPanel; + + private FlexTable hourTable; + + private EntrySource entrySource; + + private TableListener ftListener = new HourTableListener(); + + private int realResolution = RESOLUTION_DAY; + + public IEntryCalendar() { + super(); + setStyleName(CLASSNAME + "-entrycalendar"); + calPanel = new ICalendarPanel(this); + add(calPanel); + this.entrySource = new EntrySource(); + calPanel.setCalendarEntrySource(this.entrySource); + calPanel.addTableListener(new TableListener() { + public void onCellClicked(SourcesTableEvents sender, int row, + int cell) { + buildDayView(date); + } + }); + } + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + super.updateFromUIDL(uidl, client); + // We want to draw our own hour list + this.realResolution = currentResolution; + this.currentResolution = RESOLUTION_DAY; + if (uidl.hasAttribute("min")) { + String mins = uidl.getStringAttribute("min"); + long min = (mins != null ? Long.parseLong(mins) : 0); + String maxs = uidl.getStringAttribute("max"); + long max = (maxs != null ? Long.parseLong(maxs) : 0); + Date minDate = (min > 0 ? new Date(min) : null); + Date maxDate = (max > 0 ? new Date(max) : null); + calPanel.setLimits(minDate, maxDate); + } + for (Iterator cit = uidl.getChildIterator(); cit.hasNext();) { + UIDL child = (UIDL) cit.next(); + if (child.getTag().equals("items")) { + for (Iterator iit = child.getChildIterator(); iit.hasNext();) { + UIDL item = (UIDL) iit.next(); + this.entrySource.addItem(item); + } + break; + } + } + calPanel.updateCalendar(); + buildDayView(this.date); + } + + protected void buildDayView(Date date) { + boolean firstRender = false; + if (this.hourTable == null) { + hourTable = new FlexTable(); + firstRender = true; + hourTable.addTableListener(this.ftListener); + } + Date curr = new Date(date.getTime()); + for (int i = 0; i < 24; i++) { + curr.setHours(i); + String style = (i % 2 == 0 ? "even" : "odd"); + if (realResolution >= RESOLUTION_HOUR) { + if (this.date != null && this.date.getHours() == i) { + style = "selected"; + } + } + hourTable.getRowFormatter().setStyleName(i, + getStyleName() + "-row-" + style); + if (firstRender) { + String hstr = (i < 10 ? "0" : "") + i + ":00"; + if (this.dts.isTwelveHourClock()) { + String ampm = (i < 12 ? "am" : "pm"); + hstr = (i <= 12 ? i : i - 12) + ":00 " + ampm; + } + hourTable.setHTML(i, 0, "" + hstr + ""); + } + List entries = this.entrySource.getEntries(curr, + DateTimeService.RESOLUTION_HOUR); + if (entries != null) { + String text = ""; + for (Iterator it = entries.iterator(); it.hasNext();) { + String title = ((ICalendarEntry) it.next()).getTitle(); + text += (text == "" ? "" : ", ") + + (title != null ? title : "?"); + } + hourTable.setHTML(i, 1, "" + text + ""); + } + } + + this.calPanel.getFlexCellFormatter().setColSpan(8, 0, 7); + this.calPanel.setWidget(8, 0, hourTable); + } + + private class HourTableListener implements TableListener { + + public void onCellClicked(SourcesTableEvents sender, int row, int cell) { + if (realResolution < RESOLUTION_HOUR || date == null) { + return; + } + date.setHours(row); + client.updateVariable(id, "hour", row, immediate); + } + + } + + private class EntrySource implements ICalendarPanel.CalendarEntrySource { + + private HashMap items = new HashMap(); + + public void addItem(UIDL item) { + Integer id = new Integer(item.getIntAttribute("id")); + long start = Long.parseLong(item.getStringAttribute("start")); + Date startDate = new Date(start); + long end = Long.parseLong(item.getStringAttribute("end")); + Date endDate = (end > 0 && end != start ? new Date(end) : new Date( + start)); + String title = item.getStringAttribute("title"); + boolean notime = item.getBooleanAttribute("notime"); + if (items.containsKey(id)) { + items.remove(id); + } + items.put(id, new ICalendarEntry(startDate, endDate, title, notime)); + } + + public List getEntries(Date date, int resolution) { + ArrayList res = new ArrayList(); + for (Iterator it = this.items.values().iterator(); it.hasNext();) { + ICalendarEntry item = (ICalendarEntry) it.next(); + if (DateTimeService.isInRange(date, item.getStart(), item + .getEnd(), resolution)) { + res.add(item); + } + } + + return res; + } + + } + +} diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/calendar/ICalendarEntry.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/calendar/ICalendarEntry.java new file mode 100644 index 0000000000..0559cb1bb8 --- /dev/null +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/calendar/ICalendarEntry.java @@ -0,0 +1,102 @@ +package com.itmill.toolkit.terminal.gwt.client.ui.calendar; + +import java.util.Date; + +import com.itmill.toolkit.terminal.gwt.client.DateTimeService; + +public class ICalendarEntry { + private Date start; + private Date end; + private String title; + private boolean notime; + + public ICalendarEntry(Date start, Date end, String title, boolean notime) { + if (notime) { + Date d = new Date(start.getTime()); + d.setSeconds(0); + d.setMinutes(0); + this.start = d; + if (end != null) { + d = new Date(end.getTime()); + d.setSeconds(0); + d.setMinutes(0); + this.end = d; + } else { + end = start; + } + } else { + this.start = start; + this.end = end; + } + this.title = title; + this.notime = notime; + } + + public ICalendarEntry(Date start, Date end, String title) { + this(start, end, title, false); + } + + public Date getStart() { + return start; + } + + public void setStart(Date start) { + this.start = start; + } + + public Date getEnd() { + return end; + } + + public void setEnd(Date end) { + this.end = end; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public boolean isNotime() { + return notime; + } + + public void setNotime(boolean notime) { + this.notime = notime; + } + + public String getStringForDate(Date d) { + // TODO format from DateTimeService + String s = ""; + if (!notime) { + if (!DateTimeService.isSameDay(d, start)) { + s += (start.getYear() + 1900) + "." + (start.getMonth() + 1) + + "." + start.getDate() + " "; + } + int i = start.getHours(); + s += (i < 10 ? "0" : "") + i; + s += ":"; + i = start.getMinutes(); + s += (i < 10 ? "0" : "") + i; + if (!start.equals(end)) { + s += " - "; + if (!DateTimeService.isSameDay(start, end)) { + s += (end.getYear() + 1900) + "." + (end.getMonth() + 1) + "." + + end.getDate() + " "; + } + i = end.getHours(); + s += (i < 10 ? "0" : "") + i; + s += ":"; + i = end.getMinutes(); + s += (i < 10 ? "0" : "") + i; + } + s += " "; + } + s += title; + return s; + } + +} \ No newline at end of file diff --git a/src/com/itmill/toolkit/ui/CalendarField.java b/src/com/itmill/toolkit/ui/CalendarField.java new file mode 100644 index 0000000000..065065114c --- /dev/null +++ b/src/com/itmill/toolkit/ui/CalendarField.java @@ -0,0 +1,285 @@ +package com.itmill.toolkit.ui; + +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; + +import com.itmill.toolkit.data.Container; +import com.itmill.toolkit.data.Item; +import com.itmill.toolkit.data.Property; +import com.itmill.toolkit.terminal.PaintException; +import com.itmill.toolkit.terminal.PaintTarget; + +// TODO use Calendar +// TODO lazyLoading +// TODO check date limit when updating variables +// TODO Allow item selection +public class CalendarField extends DateField implements Container.Viewer { + + private Date minDate; + private Date maxDate; + + private Container dataSource; + private Object itemStartPropertyId; + private Object itemEndPropertyId; + private Object itemTitlePropertyId; + private Object itemNotimePropertyId; + + public CalendarField() { + super(); + init(); + } + + public CalendarField(Property dataSource) throws IllegalArgumentException { + super(dataSource); + init(); + } + + public CalendarField(String caption, Date value) { + super(caption, value); + init(); + } + + public CalendarField(String caption, Property dataSource) { + super(caption, dataSource); + init(); + } + + public CalendarField(String caption) { + super(caption); + init(); + } + + /* + * Gets the components UIDL tag string. Don't add a JavaDoc comment here, we + * use the default documentation from implemented interface. + */ + public String getTag() { + return "calendarfield"; + } + + public void init() { + super.setResolution(RESOLUTION_HOUR); + + } + + /** + * Sets the resolution of the CalendarField. Only RESOLUTION_DAY and + * RESOLUTION_HOUR are supported. + * + * @param resolution + * the resolution to set. + * @see com.itmill.toolkit.ui.DateField#setResolution(int) + */ + public void setResolution(int resolution) { + if (resolution != RESOLUTION_DAY && resolution != RESOLUTION_HOUR) { + throw new IllegalArgumentException(); + } + super.setResolution(resolution); + } + + public void setMinimumDate(Date date) { + this.minDate = date; + requestRepaint(); + } + + public Date getMinimumDate() { + return minDate; + } + + public void setMaximumDate(Date date) { + this.maxDate = date; + requestRepaint(); + } + + public Date getMaximumDate() { + return maxDate; + } + + public Container getContainerDataSource() { + return this.dataSource; + } + + public void setContainerDataSource(Container newDataSource) { + if (checkDataSource(newDataSource)) { + this.dataSource = newDataSource; + } else { + // TODO error message + throw new IllegalArgumentException(); + } + requestRepaint(); + } + + private boolean checkDataSource(Container dataSource) { + /* + * if (!(dataSource instanceof Container.Sortable)) { // we really want + * the data source to be sortable return false; } + */ + // Check old propertyIds + if (this.itemEndPropertyId != null) { + Class c = dataSource.getType(this.itemEndPropertyId); + if (!Date.class.isAssignableFrom(c)) { + this.itemEndPropertyId = null; + } + } + if (this.itemNotimePropertyId != null) { + Class c = dataSource.getType(this.itemNotimePropertyId); + if (!Boolean.class.isAssignableFrom(c)) { + this.itemNotimePropertyId = null; + } + } + if (this.itemStartPropertyId != null) { + Class c = dataSource.getType(this.itemStartPropertyId); + if (Date.class.isAssignableFrom(c)) { + // All we _really_ need is one date + return true; + } else { + this.itemStartPropertyId = null; + } + } + // We need at least one Date + Collection ids = dataSource.getContainerPropertyIds(); + for (Iterator it = ids.iterator(); it.hasNext();) { + Object id = it.next(); + Class c = dataSource.getType(id); + if (Date.class.isAssignableFrom(c)) { + this.itemStartPropertyId = id; + return true; + } + } + + return false; + } + + public Object getItemStartPropertyId() { + return itemStartPropertyId; + } + + public void setItemStartPropertyId(Object propertyId) { + // TODO nullcheck for property id + if (this.dataSource != null + && !Date.class.isAssignableFrom(dataSource.getType(propertyId))) { + // TODO error message + throw new IllegalArgumentException(); + } + this.itemStartPropertyId = propertyId; + } + + public Object getItemEndPropertyId() { + return itemEndPropertyId; + } + + public void setItemEndPropertyId(Object propertyId) { + // TODO nullcheck for property id + if (this.dataSource != null + && !Date.class.isAssignableFrom(dataSource.getType(propertyId))) { + // TODO error message + throw new IllegalArgumentException(); + } + this.itemEndPropertyId = propertyId; + } + + public Object getItemTitlePropertyId() { + return itemTitlePropertyId; + } + + public void setItemTitlePropertyId(Object propertyId) { + this.itemTitlePropertyId = propertyId; + } + + public Object getitemNotimePropertyId() { + return itemNotimePropertyId; + } + + public void setItemNotimePropertyId(Object propertyId) { + // TODO nullcheck for property id + if (this.dataSource != null + && !Boolean.class.isAssignableFrom(dataSource.getType(propertyId))) { + // TODO error message + throw new IllegalArgumentException(); + } + this.itemNotimePropertyId = propertyId; + } + + /** + * Paints the content of this component. + * + * @param target + * the Paint Event. + * @throws PaintException + * if the paint operation failed. + */ + public void paintContent(PaintTarget target) throws PaintException { + super.paintContent(target); + + if (this.minDate != null) { + target.addAttribute("min", String.valueOf(this.minDate.getTime())); + } + if (this.maxDate != null) { + target.addAttribute("max", String.valueOf(this.maxDate.getTime())); + } + + if (this.dataSource != null) { + target.startTag("items"); + + // send one month now, the rest via lazyloading + int month = new Date().getMonth(); + Object value = getValue(); + if (value != null && value instanceof Date) { + month = ((Date) value).getMonth(); + } + + for (Iterator it = this.dataSource.getItemIds().iterator(); it + .hasNext();) { + Object itemId = it.next(); + Item item = (Item) this.dataSource.getItem(itemId); + Property p = item.getItemProperty(this.itemStartPropertyId); + Date start = (Date) p.getValue(); + Date end = start; // assume same day + if (this.itemEndPropertyId != null) { + p = item.getItemProperty(this.itemEndPropertyId); + end = (Date) p.getValue(); + if (end == null) { + end = start; + } else if (end.before(start)) { + Date tmp = start; + start = end; + end = tmp; + } + } + + if (start != null) { + if ((start.getMonth() <= month || end.getMonth() >= month)) { + target.startTag("item"); + // TODO different id! + target.addAttribute("id", itemId.hashCode()); + target.addAttribute("start", ""+start.getTime()); + if (end != start) { + target.addAttribute("end", ""+end.getTime()); + } + if (this.itemTitlePropertyId != null) { + p = item.getItemProperty(this.itemTitlePropertyId); + Object val = p.getValue(); + if (val != null) { + target.addAttribute("title", val.toString()); + } + } + if (this.itemNotimePropertyId != null) { + p = item + .getItemProperty(this.itemNotimePropertyId); + Object val = p.getValue(); + if (val != null) { + target.addAttribute("notime", ((Boolean) val) + .booleanValue()); + } + } + + target.endTag("item"); + } + } + } + + target.endTag("items"); + } + } +}