Author: dmaliarevich
Date: 2008-02-11 05:10:09 -0500 (Mon, 11 Feb 2008)
New Revision: 6225
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/calendar/calendar.css
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/HtmlComponentUtil.java
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesCalendarTemplate.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1682
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/calendar/calendar.css
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/calendar/calendar.css 2008-02-11
10:08:46 UTC (rev 6224)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/resources/calendar/calendar.css 2008-02-11
10:10:09 UTC (rev 6225)
@@ -1,3 +1,14 @@
+.rich-calendar-input {
+ cursor:pointer;
+ vertical-align:middle;
+}
+
+.rich-calendar-button {
+ cursor:pointer;
+ vertical-align:middle;
+ text-align: left;
+}
+
.rich-calendar-exterior {
border: 1px solid #c0c0c0; /*panelBorderColor*/
}
@@ -2,6 +13,2 @@
-.rich-calendar-btn {
- cursor: pointer;
-}
-
.rich-calendar-header {
@@ -15,22 +22,6 @@
height: 22px;
}
-.rich-cell-size {
- width: 25px;
- height: 22px;
-}
-
-.rich-calendar-cell {
- background-color: #FFFFFF; /*generalBackgroundColor*/
- border-bottom: 1px solid #c0c0c0; /*panelBorderColor*/
- border-right: 1px solid #c0c0c0; /*panelBorderColor*/
- font-size: 11px; /*generalSizeFont*/
- font-family: verdana; /*generalFamilyFont*/
- padding: 0px;
- vertical-align: middle;
- text-align: center;
-}
-
.rich-calendar-tool {
border-bottom: 1px solid #c0c0c0; /*panelBorderColor*/
background-color: #D4CFC7; /*headerBackgroundColor*/
@@ -50,8 +41,7 @@
border-bottom-color: #C4C0B9;
font-size: 11px; /*headerSizeFont*/
font-family: Arial, Verdana, sans-serif;
- color: #000000;
- /*headerTextColor*/
+ color: #000000; /*headerTextColor*/
font-weight: bold;
vertical-align: middle;
text-align: center;
@@ -59,6 +49,13 @@
font-size: 11px
}
+.rich-calendar-tool-close {
+/*background-image:url(/richfaces-demo/a4j_3_1_4.GAorg.richfaces.renderkit.html.iconimages.CalendarSeparator/DATB/eAFjYGAAAAADAAE_.jsf);*/
+background-position:left center;
+background-repeat:no-repeat;
+padding:2px 2px 2px 4px;
+}
+
.rich-calendar-days {
background: #F1EEE9 none repeat scroll 0%;
border-bottom: 1px solid #C4C0B9; /*panelBorderColor*/
@@ -71,50 +68,63 @@
vertical-align: middle;
}
-.rich-calendar-days-holly {
- color: RED;
+.rich-calendar-weekends {
+ color:red;
}
.rich-calendar-week {
- border-bottom: 1px solid #c0c0c0; /*panelBorderColor*/
- border-right: 1px solid #c0c0c0; /*panelBorderColor*/
- font-size: 11px; /*generalSizeFont*/
- font-family: verdana; /*generalFamilyFont*/
- background-color: #f5f5f5; /*unknown parameter - need to add*/
- vertical-align: middle;
- text-align: center;
- width: 25px;
+ background:#F1EEE9 none repeat scroll 0%;
+ font-family:Arial,Verdana,sans-serif;
+ font-size:11px;
+ padding: 0pt;
+ border-bottom:1px solid #C4C0B9;
+ border-right:1px solid #C4C0B9;
+ text-align:center;
+ vertical-align:middle;
+ width:25px;
}
+.rich-calendar-cell {
+ background-color:#FFFFFF;
+ font-family:Arial,Verdana,sans-serif;
+ font-size:11px;
+ border-bottom:1px solid #C4C0B9;
+ border-right:1px solid #C4C0B9;
+ padding:0pt;
+ text-align:center;
+ vertical-align:middle;
+}
+
+.rich-calendar-cell-size {
+height:22px;
+width:25px;
+}
+
.rich-calendar-holly {
background-color: #FFEBDA; /*unknown parameter - need to add*/
color: #FF7800; /*unknown parameter - need to add*/
}
+.rich-calendar-boundary-dates {
+color:#A0A0A0;
+}
+
+.rich-calendar-btn {
+cursor:pointer;
+}
+
.rich-calendar-today {
background-color: #ff7800; /*unknown parameter - need to add*/
color: #ffebda; /*unknown parameter - need to add*/
font-weight: bold;
}
-.rich-calendar-spec {
- background-color: #e4f5e2; /*unknown parameter - need to add*/
-}
-
.rich-calendar-select {
background-color: #224986; /*headerBackgroundColor*/
color: #FFFFFF; /*headerTextColor*/
font-weight: bold;
}
-.rich-right-cell {
- border-right: 0px;
-}
-
-.rich-bottom-cell {
- border-bottom: 0px;
-}
-
.rich-calendar-toolfooter {
border-top: 1px solid #c0c0c0; /*panelBorderColor*/
border-right: 0px solid #c0c0c0; /*panelBorderColor*/
@@ -135,21 +145,17 @@
height: 22px;
}
-.rich-calendar-popupicon {
- cursor: pointer;
- vertical-align: middle;
+.rich-calendar-other-month {
+ color: #C7D7EC
}
-.rich-calendar-popupinput {
- vertical-align: middle;
+.rich-calendar-header-optional {
+ background: #D4CFC7;
+ text-align: center;
}
-.rich-calendar-today {
- background-color: #ff7800; /*unknown parameter - need to add*/
- color: #ffebda; /*unknown parameter - need to add*/
- font-weight: bold;
+.rich-calendar-footer-optional {
+ background: #F1EEE9;
+ text-align: center;
}
-.rich-calendar-other-month {
- color: #C7D7EC
-}
\ No newline at end of file
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/HtmlComponentUtil.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/HtmlComponentUtil.java 2008-02-11
10:08:46 UTC (rev 6224)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/HtmlComponentUtil.java 2008-02-11
10:10:09 UTC (rev 6225)
@@ -170,4 +170,7 @@
/** HTML_ATTR_BACKGROUND */
public static final String HTML_ATTR_BACKGROUND = "background";
+
+ /** HTML_ATTR_BACKGROUND */
+ public static final String HTML_ATTR_DISABLED = "disabled";
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesCalendarTemplate.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesCalendarTemplate.java 2008-02-11
10:08:46 UTC (rev 6224)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/template/RichFacesCalendarTemplate.java 2008-02-11
10:10:09 UTC (rev 6225)
@@ -13,12 +13,21 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.TimeZone;
+import javax.smartcardio.ATR;
+
import org.jboss.tools.jsf.vpe.richfaces.ComponentUtil;
import org.jboss.tools.jsf.vpe.richfaces.HtmlComponentUtil;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
+import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
@@ -37,8 +46,6 @@
public class RichFacesCalendarTemplate extends VpeAbstractTemplate {
static String[] HEADER_CONTENT = { "<<", "<",
"", ">", ">>" };
- private List<String> holidays = new ArrayList<String>();
- private String[] weeks = new String[7];
final static int MONTH_LENGTH[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
30, 31 };
final static int LEAP_MONTH_LENGTH[] = { 31, 29, 31, 30, 31, 30, 31, 31,
@@ -50,38 +57,106 @@
final static int NUM_DAYS_IN_WEEK = 7;
final static int NUM_WEEK_ON_PAGE = 6;
final static String TODAY = "Today";
+ final static String VERTICAL_SEPARATOR = "|";
+ final static String APPLY = "Apply";
final static int CALENDAR_WIDTH = 200;
+ final static int CALENDAR_INPUT_WIDTH = CALENDAR_WIDTH - 20;
final static int CALENDAR_IMAGE_WIDTH = 20;
- final static String ATTRIBUTE_POPUP = "popup";
+ final static int CALENDAR_CUSTOM_IMAGE_WIDTH = 40;
+ final static int CALENDAR_BUTTON_WIDTH = 100;
final static String ATTRIBUTE_TEXT = "text";
- final static String WEEK_DAY_HTML_CLASS_ATTR = "rich-calendar-days";
- final static String HOL_WEEK_DAY_HTML_CLASS_ATTR = "rich-calendar-days
rich-calendar-days-holly";
- final static String TODAY_HTML_CLASS_ATTR = "rich-cell-size rich-calendar-cell
rich-calendar-today ";
- final static String CUR_MONTH_HTML_CLASS_ATTR = "rich-cell-size
rich-calendar-cell";
- final static String HOL_CUR_MONTH_HTML_CLASS_ATTR = "rich-cell-size
rich-calendar-cell rich-calendar-holly "/* rich-right-cell " */;
- final static String OTHER_MONTH_HTML_CLASS_ATTR = "rich-cell-size
rich-calendar-cell rich-calendar-other-month ";
- final static String HOL_OTHER_MONTH_HTML_CLASS_ATTR = "rich-cell-size
rich-calendar-cell rich-calendar-holly rich-calendar-other-month" /* rich-right-cell
" */;
+ static final String DEFAULT_DATE_PATTERN = "MMMM, yyyy";
+ static final String HEADER = "header";
+ static final String FOOTER = "footer";
+
+ /*Attributes*/
+ static final String BUTTON_LABEL = "buttonLabel";
+ static final String BUTTON_ICON = "buttonIcon";
+ static final String DIRECTION = "direction";
+ static final String ENABLE_MANUAL_INPUT = "enableManualInput";
+ static final String CELL_HEIGHT = "cellHeight";
+ static final String CELL_WIDTH = "cellWidth";
+ static final String DATE_PATTERN = "datePattern";
+ static final String DISABLED = "disabled";
+ static final String HORIZONTAL_OFFSET = "horizontalOffset";
+ static final String VERTICAL_OFFSET = "verticalOffset";
+ static final String LOCALE = "locale";
+ static final String POPUP = "popup";
+ static final String SHOW_APPLY_BUTTON = "showApplyButton";
+ static final String SHOW_INPUT = "showInput";
+ static final String SHOW_SHOW_WEEKS_DAY_BAR = "showWeekDaysBar";
+ static final String SHOW_WEEKS_BAR = "showWeeksBar";
+ static final String TODAY_CONTROL_MODE = "todayControlMode";
+
+ /*Attribute values*/
+ static final String DIRECTIONS_TOP_LEFT = "top-left";
+ static final String DIRECTIONS_TOP_RIGHT = "top-right";
+ static final String DIRECTIONS_BOTTOM_LEFT = "bottom-left";
+ static final String DIRECTIONS_BOTTOM_RIGHT = "top-right";
+ /*CSS classes*/
+ static final String CSS_R_C_INPUT = "rich-calendar-input";
+ static final String CSS_R_C_BUTTON = "rich-calendar-button";
+ static final String CSS_R_C_EXTERIOR = "rich-calendar-exterior";
+ static final String CSS_R_C_HEADER = "rich-calendar-header";
+ static final String CSS_R_C_TOOL = "rich-calendar-tool";
+ static final String CSS_R_C_MONTH = "rich-calendar-month";
+ static final String CSS_R_C_TOOL_CLOSE = "rich-calendar-tool-close";
+ static final String CSS_R_C_DAYS = "rich-calendar-days";
+ static final String CSS_R_C_WEEKENDS = "rich-calendar-weekends";
+ static final String CSS_R_C_WEEK = "rich-calendar-week";
+ static final String CSS_R_C_CELL = "rich-calendar-cell";
+ static final String CSS_R_C_CELL_SIZE = "rich-calendar-cell-size";
+ static final String CSS_R_C_HOLLY = "rich-calendar-holly";
+ static final String CSS_R_C_BOUNDARY_DATES = "rich-calendar-boundary-dates";
+ static final String CSS_R_C_BTN = "rich-calendar-btn";
+ static final String CSS_R_C_TODAY = "rich-calendar-today";
+ static final String CSS_R_C_SELECT = "rich-calendar-select";
+ static final String CSS_R_C_TOOLFOOTER = "rich-calendar-toolfooter";
+ static final String CSS_R_C_FOOTER = "rich-calendar-footer";
+ static final String CSS_R_C_OTHER_MONTH = "rich-calendar-other-month";
+ static final String CSS_R_C_HEADER_OPTIONAL =
"rich-calendar-header-optional";
+ static final String CSS_R_C_FOOTER_OPTIONAL =
"rich-calendar-footer-optional";
+
+ final static String WEEK_DAY_HTML_CLASS_ATTR = CSS_R_C_DAYS;
+ final static String HOL_WEEK_DAY_HTML_CLASS_ATTR = CSS_R_C_DAYS + " " +
CSS_R_C_WEEKENDS;
+ final static String TODAY_HTML_CLASS_ATTR = CSS_R_C_CELL_SIZE + " "+
CSS_R_C_CELL + " "+ CSS_R_C_TODAY;
+ final static String CUR_MONTH_HTML_CLASS_ATTR = CSS_R_C_CELL_SIZE + " "+
CSS_R_C_CELL;
+ final static String HOL_CUR_MONTH_HTML_CLASS_ATTR = CSS_R_C_CELL_SIZE + " "+
CSS_R_C_CELL + " "+ CSS_R_C_HOLLY;
+ final static String OTHER_MONTH_HTML_CLASS_ATTR = CSS_R_C_CELL_SIZE + " "+
CSS_R_C_CELL + " "+ CSS_R_C_BOUNDARY_DATES;
+ final static String HOL_OTHER_MONTH_HTML_CLASS_ATTR = CSS_R_C_CELL_SIZE + " "+
CSS_R_C_CELL + " "+ CSS_R_C_HOLLY + " " + CSS_R_C_BOUNDARY_DATES ;
+
+ private String buttonLabel;
+ private String buttonIcon;
+ private String direction;
+ private String cellHeight;
+ private String cellWidth;
+ private String datePattern;
+ private String disabled;
+ private String enableManualInput;
+ private String horizontalOffset;
+ private String verticalOffset;
+ private String locale;
+ private String popup;
+ private String showApplyButton;
+ private String showInput;
+ private String showWeekDaysBar;
+ private String showWeeksBar;
+ private String todayControlMode;
+
+ private List<String> holidays = new ArrayList<String>();
+ private String[] weeks = new String[7];
+ static Set<String> directions;
+
public RichFacesCalendarTemplate() {
super();
- Calendar cal = Calendar.getInstance();
- int firstDayOfWeek = cal.getFirstDayOfWeek();
- while (firstDayOfWeek != cal.get(Calendar.DAY_OF_WEEK)) {
- cal.add(Calendar.DAY_OF_MONTH, 1);
- }
-
- SimpleDateFormat sdf = new SimpleDateFormat("EE");
- String dayOfWeek = "";
- for (int i = 0; i < NUM_DAYS_IN_WEEK; i++) {
- dayOfWeek = sdf.format(cal.getTime());
- weeks[i] = dayOfWeek;
- if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY
- || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
- holidays.add(dayOfWeek);
- cal.add(Calendar.DAY_OF_MONTH, 1);
- }
-
+ directions = new HashSet<String>(4);
+ directions.add(DIRECTIONS_TOP_LEFT);
+ directions.add(DIRECTIONS_TOP_RIGHT);
+ directions.add(DIRECTIONS_BOTTOM_LEFT);
+ directions.add(DIRECTIONS_BOTTOM_RIGHT);
+
}
/**
@@ -100,16 +175,29 @@
public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument) {
Element source = (Element) sourceNode;
- String popup = source.getAttribute(ATTRIBUTE_POPUP);
+
+ readAttributes(sourceNode);
+ initCalendar();
+
ComponentUtil.setCSSLink(pageContext, STYLE_PATH, "calendar");
- VpeCreationData creationData;
+ nsIDOMElement div = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ VpeCreationData creationData = new VpeCreationData(div);
if (popup != null && popup.equalsIgnoreCase("false")) {
- nsIDOMElement calendar = createCalendar(visualDocument);
- creationData = new VpeCreationData(calendar);
+ nsIDOMElement calendar;
+ if ("true".equalsIgnoreCase(disabled)) {
+ calendar = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_DIV);
+ } else {
+ calendar = createCalendar(visualDocument, creationData, source);
+ }
+ //creationData = new VpeCreationData(calendar);
+ div.appendChild(calendar);
} else {
nsIDOMElement calendarWithPopup = createCalendarWithPopup(
visualDocument, source);
- creationData = new VpeCreationData(calendarWithPopup);
+ //creationData = new VpeCreationData(calendarWithPopup);
+ div.appendChild(calendarWithPopup);
}
return creationData;
}
@@ -121,33 +209,83 @@
*/
private nsIDOMElement createCalendarWithPopup(
nsIDOMDocument visualDocument, Element source) {
+ nsIDOMElement table = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_TABLE);
+ nsIDOMElement tr = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_TR);
+ nsIDOMElement td1 = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_TD);
+ nsIDOMElement td2 = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_TD);
+
+ table.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
+ HtmlComponentUtil.HTML_ATR_WIDTH + " : 100%");
+
+ tr.appendChild(td1);
+ tr.appendChild(td2);
+ table.appendChild(tr);
+
nsIDOMElement div = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_DIV);
- div.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
- HtmlComponentUtil.HTML_ATR_WIDTH + " : " + CALENDAR_WIDTH
- + "px;");
- nsIDOMElement input = visualDocument
+ int divWidth = CALENDAR_WIDTH + CALENDAR_IMAGE_WIDTH;
+ div.appendChild(table);
+
+ if (!"false".equalsIgnoreCase(showInput)) {
+ nsIDOMElement input = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_INPUT);
- input.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
- HtmlComponentUtil.HTML_ATR_WIDTH + " : "
- + (CALENDAR_WIDTH - CALENDAR_IMAGE_WIDTH) + "px;");
- input.setAttribute(HtmlComponentUtil.HTML_TYPE_ATTR, ATTRIBUTE_TEXT);
- input.setAttribute(HtmlComponentUtil.HTML_READONLY_ATTR, "true");
- input.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
"rich-calendar-popupinput");
- String value = source.getAttribute(HtmlComponentUtil.HTML_VALUE_ATTR);
- if (value != null) {
- input.setAttribute(HtmlComponentUtil.HTML_VALUE_ATTR, value);
+ input.setAttribute(HtmlComponentUtil.HTML_TYPE_ATTR, ATTRIBUTE_TEXT);
+ input.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_R_C_INPUT);
+ input.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
+ HtmlComponentUtil.HTML_ATR_WIDTH + " : "
+ + CALENDAR_INPUT_WIDTH + "px;");
+
+ if ("true".equals(enableManualInput)) {
+ input.setAttribute(HtmlComponentUtil.HTML_READONLY_ATTR, "true");
+ }
+ if ("true".equals(disabled)) {
+ input.setAttribute(HtmlComponentUtil.HTML_ATTR_DISABLED, "true");
+ }
+
+ if (attrPresents(datePattern)) {
+ input.setAttribute(HtmlComponentUtil.HTML_VALUE_ATTR, datePattern);
+ }
+ td1.appendChild(input);
+ //div.appendChild(input);
}
+
- nsIDOMElement image = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_IMG);
- image.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- "rich-calendar-popupicon");
- ComponentUtil.setImg(image, BUTTON_IMG);
-
- div.appendChild(input);
- div.appendChild(image);
-
+ if (attrPresents(buttonLabel)) {
+ nsIDOMElement button = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_INPUT);
+ button.setAttribute(HtmlComponentUtil.HTML_TYPE_ATTR,
+ HtmlComponentUtil.HTML_TAG_BUTTON);
+ button.setAttribute(HtmlComponentUtil.HTML_VALUE_ATTR, buttonLabel);
+ button.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_R_C_BUTTON);
+ if ("true".equalsIgnoreCase(disabled)) {
+ button.setAttribute(HtmlComponentUtil.HTML_ATTR_DISABLED, "true");
+ }
+
+ td2.appendChild(button);
+ divWidth = CALENDAR_WIDTH + CALENDAR_BUTTON_WIDTH;
+ //div.appendChild(button);
+ } else {
+ nsIDOMElement image = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_IMG);
+ image.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
+ CSS_R_C_BUTTON);
+ if (attrPresents(buttonIcon)) {
+ image.setAttribute(HtmlComponentUtil.HTML_ATR_SRC, buttonIcon);
+ divWidth = CALENDAR_WIDTH + CALENDAR_CUSTOM_IMAGE_WIDTH;
+ } else {
+ ComponentUtil.setImg(image, BUTTON_IMG);
+ divWidth = CALENDAR_WIDTH + CALENDAR_IMAGE_WIDTH;
+ }
+ td2.appendChild(image);
+ //div.appendChild(image);
+ }
+ div.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
+ HtmlComponentUtil.HTML_ATR_WIDTH + " : "
+ + divWidth + "px; overflow: hidden;");
return div;
}
@@ -175,10 +313,13 @@
public boolean isRecreateAtAttrChange(VpePageContext pageContext,
Element sourceElement, nsIDOMDocument visualDocument,
nsIDOMElement visualNode, Object data, String name, String value) {
- if (name.equalsIgnoreCase(ATTRIBUTE_POPUP)) {
+/*
+ if (name.equalsIgnoreCase(POPUP)) {
return true;
}
return false;
+*/
+ return true;
}
/**
@@ -186,32 +327,67 @@
* @param visualDocument
* @return Node of the visual tree.
*/
- private nsIDOMElement createCalendar(nsIDOMDocument visualDocument) {
+ private nsIDOMElement createCalendar(nsIDOMDocument visualDocument, VpeCreationData
creationData, Element sourceElement) {
nsIDOMElement div = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_DIV);
div.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
HtmlComponentUtil.HTML_ATR_WIDTH + " : " + CALENDAR_WIDTH
- + "px;");
+ + "px; overflow: hidden;");
+
nsIDOMElement table = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_TABLE);
table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR, "0");
table.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, "0");
table.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR, "0");
table.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- "calendar-exterior");
+ CSS_R_C_EXTERIOR);
nsIDOMElement tbody = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_TBODY);
+ Element headerFacet = ComponentUtil.getFacet(sourceElement, HEADER);
+ nsIDOMElement optionalHeader = createCalendarOptionalHeaderOrFooter(visualDocument,
creationData, headerFacet, true);
+ Element footerFacet = ComponentUtil.getFacet(sourceElement, FOOTER);
+ nsIDOMElement optionalFooter = createCalendarOptionalHeaderOrFooter(visualDocument,
creationData, footerFacet, false);
nsIDOMElement header = createCalendarHeader(visualDocument);
nsIDOMElement calendarBody = createCalendarBody(visualDocument);
+
+ tbody.appendChild(optionalHeader);
tbody.appendChild(header);
tbody.appendChild(calendarBody);
+ tbody.appendChild(optionalFooter);
+
table.appendChild(tbody);
div.appendChild(table);
- return div;
+ //return div;
+ return table;
}
+ private nsIDOMElement createCalendarOptionalHeaderOrFooter(
+ nsIDOMDocument visualDocument, VpeCreationData creationData, Element facetBody,
boolean isHeader) {
+ nsIDOMElement tr = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_TR);
+ nsIDOMElement td = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_TD);
+ td.setAttribute(HtmlComponentUtil.HTML_TABLE_COLSPAN, "" + COLUMN);
+ tr.appendChild(td);
+
+ if (isHeader) {
+ td.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_R_C_HEADER_OPTIONAL);
+ //td.appendChild(visualDocument
+ // .createTextNode("header Here->"));
+ } else {
+ td.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, CSS_R_C_FOOTER_OPTIONAL);
+ td.appendChild(visualDocument
+ .createTextNode("footer Here->"));
+ }
+
+ VpeChildrenInfo child = new VpeChildrenInfo(td);
+ child.addSourceChild(facetBody);
+ creationData.addChildrenInfo(child);
+ return tr;
+ }
+
/**
*
* @param visualDocument
@@ -219,45 +395,59 @@
*/
private nsIDOMElement createCalendarHeader(nsIDOMDocument visualDocument) {
nsIDOMElement tr = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TR);
- nsIDOMElement td = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- td.setAttribute(HtmlComponentUtil.HTML_TABLE_COLSPAN, "" + COLUMN);
+ .createElement(HtmlComponentUtil.HTML_TAG_TR);
+ nsIDOMElement td = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_TD);
+ td.setAttribute(HtmlComponentUtil.HTML_TABLE_COLSPAN, "" + COLUMN);
- SimpleDateFormat sdf = new SimpleDateFormat("MMMM, yyyy");
- Calendar cal = Calendar.getInstance();
- HEADER_CONTENT[2] = sdf.format(cal.getTime());
+ SimpleDateFormat sdf = new SimpleDateFormat();
+// Date date = Calendar.getInstance().getTime();
+ Date date = getCalendarWithLocale().getTime();
+ String dateStr = "";
+ if (attrPresents(datePattern)) {
+ try {
+ sdf.applyPattern(datePattern);
+ dateStr = sdf.format(date);
+ } catch (Exception e) {
+ sdf.applyPattern(DEFAULT_DATE_PATTERN);
+ dateStr = sdf.format(date);
+ }
+ } else {
+ sdf.applyPattern(DEFAULT_DATE_PATTERN);
+ dateStr = sdf.format(date);
+ }
+ HEADER_CONTENT[2] = dateStr;
- nsIDOMElement table = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TABLE);
- table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR, "0");
- table.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR, "0");
- table.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, "0");
- table.setAttribute(HtmlComponentUtil.HTML_ATR_WIDTH, FILL_WIDTH);
+ nsIDOMElement table = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_TABLE);
+ table.setAttribute(HtmlComponentUtil.HTML_CELLPADDING_ATTR, "0");
+ table.setAttribute(HtmlComponentUtil.HTML_CELLSPACING_ATTR, "0");
+ table.setAttribute(HtmlComponentUtil.HTML_BORDER_ATTR, "0");
+ table.setAttribute(HtmlComponentUtil.HTML_ATR_WIDTH, FILL_WIDTH);
- nsIDOMElement tbody = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TBODY);
+ nsIDOMElement tbody = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_TBODY);
- nsIDOMElement tr1 = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TR);
- for (int i = 0; i < HEADER_CONTENT.length; i++) {
- nsIDOMElement td1 = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- td1.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- i == 2 ? "rich-calendar-month" : "rich-calendar-tool");
+ nsIDOMElement tr1 = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_TR);
+ for (int i = 0; i < HEADER_CONTENT.length; i++) {
+ nsIDOMElement td1 = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_TD);
+ td1.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
+ i == 2 ? CSS_R_C_MONTH : CSS_R_C_TOOL);
- nsIDOMText text1 = visualDocument.createTextNode(HEADER_CONTENT[i]);
- td1.appendChild(text1);
- tr1.appendChild(td1);
+ nsIDOMText text1 = visualDocument.createTextNode(HEADER_CONTENT[i]);
+ td1.appendChild(text1);
+ tr1.appendChild(td1);
+ }
+
+ tbody.appendChild(tr1);
+ table.appendChild(tbody);
+ td.appendChild(table);
+ tr.appendChild(td);
+ return tr;
}
- tbody.appendChild(tr1);
- table.appendChild(tbody);
- td.appendChild(table);
- tr.appendChild(td);
- return tr;
- }
-
/**
*
* @param visualDocument
@@ -271,44 +461,47 @@
nsIDOMElement bodyTR = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_TR);
- Calendar cal1 = Calendar.getInstance();
+ //Calendar cal1 = Calendar.getInstance();
+ Calendar cal1 = getCalendarWithLocale();
SimpleDateFormat wdf = new SimpleDateFormat("EE");
cal1.set(Calendar.WEEK_OF_MONTH, Calendar.SATURDAY);
-
- for (int i = 0; i < COLUMN; i++) {
- nsIDOMElement td = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
-
- if (i == 0) {
- td.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- WEEK_DAY_HTML_CLASS_ATTR);
- nsIDOMElement br = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_BR);
- td.appendChild(br);
- } else {
- if (holidays.contains(weeks[i - 1])) {
+ // Create week days row
+ if (!"false".equalsIgnoreCase(showWeekDaysBar)) {
+ for (int i = 0; i < COLUMN; i++) {
+ nsIDOMElement td = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_TD);
+ if ((i == 0) && (!"false".equalsIgnoreCase(showWeeksBar))) {
td.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- HOL_WEEK_DAY_HTML_CLASS_ATTR);
- } else {
- td.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
WEEK_DAY_HTML_CLASS_ATTR);
+ nsIDOMElement br = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_BR);
+ td.appendChild(br);
+ bodyTR.appendChild(td);
+ } else if ( i > 0) {
+ if (holidays.contains(weeks[i - 1])) {
+ td.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
+ HOL_WEEK_DAY_HTML_CLASS_ATTR);
+ } else {
+ td.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
+ WEEK_DAY_HTML_CLASS_ATTR);
+ }
+ nsIDOMText text = visualDocument.createTextNode(i == 0 ? ""
+ : weeks[i - 1]);
+ td.appendChild(text);
+ bodyTR.appendChild(td);
}
- nsIDOMText text = visualDocument.createTextNode(i == 0 ? ""
- : weeks[i - 1]);
- td.appendChild(text);
+ //bodyTR.appendChild(td);
}
- bodyTR.appendChild(td);
- }
+ tbody.appendChild(bodyTR);
+ } // showWeekDaysBar
- tbody.appendChild(bodyTR);
-
// Calendar body
+ //Calendar cal = Calendar.getInstance();
+ Calendar cal = getCalendarWithLocale();
- Calendar cal = Calendar.getInstance();
-
int month = cal.get(Calendar.MONTH);
int dayN = cal.get(Calendar.DAY_OF_MONTH);
@@ -323,16 +516,20 @@
nsIDOMElement tr = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_TR);
- // Week in year
- nsIDOMElement weekTD = visualDocument
- .createElement(HtmlComponentUtil.HTML_TAG_TD);
- weekTD.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- "rich-calendar-week");
- nsIDOMText weekText = visualDocument.createTextNode(""
- + cal.get(Calendar.WEEK_OF_YEAR));
- weekTD.appendChild(weekText);
- tr.appendChild(weekTD);
+
+ if (!"false".equalsIgnoreCase(showWeeksBar)) {
+ // Week in year
+ nsIDOMElement weekTD = visualDocument
+ .createElement(HtmlComponentUtil.HTML_TAG_TD);
+ weekTD.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
+ CSS_R_C_WEEK);
+ nsIDOMText weekText = visualDocument.createTextNode(""
+ + cal.get(Calendar.WEEK_OF_YEAR));
+ weekTD.appendChild(weekText);
+ tr.appendChild(weekTD);
+ }
+
//for number of days in week
for (int j = NUM_DAYS_IN_WEEK; j > 0; j--) {
@@ -372,6 +569,19 @@
}
td.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR, currentAttr);
+ if (attrPresents(cellWidth) && attrPresents(cellHeight)) {
+ td.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
+ HtmlComponentUtil.HTML_ATR_WIDTH + ":" + cellWidth
+ + "px;" + HtmlComponentUtil.HTML_ATR_HEIGHT
+ + ":" + cellHeight + "px;");
+ } else if (attrPresents(cellWidth)) {
+ td.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
+ HtmlComponentUtil.HTML_ATR_WIDTH +":" + cellWidth + "px;");
+ } else if (attrPresents(cellHeight)) {
+ td.setAttribute(HtmlComponentUtil.HTML_STYLE_ATTR,
+ HtmlComponentUtil.HTML_ATR_HEIGHT+":" + cellHeight + "px;");
+ }
+
nsIDOMText text = visualDocument.createTextNode(""
+ cal.get(Calendar.DAY_OF_MONTH));
td.appendChild(text);
@@ -405,10 +615,11 @@
nsIDOMElement td1 = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_TD);
td1.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- "rich-calendar-toolfooter");
+ CSS_R_C_TOOLFOOTER);
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
- cal = Calendar.getInstance();
+// cal = Calendar.getInstance();
+ cal = getCalendarWithLocale();
nsIDOMText text1 = visualDocument.createTextNode(sdf.format(cal
.getTime()));
@@ -419,17 +630,33 @@
.createElement(HtmlComponentUtil.HTML_TAG_TD);
td2.setAttribute(HtmlComponentUtil.HTML_ATR_WIDTH, FILL_WIDTH);
td2.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- "rich-calendar-toolfooter");
+ CSS_R_C_TOOLFOOTER);
tr1.appendChild(td2);
nsIDOMElement td3 = visualDocument
.createElement(HtmlComponentUtil.HTML_TAG_TD);
td3.setAttribute(HtmlComponentUtil.HTML_ATR_WIDTH, FILL_WIDTH);
td3.setAttribute(HtmlComponentUtil.HTML_CLASS_ATTR,
- "rich-calendar-toolfooter");
+ CSS_R_C_TOOLFOOTER);
td3.setAttribute(HtmlComponentUtil.HTML_ALIGN_ATTR,
HtmlComponentUtil.HTML_ALIGN_RIGHT_VALUE);
- nsIDOMText text3 = visualDocument.createTextNode(TODAY);
+
+ String nodeText;
+ if ("false".equalsIgnoreCase(showApplyButton)) {
+ if ("hidden".equalsIgnoreCase(todayControlMode)) {
+ nodeText = "";
+ } else {
+ nodeText = TODAY;
+ }
+ } else {
+ if ("hidden".equalsIgnoreCase(todayControlMode)) {
+ nodeText = APPLY;
+ } else {
+ nodeText = TODAY + VERTICAL_SEPARATOR + APPLY;
+ }
+ }
+ nsIDOMText text3 = visualDocument.createTextNode(nodeText);
+
td3.appendChild(text3);
tr1.appendChild(td3);
@@ -451,7 +678,7 @@
super.setAttribute(pageContext, sourceElement, visualDocument,
visualNode, data, name, value);
if (name.equalsIgnoreCase(HtmlComponentUtil.HTML_VALUE_ATTR)) {
- String popup = sourceElement.getAttribute(ATTRIBUTE_POPUP);
+ String popup = sourceElement.getAttribute(POPUP);
if (popup != null && popup.equalsIgnoreCase("false"))
return;
nsIDOMElement element = (nsIDOMElement) visualNode
@@ -474,7 +701,7 @@
super.removeAttribute(pageContext, sourceElement, visualDocument,
visualNode, data, name);
if (name.equalsIgnoreCase(HtmlComponentUtil.HTML_VALUE_ATTR)) {
- String popup = sourceElement.getAttribute(ATTRIBUTE_POPUP);
+ String popup = sourceElement.getAttribute(POPUP);
if (popup != null && popup.equalsIgnoreCase("false"))
return;
nsIDOMElement element = (nsIDOMElement) visualNode
@@ -486,4 +713,89 @@
input.removeAttribute(HtmlComponentUtil.HTML_VALUE_ATTR);
}
}
+
+ private void readAttributes(Node sourceNode) {
+ Element source = (Element) sourceNode;
+ buttonLabel = source.getAttribute(BUTTON_LABEL);
+ buttonIcon = source.getAttribute(BUTTON_ICON);
+ direction = source.getAttribute(DIRECTION);
+ cellHeight = source.getAttribute(CELL_HEIGHT);
+ cellWidth = source.getAttribute(CELL_WIDTH);
+ datePattern = source.getAttribute(DATE_PATTERN);
+ disabled = source.getAttribute(DISABLED);
+ enableManualInput = source.getAttribute(ENABLE_MANUAL_INPUT);
+ horizontalOffset = source.getAttribute(HORIZONTAL_OFFSET);
+ verticalOffset = source.getAttribute(VERTICAL_OFFSET);
+ locale = source.getAttribute(LOCALE);
+ popup = source.getAttribute(POPUP);
+ showApplyButton = source.getAttribute(SHOW_APPLY_BUTTON);
+ showInput = source.getAttribute(SHOW_INPUT);
+ showWeekDaysBar = source.getAttribute(SHOW_SHOW_WEEKS_DAY_BAR);
+ showWeeksBar = source.getAttribute(SHOW_WEEKS_BAR);
+ todayControlMode = source.getAttribute(TODAY_CONTROL_MODE);
+ }
+
+ private boolean attrPresents(String attr) {
+ return ((null != attr) && (!"".equals(attr)));
+ }
+
+ private void initCalendar() {
+// Calendar cal = Calendar.getInstance();
+ Calendar cal = getCalendarWithLocale();
+
+ int firstDayOfWeek = cal.getFirstDayOfWeek();
+ while (firstDayOfWeek != cal.get(Calendar.DAY_OF_WEEK)) {
+ cal.add(Calendar.DAY_OF_MONTH, 1);
+ }
+
+ SimpleDateFormat sdf = new SimpleDateFormat("EE");
+ String dayOfWeek = "";
+ for (int i = 0; i < NUM_DAYS_IN_WEEK; i++) {
+ dayOfWeek = sdf.format(cal.getTime());
+ weeks[i] = dayOfWeek;
+ if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY
+ || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
+ holidays.add(dayOfWeek);
+ cal.add(Calendar.DAY_OF_MONTH, 1);
+ }
+ }
+
+ private Calendar getCalendarWithLocale() {
+ Locale customLocale;
+ if (attrPresents(this.locale)) {
+ customLocale = parseLocale(locale);
+ return Calendar.getInstance(customLocale);
+ }
+ return Calendar.getInstance();
+ }
+
+public Locale parseLocale(String localeStr){
+
+ int length = localeStr.length();
+ if(null==localeStr||length<2){
+ return Locale.getDefault();
+ }
+
+ //Lookup index of first '_' in string locale representation.
+ int index1 = localeStr.indexOf("_");
+ //Get first charters (if exist) from string
+ String language = null;
+ if(index1!=-1){
+ language = localeStr.substring(0, index1);
+ }else{
+ return new Locale(localeStr);
+ }
+ //Lookup index of second '_' in string locale representation.
+ int index2 = localeStr.indexOf("_", index1+1);
+ String country = null;
+ if(index2!=-1){
+ country = localeStr.substring(index1+1, index2);
+ String variant = localeStr.substring(index2+1);
+ return new Locale(language, country, variant);
+ }else{
+ country = localeStr.substring(index1+1);
+ return new Locale(language, country);
+ }
+ }
+
}