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