Author: akushunin
Date: 2007-07-30 12:27:27 -0400 (Mon, 30 Jul 2007)
New Revision: 1934
Modified:
trunk/sandbox/ui/calendar/src/main/config/component/calendar.xml
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
trunk/sandbox/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java
Log:
added tooltipMode
Modified: trunk/sandbox/ui/calendar/src/main/config/component/calendar.xml
===================================================================
--- trunk/sandbox/ui/calendar/src/main/config/component/calendar.xml 2007-07-30 16:26:36
UTC (rev 1933)
+++ trunk/sandbox/ui/calendar/src/main/config/component/calendar.xml 2007-07-30 16:27:27
UTC (rev 1934)
@@ -137,5 +137,11 @@
<description></description>
<defaultvalue>"popupButton"</defaultvalue>
</property>
+ <property>
+ <name>toolTipMode</name>
+ <classname>java.lang.String</classname>
+ <description></description>
+ <defaultvalue>"batch"</defaultvalue>
+ </property>
</component>
</components>
Modified: trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java
===================================================================
---
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java 2007-07-30
16:26:36 UTC (rev 1933)
+++
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java 2007-07-30
16:27:27 UTC (rev 1934)
@@ -118,16 +118,19 @@
public abstract String getDirection();
public abstract void setDirection(String direction);
-
+
public abstract boolean isPopup();
public abstract void setPopup(boolean popup);
-
+
public abstract String getButtonLabel();
public abstract void setButtonLabel(String buttonLabel);
-
+ public abstract String getToolTipMode();
+
+ public abstract void setToolTipMode(String toolTipMode);
+
// currentDate processing -------------------------------------------------
public String getValueAsString(FacesContext context, UIComponent component)
@@ -193,16 +196,16 @@
return calendar.getTime();
}
}
-
- public Object getTooltip(Date date){
-
+
+ public Object getTooltip(Date date) {
+
CalendarDataModel calendarDM = (CalendarDataModel) getData();
- if (calendarDM != null) {
- return calendarDM.getToolTip(date);
- }else{
- return null;
- }
-
+ if (calendarDM != null) {
+ return calendarDM.getToolTip(date);
+ } else {
+ return null;
+ }
+
}
protected Date getDefaultPreloadBegin(Date date) {
@@ -216,7 +219,6 @@
return calendar.getTime();
}
-
protected Date getDefaultPreloadEnd(Date date) {
Calendar calendar = Calendar.getInstance(getTimeZone(), getLocale());
calendar.setTime(date);
Modified:
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
===================================================================
---
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2007-07-30
16:26:36 UTC (rev 1933)
+++
trunk/sandbox/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2007-07-30
16:27:27 UTC (rev 1934)
@@ -39,6 +39,7 @@
import javax.faces.convert.DateTimeConverter;
import javax.faces.event.PhaseId;
+import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.event.AjaxEvent;
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSFunctionDefinition;
@@ -68,7 +69,7 @@
public static final String DATE_SCROLL = "DateScroll";
protected static final String MARKUP_SUFFIX = "Markup";
-
+
/*
* (non-Javadoc)
*
@@ -85,6 +86,17 @@
return HtmlUtil.qualifySize(size.toString());
}
+ public void addPopupToAjaxRendered(FacesContext context,
+ UICalendar component) {
+
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ if (ajaxContext.isAjaxRequest()) {
+ ajaxContext.getAjaxRenderedAreas().add(
+ component.getClientId(context) + "Popup");
+ }
+
+ }
+
public Object getConvertedValue(FacesContext context,
UIComponent component, Object submittedValue)
throws ConverterException {
@@ -97,9 +109,10 @@
converter.setPattern(calendar.getDatePattern());
converter.setLocale(calendar.getLocale());
converter.setTimeZone(calendar.getTimeZone());
- return converter.getAsObject(context, component, (String) submittedValue);
+ return converter.getAsObject(context, component,
+ (String) submittedValue);
}
-
+
public Date convertCurrentDate(String currentDateString) {
Calendar calendar = Calendar.getInstance();
@@ -120,7 +133,7 @@
super.doDecode(context, component);
String clientId = component.getClientId(context);
-
+
Map requestParameterMap = context.getExternalContext()
.getRequestParameterMap();
@@ -128,26 +141,26 @@
+ DATE_SCROLL);
if (currentDateString != null) {
-// ((UICalendar) component)
-// .setCurrentDate(convertCurrentDate(currentDateString));
- CurrentDateChangeEvent ev = new CurrentDateChangeEvent(component, currentDateString)
;
+ // ((UICalendar) component)
+ // .setCurrentDate(convertCurrentDate(currentDateString));
+ CurrentDateChangeEvent ev = new CurrentDateChangeEvent(component,
+ currentDateString);
ev.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
ev.queue();
-
+
new AjaxEvent(component).queue();
}
-
- String selectedDateString = (String) requestParameterMap.get(clientId +
"InputSelectedDate");
+
+ String selectedDateString = (String) requestParameterMap.get(clientId
+ + "InputSelectedDate");
if (selectedDateString != null) {
((UICalendar) component).setSubmittedValue(selectedDateString);
}
}
-
+ public void encodeChildren(FacesContext context, UIComponent calendar)
+ throws IOException {
- public void encodeChildren(FacesContext context, UIComponent calendar)
- throws IOException {
-
}
public void writeMarkupScriptBody(FacesContext context,
@@ -166,7 +179,6 @@
}
}
-
public void writePreloadBody(FacesContext context, UICalendar calendar)
throws IOException {
Object preload = calendar.getPreload();
@@ -189,8 +201,8 @@
options.put("calendar", JSReference.THIS);
options.put("single", JSReference.TRUE);
// ajax single
- //options.put("control", new JSReference(JSReference.THIS.toScript(),
- // "id"));
+ // options.put("control", new JSReference(JSReference.THIS.toScript(),
+ // "id"));
String oncomplete = AjaxRendererUtils.getAjaxOncomplete(calendar);
JSFunctionDefinition oncompleteDefinition = new JSFunctionDefinition();
@@ -214,35 +226,36 @@
writer.write(definition.toScript());
}
- public String getInputValue(FacesContext context, UIComponent component){
- // UIInput input = (UIInput) component;
+ public String getInputValue(FacesContext context, UIComponent component) {
UICalendar input = (UICalendar) component;
String value = (String) input.getSubmittedValue();
- if(value == null){
+ if (value == null) {
Object curVal = input.getValue();
DateTimeConverter converter = new DateTimeConverter();
converter.setPattern(input.getDatePattern());
converter.setLocale(input.getLocale());
- converter.setTimeZone(input.getTimeZone());
- // Converter converter = SelectUtils.getConverterForProperty(context, input,
"value");
-
- if(converter != null){
+ // converter.setTimeZone(input.getTimeZone());
+ // Converter converter =
+ // SelectUtils.getConverterForProperty(context, input, "value");
+
+ if (converter != null) {
value = converter.getAsString(context, input, curVal);
} else {
- if(curVal == null){
+ if (curVal == null) {
value = "";
} else {
value = curVal.toString();
}
}
}
- if(value == null){
+ if (value == null) {
value = "";
}
return value;
}
- public void writeSymbols(FacesContext facesContext, UICalendar calendar) throws
IOException {
+ public void writeSymbols(FacesContext facesContext, UICalendar calendar)
+ throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
Map symbolsMap = getSymbolsMap(facesContext, calendar);
Iterator entryIterator = symbolsMap.entrySet().iterator();
@@ -252,24 +265,26 @@
writer.writeText(entry.getKey(), null);
writer.writeText(": ", null);
writer.writeText(ScriptUtils.toScript(entry.getValue()), null);
-
+
if (entryIterator.hasNext()) {
writer.writeText(", ", null);
}
}
}
-
- private static String[] shiftDates(int firstDayOfWeek, int minimum, int maximum,
String[] labels) {
+
+ private static String[] shiftDates(int firstDayOfWeek, int minimum,
+ int maximum, String[] labels) {
if (minimum == 0) {
return labels;
}
String[] shiftedLabels = new String[maximum - minimum + 1];
- System.arraycopy(labels, minimum, shiftedLabels, 0, maximum - minimum + 1);
-
+ System.arraycopy(labels, minimum, shiftedLabels, 0, maximum - minimum
+ + 1);
+
return shiftedLabels;
}
-
+
protected Map getSymbolsMap(FacesContext facesContext, UICalendar calendar) {
Map map = new HashMap();
@@ -278,61 +293,74 @@
int maximum = cal.getActualMaximum(Calendar.DAY_OF_WEEK);
int minimum = cal.getActualMinimum(Calendar.DAY_OF_WEEK);
int firstDayOfWeek = cal.getFirstDayOfWeek();
-
- //.getInstance(locale) changet to new DateFormatSymbols(locale) by Alexej Kushunin ;
+
+ // .getInstance(locale) changet to new DateFormatSymbols(locale) by
+ // Alexej Kushunin ;
DateFormatSymbols symbols = new DateFormatSymbols(locale);
- String[] weekDayLabels = ComponentUtil.asArray(calendar.getWeekDayLabels());
+ String[] weekDayLabels = ComponentUtil.asArray(calendar
+ .getWeekDayLabels());
if (weekDayLabels == null) {
weekDayLabels = symbols.getWeekdays();
- weekDayLabels = shiftDates(firstDayOfWeek, minimum, maximum, weekDayLabels);
+ weekDayLabels = shiftDates(firstDayOfWeek, minimum, maximum,
+ weekDayLabels);
}
-
- String[] weekDayLabelsShort = ComponentUtil.asArray(calendar.getWeekDayLabelsShort());
+
+ String[] weekDayLabelsShort = ComponentUtil.asArray(calendar
+ .getWeekDayLabelsShort());
if (weekDayLabelsShort == null) {
weekDayLabelsShort = symbols.getShortWeekdays();
- weekDayLabelsShort = shiftDates(firstDayOfWeek, minimum, maximum,
weekDayLabelsShort);
+ weekDayLabelsShort = shiftDates(firstDayOfWeek, minimum, maximum,
+ weekDayLabelsShort);
}
String[] monthLabels = ComponentUtil.asArray(calendar.getMonthLabels());
if (monthLabels == null) {
monthLabels = symbols.getMonths();
}
-
- String[] monthLabelsShort = ComponentUtil.asArray(calendar.getMonthLabelsShort());
+
+ String[] monthLabelsShort = ComponentUtil.asArray(calendar
+ .getMonthLabelsShort());
if (monthLabelsShort == null) {
monthLabelsShort = symbols.getShortMonths();
}
-
+
map.put(WEEK_DAY_LABELS, weekDayLabels);
map.put(WEEK_DAY_LABELS_SHORT, weekDayLabelsShort);
map.put(MONTH_LABELS, monthLabels);
map.put(MONTH_LABELS_SHORT, monthLabelsShort);
-
+
return map;
}
-
- public String getFirstWeekDay(FacesContext context, UICalendar calendar) throws
IOException {
+
+ public String getFirstWeekDay(FacesContext context, UICalendar calendar)
+ throws IOException {
Calendar cal = calendar.getCalendar();
- return String.valueOf(cal.getFirstDayOfWeek() -
cal.getActualMinimum(Calendar.DAY_OF_WEEK));
+ return String.valueOf(cal.getFirstDayOfWeek()
+ - cal.getActualMinimum(Calendar.DAY_OF_WEEK));
}
-
- public String getMinDaysInFirstWeek(FacesContext context, UICalendar calendar) throws
IOException {
+
+ public String getMinDaysInFirstWeek(FacesContext context,
+ UICalendar calendar) throws IOException {
Calendar cal = calendar.getCalendar();
return String.valueOf(cal.getMinimalDaysInFirstWeek());
}
- public String getCurrentDate(FacesContext context, UICalendar calendar) throws
IOException {
+ public String getCurrentDate(FacesContext context, UICalendar calendar)
+ throws IOException {
Date date = calendar.getCurrentDateOrDefault();
return ScriptUtils.toScript(formatDate(date));
}
- public String getSelectedDate(FacesContext context, UICalendar calendar) throws
IOException {
+ public String getSelectedDate(FacesContext context, UICalendar calendar)
+ throws IOException {
Object submittedValue = calendar.getSubmittedValue();
Date date;
-
+
if (submittedValue instanceof String) {
- Converter converter = SelectUtils.getConverterForProperty(context, calendar,
"value");
- date = (Date) converter.getAsObject(context, calendar, (String) submittedValue);
+ Converter converter = SelectUtils.getConverterForProperty(context,
+ calendar, "value");
+ date = (Date) converter.getAsObject(context, calendar,
+ (String) submittedValue);
} else if (submittedValue != null) {
date = (Date) submittedValue;
} else {
Modified:
trunk/sandbox/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java
===================================================================
---
trunk/sandbox/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java 2007-07-30
16:26:36 UTC (rev 1933)
+++
trunk/sandbox/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java 2007-07-30
16:27:27 UTC (rev 1934)
@@ -18,6 +18,7 @@
import org.apache.commons.lang.StringUtils;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlScript;
@@ -57,6 +58,7 @@
calendar = (UICalendar) application
.createComponent(UICalendar.COMPONENT_TYPE);
calendar.setLocale(Locale.CHINESE);
+ calendar.setDatePattern("d/MM/yyyy");
Calendar calendarObject = Calendar.getInstance();
calendarObject.set(2001, Calendar.SEPTEMBER, 11);
calendar.setId("calendar");
@@ -140,17 +142,19 @@
HtmlPage page = renderView();
assertNotNull(page);
- //System.out.println(page.asXml());
+ // System.out.println(page.asXml());
HtmlElement htmlCalendar =
page.getHtmlElementById(calendar.getClientId(facesContext));
assertNotNull(htmlCalendar);
+ System.out.println(htmlCalendar.getAttributeValue("datePattern"));
//System.out.println(htmlCalendar.getAttributeValue("class"));
htmlCalendar.getAttributeValue("class");
- HtmlElement htmlCalendarInput =
page.getHtmlElementById(calendar.getClientId(facesContext)+"Input");
+ HtmlInput htmlCalendarInput = (HtmlInput)
page.getHtmlElementById(calendar.getClientId(facesContext)+"PopupInput");
HtmlElement htmlCalendarButton =
page.getHtmlElementById(calendar.getClientId(facesContext)+"PopupButton");
assertNotNull(htmlCalendarInput);
assertNotNull(htmlCalendarButton);
- assertTrue(htmlCalendarInput.getAttributeValue("class").contains("org.richfaces.component.html.HtmlCalendar"));
+ htmlCalendarInput.setValueAttribute("11/09/2001");
+ // assertTrue(htmlCalendarInput.getAttributeValue("class").contains("org.richfaces.component.html.HtmlCalendar"));
// assertTrue(htmlCalendarButton.getAttributeValue("class").contains("org.richfaces.component.html.HtmlCalendar"));
}