svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / Table.java @ 3996
History | View | Annotate | Download (22.4 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.gui; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.event.MouseAdapter; |
45 |
import java.awt.event.MouseEvent; |
46 |
import java.beans.PropertyChangeEvent; |
47 |
import java.beans.PropertyChangeListener; |
48 |
import java.io.File; |
49 |
import java.io.IOException; |
50 |
import java.text.DateFormat; |
51 |
import java.text.NumberFormat; |
52 |
import java.text.ParseException; |
53 |
import java.util.BitSet; |
54 |
|
55 |
import javax.swing.DefaultListSelectionModel; |
56 |
import javax.swing.JFileChooser; |
57 |
import javax.swing.JLabel; |
58 |
import javax.swing.JPanel; |
59 |
import javax.swing.event.ListSelectionEvent; |
60 |
import javax.swing.event.ListSelectionListener; |
61 |
import javax.swing.table.AbstractTableModel; |
62 |
|
63 |
import org.apache.log4j.Logger; |
64 |
|
65 |
import com.hardcode.driverManager.DriverLoadException; |
66 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
67 |
import com.hardcode.gdbms.engine.values.NullValue; |
68 |
import com.hardcode.gdbms.engine.values.Value; |
69 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
70 |
import com.iver.andami.PluginServices; |
71 |
import com.iver.andami.messages.NotificationManager; |
72 |
import com.iver.andami.ui.mdiFrame.MainFrame; |
73 |
import com.iver.andami.ui.mdiManager.SingletonView; |
74 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
75 |
import com.iver.cit.gvsig.fmap.FMap; |
76 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
77 |
import com.iver.cit.gvsig.fmap.core.IRow; |
78 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
79 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
80 |
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter; |
81 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
82 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
83 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
84 |
import com.iver.cit.gvsig.fmap.layers.SelectionEvent; |
85 |
import com.iver.cit.gvsig.fmap.layers.SelectionListener; |
86 |
import com.iver.cit.gvsig.gui.tables.EditionTable; |
87 |
import com.iver.cit.gvsig.gui.tables.PopupMenu; |
88 |
import com.iver.cit.gvsig.project.ProjectTable; |
89 |
import com.iver.utiles.SimpleFileFilter; |
90 |
import com.iver.utiles.swing.jtable.FieldSelectionEvent; |
91 |
import com.iver.utiles.swing.jtable.FieldSelectionListener; |
92 |
import com.iver.utiles.swing.jtable.JTable; |
93 |
import com.iver.utiles.swing.jtable.SelectionHeaderSupport; |
94 |
import com.iver.utiles.swing.jtable.TextFieldCellEditor; |
95 |
|
96 |
|
97 |
/**
|
98 |
* DOCUMENT ME!
|
99 |
*
|
100 |
* @author Fernando Gonz?lez Cort?s
|
101 |
*/
|
102 |
public class Table extends JPanel implements SingletonView,EditionTable { |
103 |
private static Logger logger = Logger.getLogger(Table.class.getName()); |
104 |
private javax.swing.JScrollPane jScrollPane = null; |
105 |
private JTable table = null; |
106 |
private ProjectTable model = null; |
107 |
private DateFormat df = DateFormat.getDateInstance(); |
108 |
private NumberFormat nf = NumberFormat.getInstance(); |
109 |
private JLabel jLabelStatus = null; |
110 |
private ViewInfo m_viewInfo = null; |
111 |
private FMap fmap;
|
112 |
|
113 |
private boolean updating = false; |
114 |
|
115 |
private TableSelectionListener selectionListener = new TableSelectionListener(); |
116 |
private long numReg=0; |
117 |
private SelectionHeaderSupport headerSelectionSupport = new SelectionHeaderSupport(); |
118 |
|
119 |
private long[] orderIndexes = null; |
120 |
private long[] orderIndexesInverted = null; |
121 |
|
122 |
//private DataWare dw;
|
123 |
private IRow[] rowsCopied=null; |
124 |
|
125 |
/**
|
126 |
* This is the default constructor
|
127 |
*/
|
128 |
public Table() {
|
129 |
super();
|
130 |
initialize(); |
131 |
} |
132 |
|
133 |
/**
|
134 |
* DOCUMENT ME!
|
135 |
*
|
136 |
* @return DOCUMENT ME!
|
137 |
*/
|
138 |
public ProjectTable getModel() {
|
139 |
return model;
|
140 |
} |
141 |
|
142 |
public BitSet getSelectedFieldIndices(){ |
143 |
return headerSelectionSupport.getSelectedColumns();
|
144 |
} |
145 |
public int[] getSelectedRowIndices(){ |
146 |
return getTable().getSelectedRows();
|
147 |
} |
148 |
private void refreshControls(){ |
149 |
try{
|
150 |
MainFrame mF = PluginServices.getMainFrame(); |
151 |
if (mF != null) |
152 |
PluginServices.getMDIManager().getViewInfo(Table.this).setTitle(PluginServices.getText(this, "Tabla")+": " + model.getName()); |
153 |
|
154 |
if (model.getAssociatedTable() != null){ |
155 |
this.fmap = ((FLayer)model.getAssociatedTable()).getFMap();
|
156 |
}else{
|
157 |
this.fmap = null; |
158 |
} |
159 |
|
160 |
SelectableDataSource dataSource = (SelectableDataSource)model.getModelo().getRecordset(); |
161 |
logger.debug("dataSource.start()");
|
162 |
dataSource.start(); |
163 |
|
164 |
AbstractTableModel dataModel = new DataSourceDataModel(model); |
165 |
|
166 |
getTable().setModel(dataModel); |
167 |
|
168 |
headerSelectionSupport.setTableHeader(getTable().getTableHeader()); |
169 |
headerSelectionSupport.addFieldSelectionListener(new FieldSelectionListener() {
|
170 |
public void fieldSelected(FieldSelectionEvent e) { |
171 |
if (PluginServices.getMainFrame() != null) |
172 |
PluginServices.getMainFrame().enableControls(); |
173 |
} |
174 |
}); |
175 |
|
176 |
model.getModelo().getRecordset().addSelectionListener(selectionListener); |
177 |
|
178 |
updateSelection(); |
179 |
}catch (DriverException e){
|
180 |
NotificationManager.addError("No se pudo leer la informaci?n", e);
|
181 |
} catch (DriverLoadException e) {
|
182 |
NotificationManager.addError("No se pudo leer la informaci?n", e);
|
183 |
} |
184 |
|
185 |
} |
186 |
|
187 |
/**
|
188 |
* DOCUMENT ME!
|
189 |
*
|
190 |
* @param table DOCUMENT ME!
|
191 |
*/
|
192 |
public void setModel(ProjectTable table) { |
193 |
//SelectableDataSource dataSource;
|
194 |
model = table; |
195 |
|
196 |
//Gesti?n del nombre de la ventana
|
197 |
model.addPropertyChangeListener(new PropertyChangeListener() { |
198 |
public void propertyChange(PropertyChangeEvent evt) { |
199 |
if (evt.getPropertyName().equals("name")){ |
200 |
PluginServices.getMDIManager().getViewInfo(Table.this).setTitle(PluginServices.getText(this, "Tabla")+": " + (String)evt.getNewValue()); |
201 |
}else if (evt.getPropertyName().equals("model")){ |
202 |
refreshControls(); |
203 |
} |
204 |
} |
205 |
}); |
206 |
|
207 |
refreshControls(); |
208 |
} |
209 |
|
210 |
/**
|
211 |
*
|
212 |
*/
|
213 |
private void updateSelection() { |
214 |
updating = true;
|
215 |
try {
|
216 |
DefaultListSelectionModel sm = (DefaultListSelectionModel) getTable() |
217 |
.getSelectionModel(); |
218 |
sm.clearSelection(); |
219 |
BitSet bs = (model.getModelo().getRecordset()).getSelection();
|
220 |
sm.setValueIsAdjusting(true);
|
221 |
|
222 |
if (orderIndexes != null){ |
223 |
for (int i = 0; i < orderIndexes.length; i++) { |
224 |
if (bs.get(i)){
|
225 |
sm.addSelectionInterval((int) orderIndexesInverted[i], (int) orderIndexesInverted[i]); |
226 |
} |
227 |
} |
228 |
}else{
|
229 |
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { |
230 |
sm.addSelectionInterval(i, i); |
231 |
} |
232 |
} |
233 |
|
234 |
sm.setValueIsAdjusting(false);
|
235 |
|
236 |
try {
|
237 |
numReg=model.getModelo().getRowCount(); |
238 |
} catch (IOException e) { |
239 |
// TODO Auto-generated catch block
|
240 |
e.printStackTrace(); |
241 |
} |
242 |
jLabelStatus.setText(" " + ((SelectableDataSource)model.getModelo().getRecordset()).getSelection().cardinality() + " / " + numReg +" "+ |
243 |
PluginServices.getText(this, "registros_seleccionados_total") + "."); |
244 |
} catch (DriverIOException e) {
|
245 |
// TODO Auto-generated catch block
|
246 |
e.printStackTrace(); |
247 |
} catch (DriverLoadException e) {
|
248 |
// TODO Auto-generated catch block
|
249 |
e.printStackTrace(); |
250 |
} |
251 |
updating = false;
|
252 |
} |
253 |
|
254 |
/**
|
255 |
* This method initializes this
|
256 |
*/
|
257 |
private void initialize() { |
258 |
jLabelStatus = new JLabel(); |
259 |
setLayout(new java.awt.BorderLayout());
|
260 |
jLabelStatus.setText("");
|
261 |
jLabelStatus.setName("");
|
262 |
jLabelStatus.setPreferredSize(new java.awt.Dimension(100, 18)); |
263 |
add(getJScrollPane(), java.awt.BorderLayout.CENTER); |
264 |
this.add(jLabelStatus, java.awt.BorderLayout.SOUTH);
|
265 |
} |
266 |
|
267 |
/**
|
268 |
* This method initializes table
|
269 |
*
|
270 |
* @return javax.swing.JTable
|
271 |
*/
|
272 |
public javax.swing.JTable getTable() {
|
273 |
if (table == null) { |
274 |
table = new JTable(); |
275 |
table.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF); |
276 |
table.setSelectionModel(new DefaultListSelectionModel()); |
277 |
table.getTableHeader().addMouseListener(new MouseHandler());
|
278 |
table.addMouseListener(new MouseRow());
|
279 |
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
280 |
public void valueChanged(ListSelectionEvent e) { |
281 |
if (updating) return; |
282 |
|
283 |
SelectableDataSource dataModel=null;
|
284 |
try {
|
285 |
dataModel = Table.this.model.getModelo().getRecordset(); |
286 |
} catch (DriverLoadException e1) {
|
287 |
// TODO Auto-generated catch block
|
288 |
e1.printStackTrace(); |
289 |
} |
290 |
|
291 |
DefaultListSelectionModel model = (DefaultListSelectionModel) table.getSelectionModel(); |
292 |
BitSet selection = dataModel.getSelection();
|
293 |
|
294 |
for (int i = e.getFirstIndex(); |
295 |
i <= e.getLastIndex(); i++) { |
296 |
if (orderIndexes != null){ |
297 |
selection.set((int) orderIndexes[i], model.isSelectedIndex(i));
|
298 |
}else{
|
299 |
selection.set(i, model.isSelectedIndex(i)); |
300 |
} |
301 |
} |
302 |
|
303 |
if (e.getValueIsAdjusting() == false) { |
304 |
if (fmap != null){ |
305 |
fmap.endAtomicEvent(); |
306 |
} |
307 |
dataModel.fireSelectionEvents(); |
308 |
}else{
|
309 |
if (fmap != null) |
310 |
fmap.beginAtomicEvent(); |
311 |
} |
312 |
jLabelStatus.setText(" " + selection.cardinality() + " / " + numReg + " " + |
313 |
PluginServices.getText(this, "registros_seleccionados_total") + "."); |
314 |
} |
315 |
}); |
316 |
TextFieldCellEditor ce = new TextFieldCellEditor();
|
317 |
for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) { |
318 |
table.getColumnModel().getColumn(i).setCellEditor(ce); |
319 |
} |
320 |
} |
321 |
|
322 |
return table;
|
323 |
} |
324 |
|
325 |
/**
|
326 |
* This method initializes jScrollPane
|
327 |
*
|
328 |
* @return javax.swing.JScrollPane
|
329 |
*/
|
330 |
private javax.swing.JScrollPane getJScrollPane() {
|
331 |
if (jScrollPane == null) { |
332 |
jScrollPane = new javax.swing.JScrollPane();
|
333 |
jScrollPane.setViewportView(getTable()); |
334 |
} |
335 |
|
336 |
return jScrollPane;
|
337 |
} |
338 |
|
339 |
/**
|
340 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel()
|
341 |
*/
|
342 |
public Object getViewModel() { |
343 |
return model;
|
344 |
} |
345 |
|
346 |
/**
|
347 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
348 |
*/
|
349 |
public ViewInfo getViewInfo() {
|
350 |
ViewInfo m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE | ViewInfo.MAXIMIZABLE |
|
351 |
ViewInfo.RESIZABLE); |
352 |
m_viewInfo.setTitle(PluginServices.getText(this, "Tabla")); |
353 |
m_viewInfo.setWidth(300);
|
354 |
m_viewInfo.setHeight(200);
|
355 |
|
356 |
return m_viewInfo;
|
357 |
} |
358 |
|
359 |
/**
|
360 |
* DOCUMENT ME!
|
361 |
*
|
362 |
* @author Fernando Gonz?lez Cort?s
|
363 |
*/
|
364 |
public class DataSourceDataModel extends AbstractTableModel { |
365 |
//private SelectableDataSource dataSource;
|
366 |
private ProjectTable pt;
|
367 |
private String[] aliases; |
368 |
private int[] mapping; |
369 |
private int dif=0; |
370 |
/**
|
371 |
* Crea un nuevo DataSourceDataModel.
|
372 |
*
|
373 |
* @param ds DOCUMENT ME!
|
374 |
*/
|
375 |
public DataSourceDataModel(ProjectTable pt) {
|
376 |
this.pt = pt;
|
377 |
//try {
|
378 |
//dataSource = pt.getModelo().getRecordset();
|
379 |
//} catch (DriverLoadException e) {
|
380 |
// TODO Auto-generated catch block
|
381 |
// e.printStackTrace();
|
382 |
//}
|
383 |
aliases = pt.getAliases(); |
384 |
mapping = pt.getMapping(); |
385 |
} |
386 |
|
387 |
/**
|
388 |
* Returns the name of the field.
|
389 |
*
|
390 |
* @param col index of field
|
391 |
*
|
392 |
* @return Name of field
|
393 |
*/
|
394 |
public String getColumnName(int col) { |
395 |
return aliases[mapping[col]];
|
396 |
} |
397 |
|
398 |
/**
|
399 |
* Returns the number of fields.
|
400 |
*
|
401 |
* @return number of fields
|
402 |
*/
|
403 |
public int getColumnCount() { |
404 |
return mapping.length;
|
405 |
} |
406 |
|
407 |
/**
|
408 |
* Returns number of rows.
|
409 |
*
|
410 |
* @return number of rows.
|
411 |
*/
|
412 |
public int getRowCount() { |
413 |
try {
|
414 |
return (int) getModel().getModelo().getRowCount(); |
415 |
} catch (DriverIOException e) {
|
416 |
return 0; |
417 |
} catch (IOException e) { |
418 |
return 0; |
419 |
} |
420 |
} |
421 |
|
422 |
/**
|
423 |
* DOCUMENT ME!
|
424 |
*
|
425 |
* @param row DOCUMENT ME!
|
426 |
* @param col DOCUMENT ME!
|
427 |
*
|
428 |
* @return DOCUMENT ME!
|
429 |
*/
|
430 |
public Object getValueAt(int row, int col) { |
431 |
try {
|
432 |
//if (dw != null){
|
433 |
//return dw.getFieldValue(row, mapping[col]);
|
434 |
//}else{
|
435 |
if (orderIndexes != null){ |
436 |
return getModel().getModelo().getRow(row).getAttribute(col);//getRecordset().getFieldValue(orderIndexes[row], mapping[col]); |
437 |
}else{
|
438 |
Object obj= getModel().getModelo().getRow(row).getAttribute( mapping[col]);//getRecordset().getFieldValue(row, mapping[col]); |
439 |
//if (obj instanceof NullValue)
|
440 |
// return null;
|
441 |
return obj;
|
442 |
} |
443 |
//}
|
444 |
}catch (DriverIOException e) {
|
445 |
return ValueFactory.createValue("").toString(); |
446 |
} catch (IOException e) { |
447 |
return ValueFactory.createValue("").toString(); |
448 |
} |
449 |
|
450 |
} |
451 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
452 |
return false;//(dw != null); |
453 |
} |
454 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
455 |
Value v; |
456 |
try {
|
457 |
v = ValueFactory.createValueByType(aValue.toString(), getModel().getModelo().getRecordset().getFieldType(columnIndex)); |
458 |
//dw.setFieldValue(rowIndex, mapping[columnIndex], v);
|
459 |
} catch (DriverException e1) {
|
460 |
throw new RuntimeException(e1); |
461 |
} catch (ParseException e) { |
462 |
throw new RuntimeException(e); |
463 |
} catch (DriverLoadException e) {
|
464 |
throw new RuntimeException(e); |
465 |
} |
466 |
} |
467 |
} |
468 |
|
469 |
public class TableSelectionListener implements SelectionListener{ |
470 |
|
471 |
/**
|
472 |
* @see com.iver.cit.gvsig.fmap.layers.LegendListener#selectionChanged(com.iver.cit.gvsig.fmap.layers.LayerEvent)
|
473 |
*/
|
474 |
public void selectionChanged(SelectionEvent e) { |
475 |
updateSelection(); |
476 |
Table.this.repaint(); |
477 |
} |
478 |
|
479 |
} |
480 |
|
481 |
/**
|
482 |
* @param ds
|
483 |
* @throws IOException
|
484 |
*/
|
485 |
public void setOrder(long[] indexes) throws IOException { |
486 |
orderIndexes = indexes; |
487 |
orderIndexesInverted = new long[orderIndexes.length]; |
488 |
for (int i = 0; i < indexes.length; i++) { |
489 |
orderIndexesInverted[(int) indexes[i]] = i;
|
490 |
} |
491 |
|
492 |
updating=true;
|
493 |
((DataSourceDataModel)getTable().getModel()).fireTableDataChanged(); |
494 |
updating=false;
|
495 |
updateSelection(); |
496 |
|
497 |
} |
498 |
|
499 |
/* public void startEditing() throws DriverException{
|
500 |
// dw = model.getModelo().getDataWare(DataSourceFactory.DATA_WARE_COHERENT_ROW_ORDER);
|
501 |
// dw.beginTrans();
|
502 |
}
|
503 |
*/
|
504 |
/**
|
505 |
* @throws DriverException
|
506 |
*
|
507 |
*/
|
508 |
/* public void cancelEditing() throws DriverException {
|
509 |
dw.rollBackTrans();
|
510 |
dw = null;
|
511 |
}
|
512 |
*/
|
513 |
/**
|
514 |
* @throws DriverException
|
515 |
*
|
516 |
*/
|
517 |
/* public void stopEditing() throws DriverException {
|
518 |
// dw.commitTrans();
|
519 |
// dw = null;
|
520 |
// model.getModelo().stop();
|
521 |
// model.getModelo().start();
|
522 |
}
|
523 |
*/
|
524 |
/**
|
525 |
* @return
|
526 |
*/
|
527 |
/* public boolean isEditing() {
|
528 |
return dw != null;
|
529 |
}
|
530 |
*/
|
531 |
/**
|
532 |
* Quita los campos seleccionados
|
533 |
*/
|
534 |
public void clearSelectedFields() |
535 |
{ |
536 |
headerSelectionSupport.clearSelectedColumns(); |
537 |
} |
538 |
private class MouseHandler extends MouseAdapter { |
539 |
public void mouseClicked(MouseEvent e) { |
540 |
/* JTableHeader h = (JTableHeader) e.getSource();
|
541 |
TableColumnModel columnModel = h.getColumnModel();
|
542 |
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
|
543 |
int column = columnModel.getColumn(viewColumn).getModelIndex();
|
544 |
if (column != -1) {
|
545 |
|
546 |
}*/
|
547 |
} |
548 |
} |
549 |
private class MouseRow extends MouseAdapter { |
550 |
public void mouseClicked(MouseEvent e) { |
551 |
PluginServices.getMainFrame().enableControls(); |
552 |
if (e.getButton()==MouseEvent.BUTTON3){ |
553 |
new PopupMenu(e.getPoint()); |
554 |
} |
555 |
} |
556 |
} |
557 |
public Value[] getValueRow(int index){ |
558 |
DataSourceDataModel dsdm=(DataSourceDataModel)getTable().getModel(); |
559 |
Value [] values=new Value[dsdm.getColumnCount()]; |
560 |
for (int i=0;i<dsdm.getColumnCount();i++){ |
561 |
values[i]=(Value)dsdm.getValueAt(index,i); |
562 |
} |
563 |
return values;
|
564 |
} |
565 |
/* private void refresh() throws DriverException{
|
566 |
//dw.commitTrans();
|
567 |
//model.getModelo().stop();
|
568 |
//dw.beginTrans();
|
569 |
//DataSourceDataModel dsdm=(DataSourceDataModel)getTable().getModel();
|
570 |
//dsdm.fireTableDataChanged();
|
571 |
}*/
|
572 |
/* public void addEmptyRow() throws DriverException{
|
573 |
ValueCollection valuePK=new ValueCollection();
|
574 |
valuePK.setValues(new Value[]{ValueFactory.createValue(dw.getRowCount())});
|
575 |
dw.insertEmptyRow(valuePK);
|
576 |
refresh();
|
577 |
}
|
578 |
*/
|
579 |
/* public void copySelectedRows() throws DriverException{
|
580 |
int[] sel=getSelectedRowIndices();
|
581 |
for(int i=0;i<sel.length;i++){
|
582 |
rowsCopied.add(getValueRow(sel[i]));
|
583 |
}
|
584 |
}
|
585 |
*/
|
586 |
/* public void addSelectionToEnd() throws DriverException {
|
587 |
for (int i=0;i<rowsCopied.size();i++){
|
588 |
dw.insertFilledRow((Value[])rowsCopied.get(i));
|
589 |
}
|
590 |
refresh();
|
591 |
}
|
592 |
*/
|
593 |
/*public void delSelectionRow() throws DriverException{
|
594 |
int[] sel=getSelectedRowIndices();
|
595 |
for(int i=sel.length-1;i>=0;i--){
|
596 |
dw.deleteRow(sel[i]);
|
597 |
}
|
598 |
refresh();
|
599 |
|
600 |
}
|
601 |
*/
|
602 |
/*public boolean isCopy(){
|
603 |
return !rowsCopied.isEmpty();
|
604 |
}
|
605 |
*/
|
606 |
/*
|
607 |
public void addSelectionToRow() throws DriverException {
|
608 |
int[] sel=getSelectedRowIndices();
|
609 |
dw.insertFilledRow((Value[])rowsCopied.get(i),sel[0]);
|
610 |
refresh();
|
611 |
}
|
612 |
*/
|
613 |
|
614 |
public void startEditing() throws EditionException { |
615 |
getModel().getModelo().startEdition(); |
616 |
|
617 |
} |
618 |
|
619 |
public void stopEditing() { |
620 |
try {
|
621 |
JFileChooser jfc = new JFileChooser(); |
622 |
SimpleFileFilter filterShp = new SimpleFileFilter("shp", "Ficheros .shp"); |
623 |
jfc.setFileFilter(filterShp); |
624 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
625 |
File newFile = jfc.getSelectedFile();
|
626 |
//VectorialEditableAdapter vea = (VectorialEditableAdapter) layer.getSource();
|
627 |
// File newFile = vea.getDriver().
|
628 |
|
629 |
; |
630 |
ShpWriter writer = new ShpWriter(newFile,(FLyrVect) getModel().getAssociatedTable());
|
631 |
|
632 |
|
633 |
getModel().getModelo().stopEdition(writer); |
634 |
//layer.setSource(getModel().getModelo().getOriginalAdapter());
|
635 |
//layer.setEditing(false);
|
636 |
//vista.hideConsole();
|
637 |
} |
638 |
//}
|
639 |
} catch (Exception e) { |
640 |
NotificationManager.addError("No se pudo guardar la edici?n", e);
|
641 |
} |
642 |
} |
643 |
|
644 |
public void hideColumns(int[] index) { |
645 |
// TODO Auto-generated method stub
|
646 |
|
647 |
} |
648 |
|
649 |
public void setUneditableColumns(int[] index) { |
650 |
// TODO Auto-generated method stub
|
651 |
|
652 |
} |
653 |
|
654 |
public void setDefaultValues(int[] numColumns, Value[] values) { |
655 |
// TODO Auto-generated method stub
|
656 |
|
657 |
} |
658 |
|
659 |
public Value getDefaultValue() {
|
660 |
// TODO Auto-generated method stub
|
661 |
return null; |
662 |
} |
663 |
|
664 |
public int[] getSelectedColumns() { |
665 |
return null; |
666 |
} |
667 |
|
668 |
public void cancelEditing() throws IOException { |
669 |
getModel().getModelo().cancelEdition(); |
670 |
} |
671 |
|
672 |
public boolean isEditing() { |
673 |
return getModel().getModelo().isEditing();
|
674 |
} |
675 |
|
676 |
public void refresh() { |
677 |
updating=true;
|
678 |
((DataSourceDataModel)getTable().getModel()).fireTableDataChanged(); |
679 |
updating=false;
|
680 |
updateSelection(); |
681 |
} |
682 |
|
683 |
public void addRow(IRow[] rows) throws DriverIOException, IOException { |
684 |
if (rows==null){ |
685 |
IRow row=new DefaultFeature(null,null); |
686 |
getModel().getModelo().addRow(row); |
687 |
}else{
|
688 |
for (int i=0;i<rows.length;i++){ |
689 |
getModel().getModelo().addRow(rows[i]); |
690 |
} |
691 |
} |
692 |
refresh(); |
693 |
} |
694 |
|
695 |
public void copyRow() throws DriverIOException, IOException { |
696 |
int[] index=getSelectedRowIndices(); |
697 |
rowsCopied=new IRow[index.length];
|
698 |
for (int i=0;i<index.length;i++){ |
699 |
rowsCopied[i]=getModel().getModelo().getRow(index[i]); |
700 |
} |
701 |
} |
702 |
|
703 |
public void cutRow() throws DriverIOException, IOException { |
704 |
int[] index=getSelectedRowIndices(); |
705 |
rowsCopied=new IRow[index.length];
|
706 |
for (int i=0;i<index.length;i++){ |
707 |
rowsCopied[i]=getModel().getModelo().getRow(index[i]); |
708 |
} |
709 |
removeRow(); |
710 |
|
711 |
} |
712 |
|
713 |
public void removeRow() throws DriverIOException, IOException { |
714 |
int[] index=getSelectedRowIndices(); |
715 |
for (int i=0;i<index.length;i++){ |
716 |
getModel().getModelo().removeRow(index[i]); |
717 |
//getTable().removeRowSelectionInterval(index[i],index[i]+1);
|
718 |
} |
719 |
|
720 |
refresh(); |
721 |
} |
722 |
|
723 |
public void addColumn() { |
724 |
// TODO Auto-generated method stub
|
725 |
refresh(); |
726 |
} |
727 |
|
728 |
public void removeColumn() { |
729 |
// TODO Auto-generated method stub
|
730 |
refresh(); |
731 |
} |
732 |
|
733 |
public boolean isCopied() { |
734 |
return (rowsCopied!=null); |
735 |
} |
736 |
|
737 |
public void pasteRow() throws DriverIOException, IOException { |
738 |
addRow(rowsCopied); |
739 |
} |
740 |
} |