Revision 44291 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.awt.event.ComponentAdapter; |
|
29 |
import java.awt.event.ComponentEvent; |
|
28 | 30 |
import java.util.ArrayList; |
29 | 31 |
import java.util.Collection; |
30 | 32 |
import java.util.List; |
... | ... | |
66 | 68 |
import org.gvsig.fmap.dal.swing.impl.DefaultDataSwingManager; |
67 | 69 |
import org.gvsig.fmap.dal.swing.impl.actions.ShowFormAction.ShowFormActionFactory; |
68 | 70 |
import org.gvsig.tools.ToolsLocator; |
71 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
69 | 72 |
import org.gvsig.tools.dynform.AbortActionException; |
70 | 73 |
import org.gvsig.tools.dynform.DynFormDefinition; |
71 | 74 |
import org.gvsig.tools.dynform.DynFormLocator; |
... | ... | |
128 | 131 |
|
129 | 132 |
} |
130 | 133 |
|
131 |
private static class FormActionContext extends AbstractDALActionContext {
|
|
134 |
private class FormActionContext extends AbstractDALActionContext { |
|
132 | 135 |
|
133 |
private final DefaultJFeaturesForm form; |
|
134 |
|
|
135 |
public FormActionContext(DefaultJFeaturesForm form) { |
|
136 |
public FormActionContext() { |
|
136 | 137 |
super(ACTION_CONTEXT_NAME); |
137 |
this.form = form; |
|
138 | 138 |
} |
139 | 139 |
|
140 | 140 |
@Override |
141 | 141 |
public DataStore getStore() { |
142 |
return this.form.getFeatureStore();
|
|
142 |
return store;
|
|
143 | 143 |
} |
144 | 144 |
|
145 | 145 |
@Override |
146 | 146 |
public Expression getFilter() { |
147 |
FeatureQuery currentQuery = this.form.getCurrentQuery();
|
|
148 |
if( currentQuery!=null ) {
|
|
149 |
Evaluator filter = currentQuery.getFilter();
|
|
147 |
FeatureQuery theCurrentQuery = currentQuery;
|
|
148 |
if( theCurrentQuery!=null ) {
|
|
149 |
Evaluator filter = theCurrentQuery.getFilter();
|
|
150 | 150 |
if( filter instanceof ExpressionEvaluator ) { |
151 | 151 |
Expression expression = ((ExpressionEvaluator)filter).getExpression(); |
152 | 152 |
return expression; |
... | ... | |
167 | 167 |
|
168 | 168 |
@Override |
169 | 169 |
public JComponent getActionButton(String actionName) { |
170 |
JDynFormSet formset = this.form.formset; |
|
171 | 170 |
if( formset == null ) { |
172 | 171 |
return null; |
173 | 172 |
} |
... | ... | |
179 | 178 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultJFeaturesForm.class); |
180 | 179 |
|
181 | 180 |
private static final int PAGE_SIZE = 500; |
182 |
private final JPanel panel;
|
|
181 |
private JPanel panel; |
|
183 | 182 |
private JDynFormSet formset; |
184 | 183 |
private FeatureStore store; |
185 | 184 |
private FeaturePagingHelper ph; |
186 | 185 |
private DynFormDefinition definition = null; |
187 | 186 |
private FeatureQuery currentQuery; |
188 |
private final List<Action> otherActions;
|
|
187 |
private List<Action> otherActions; |
|
189 | 188 |
|
190 | 189 |
public DefaultJFeaturesForm() { |
190 |
this.otherActions = new ArrayList<>(); |
|
191 | 191 |
this.panel = new JPanel(new BorderLayout()); |
192 |
this.otherActions = new ArrayList<>(); |
|
192 |
this.panel.addComponentListener(new ComponentAdapter() { |
|
193 |
@Override |
|
194 |
public void componentHidden(ComponentEvent e) { |
|
195 |
doDispose(); |
|
196 |
} |
|
197 |
}); |
|
193 | 198 |
} |
194 | 199 |
|
195 | 200 |
@Override |
... | ... | |
202 | 207 |
this.panel.add(this.getFormset().asJComponent(), BorderLayout.CENTER); |
203 | 208 |
} |
204 | 209 |
try { |
210 |
if( this.currentQuery!=null ) { |
|
211 |
this.currentQuery.retrievesAllAttributes(); |
|
212 |
} |
|
205 | 213 |
this.ph = DALLocator.getDataManager().createFeaturePagingHelper(store, this.currentQuery, PAGE_SIZE); |
206 | 214 |
this.formset.setValues(ph.asListOfDynObjects()); |
207 | 215 |
} catch (Exception ex) { |
... | ... | |
246 | 254 |
this.formset = null; |
247 | 255 |
} |
248 | 256 |
this.store = store; |
257 |
DisposeUtils.bind(store); |
|
249 | 258 |
this.ph = null; |
259 |
} |
|
250 | 260 |
|
261 |
private void doDispose() { |
|
262 |
DisposeUtils.disposeQuietly(store); |
|
263 |
this.store = null; |
|
264 |
this.panel = null; |
|
265 |
this.formset = null; |
|
266 |
this.ph = null; |
|
267 |
this.definition = null; |
|
268 |
this.currentQuery = null; |
|
269 |
this.otherActions = null; |
|
251 | 270 |
} |
252 |
|
|
271 |
|
|
253 | 272 |
@Override |
254 | 273 |
public JDynFormSet getFormset() { |
255 | 274 |
if (this.formset == null) { |
... | ... | |
275 | 294 |
this.formset.addAction(new StartEditingAction()); |
276 | 295 |
this.formset.addAction(new FinishEditingAction()); |
277 | 296 |
|
278 |
FormActionContext actionContext = new FormActionContext(this);
|
|
297 |
FormActionContext actionContext = new FormActionContext(); |
|
279 | 298 |
Collection<DALActionFactory> factories = DALSwingLocator.getSwingManager().getStoreActions(); |
280 | 299 |
for (DALActionFactory factory : factories) { |
281 | 300 |
if( StringUtils.equalsIgnoreCase(factory.getName(), ShowFormActionFactory.ACTION_NAME) ) { |
Also available in: Unified diff