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: * @(#)SubComponentCreator.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.ui;
030:
031: import org.openesb.tools.extpropertysheet.IExtProperty;
032: import org.openesb.tools.extpropertysheet.IExtPropertyGroup;
033: import org.openesb.tools.extpropertysheet.IExtPropertyGroupsBean;
034: import org.openesb.tools.extpropertysheet.IExtPropertyOption;
035: import org.openesb.tools.extpropertysheet.IExtPropertyOptions;
036: import com.sun.web.ui.component.Button;
037: import com.sun.web.ui.component.DropDown;
038: import com.sun.web.ui.component.HiddenField;
039: import com.sun.web.ui.component.Label;
040: import com.sun.web.ui.component.PropertySheet;
041: import com.sun.web.ui.component.PropertySheetSection;
042: import com.sun.web.ui.component.RadioButtonGroup;
043: import com.sun.web.ui.component.Tab;
044: import com.sun.web.ui.component.TabSet;
045: import com.sun.web.ui.component.TextField;
046: import com.sun.web.ui.model.Option;
047:
048: import java.util.ArrayList;
049: import java.util.Collection;
050: import java.util.logging.Logger;
051:
052: import java.util.HashMap;
053: import java.util.Iterator;
054: import java.util.List;
055: import java.util.ResourceBundle;
056: import javax.faces.component.UIComponent;
057: import javax.faces.context.FacesContext;
058: import javax.faces.el.MethodBinding;
059:
060: /**
061: *
062: * @author rdwivedi
063: */
064: public class SubComponentCreator {
065:
066: private static Logger mLogger = Logger
067: .getLogger(SubComponentCreator.class.getName());
068: /** Creates a new instance of SubComponentCreator */
069:
070: private ResourceBundle mRBundle = null;
071:
072: public SubComponentCreator() {
073: }
074:
075: public SubComponentCreator(String resourceBundleURL) {
076: mRBundle = PropertiesResourceBundleHelper
077: .getResourceBundle(resourceBundleURL);
078:
079: }
080:
081: private Tab createTab(IExtPropertyGroup grp) {
082: mLogger.finer("chart grp " + grp.getGroupName());
083: Collection col = grp.getAllProperties();
084: String tabLabel = grp.getGroupName();
085: Tab tab = new Tab();
086: tab.setId("tab_" + tabLabel);
087: String tabDisp = tabLabel;
088: if (mRBundle != null) {
089: tabDisp = (String) mRBundle.getObject(tabLabel);
090: }
091: /* try{
092: tabDisp = PropertiesResourceBundleHelper.getResourceBundle().getString(props.getGroupName());
093: } catch(Exception e) {
094: mLogger.info("Resource not found for key =" +tabLabel + " :: EXception is " + e.getMessage() );
095: }
096: */
097: tab.setText(tabDisp);
098: PropertySheet ps = createPropertySheet(grp);
099: if (ps != null) {
100:
101: tab.getChildren().add(ps);
102: Button b = new Button();
103: b.setId("_b1");
104: b.setText("Update");
105:
106: //MethodBinding binding = getFacesContext().getCurrentInstance().getApplication().createMethodBinding("#{ChartPropertySheetBean.update}",null);
107:
108: //b.setAction(binding);
109: // b.setOnMouseUp("parent.frames['chartPreviewFrame'].document.location=\"\\ChartPanel.jsp\"");
110: tab.getChildren().add(b);
111:
112: }
113: return tab;
114:
115: }
116:
117: public TabSet createTabSet(IExtPropertyGroupsBean grps,
118: FacesContext context) {
119: TabSet mTS = new TabSet();
120: mTS.setId("_propTS");
121: //mLogger.info("prop group is " + grps);
122: if (grps != null) {
123:
124: Collection col = grps.getAllGroups();
125: //mLogger.info("collection group is " + col);
126: if (col != null) {
127: Iterator iter = col.iterator();
128: while (iter.hasNext()) {
129:
130: IExtPropertyGroup group = (IExtPropertyGroup) iter
131: .next();
132: //mLogger.info(" group is " + group);
133: Tab tab = createTab(group);
134: mTS.getChildren().add(tab);
135: }
136: }
137: }
138: return mTS;
139:
140: }
141:
142: private PropertySheet createPropertySheet(IExtPropertyGroup group) {
143: String label = group.getGroupName();
144: Collection col = group.getAllProperties();
145:
146: Iterator iter = col.iterator();
147: IExtProperty prop = null;
148: PropertySheet ps = new PropertySheet();
149: ps.setId("_ps" + label);
150:
151: PropertySheetSection sec = new PropertySheetSection();
152: sec.setId("_pss" + label);
153: while (iter.hasNext()) {
154: prop = (IExtProperty) iter.next();
155: String propName = prop.getName();
156: String propLabel = propName;
157: if (mRBundle != null) {
158: propLabel = (String) mRBundle.getObject(propName);
159: }
160: Object propValue = prop.getValue();
161:
162: IExtPropertyOptions options = prop.getOptions();
163: short propType = prop.getType();
164:
165: String val = null;
166: val = propValue.toString();
167: /*if(actValue != null) {
168: val = prop.getValueConvertor().getStringValue(actValue);
169: }
170: */
171: addPropertyIntoPropertySheet(sec, propName, propLabel, val,
172: propType, options);
173: }
174: ps.getChildren().add(sec);
175: return ps;
176: }
177:
178: private void addPropertyIntoPropertySheet(PropertySheetSection sec,
179: String pName, String pLabel, String pValue, short type,
180: IExtPropertyOptions options) {
181: com.sun.web.ui.component.Property p = new com.sun.web.ui.component.Property();
182:
183: p.setId("_p" + pName);
184: p.setLabel(pLabel);
185: //mLogger.info("Adding a property " + pName + pLabel);
186: //TextField field = new TextField();
187: //field.setId(pName);
188: // field.setLabel(pLabel);
189: //field.setValue(pValue);
190: UIComponent field = createComponent(type, pName, pValue,
191: options);
192: if (type != IExtProperty.HIDDEN_TEXT) {
193: p.getChildren().add(field);
194: sec.getChildren().add(p);
195: }
196: }
197:
198: private UIComponent createComponent(short type, String pName,
199: String pValue, IExtPropertyOptions options) {
200: UIComponent comp = null;
201: //mLogger.info("The component type is " + type);
202: switch (type) {
203: case IExtProperty.INPUT_TEXT:
204: case IExtProperty.INPUT_INT_TYPE:
205: case IExtProperty.INPUT_FLOAT_TYPE:
206: comp = new TextField();
207: ((TextField) comp).setValue(pValue);
208: break;
209: case IExtProperty.OUTPUT_TEXT:
210: comp = new Label();
211: ((Label) comp).setValue(pValue);
212: break;
213: case IExtProperty.HIDDEN_TEXT:
214: comp = new HiddenField();
215: ((HiddenField) comp).setValue(pValue);
216: break;
217: case IExtProperty.SELECTONE_MENU_COMPONENT:
218: comp = new DropDown();
219: ((DropDown) comp).setValue(pValue);
220: ((DropDown) comp).setMultiple(false);
221: ArrayList pl = new ArrayList();
222: Collection col = options.getAllOptions();
223: //Option[] listOptions = new Option[list.size()];
224: Iterator iter = col.iterator();
225:
226: while (iter.hasNext()) {
227: IExtPropertyOption pOption = (IExtPropertyOption) iter
228: .next();
229: Option option = new Option();
230: option.setLabel(pOption.getOptionLabel());
231: option.setValue(pOption.getOptionValue());
232: pl.add(option);
233: }
234: ((DropDown) comp).setItems(pl);
235: break;
236: case IExtProperty.COLOR_SELECTOR:
237: //comp = new RbCbSelector();
238: comp = new Label();
239: ((Label) comp).setValue(pValue);
240: break;
241: case IExtProperty.BOOLEAN_RADIO_BUTTON:
242: comp = new RadioButtonGroup();
243:
244: Option b = new Option();
245: b.setLabel("Yes");
246: b.setValue("true");
247:
248: Option d = new Option();
249: d.setLabel("No");
250: d.setValue("false");
251:
252: ArrayList l = new ArrayList();
253: l.add(b);
254: l.add(d);
255: ((RadioButtonGroup) comp).setValue(pValue);
256: ((RadioButtonGroup) comp).setColumns(2);
257: ((RadioButtonGroup) comp).setItems(l);
258: break;
259: default:
260: comp = new Label();
261: ((Label) comp).setValue(pValue);
262: }
263: comp.setId(pName);
264:
265: return comp;
266: }
267:
268: }
|