001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)ExtPropertyGroup.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package org.openesb.tools.extpropertysheet.impl;
030:
031: import org.openesb.tools.extpropertysheet.IExtProperty;
032: import org.openesb.tools.extpropertysheet.IExtPropertyGroup;
033: import org.openesb.tools.extpropertysheet.IExtPropertyOptions;
034: import java.awt.Color;
035: import java.awt.Font;
036: import java.util.Collection;
037: import java.util.Collections;
038: import java.util.HashMap;
039: import java.util.Iterator;
040: import java.util.logging.Logger;
041:
042: /**
043: *
044: * @author rdwivedi
045: */
046: public class ExtPropertyGroup implements IExtPropertyGroup {
047:
048: private HashMap mPropsMap = new HashMap();
049: private String mGroupName = null;
050: private static Logger mLogger = Logger
051: .getLogger(ExtPropertyGroup.class.getName());
052:
053: /** Creates a new instance of ExtPropertyGroup */
054: public ExtPropertyGroup() {
055: }
056:
057: public void add(IExtProperty prop) {
058: mPropsMap.put(prop.getName(), prop);
059: }
060:
061: public IExtProperty removeProperty(IExtProperty prop) {
062: return (IExtProperty) mPropsMap.remove(prop.getName());
063: }
064:
065: public IExtProperty removePoperty(String name) {
066: return (IExtProperty) mPropsMap.remove(name);
067: }
068:
069: public Collection getAllProperties() {
070: return Collections.unmodifiableCollection(mPropsMap.values());
071: }
072:
073: public void empty() {
074: mPropsMap.clear();
075: }
076:
077: public IExtProperty getProperty(String name) {
078: return (IExtProperty) mPropsMap.get(name);
079: }
080:
081: public int size() {
082: return mPropsMap.size();
083: }
084:
085: public String getGroupName() {
086: return mGroupName;
087: }
088:
089: public void setGroupName(String name) {
090: mGroupName = name;
091: }
092:
093: public void toXML(StringBuffer buffer) {
094: buffer.append("<PROPGROUP ");
095: buffer.append("name=").append(getGroupName()).append(" ");
096: buffer.append(">");
097: Iterator iter = getAllProperties().iterator();
098: while (iter.hasNext()) {
099: IExtProperty p = (IExtProperty) iter.next();
100: p.toXML(buffer);
101: }
102: buffer.append("</PROPGROUP>//n");
103: }
104:
105: public void setProperty(String name, Object value) {
106:
107: if (value instanceof Integer) {
108: setProperty(name, value, IExtProperty.INPUT_INT_TYPE);
109: } else if (value instanceof Number) {
110: setProperty(name, value, IExtProperty.INPUT_FLOAT_TYPE);
111: } else if (value instanceof Boolean) {
112: setProperty(name, value, IExtProperty.BOOLEAN_RADIO_BUTTON);
113: } else if (value instanceof Color) {
114: setProperty(name, value, IExtProperty.COLOR_SELECTOR);
115: } else if (value instanceof Font) {
116: setProperty(name, value, IExtProperty.FONT_TYPE);
117: } else {
118: setProperty(name, value, IExtProperty.INPUT_TEXT);
119: }
120: }
121:
122: public void setProperty(String name, Object value, short type) {
123: IExtProperty prop = new ExtProperty();
124: prop.setName(name);
125: prop.setValue(value);
126: prop.setType(type);
127: add(prop);
128: }
129:
130: public void setProperty(String name, Object value,
131: IExtPropertyOptions options) {
132: IExtProperty prop = new ExtProperty();
133: prop.setName(name);
134: prop.setValue(value);
135: if (value instanceof Integer) {
136: prop.setType(IExtProperty.INPUT_INT_LIST_TYPE);
137: } else if (value instanceof Number) {
138: prop.setType(IExtProperty.INPUT_FLOAT_LIST_TYPE);
139: } else {
140:
141: prop.setType(IExtProperty.SELECTONE_MENU_COMPONENT);
142: }
143: prop.setOptions(options);
144: add(prop);
145: }
146:
147: public Object getPropertyValue(String name) {
148: IExtProperty prop = getProperty(name);
149: if (prop == null) {
150: mLogger.info("The property with name " + name
151: + " is not found.");
152: return null;
153: }
154: return getProperty(name).getValue();
155: }
156:
157: }
|