gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.dynform / org.gvsig.tools.dynform.services / src / main / java / org / gvsig / tools / dynform / services / dynformfield / DynObject / JDynFormFieldDynObject.java @ 1361
History | View | Annotate | Download (4.51 KB)
1 | 1031 | jbadia | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | package org.gvsig.tools.dynform.services.dynformfield.DynObject; |
||
25 | |||
26 | import java.awt.BorderLayout; |
||
27 | 1145 | jjdelcerro | import java.awt.Color; |
28 | 1031 | jbadia | import java.awt.event.FocusEvent; |
29 | import java.awt.event.FocusListener; |
||
30 | 1145 | jjdelcerro | import javax.swing.BorderFactory; |
31 | 1031 | jbadia | |
32 | import javax.swing.JPanel; |
||
33 | |||
34 | import org.gvsig.tools.dynform.DynFormFieldDefinition; |
||
35 | import org.gvsig.tools.dynform.DynFormLocator; |
||
36 | import org.gvsig.tools.dynform.JDynForm; |
||
37 | import org.gvsig.tools.dynform.JDynForm.JDynFormListener; |
||
38 | import org.gvsig.tools.dynform.JDynFormField; |
||
39 | 1361 | jjdelcerro | import org.gvsig.tools.dynform.spi.AbstractJDynForm; |
40 | 1031 | jbadia | import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
41 | import org.gvsig.tools.dynobject.DynField_v2; |
||
42 | import org.gvsig.tools.dynobject.DynObject; |
||
43 | import org.gvsig.tools.dynobject.DynStruct; |
||
44 | import org.gvsig.tools.service.spi.ServiceManager; |
||
45 | |||
46 | public class JDynFormFieldDynObject extends AbstractJDynFormField implements JDynFormField, JDynFormListener, FocusListener { |
||
47 | |||
48 | protected DynObject assignedValue = null; |
||
49 | protected DynObject currentValue = null; |
||
50 | protected JDynForm jdynForm = null; |
||
51 | protected boolean readonly = false; |
||
52 | |||
53 | public JDynFormFieldDynObject(DynObject parameters,
|
||
54 | ServiceManager serviceManager) { |
||
55 | super(parameters, serviceManager);
|
||
56 | this.assignedValue = (DynObject) this.getParameterValue(); |
||
57 | } |
||
58 | |||
59 | public void setReadOnly(boolean readonly) { |
||
60 | 1140 | jbadia | super.setReadOnly(readonly);
|
61 | 1076 | jjdelcerro | if( this.jdynForm != null ) { |
62 | 1031 | jbadia | this.jdynForm.setReadOnly(readonly);
|
63 | } |
||
64 | } |
||
65 | |||
66 | public Object getAssignedValue() { |
||
67 | return this.assignedValue; |
||
68 | } |
||
69 | |||
70 | public void initComponent() { |
||
71 | this.contents = new JPanel(); |
||
72 | this.contents.setLayout(new BorderLayout()); |
||
73 | try {
|
||
74 | 1225 | jjdelcerro | DynStruct struct = this.getDefinition().getDynClassOfValue();
|
75 | 1031 | jbadia | this.jdynForm = DynFormLocator.getDynFormManager().createJDynForm(struct);
|
76 | 1225 | jjdelcerro | this.jdynForm.setLayoutMode(getTagValueAsInt("layoutMode", "dynform.layoutmode", JDynForm.USE_PLAIN )); |
77 | 1031 | jbadia | this.jdynForm.setUseScrollBars(false); |
78 | this.jdynForm.setShowMessageStatus(false); |
||
79 | this.jdynForm.addListener(this); |
||
80 | this.contents.add(jdynForm.asJComponent(),BorderLayout.CENTER); |
||
81 | this.contents.setVisible(true); |
||
82 | this.jdynForm.setReadOnly(readonly);
|
||
83 | 1361 | jjdelcerro | if( !getTagValueAsBoolean("dynform.border.empty", false) ) { |
84 | if( this.jdynForm instanceof AbstractJDynForm ) { |
||
85 | ((AbstractJDynForm)this.jdynForm).setBorder(true); |
||
86 | 1225 | jjdelcerro | } |
87 | 1145 | jjdelcerro | } |
88 | 1031 | jbadia | this.setValue(this.assignedValue); |
89 | } catch (Exception e) { |
||
90 | // TODO Auto-generated catch block
|
||
91 | e.printStackTrace(); |
||
92 | } |
||
93 | // this.jdynForm.addFocusListener(this);
|
||
94 | |||
95 | } |
||
96 | |||
97 | |||
98 | public void setValue(Object value) { |
||
99 | if( value == null ) { |
||
100 | // TODO
|
||
101 | // this.jdynForm.clear();
|
||
102 | } else {
|
||
103 | if( !(value instanceof DynObject) ) { |
||
104 | logger.info("setValue invoked with non DynObject value ("+value.toString()+")."); |
||
105 | return;
|
||
106 | } |
||
107 | this.jdynForm.setValues((DynObject)value);
|
||
108 | } |
||
109 | this.assignedValue = (DynObject) value;
|
||
110 | this.currentValue = this.assignedValue; |
||
111 | } |
||
112 | |||
113 | public Object getValue() { |
||
114 | this.jdynForm.getValues(this.currentValue); |
||
115 | return this.currentValue; |
||
116 | } |
||
117 | |||
118 | public boolean hasValidValue() { |
||
119 | return true; |
||
120 | } |
||
121 | |||
122 | public void focusGained(FocusEvent arg0) { |
||
123 | fireFieldEnterEvent(); |
||
124 | this.problemIndicator().restore();
|
||
125 | } |
||
126 | |||
127 | public void focusLost(FocusEvent arg0) { |
||
128 | fireFieldExitEvent(); |
||
129 | } |
||
130 | |||
131 | public void message(String message) { |
||
132 | fireMessageEvent(message); |
||
133 | } |
||
134 | 1092 | jbadia | |
135 | public void fieldChanged(JDynFormField field) { |
||
136 | // TODO Auto-generated method stub
|
||
137 | |||
138 | } |
||
139 | 1031 | jbadia | |
140 | 1145 | jjdelcerro | public void clear() { |
141 | if( this.jdynForm!=null ) { |
||
142 | this.jdynForm.clear();
|
||
143 | } |
||
144 | } |
||
145 | 1031 | jbadia | } |