001: /**
002: * $Id: Property.java,v 1.9 2005/11/07 21:42:51 rt94277 Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.admin.console.desktop;
014:
015: import java.text.MessageFormat;
016:
017: import com.sun.portal.admin.console.common.PSBaseBean;
018: import com.sun.portal.admin.common.DesktopConstants;
019: import java.util.List;
020: import java.util.ArrayList;
021: import java.util.Iterator;
022: import com.sun.web.ui.model.Option;
023:
024: public class Property {
025:
026: public String name; //name of the property
027: public short type; //DesktopConstants.KEY_TYPE
028: public boolean named; //DesktopConstants.KEY_NAMED
029: public List values = new ArrayList(); //DesktopConstants.KEY_VALUE
030: public boolean advanced; //DesktopConstants.KEY_CATEGORY
031: public String state; //DesktopConstants.KEY_STATE
032:
033: public Property(String name, boolean named, short type,
034: Object value, boolean advanced, String state) {
035: this .name = name;
036: this .named = named;
037: this .type = type;
038: //the value is a List only if the type is string list
039: if (type == DesktopConstants.TYPE_STRING_LIST_PROPERTY) {
040: this .values = (List) value;
041: } else { //otherwise the value is just a string
042: this .values.add(0, value.toString());
043: }
044: this .advanced = advanced;
045: this .state = state;
046: }
047:
048: public String getName() {
049: return name;
050: }
051:
052: public boolean isNamed() {
053: return named;
054: }
055:
056: public String getValue() {
057: return (String) values.get(0);
058: }
059:
060: public void setvalue(String value) {
061: values.add(0, value);
062: }
063:
064: public Boolean getBoolTrueValue() {
065: return new Boolean((String) values.get(0));
066: }
067:
068: public void setBoolTrueValue(Boolean value) {
069: values.add(0, value.toString());
070: }
071:
072: public Boolean getBoolFalseValue() {
073: Boolean b = new Boolean(!getBoolTrueValue().booleanValue());
074: return b;
075: }
076:
077: public void setBoolFalseValue(Boolean value) {
078: //nothing
079: }
080:
081: public String getCategory() {
082: if (advanced) {
083: return PSBaseBean.getLocalizedString("desktop",
084: "edit.properties.category.advanced");
085: } else {
086: return PSBaseBean.getLocalizedString("desktop",
087: "edit.properties.category.basic");
088: }
089: }
090:
091: public String getState() {
092: return PSBaseBean.getLocalizedString("desktop", state);
093: }
094:
095: public String getStateTip() {
096: return PSBaseBean.getLocalizedString("desktop", state
097: + ".toolTip");
098: }
099:
100: public boolean isCustomized() {
101: if ("property.state.customized".equals(state)) {
102: return true;
103: } else {
104: return false;
105: }
106: }
107:
108: public boolean isInherited() {
109: if ("property.state.inherited".equals(state)) {
110: return true;
111: } else {
112: return false;
113: }
114: }
115:
116: public boolean isNested() {
117: if (type == DesktopConstants.TYPE_COLLECTION_PROPERTY) {
118: return true;
119: } else {
120: return false;
121: }
122: }
123:
124: public boolean isString() {
125: if (type == DesktopConstants.TYPE_STRING_PROPERTY) {
126: return true;
127: } else {
128: return false;
129: }
130: }
131:
132: public boolean isNumeric() {
133: if (type == DesktopConstants.TYPE_INTEGER_PROPERTY) {
134: return true;
135: } else {
136: return false;
137: }
138: }
139:
140: public boolean isBool() {
141: if (type == DesktopConstants.TYPE_BOOLEAN_PROPERTY) {
142: return true;
143: } else {
144: return false;
145: }
146: }
147:
148: public String[] getValueArray() {
149: Object[] oa = values.toArray();
150: String[] sa = new String[oa.length];
151: for (int i = 0; i < oa.length; i++) {
152: sa[i] = (String) oa[i];
153: }
154: return sa;
155: }
156:
157: public void setValueArray(String[] strValues) {
158: values.clear();
159: for (int i = 0; i < strValues.length; i++) {
160: values.add(strValues[i]);
161: }
162: }
163:
164: public String getToolTipValues() {
165: StringBuffer vlist = new StringBuffer();
166: Iterator iter = values.iterator();
167: while (iter.hasNext()) {
168: vlist.append((String) iter.next()).append(", ");
169: }
170: return vlist.toString();
171: }
172:
173: public String getNumValues() {
174: String message = PSBaseBean.getLocalizedString("desktop",
175: "edit.properties.label.numValues");
176: Object[] tokens = { new Integer(values.size()) };
177: MessageFormat mf = new MessageFormat(message);
178: message = mf.format(tokens);
179: return message;
180: }
181:
182: public boolean isList() {
183: if (type == DesktopConstants.TYPE_STRING_LIST_PROPERTY) {
184: return true;
185: } else {
186: return false;
187: }
188: }
189:
190: public boolean isListEmpty() {
191: if (type == DesktopConstants.TYPE_STRING_LIST_PROPERTY
192: && values.isEmpty()) {
193: return true;
194: } else {
195: return false;
196: }
197: }
198:
199: /**
200: * for debug purpose
201: */
202: // public String toString() {
203: // return
204: // "Name=" + name + ", " +
205: // "Value=" + values + ", " +
206: // "Type=" + type + ", " +
207: // "Advanced=" + advanced + ", " +
208: // "State=" + state;
209: //
210: // }
211: }
|