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 @ 2548
History | View | Annotate | Download (4.81 KB)
1 |
/**
|
---|---|
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 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 |
*
|
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 |
*
|
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.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
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 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
31 |
|
32 |
import org.gvsig.tools.dynform.DynFormLocator; |
33 |
import org.gvsig.tools.dynform.JDynForm.JDynFormListener; |
34 |
import org.gvsig.tools.dynform.JDynFormField; |
35 |
import org.gvsig.tools.dynform.spi.dynform.AbstractJDynForm; |
36 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
37 |
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory; |
38 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
39 |
import org.gvsig.tools.dynobject.DynObject; |
40 |
import org.gvsig.tools.dynobject.DynStruct; |
41 |
|
42 |
public class JDynFormFieldDynObject extends AbstractJDynFormField implements JDynFormField, JDynFormListener, FocusListener { |
43 |
|
44 |
protected DynObject assignedValue = null; |
45 |
protected DynObject currentValue = null; |
46 |
protected AbstractJDynForm jdynForm = null; |
47 |
protected boolean readonly = false; |
48 |
|
49 |
public JDynFormFieldDynObject(
|
50 |
DynFormSPIManager serviceManager, |
51 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
52 |
JDynFormFieldFactory factory, |
53 |
DynFormFieldDefinition definition, |
54 |
Object value
|
55 |
) { |
56 |
super(serviceManager, componentsFactory, factory, definition, value);
|
57 |
this.assignedValue = (DynObject) value;
|
58 |
} |
59 |
|
60 |
@Override
|
61 |
public void setReadOnly(boolean readonly) { |
62 |
super.setReadOnly(readonly);
|
63 |
if (this.jdynForm != null) { |
64 |
this.jdynForm.setReadOnly(readonly);
|
65 |
} |
66 |
} |
67 |
|
68 |
@Override
|
69 |
public Object getAssignedValue() { |
70 |
return this.assignedValue; |
71 |
} |
72 |
|
73 |
@Override
|
74 |
public void initComponent() { |
75 |
this.contents = new JPanel(); |
76 |
this.contents.setLayout(new BorderLayout()); |
77 |
try {
|
78 |
DynStruct struct = this.getDefinition().getDynClassOfValue();
|
79 |
this.jdynForm = (AbstractJDynForm) DynFormLocator.getDynFormManager().createJDynForm(struct);
|
80 |
this.jdynForm.setUseScrollBars(false); |
81 |
this.jdynForm.setReadOnly(readonly);
|
82 |
this.jdynForm.loadDefaultValuesFromTags(this.getDefinition().getTags()); |
83 |
|
84 |
this.jdynForm.addListener(this); |
85 |
this.contents.add(jdynForm.asJComponent(), BorderLayout.CENTER); |
86 |
this.jdynForm.setShowMessageStatus(false); |
87 |
this.contents.setVisible(true); |
88 |
this.setValue(this.assignedValue); |
89 |
} catch (Exception e) { |
90 |
LOGGER.warn("Can't initialize JDynFormFiledDynObject.", e);
|
91 |
} |
92 |
|
93 |
} |
94 |
|
95 |
public void setValue(Object value) { |
96 |
if (value == null) { |
97 |
// TODO
|
98 |
// this.jdynForm.clear();
|
99 |
} else {
|
100 |
if (!(value instanceof DynObject)) { |
101 |
LOGGER.info("setValue invoked with non DynObject value (" + value.toString() + ")."); |
102 |
return;
|
103 |
} |
104 |
this.jdynForm.setValues((DynObject) value);
|
105 |
} |
106 |
this.assignedValue = (DynObject) value;
|
107 |
this.currentValue = this.assignedValue; |
108 |
} |
109 |
|
110 |
public Object getValue() { |
111 |
this.jdynForm.getValues(this.currentValue); |
112 |
return this.currentValue; |
113 |
} |
114 |
|
115 |
public boolean hasValidValue() { |
116 |
return true; |
117 |
} |
118 |
|
119 |
public void focusGained(FocusEvent arg0) { |
120 |
fireFieldEnterEvent(); |
121 |
this.problemIndicator().restore();
|
122 |
} |
123 |
|
124 |
public void focusLost(FocusEvent arg0) { |
125 |
fireFieldExitEvent(); |
126 |
} |
127 |
|
128 |
public void message(String message) { |
129 |
fireMessageEvent(message); |
130 |
} |
131 |
|
132 |
public void fieldChanged(JDynFormField field) { |
133 |
fireFieldChangedEvent(); |
134 |
} |
135 |
|
136 |
public void clear() { |
137 |
if (this.jdynForm != null) { |
138 |
this.jdynForm.clear();
|
139 |
} |
140 |
} |
141 |
|
142 |
@Override
|
143 |
public boolean isModified() { |
144 |
return this.jdynForm.isModified(); |
145 |
} |
146 |
|
147 |
|
148 |
} |