01: /*
02: * Copyright (C) 2005 Jeff Tassin
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package com.jeta.swingbuilder.codegen.builder.properties;
20:
21: import java.util.Collection;
22: import java.util.Iterator;
23:
24: import javax.swing.JComboBox;
25:
26: import com.jeta.forms.gui.beans.JETAPropertyDescriptor;
27: import com.jeta.forms.store.properties.ItemsProperty;
28: import com.jeta.swingbuilder.codegen.builder.BeanWriter;
29: import com.jeta.swingbuilder.codegen.builder.DeclarationManager;
30: import com.jeta.swingbuilder.codegen.builder.MethodStatement;
31: import com.jeta.swingbuilder.codegen.builder.PropertyWriter;
32: import com.jeta.swingbuilder.codegen.builder.StringExpression;
33:
34: public class ItemsPropertyWriter implements PropertyWriter {
35: /**
36: * PropertyWriter implementation
37: */
38: public void writeProperty(DeclarationManager declMgr,
39: BeanWriter writer, JETAPropertyDescriptor pd, Object value) {
40: try {
41: if (value instanceof ItemsProperty) {
42: ItemsProperty iprop = (ItemsProperty) value;
43: if (JComboBox.class.isAssignableFrom(writer
44: .getBeanType())) {
45: Collection items = iprop.getItems();
46: if (items != null) {
47: Iterator iter = items.iterator();
48: while (iter.hasNext()) {
49: MethodStatement ms = new MethodStatement(
50: writer.getBeanVariable(), "addItem");
51: ms.addParameter(new StringExpression(iter
52: .next().toString()));
53: writer.addStatement(ms);
54: }
55: }
56: }
57: }
58: } catch (Exception e) {
59: e.printStackTrace();
60: }
61: }
62: }
|