From: Marc Englund Date: Fri, 17 Aug 2007 13:02:02 +0000 (+0000) Subject: Calendar updates. X-Git-Tag: 6.7.0.beta1~6085 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f821f31dd9a65757f617be0788f163872903f382;p=vaadin-framework.git Calendar updates. svn changeset:2058/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/demo/CalendarDemo.java b/src/com/itmill/toolkit/demo/CalendarDemo.java index abcde1eadc..24f1ba9681 100644 --- a/src/com/itmill/toolkit/demo/CalendarDemo.java +++ b/src/com/itmill/toolkit/demo/CalendarDemo.java @@ -3,10 +3,12 @@ package com.itmill.toolkit.demo; import java.sql.SQLException; import java.util.Date; +import com.itmill.toolkit.data.Property.ValueChangeEvent; +import com.itmill.toolkit.data.Property.ValueChangeListener; import com.itmill.toolkit.data.util.QueryContainer; import com.itmill.toolkit.demo.util.SampleCalendarDatabase; -import com.itmill.toolkit.ui.Button; import com.itmill.toolkit.ui.CalendarField; +import com.itmill.toolkit.ui.OrderedLayout; import com.itmill.toolkit.ui.Window; /** @@ -25,7 +27,8 @@ public class CalendarDemo extends com.itmill.toolkit.Application { private SampleCalendarDatabase sampleDatabase; // The calendar UI component - private CalendarField calendar; + private CalendarField from; + private CalendarField to; /** * Initialize Application. Demo components are added to main window. @@ -33,33 +36,62 @@ public class CalendarDemo extends com.itmill.toolkit.Application { public void init() { Window main = new Window("Calendar demo"); setMainWindow(main); + + main.setLayout(new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL)); // set the application to use Corporate -theme setTheme("corporate"); // create the calendar component and add to layout - calendar = new CalendarField(); - main.addComponent(calendar); - calendar.setResolution(CalendarField.RESOLUTION_HOUR); + from = new CalendarField(); + main.addComponent(from); + from.setResolution(CalendarField.RESOLUTION_HOUR); + from.setImmediate(true); + + to = new CalendarField(); + main.addComponent(to); + to.setResolution(CalendarField.RESOLUTION_HOUR); + to.setEnabled(false); + to.setImmediate(true); + + from.addListener(new ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + Date fd = (Date)from.getValue(); + Date td = (Date)to.getValue(); + if (fd == null) { + to.setValue(null); + to.setEnabled(false); + return; + } else { + to.setEnabled(true); + } + to.setMinimumDate(fd); + if (td == null||td.before(fd)) { + to.setValue(fd); + } + } + }); + // initialize the sample database and set as calendar datasource sampleDatabase = new SampleCalendarDatabase(); - initCalendar(); + initCalendars(); // Don't allow dates before today - calendar.setMinimumDate(new Date()); + from.setMinimumDate(new Date()); } /** * Populates table component with all rows from calendar table. */ - private void initCalendar() { + private void initCalendars() { try { QueryContainer qc = new QueryContainer("SELECT * FROM " + SampleCalendarDatabase.DB_TABLE_NAME, sampleDatabase .getConnection()); - calendar.setContainerDataSource(qc); + from.setContainerDataSource(qc); + to.setContainerDataSource(qc); } catch (SQLException e) { e.printStackTrace(); } @@ -69,11 +101,18 @@ public class CalendarDemo extends com.itmill.toolkit.Application { // first one, so it's intentionally left out. // Start is the only mandatory property, but you'll probably want to // specify title as well. - calendar.setItemEndPropertyId(SampleCalendarDatabase.PROPERTY_ID_END); - calendar + from.setItemEndPropertyId(SampleCalendarDatabase.PROPERTY_ID_END); + from + .setItemTitlePropertyId(SampleCalendarDatabase.PROPERTY_ID_TITLE); + from + .setItemNotimePropertyId(SampleCalendarDatabase.PROPERTY_ID_NOTIME); + + to.setItemEndPropertyId(SampleCalendarDatabase.PROPERTY_ID_END); + to .setItemTitlePropertyId(SampleCalendarDatabase.PROPERTY_ID_TITLE); - calendar + to .setItemNotimePropertyId(SampleCalendarDatabase.PROPERTY_ID_NOTIME); + } } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java index f6473430c0..c9666b9e9e 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java @@ -29,9 +29,11 @@ public class ICalendar extends IDateField { private int realResolution = RESOLUTION_DAY; + private static final String CLASSNAME = IDateField.CLASSNAME + "-entrycalendar"; + public ICalendar() { super(); - setStyleName(CLASSNAME + "-entrycalendar"); + setStyleName(CLASSNAME); calPanel = new ICalendarPanel(this); add(calPanel); this.entrySource = new EntrySource(); @@ -80,7 +82,7 @@ public class ICalendar extends IDateField { hourTable.addTableListener(this.ftListener); SimplePanel p = new SimplePanel(); p.add(hourTable); - p.setStyleName(getStyleName() + "-hours"); + p.setStyleName(CLASSNAME + "-hours"); this.calPanel.getFlexCellFormatter().setColSpan(8, 0, 7); this.calPanel.setWidget(8, 0, p); } @@ -94,7 +96,7 @@ public class ICalendar extends IDateField { } } hourTable.getRowFormatter().setStyleName(i, - getStyleName() + "-row-" + style); + CLASSNAME + "-row-" + style); if (firstRender) { String hstr = (i < 10 ? "0" : "") + i + ":00"; if (this.dts.isTwelveHourClock()) { @@ -103,21 +105,21 @@ public class ICalendar extends IDateField { } hourTable.setHTML(i, 0, "" + hstr + ""); hourTable.getCellFormatter().setStyleName(i, 0, - getStyleName() + "-time"); + CLASSNAME + "-time"); } List entries = this.entrySource.getEntries(curr, DateTimeService.RESOLUTION_HOUR); + String text = ""; 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 + ""); - hourTable.getCellFormatter().setStyleName(i, 1, - getStyleName() + "-title"); } + hourTable.setHTML(i, 1, "" + text + ""); + hourTable.getCellFormatter().setStyleName(i, 1, + CLASSNAME + "-title"); } } diff --git a/src/com/itmill/toolkit/terminal/gwt/public/component-themes/common/css/common.css b/src/com/itmill/toolkit/terminal/gwt/public/component-themes/common/css/common.css index 393b5733d4..f2769090a0 100644 --- a/src/com/itmill/toolkit/terminal/gwt/public/component-themes/common/css/common.css +++ b/src/com/itmill/toolkit/terminal/gwt/public/component-themes/common/css/common.css @@ -24,7 +24,7 @@ select { .i-disabled { opacity: 0.3; - filter: alpha(opacity:30); + filter: Alpha(opacity=30); } .i-contextmenu {