001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.rave.web.ui.model.scheduler;
042:
043: import java.io.IOException;
044: import java.io.Serializable;
045: import java.util.Calendar;
046: import javax.faces.context.FacesContext;
047: import com.sun.rave.web.ui.theme.Theme;
048: import com.sun.rave.web.ui.util.ThemeUtilities;
049:
050: import javax.faces.context.FacesContext;
051:
052: // Delete the setters once you have reimplemented this not to
053: // use the default Serializable mechanism, but the same as
054: // in the converter....
055:
056: public class RepeatUnit implements Serializable {
057:
058: public final static String HOURS = "HOURS";
059: public final static String DAYS = "DAYS";
060: public final static String WEEKS = "WEEKS";
061: public final static String MONTHS = "MONTHS";
062:
063: private static final boolean DEBUG = false;
064:
065: private static RepeatUnit HOURS_RI = null;
066: private static RepeatUnit DAYS_RI = null;
067: private static RepeatUnit WEEKS_RI = null;
068: private static RepeatUnit MONTHS_RI = null;
069:
070: private Integer calField = null;
071: private String key = null;
072: private String representation = null;
073:
074: public RepeatUnit() {
075: }
076:
077: public RepeatUnit(int calFieldInt, String key, String rep) {
078: if (DEBUG)
079: log("Create new RU");
080: this .calField = new Integer(calFieldInt);
081: this .key = key;
082: this .representation = rep;
083: if (DEBUG)
084: log("Representation is " + this .representation);
085: }
086:
087: public static RepeatUnit getInstance(String representation) {
088:
089: if (DEBUG)
090: log("getInstance(" + representation + ")");
091:
092: if (representation.equals(HOURS)) {
093: if (HOURS_RI == null) {
094: HOURS_RI = new RepeatUnit(Calendar.HOUR_OF_DAY,
095: "Scheduler.hours", HOURS);
096: }
097: return HOURS_RI;
098: }
099: if (representation.equals(DAYS)) {
100: if (DAYS_RI == null) {
101: DAYS_RI = new RepeatUnit(Calendar.DATE,
102: "Scheduler.days", DAYS);
103: }
104: return DAYS_RI;
105: }
106: if (representation.equals(WEEKS)) {
107: if (WEEKS_RI == null) {
108: WEEKS_RI = new RepeatUnit(Calendar.WEEK_OF_YEAR,
109: "Scheduler.weeks", WEEKS);
110: }
111: return WEEKS_RI;
112: }
113: if (representation.equals(MONTHS)) {
114: if (MONTHS_RI == null) {
115: MONTHS_RI = new RepeatUnit(Calendar.MONTH,
116: "Scheduler.months", MONTHS);
117: }
118: return MONTHS_RI;
119: }
120: return null;
121: }
122:
123: /**
124: * Getter for property calendarField.
125: * @return Value of property calendarField.
126: */
127: public Integer getCalendarField() {
128: return calField;
129: }
130:
131: /**
132: * Setter for property calendarField.
133: * @return Value of property calendarField.
134: */
135: public void setCalendarField(Integer calField) {
136: this .calField = calField;
137: }
138:
139: public void setKey(String key) {
140: this .key = key;
141: }
142:
143: public String getKey() {
144: return key;
145: }
146:
147: public void setRepresentation(String representation) {
148: this .representation = representation;
149: }
150:
151: public String getRepresentation() {
152: return representation;
153: }
154:
155: /**
156: * Getter for property labelKey.
157: * @return Value of property labelKey.
158: */
159: public String getLabel(FacesContext context) {
160: return ThemeUtilities.getTheme(context).getMessage(key);
161: }
162:
163: public boolean equals(Object object) {
164: if (object == null) {
165: return false;
166: }
167: if (!(object instanceof RepeatUnit)) {
168: return false;
169: }
170: return (((RepeatUnit) object).getRepresentation()
171: .equals(representation));
172: }
173:
174: private static void log(String s) {
175: System.out.println("RepeatUnit::" + s);
176: }
177: }
|