gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.swing / org.gvsig.tools.swing.impl / src / main / java / org / gvsig / tools / swing / impl / dynobject / DefaultDynObjectSwingManager.java @ 497
History | View | Annotate | Download (7.06 KB)
1 | 93 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | 101 | cordinyana | *
|
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
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 2
|
||
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 | */
|
||
22 | 93 | cordinyana | package org.gvsig.tools.swing.impl.dynobject; |
23 | |||
24 | 168 | cmartin | import org.gvsig.tools.dynobject.DynClass; |
25 | 101 | cordinyana | import org.gvsig.tools.dynobject.DynField; |
26 | 93 | cordinyana | import org.gvsig.tools.dynobject.DynObject; |
27 | 245 | cordinyana | import org.gvsig.tools.dynobject.DynObjectSet; |
28 | 497 | cmartin | import org.gvsig.tools.dynobject.DynStruct; |
29 | 245 | cordinyana | import org.gvsig.tools.exception.BaseException; |
30 | 168 | cmartin | import org.gvsig.tools.service.AbstractMultiServiceImplManager; |
31 | import org.gvsig.tools.service.Service; |
||
32 | import org.gvsig.tools.service.ServiceException; |
||
33 | 497 | cmartin | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
34 | 168 | cmartin | import org.gvsig.tools.swing.api.dynobject.DynObjectModel; |
35 | 93 | cordinyana | import org.gvsig.tools.swing.api.dynobject.DynObjectSwingManager; |
36 | import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent; |
||
37 | 101 | cordinyana | import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent; |
38 | 168 | cmartin | import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField; |
39 | 245 | cordinyana | import org.gvsig.tools.swing.api.dynobject.set.JDynObjectSetComponent; |
40 | import org.gvsig.tools.swing.impl.dynobject.set.DefaultJDynObjectSetComponent; |
||
41 | 168 | cmartin | import org.gvsig.tools.swing.spi.DynObjectSwingServiceManager; |
42 | import org.gvsig.tools.swing.spi.ToolsSwingServiceLocator; |
||
43 | 93 | cordinyana | |
44 | /**
|
||
45 | * Default {@link DynObjectSwingManager} implementation.
|
||
46 | *
|
||
47 | 228 | cordinyana | * @author gvSIG team
|
48 | 93 | cordinyana | */
|
49 | 168 | cmartin | public class DefaultDynObjectSwingManager extends |
50 | 270 | cmartin | AbstractMultiServiceImplManager implements DynObjectSwingManager {
|
51 | 93 | cordinyana | |
52 | 497 | cmartin | private DefaultDynModelList dynModelList;
|
53 | |||
54 | 270 | cmartin | /**
|
55 | * Empty constructor.
|
||
56 | */
|
||
57 | public DefaultDynObjectSwingManager() {
|
||
58 | super(ToolsSwingServiceLocator.getServiceManager());
|
||
59 | } |
||
60 | 101 | cordinyana | |
61 | 270 | cmartin | public DynObjectModel createDynObjectModel(DynClass dynClass)
|
62 | throws ServiceException {
|
||
63 | 497 | cmartin | if (dynClass == null) { |
64 | return null; |
||
65 | } |
||
66 | |||
67 | DynObjectModel model = ToolsSwingLocator.getDynObjectSwingManager().getDynModel(dynClass); |
||
68 | |||
69 | if (model != null) { |
||
70 | return model;
|
||
71 | } |
||
72 | |||
73 | |||
74 | 270 | cmartin | return new DefaultDynObjectModel(dynClass, true); |
75 | } |
||
76 | 93 | cordinyana | |
77 | 270 | cmartin | public DynObjectModel createEmptyDynObjectModel(DynClass dynClass)
|
78 | throws ServiceException {
|
||
79 | return new DefaultDynObjectModel(dynClass, false); |
||
80 | } |
||
81 | 93 | cordinyana | |
82 | 306 | cordinyana | public JDynFieldComponent createJDynFieldComponent(ValueField valueField)
|
83 | throws ServiceException {
|
||
84 | return createJDynFieldComponent(valueField, false); |
||
85 | } |
||
86 | 101 | cordinyana | |
87 | 306 | cordinyana | public JDynFieldComponent createJDynFieldComponent(ValueField valueField,
|
88 | boolean writable) throws ServiceException { |
||
89 | JDynFieldComponent component; |
||
90 | DynField field = valueField.getDynField(); |
||
91 | if (field.getElementsType() != null) { |
||
92 | component = ((DynObjectSwingServiceManager) this
|
||
93 | .getServiceManager()).getJDynFieldComponent(valueField, |
||
94 | true, writable);
|
||
95 | } else {
|
||
96 | component = ((DynObjectSwingServiceManager) this
|
||
97 | .getServiceManager()).getJDynFieldComponent(valueField, |
||
98 | false, writable);
|
||
99 | } |
||
100 | return component;
|
||
101 | } |
||
102 | |||
103 | 270 | cmartin | public JDynObjectComponent createJDynObjectComponent(DynObject dynObject)
|
104 | throws ServiceException {
|
||
105 | 306 | cordinyana | return createJDynObjectComponent(dynObject, false); |
106 | 270 | cmartin | } |
107 | 101 | cordinyana | |
108 | 270 | cmartin | public JDynObjectComponent createJDynObjectComponent(DynObject dynObject,
|
109 | 306 | cordinyana | boolean writable) throws ServiceException { |
110 | 497 | cmartin | if (dynObject == null){ |
111 | return createJDynObjectComponent(dynObject, null, MODE_FORM, writable); |
||
112 | } |
||
113 | 477 | jjdelcerro | return createJDynObjectComponent(dynObject,
|
114 | createDynObjectModel(dynObject.getDynClass()), writable); |
||
115 | 306 | cordinyana | } |
116 | |||
117 | public JDynObjectComponent createJDynObjectComponent(DynObject dynObject,
|
||
118 | 270 | cmartin | DynObjectModel model) throws ServiceException {
|
119 | 306 | cordinyana | return createJDynObjectComponent(dynObject, model, MODE_FORM, false); |
120 | 270 | cmartin | } |
121 | 101 | cordinyana | |
122 | 306 | cordinyana | public JDynObjectComponent createJDynObjectComponent(DynObject dynObject,
|
123 | DynObjectModel model, boolean writable) throws ServiceException { |
||
124 | return createJDynObjectComponent(dynObject, model, MODE_FORM, writable);
|
||
125 | } |
||
126 | |||
127 | 270 | cmartin | public JDynObjectComponent createJDynObjectComponent(DynObject dynObject,
|
128 | DynObjectModel model, String mode) throws ServiceException { |
||
129 | 306 | cordinyana | return createJDynObjectComponent(dynObject, model, mode, false); |
130 | } |
||
131 | |||
132 | public JDynObjectComponent createJDynObjectComponent(DynObject dynObject,
|
||
133 | DynObjectModel model, String mode, boolean writable) |
||
134 | throws ServiceException {
|
||
135 | 270 | cmartin | DynObject serviceParams = |
136 | this.createServiceParameters(getServiceName(dynObject, mode));
|
||
137 | 168 | cmartin | |
138 | 270 | cmartin | serviceParams.setDynValue(JDynObjectComponent.PARAMETERS.DYNMODEL, |
139 | model); |
||
140 | serviceParams.setDynValue(JDynObjectComponent.PARAMETERS.DYNOBJECT, |
||
141 | dynObject); |
||
142 | 306 | cordinyana | serviceParams.setDynValue(JDynObjectComponent.PARAMETERS.WRITABLE, |
143 | (writable ? Boolean.TRUE : Boolean.FALSE)); |
||
144 | 168 | cmartin | |
145 | 270 | cmartin | return (JDynObjectComponent) this.getService(serviceParams); |
146 | } |
||
147 | 168 | cmartin | |
148 | 270 | cmartin | public JDynObjectComponent createJDynObjectComponent(DynObject dynObject,
|
149 | String mode) throws ServiceException { |
||
150 | 306 | cordinyana | return createJDynObjectComponent(dynObject, mode, false); |
151 | } |
||
152 | |||
153 | public JDynObjectComponent createJDynObjectComponent(DynObject dynObject,
|
||
154 | String mode, boolean writable) throws ServiceException { |
||
155 | 270 | cmartin | return createJDynObjectComponent(dynObject,
|
156 | 306 | cordinyana | createDynObjectModel(dynObject.getDynClass()), writable); |
157 | } |
||
158 | 168 | cmartin | |
159 | 270 | cmartin | public Service getService(DynObject serviceParams) throws ServiceException { |
160 | return this.getServiceManager().createService(serviceParams); |
||
161 | } |
||
162 | 168 | cmartin | |
163 | 270 | cmartin | /**
|
164 | * @param dynObject
|
||
165 | * @param mode
|
||
166 | * @return
|
||
167 | */
|
||
168 | private String getServiceName(DynObject dynObject, String mode) { |
||
169 | return mode;
|
||
170 | } |
||
171 | 306 | cordinyana | |
172 | public JDynObjectSetComponent createJDynObjectSetComponent(
|
||
173 | DynObjectSet dynObjectSet) throws BaseException {
|
||
174 | return createJDynObjectSetComponent(dynObjectSet, false); |
||
175 | } |
||
176 | |||
177 | public JDynObjectSetComponent createJDynObjectSetComponent(
|
||
178 | DynObjectSet dynObjectSet, boolean writable) throws BaseException { |
||
179 | return new DefaultJDynObjectSetComponent(dynObjectSet, this, writable); |
||
180 | } |
||
181 | |||
182 | 497 | cmartin | public void registerDynModel(DynStruct dynStruct, DynObjectModel model) { |
183 | getDynModelList().addModel(dynStruct, model); |
||
184 | } |
||
185 | |||
186 | private DefaultDynModelList getDynModelList() {
|
||
187 | if (dynModelList == null){ |
||
188 | dynModelList = new DefaultDynModelList();
|
||
189 | } |
||
190 | return dynModelList;
|
||
191 | } |
||
192 | |||
193 | public DynObjectModel getDynModel(DynStruct dynStruct){
|
||
194 | return getDynModelList().getModel(dynStruct);
|
||
195 | } |
||
196 | |||
197 | 270 | cmartin | } |