001: /*
002: * Preference.java
003: *
004: * Created on July 10, 2005, 1:35 PM
005: *
006: * To change this template, choose Tools | Options and locate the template under
007: * the Source Creation and Management node. Right-click the template and choose
008: * Open. You can then make changes to the template in the Source Editor.
009: */
010:
011: package com.sun.portal.admin.console.desktop;
012:
013: import java.util.List;
014: import java.util.ArrayList;
015: import java.util.Iterator;
016: import java.text.MessageFormat;
017:
018: import com.sun.web.ui.model.Option;
019:
020: import com.sun.portal.admin.console.common.PSBaseBean;
021:
022: /**
023: *
024: * @author rt94277
025: */
026: public class Preference {
027:
028: private static final String BREAK_TAG = "<BR>";
029:
030: /** Creates a new instance of Preference */
031: public Preference() {
032: }
033:
034: public String name; //name of the property
035: public List values = new ArrayList();
036: public boolean isReadOnly;
037:
038: public Preference(String name, boolean readOnly, List values) {
039: this .name = name;
040: this .values = (List) values;
041: this .isReadOnly = readOnly;
042: }
043:
044: public String getName() {
045: return name;
046: }
047:
048: public String getValue() {
049: return (String) values.get(0);
050: }
051:
052: public void setvalue(String value) {
053: values.add(0, value);
054: }
055:
056: public String getReadOnly() {
057: if (isReadOnly) {
058: return PSBaseBean.getLocalizedString("desktop",
059: "edit.preferences.readonly.yes");
060: } else {
061: return PSBaseBean.getLocalizedString("desktop",
062: "edit.preferences.readonly.no");
063: }
064: }
065:
066: public String[] getValueArray() {
067: Object[] oa = values.toArray();
068: String[] sa = new String[oa.length];
069: for (int i = 0; i < oa.length; i++) {
070: sa[i] = (String) oa[i];
071: }
072: return sa;
073: }
074:
075: public void setValueArray(String[] strValues) {
076: values.clear();
077: for (int i = 0; i < strValues.length; i++) {
078: values.add(strValues[i]);
079: }
080: }
081:
082: public String getToolTipValues() {
083: StringBuffer vlist = new StringBuffer();
084: Iterator iter = values.iterator();
085: while (iter.hasNext()) {
086: vlist.append((String) iter.next()).append(", ");
087: }
088: return vlist.toString();
089: }
090:
091: public String getValueString() {
092: StringBuffer vlist = new StringBuffer();
093: int numValues = values.size();
094: int count = numValues;
095: //show only 3 values
096: if (count > 3) {
097: count = 3;
098: }
099: for (int i = 0; i < count; i++) {
100: String prefValue = ((String) values.get(i)).trim();
101: if (prefValue.length() > 40) {
102: prefValue = (prefValue.substring(0, 40)).concat("...");
103: }
104: if (prefValue.length() != 0) {
105: vlist.append(prefValue).append(BREAK_TAG);
106: }
107: }
108: if (numValues > 3) {
109: //append more string
110: String message = PSBaseBean.getLocalizedString("desktop",
111: "edit.preferences.label.moreValues");
112: Object[] tokens = { new Integer(numValues - 3) };
113: MessageFormat mf = new MessageFormat(message);
114: message = mf.format(tokens);
115: vlist.append(message).append(BREAK_TAG);
116: }
117: return vlist.toString();
118: }
119:
120: public String getNumValues() {
121: String message = PSBaseBean.getLocalizedString("desktop",
122: "edit.preferences.label.numValues");
123: Object[] tokens = { new Integer(values.size()) };
124: MessageFormat mf = new MessageFormat(message);
125: message = mf.format(tokens);
126: return message;
127: }
128:
129: }
|