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 @ 1405
History | View | Annotate | Download (4.38 KB)
1 | 1031 | jbadia | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 1405 | jjdelcerro | * 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 | 1031 | jbadia | *
|
11 | 1405 | jjdelcerro | * 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 | 1031 | jbadia | *
|
16 | 1405 | jjdelcerro | * 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.
|
||
19 | 1031 | jbadia | *
|
20 | 1405 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 1031 | jbadia | */
|
23 | package org.gvsig.tools.dynform.services.dynformfield.DynObject; |
||
24 | |||
25 | import java.awt.BorderLayout; |
||
26 | import java.awt.event.FocusEvent; |
||
27 | import java.awt.event.FocusListener; |
||
28 | |||
29 | import javax.swing.JPanel; |
||
30 | |||
31 | import org.gvsig.tools.dynform.DynFormLocator; |
||
32 | import org.gvsig.tools.dynform.JDynForm.JDynFormListener; |
||
33 | import org.gvsig.tools.dynform.JDynFormField; |
||
34 | 1361 | jjdelcerro | import org.gvsig.tools.dynform.spi.AbstractJDynForm; |
35 | 1031 | jbadia | import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
36 | import org.gvsig.tools.dynobject.DynObject; |
||
37 | import org.gvsig.tools.dynobject.DynStruct; |
||
38 | import org.gvsig.tools.service.spi.ServiceManager; |
||
39 | |||
40 | public class JDynFormFieldDynObject extends AbstractJDynFormField implements JDynFormField, JDynFormListener, FocusListener { |
||
41 | |||
42 | 1405 | jjdelcerro | protected DynObject assignedValue = null; |
43 | protected DynObject currentValue = null; |
||
44 | protected AbstractJDynForm jdynForm = null; |
||
45 | protected boolean readonly = false; |
||
46 | 1031 | jbadia | |
47 | 1405 | jjdelcerro | public JDynFormFieldDynObject(DynObject parameters,
|
48 | ServiceManager serviceManager) { |
||
49 | super(parameters, serviceManager);
|
||
50 | this.assignedValue = (DynObject) this.getParameterValue(); |
||
51 | } |
||
52 | 1031 | jbadia | |
53 | 1405 | jjdelcerro | @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) { |
||
90 | 1031 | jbadia | // TODO
|
91 | 1405 | jjdelcerro | // 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 | } |
||
102 | 1031 | jbadia | |
103 | 1405 | jjdelcerro | public Object getValue() { |
104 | this.jdynForm.getValues(this.currentValue); |
||
105 | return this.currentValue; |
||
106 | } |
||
107 | 1031 | jbadia | |
108 | 1405 | jjdelcerro | public boolean hasValidValue() { |
109 | return true; |
||
110 | } |
||
111 | 1031 | jbadia | |
112 | 1405 | jjdelcerro | public void focusGained(FocusEvent arg0) { |
113 | fireFieldEnterEvent(); |
||
114 | this.problemIndicator().restore();
|
||
115 | } |
||
116 | 1092 | jbadia | |
117 | 1405 | jjdelcerro | 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) { |
||
126 | 1092 | jbadia | // TODO Auto-generated method stub
|
127 | 1405 | jjdelcerro | |
128 | } |
||
129 | |||
130 | 1145 | jjdelcerro | public void clear() { |
131 | 1405 | jjdelcerro | if (this.jdynForm != null) { |
132 | 1145 | jjdelcerro | this.jdynForm.clear();
|
133 | } |
||
134 | } |
||
135 | 1031 | jbadia | } |