Revision 44202 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/featureform/swing/impl/DefaultJFeaturesForm.java
DefaultJFeaturesForm.java | ||
---|---|---|
25 | 25 |
import java.awt.BorderLayout; |
26 | 26 |
import java.awt.Dimension; |
27 | 27 |
import java.awt.event.ActionEvent; |
28 |
import java.io.File; |
|
29 | 28 |
import java.util.ArrayList; |
30 | 29 |
import java.util.List; |
31 | 30 |
import javax.swing.AbstractAction; |
32 | 31 |
import javax.swing.Action; |
32 |
import static javax.swing.Action.ACTION_COMMAND_KEY; |
|
33 |
import static javax.swing.Action.NAME; |
|
34 |
import static javax.swing.Action.SHORT_DESCRIPTION; |
|
35 |
import static javax.swing.Action.SMALL_ICON; |
|
33 | 36 |
|
34 | 37 |
import javax.swing.JComponent; |
35 | 38 |
import javax.swing.JOptionPane; |
36 | 39 |
import javax.swing.JPanel; |
37 |
import org.apache.commons.lang3.StringUtils; |
|
38 | 40 |
import org.gvsig.expressionevaluator.Expression; |
39 | 41 |
import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
40 | 42 |
|
... | ... | |
43 | 45 |
|
44 | 46 |
import org.gvsig.featureform.swing.JFeaturesForm; |
45 | 47 |
import org.gvsig.fmap.dal.DALLocator; |
46 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
47 | 48 |
import org.gvsig.fmap.dal.exception.DataException; |
48 | 49 |
import org.gvsig.fmap.dal.feature.Feature; |
49 | 50 |
import org.gvsig.fmap.dal.feature.FacadeOfAFeature; |
50 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
51 | 51 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
52 | 52 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
53 | 53 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
54 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
55 | 54 |
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
56 | 55 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
57 | 56 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
57 |
import org.gvsig.fmap.dal.swing.impl.DefaultDataSwingManager; |
|
58 | 58 |
import org.gvsig.tools.ToolsLocator; |
59 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
60 | 59 |
import org.gvsig.tools.dynform.AbortActionException; |
61 | 60 |
import org.gvsig.tools.dynform.DynFormDefinition; |
62 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
63 | 61 |
import org.gvsig.tools.dynform.DynFormLocator; |
64 | 62 |
import org.gvsig.tools.dynform.DynFormManager; |
63 |
import org.gvsig.tools.dynform.JDynForm; |
|
65 | 64 |
import org.gvsig.tools.dynform.JDynFormSet; |
66 | 65 |
import org.gvsig.tools.dynform.JDynFormSet.JDynFormSetListener; |
67 | 66 |
import org.gvsig.tools.dynobject.DynClass; |
68 | 67 |
import org.gvsig.tools.dynobject.DynObject; |
69 |
import org.gvsig.tools.dynobject.DynStruct_v2; |
|
70 |
import org.gvsig.tools.dynobject.Tags; |
|
71 | 68 |
import org.gvsig.tools.exception.BaseException; |
72 | 69 |
import org.gvsig.tools.i18n.I18nManager; |
73 | 70 |
import org.gvsig.tools.observer.Observable; |
... | ... | |
119 | 116 |
} catch (Exception ex) { |
120 | 117 |
throw new RuntimeException("Can't update form", ex); |
121 | 118 |
} |
122 |
this.formset.setReadOnly(false); |
|
123 | 119 |
} |
124 | 120 |
|
125 | 121 |
@Override |
... | ... | |
140 | 136 |
throw new IllegalArgumentException("bind need a store as parameter, not a null."); |
141 | 137 |
} |
142 | 138 |
try { |
143 |
this.bind(store, store.getDefaultFeatureType()); |
|
139 |
DefaultDataSwingManager manager = (DefaultDataSwingManager) DALSwingLocator.getSwingManager(); |
|
140 |
DynClass theDefinition = manager.featureType2DynClass(store, store.getDefaultFeatureType()); |
|
141 |
this.bind(store, theDefinition); |
|
144 | 142 |
} catch (Exception ex) { |
145 | 143 |
throw new RuntimeException("Can't bind store '" + store.getName() + "' to form", ex); |
146 | 144 |
} |
... | ... | |
151 | 149 |
return; |
152 | 150 |
} |
153 | 151 |
DynFormManager formManager = DynFormLocator.getDynFormManager(); |
154 |
if( definition == null || definition instanceof FeatureType ) { |
|
155 |
DataServerExplorer explorer=null; |
|
156 |
try { |
|
157 |
explorer = store.getExplorer(); |
|
158 |
} catch (Exception ex) { |
|
159 |
} |
|
160 |
FeatureType featureType = store.getDefaultFeatureType(); |
|
161 |
this.definition = formManager.getDefinition(featureType); |
|
162 |
for (FeatureAttributeDescriptor descriptor : featureType) { |
|
163 |
DynFormFieldDefinition formDescriptor = this.definition.get(descriptor.getName()); |
|
164 |
String profileName = descriptor.getDataProfileName(); |
|
165 |
if( !StringUtils.isBlank(profileName) ) { |
|
166 |
formDescriptor.setSubtype(profileName); |
|
167 |
} |
|
168 |
if( explorer!=null && formDescriptor.getType()==DataTypes.FILE ) { |
|
169 |
Tags tags = formDescriptor.getTags(); |
|
170 |
if (!tags.has("path")) { |
|
171 |
File f = explorer.getResourcePath(store, "dat"); |
|
172 |
if( f!=null ) { |
|
173 |
tags.set("path", f.getParentFile()); |
|
174 |
} |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
} |
|
179 |
} else { |
|
180 |
this.definition = formManager.getDefinition(definition); |
|
181 |
} |
|
152 |
this.definition = formManager.getDefinition(definition); |
|
182 | 153 |
if (formset != null) { |
183 | 154 |
this.panel.remove(formset.asJComponent()); |
184 | 155 |
this.formset = null; |
... | ... | |
197 | 168 |
} catch (ServiceException ex) { |
198 | 169 |
throw new RuntimeException("Can't create form set.", ex); |
199 | 170 |
} |
200 |
|
|
201 |
//this.formset.setLayoutMode(JDynForm.USE_SEPARATORS); |
|
202 |
this.formset.setReadOnly(false); |
|
171 |
List<String> groups = this.definition.getGroups(); |
|
172 |
if( groups.size()==1 && groups.get(0)==null ) { |
|
173 |
this.formset.setLayoutMode(JDynForm.USE_PLAIN); |
|
174 |
} else { |
|
175 |
this.formset.setLayoutMode(JDynForm.USE_TABS); |
|
176 |
} |
|
177 |
this.formset.setAllowNew(true); |
|
178 |
this.formset.setAllowDelete(true); |
|
179 |
this.formset.setAllowUpdate(true); |
|
203 | 180 |
this.formset.setAllowClose(true); |
204 |
this.formset.setAllowDelete(false); |
|
205 |
this.formset.setAllowNew(false); |
|
206 | 181 |
this.formset.setAllowSearch(true); |
207 |
this.formset.setAllowUpdate(true); |
|
208 | 182 |
this.formset.setAutosave(true); |
209 | 183 |
|
184 |
this.formset.addAction(new StartEditingAction()); |
|
210 | 185 |
this.formset.addAction(new FinishEditingAction()); |
211 | 186 |
for( Action action : this.otherActions ) { |
212 | 187 |
this.formset.addAction(action); |
... | ... | |
214 | 189 |
|
215 | 190 |
this.formset.addListener(new FormSetListener()); |
216 | 191 |
} |
192 |
if( this.store.isEditing() ) { |
|
193 |
this.formset.setReadOnly(false); |
|
194 |
formset.setActionVisible("startEditing", false); |
|
195 |
formset.setActionEnabled("startEditing", false); |
|
196 |
formset.setActionVisible("finishEditing", true); |
|
197 |
formset.setActionEnabled("finishEditing", true); |
|
198 |
} else { |
|
199 |
this.formset.setReadOnly(true); |
|
200 |
formset.setActionVisible("startEditing", true); |
|
201 |
formset.setActionEnabled("startEditing", true); |
|
202 |
formset.setActionVisible("finishEditing", false); |
|
203 |
formset.setActionEnabled("finishEditing", false); |
|
204 |
} |
|
217 | 205 |
return this.formset; |
218 | 206 |
} |
219 | 207 |
|
... | ... | |
295 | 283 |
FeatureStoreNotification n = (FeatureStoreNotification) notification; |
296 | 284 |
switch( n.getType() ) { |
297 | 285 |
case FeatureStoreNotification.AFTER_STARTEDITING: |
298 |
this.setEnabled(true); |
|
286 |
case FeatureStoreNotification.AFTER_FINISHEDITING: |
|
287 |
case FeatureStoreNotification.AFTER_CANCELEDITING: |
|
288 |
if( store.isEditing() ) { |
|
289 |
formset.setReadOnly(false); |
|
290 |
formset.setActionVisible("finishEditing", true); |
|
291 |
formset.setActionEnabled("finishEditing", true); |
|
292 |
} else { |
|
293 |
formset.setReadOnly(true); |
|
294 |
formset.setActionVisible("finishEditing", false); |
|
295 |
formset.setActionEnabled("finishEditing", false); |
|
296 |
} |
|
299 | 297 |
break; |
298 |
} |
|
299 |
} |
|
300 |
} |
|
301 |
|
|
302 |
} |
|
303 |
|
|
304 |
private class StartEditingAction extends AbstractAction implements Observer { |
|
305 |
|
|
306 |
@SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"}) |
|
307 |
public StartEditingAction() { |
|
308 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
309 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
|
310 |
|
|
311 |
this.putValue(NAME,null); |
|
312 |
this.putValue(SHORT_DESCRIPTION,i18nManager.getTranslation("_Start_editing")); |
|
313 |
this.putValue(SMALL_ICON, iconTheme.get("table-start-editing")); |
|
314 |
this.putValue(ACTION_COMMAND_KEY, "startEditing"); |
|
315 |
|
|
316 |
this.setEnabled(!store.isEditing()); |
|
317 |
store.addObserver(this); |
|
318 |
} |
|
319 |
|
|
320 |
@Override |
|
321 |
public void actionPerformed(ActionEvent ae) { |
|
322 |
if( !store.isEditing() ) { |
|
323 |
try { |
|
324 |
store.edit(); |
|
325 |
} catch (DataException ex) { |
|
326 |
LOGGER.warn("Can't finish editing in FeatureForm ("+store.getName()+").",ex); |
|
327 |
} |
|
328 |
} |
|
329 |
} |
|
330 |
|
|
331 |
@Override |
|
332 |
public void update(Observable observable, Object notification) { |
|
333 |
if( notification instanceof FeatureStoreNotification ) { |
|
334 |
FeatureStoreNotification n = (FeatureStoreNotification) notification; |
|
335 |
switch( n.getType() ) { |
|
336 |
case FeatureStoreNotification.AFTER_STARTEDITING: |
|
300 | 337 |
case FeatureStoreNotification.AFTER_FINISHEDITING: |
301 |
this.setEnabled(false); |
|
302 |
break; |
|
303 | 338 |
case FeatureStoreNotification.AFTER_CANCELEDITING: |
304 |
this.setEnabled(false); |
|
339 |
if( store.isEditing() ) { |
|
340 |
formset.setReadOnly(false); |
|
341 |
formset.setActionVisible("startEditing", false); |
|
342 |
formset.setActionEnabled("startEditing", false); |
|
343 |
} else { |
|
344 |
formset.setReadOnly(true); |
|
345 |
formset.setActionVisible("startEditing", true); |
|
346 |
formset.setActionEnabled("startEditing", true); |
|
347 |
} |
|
305 | 348 |
break; |
306 | 349 |
} |
307 | 350 |
} |
... | ... | |
331 | 374 |
public void showForm(MODE mode) { |
332 | 375 |
this.panel.add(this.getFormset().asJComponent(), BorderLayout.CENTER); |
333 | 376 |
WindowManager winmgr = ToolsSwingLocator.getWindowManager(); |
334 |
String title; |
|
335 |
if( this.definition instanceof DynStruct_v2 ) { |
|
336 |
title = ((DynStruct_v2)this.definition).getLabel(); |
|
337 |
} else { |
|
338 |
title = this.definition.getName(); |
|
339 |
} |
|
377 |
String title = this.definition.getLabel(); |
|
340 | 378 |
winmgr.showWindow(this.asJComponent(), title, mode); |
341 | 379 |
} |
342 | 380 |
|
Also available in: Unified diff