Revision 44149 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/fmap/dal/swing/impl/featuretype/DefaultFeatureTypePanel.java
DefaultFeatureTypePanel.java | ||
---|---|---|
8 | 8 |
import java.util.Date; |
9 | 9 |
import java.util.Objects; |
10 | 10 |
import javax.swing.JComponent; |
11 |
import javax.swing.JOptionPane; |
|
11 | 12 |
import javax.swing.event.ListSelectionEvent; |
12 | 13 |
import javax.swing.event.ListSelectionListener; |
13 | 14 |
import javax.swing.event.TableModelEvent; |
14 | 15 |
import javax.swing.table.AbstractTableModel; |
16 |
import org.apache.commons.lang3.StringUtils; |
|
17 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
|
15 | 18 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
16 | 19 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
17 | 20 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
... | ... | |
22 | 25 |
import org.gvsig.tools.i18n.I18nManager; |
23 | 26 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
24 | 27 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
28 |
import org.slf4j.Logger; |
|
29 |
import org.slf4j.LoggerFactory; |
|
25 | 30 |
|
26 | 31 |
/** |
27 | 32 |
* |
... | ... | |
32 | 37 |
implements FeatureTypePanel |
33 | 38 |
{ |
34 | 39 |
|
40 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultFeatureTypePanel.class); |
|
41 |
|
|
35 | 42 |
private class FeatureTypeTableModel extends AbstractTableModel { |
36 | 43 |
|
37 | 44 |
private final FeatureType featureType; |
... | ... | |
135 | 142 |
private boolean editable; |
136 | 143 |
private FeatureTypeTableModel tableModel; |
137 | 144 |
private FeatureStore store; |
145 |
private int currentRow; |
|
146 |
private boolean fieldSelectionAllowed; |
|
138 | 147 |
|
139 | 148 |
public DefaultFeatureTypePanel() { |
140 | 149 |
this.editable = true; |
150 |
this.currentRow = -1; |
|
151 |
this.fieldSelectionAllowed = true; |
|
141 | 152 |
this.initComponents(); |
142 | 153 |
} |
143 | 154 |
|
... | ... | |
158 | 169 |
if( e.getValueIsAdjusting() ) { |
159 | 170 |
return; |
160 | 171 |
} |
161 |
if( !btnFormFieldAccept.isEnabled() ) { |
|
162 |
doFormFieldPut(); |
|
163 |
} |
|
172 |
doChangeFieldSelection(); |
|
164 | 173 |
} |
165 | 174 |
}); |
166 | 175 |
this.descriptorPanel = new DefaultFeatureTypeAttributePanel(); |
... | ... | |
177 | 186 |
this.btnFormFieldDiscard.addActionListener(new ActionListener() { |
178 | 187 |
@Override |
179 | 188 |
public void actionPerformed(ActionEvent e) { |
180 |
doFormFieldPut();
|
|
189 |
doFormFieldDiscard();
|
|
181 | 190 |
} |
182 | 191 |
}); |
183 | 192 |
this.btnFormFieldAccept.addActionListener(new ActionListener() { |
184 | 193 |
@Override |
185 | 194 |
public void actionPerformed(ActionEvent e) { |
186 |
doFormFieldFetch();
|
|
195 |
doFormFieldAccept();
|
|
187 | 196 |
} |
188 | 197 |
}); |
189 | 198 |
this.btnNew.addActionListener(new ActionListener() { |
... | ... | |
224 | 233 |
return; |
225 | 234 |
} |
226 | 235 |
FeatureAttributeDescriptor descriptor = this.featureType.getAttributeDescriptor(row); |
236 |
this.currentRow = row; |
|
227 | 237 |
this.descriptorPanel.put(descriptor); |
228 |
this.descriptorPanel.setEnabled(true); |
|
229 |
this.descriptorPanel.setEditable(false); |
|
230 |
this.btnFormFieldAccept.setEnabled(false); |
|
231 |
this.btnFormFieldDiscard.setEnabled(false); |
|
238 |
updateButtonState(); |
|
232 | 239 |
if( descriptor instanceof EditableFeatureAttributeDescriptor ) { |
233 | 240 |
this.btnFormFieldModify.setEnabled(this.editable); |
234 | 241 |
} else { |
... | ... | |
236 | 243 |
} |
237 | 244 |
} |
238 | 245 |
|
246 |
private void updateButtonState() { |
|
247 |
this.descriptorPanel.setEnabled(true); |
|
248 |
this.descriptorPanel.setEditable(false); |
|
249 |
this.btnFormFieldAccept.setEnabled(false); |
|
250 |
this.btnFormFieldDiscard.setEnabled(false); |
|
251 |
this.btnFormFieldModify.setEnabled(this.editable); |
|
252 |
} |
|
253 |
|
|
239 | 254 |
private void doFormFieldModify() { |
240 | 255 |
int row = this.tblFields.getSelectedRow(); |
241 | 256 |
if( row<0 ) { |
... | ... | |
252 | 267 |
} else { |
253 | 268 |
this.descriptorPanel.setEditable(false); |
254 | 269 |
} |
270 |
this.fieldSelectionAllowed = false; |
|
255 | 271 |
} |
256 | 272 |
|
273 |
private void doFormFieldAccept() { |
|
274 |
doFormFieldFetch(); |
|
275 |
this.updateButtonState(); |
|
276 |
this.fieldSelectionAllowed = true; |
|
277 |
} |
|
278 |
|
|
279 |
private void doFormFieldDiscard() { |
|
280 |
doFormFieldPut(); |
|
281 |
this.updateButtonState(); |
|
282 |
this.fieldSelectionAllowed = true; |
|
283 |
} |
|
284 |
|
|
285 |
private void doChangeFieldSelection() { |
|
286 |
int row = this.tblFields.getSelectedRow(); |
|
287 |
if( row<0 ) { |
|
288 |
return; |
|
289 |
} |
|
290 |
if( !this.fieldSelectionAllowed ) { |
|
291 |
if( row !=this.currentRow ) { |
|
292 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
293 |
JOptionPane.showMessageDialog( |
|
294 |
this, |
|
295 |
i18n.getTranslation("_Before_changing_field_accept_or_discard_the_changes"), |
|
296 |
i18n.getTranslation("_Warning"), |
|
297 |
JOptionPane.WARNING_MESSAGE |
|
298 |
); |
|
299 |
this.tblFields.getSelectionModel().setSelectionInterval( |
|
300 |
this.currentRow, |
|
301 |
this.currentRow |
|
302 |
); |
|
303 |
} |
|
304 |
return; |
|
305 |
} |
|
306 |
doFormFieldPut(); |
|
307 |
} |
|
308 |
|
|
257 | 309 |
@Override |
258 | 310 |
public JComponent asJComponent() { |
259 | 311 |
return this; |
... | ... | |
261 | 313 |
|
262 | 314 |
public void setEditable(boolean editable) { |
263 | 315 |
this.editable = editable; |
264 |
this.btnFormFieldModify.setEnabled(editable); |
|
265 |
this.btnFormFieldAccept.setEnabled(editable); |
|
266 |
this.btnFormFieldDiscard.setEnabled(editable); |
|
267 | 316 |
this.btnNew.setEnabled(editable); |
268 | 317 |
this.btnDelete.setEnabled(editable); |
269 |
this.descriptorPanel.setEnabled(editable);
|
|
318 |
updateButtonState();
|
|
270 | 319 |
} |
271 | 320 |
|
272 | 321 |
@Override |
... | ... | |
281 | 330 |
this.store = null; |
282 | 331 |
} else { |
283 | 332 |
// Nos quedamos una referencia para evitar que se destruya, ya que |
284 |
// el featureTyper se guarda solo una WeakReference.
|
|
333 |
// el featureType se guarda solo una WeakReference. |
|
285 | 334 |
this.store = type.getStore(); |
286 | 335 |
} |
287 | 336 |
if( !(type instanceof EditableFeatureType) ) { |
... | ... | |
289 | 338 |
} |
290 | 339 |
this.tableModel = new FeatureTypeTableModel(type); |
291 | 340 |
this.tblFields.setModel(this.tableModel); |
292 |
if( type.size()>0 ) {
|
|
341 |
if( type!=null && !type.isEmpty() ) {
|
|
293 | 342 |
this.tblFields.getSelectionModel().setSelectionInterval(0, 0); |
294 | 343 |
} |
344 |
updateButtonState(); |
|
345 |
doFormFieldPut(); |
|
295 | 346 |
} |
296 | 347 |
|
297 | 348 |
private void doNewField() { |
... | ... | |
303 | 354 |
this.tableModel.fireUpdateEvent(); |
304 | 355 |
int row = descriptor.getIndex(); |
305 | 356 |
this.tblFields.getSelectionModel().addSelectionInterval(row,row); |
357 |
updateButtonState(); |
|
358 |
doFormFieldPut(); |
|
306 | 359 |
} |
307 | 360 |
|
308 | 361 |
private void doDeleteField() { |
... | ... | |
310 | 363 |
if( row<0 ) { |
311 | 364 |
return; |
312 | 365 |
} |
313 |
FeatureAttributeDescriptor descriptor = this.featureType.getAttributeDescriptor(row); |
|
366 |
// FeatureAttributeDescriptor descriptor = this.featureType.getAttributeDescriptor(row);
|
|
314 | 367 |
((EditableFeatureType)this.featureType).remove(row); |
315 | 368 |
this.tableModel.fireUpdateEvent(); |
316 | 369 |
if( row >= this.tblFields.getRowCount()) { |
317 | 370 |
row = this.tblFields.getRowCount()-1; |
318 | 371 |
} |
319 | 372 |
this.tblFields.getSelectionModel().addSelectionInterval(row,row); |
373 |
updateButtonState(); |
|
374 |
doFormFieldPut(); |
|
320 | 375 |
} |
321 | 376 |
|
322 | 377 |
public static String getNewFieldName(FeatureType featureType) { |
Also available in: Unified diff