Revision 3996 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/Table.java
Table.java | ||
---|---|---|
40 | 40 |
*/ |
41 | 41 |
package com.iver.cit.gvsig.gui; |
42 | 42 |
|
43 |
import java.awt.Component; |
|
43 | 44 |
import java.awt.event.MouseAdapter; |
44 | 45 |
import java.awt.event.MouseEvent; |
45 | 46 |
import java.beans.PropertyChangeEvent; |
46 | 47 |
import java.beans.PropertyChangeListener; |
48 |
import java.io.File; |
|
47 | 49 |
import java.io.IOException; |
48 |
import java.sql.Date; |
|
49 |
import java.sql.Time; |
|
50 |
import java.sql.Timestamp; |
|
51 | 50 |
import java.text.DateFormat; |
52 | 51 |
import java.text.NumberFormat; |
53 | 52 |
import java.text.ParseException; |
54 |
import java.util.ArrayList; |
|
55 | 53 |
import java.util.BitSet; |
56 | 54 |
|
57 | 55 |
import javax.swing.DefaultListSelectionModel; |
56 |
import javax.swing.JFileChooser; |
|
58 | 57 |
import javax.swing.JLabel; |
59 | 58 |
import javax.swing.JPanel; |
60 | 59 |
import javax.swing.event.ListSelectionEvent; |
61 | 60 |
import javax.swing.event.ListSelectionListener; |
62 | 61 |
import javax.swing.table.AbstractTableModel; |
63 |
import javax.swing.table.DefaultTableModel; |
|
64 |
import javax.swing.table.JTableHeader; |
|
65 |
import javax.swing.table.TableColumnModel; |
|
66 | 62 |
|
67 | 63 |
import org.apache.log4j.Logger; |
68 | 64 |
|
69 | 65 |
import com.hardcode.driverManager.DriverLoadException; |
70 |
import com.hardcode.gdbms.engine.data.DataSource; |
|
71 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
|
72 | 66 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
73 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
|
74 |
import com.hardcode.gdbms.engine.values.LongValue; |
|
67 |
import com.hardcode.gdbms.engine.values.NullValue; |
|
75 | 68 |
import com.hardcode.gdbms.engine.values.Value; |
76 |
import com.hardcode.gdbms.engine.values.ValueCollection; |
|
77 | 69 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
78 | 70 |
import com.iver.andami.PluginServices; |
79 | 71 |
import com.iver.andami.messages.NotificationManager; |
... | ... | |
81 | 73 |
import com.iver.andami.ui.mdiManager.SingletonView; |
82 | 74 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
83 | 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; |
|
84 | 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; |
|
85 | 81 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
82 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
86 | 83 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
87 | 84 |
import com.iver.cit.gvsig.fmap.layers.SelectionEvent; |
88 | 85 |
import com.iver.cit.gvsig.fmap.layers.SelectionListener; |
89 |
import com.iver.cit.gvsig.gui.layout.Popupmenu;
|
|
86 |
import com.iver.cit.gvsig.gui.tables.EditionTable;
|
|
90 | 87 |
import com.iver.cit.gvsig.gui.tables.PopupMenu; |
91 | 88 |
import com.iver.cit.gvsig.project.ProjectTable; |
89 |
import com.iver.utiles.SimpleFileFilter; |
|
92 | 90 |
import com.iver.utiles.swing.jtable.FieldSelectionEvent; |
93 | 91 |
import com.iver.utiles.swing.jtable.FieldSelectionListener; |
94 | 92 |
import com.iver.utiles.swing.jtable.JTable; |
... | ... | |
101 | 99 |
* |
102 | 100 |
* @author Fernando Gonz?lez Cort?s |
103 | 101 |
*/ |
104 |
public class Table extends JPanel implements SingletonView { |
|
102 |
public class Table extends JPanel implements SingletonView,EditionTable {
|
|
105 | 103 |
private static Logger logger = Logger.getLogger(Table.class.getName()); |
106 | 104 |
private javax.swing.JScrollPane jScrollPane = null; |
107 | 105 |
private JTable table = null; |
... | ... | |
121 | 119 |
private long[] orderIndexes = null; |
122 | 120 |
private long[] orderIndexesInverted = null; |
123 | 121 |
|
124 |
private DataWare dw; |
|
125 |
private ArrayList rowsCopied=new ArrayList();
|
|
122 |
//private DataWare dw;
|
|
123 |
private IRow[] rowsCopied=null;
|
|
126 | 124 |
|
127 | 125 |
/** |
128 | 126 |
* This is the default constructor |
... | ... | |
192 | 190 |
* @param table DOCUMENT ME! |
193 | 191 |
*/ |
194 | 192 |
public void setModel(ProjectTable table) { |
195 |
SelectableDataSource dataSource; |
|
193 |
//SelectableDataSource dataSource;
|
|
196 | 194 |
model = table; |
197 | 195 |
|
198 | 196 |
//Gesti?n del nombre de la ventana |
... | ... | |
364 | 362 |
* @author Fernando Gonz?lez Cort?s |
365 | 363 |
*/ |
366 | 364 |
public class DataSourceDataModel extends AbstractTableModel { |
367 |
private SelectableDataSource dataSource; |
|
365 |
//private SelectableDataSource dataSource;
|
|
368 | 366 |
private ProjectTable pt; |
369 | 367 |
private String[] aliases; |
370 | 368 |
private int[] mapping; |
371 |
|
|
369 |
private int dif=0; |
|
372 | 370 |
/** |
373 | 371 |
* Crea un nuevo DataSourceDataModel. |
374 | 372 |
* |
... | ... | |
376 | 374 |
*/ |
377 | 375 |
public DataSourceDataModel(ProjectTable pt) { |
378 | 376 |
this.pt = pt; |
379 |
try { |
|
380 |
dataSource = (SelectableDataSource)pt.getModelo().getRecordset();
|
|
381 |
} catch (DriverLoadException e) { |
|
377 |
//try {
|
|
378 |
//dataSource = pt.getModelo().getRecordset();
|
|
379 |
//} catch (DriverLoadException e) {
|
|
382 | 380 |
// TODO Auto-generated catch block |
383 |
e.printStackTrace(); |
|
384 |
} |
|
381 |
// e.printStackTrace();
|
|
382 |
//}
|
|
385 | 383 |
aliases = pt.getAliases(); |
386 | 384 |
mapping = pt.getMapping(); |
387 | 385 |
} |
... | ... | |
413 | 411 |
*/ |
414 | 412 |
public int getRowCount() { |
415 | 413 |
try { |
416 |
return (int) dataSource.getRowCount(); |
|
417 |
} catch (DriverException e) { |
|
418 |
return 0; |
|
419 |
} |
|
414 |
return (int) getModel().getModelo().getRowCount(); |
|
415 |
} catch (DriverIOException e) { |
|
416 |
return 0; |
|
417 |
} catch (IOException e) { |
|
418 |
return 0; |
|
419 |
} |
|
420 | 420 |
} |
421 | 421 |
|
422 | 422 |
/** |
... | ... | |
429 | 429 |
*/ |
430 | 430 |
public Object getValueAt(int row, int col) { |
431 | 431 |
try { |
432 |
if (dw != null){ |
|
433 |
return dw.getFieldValue(row, mapping[col]); |
|
434 |
}else{ |
|
432 |
//if (dw != null){
|
|
433 |
//return dw.getFieldValue(row, mapping[col]);
|
|
434 |
//}else{
|
|
435 | 435 |
if (orderIndexes != null){ |
436 |
return dataSource.getFieldValue(orderIndexes[row], mapping[col]);
|
|
436 |
return getModel().getModelo().getRow(row).getAttribute(col);//getRecordset().getFieldValue(orderIndexes[row], mapping[col]);
|
|
437 | 437 |
}else{ |
438 |
return dataSource.getFieldValue(row, mapping[col]); |
|
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; |
|
439 | 442 |
} |
440 |
} |
|
441 |
} catch (DriverException e) { |
|
442 |
return ValueFactory.createValue("").toString(); |
|
443 |
} |
|
443 |
//} |
|
444 |
}catch (DriverIOException e) { |
|
445 |
return ValueFactory.createValue("").toString(); |
|
446 |
} catch (IOException e) { |
|
447 |
return ValueFactory.createValue("").toString(); |
|
448 |
} |
|
449 |
|
|
444 | 450 |
} |
445 | 451 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
446 |
return (dw != null); |
|
452 |
return false;//(dw != null);
|
|
447 | 453 |
} |
448 | 454 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
449 | 455 |
Value v; |
450 | 456 |
try { |
451 |
v = ValueFactory.createValueByType(aValue.toString(), dataSource.getFieldType(columnIndex));
|
|
452 |
dw.setFieldValue(rowIndex, mapping[columnIndex], v); |
|
457 |
v = ValueFactory.createValueByType(aValue.toString(), getModel().getModelo().getRecordset().getFieldType(columnIndex));
|
|
458 |
//dw.setFieldValue(rowIndex, mapping[columnIndex], v);
|
|
453 | 459 |
} catch (DriverException e1) { |
454 | 460 |
throw new RuntimeException(e1); |
455 | 461 |
} catch (ParseException e) { |
456 | 462 |
throw new RuntimeException(e); |
457 |
} |
|
463 |
} catch (DriverLoadException e) { |
|
464 |
throw new RuntimeException(e); |
|
465 |
} |
|
458 | 466 |
} |
459 | 467 |
} |
460 | 468 |
|
... | ... | |
488 | 496 |
|
489 | 497 |
} |
490 | 498 |
|
491 |
public void startEditing() throws DriverException{ |
|
499 |
/* public void startEditing() throws DriverException{
|
|
492 | 500 |
// dw = model.getModelo().getDataWare(DataSourceFactory.DATA_WARE_COHERENT_ROW_ORDER); |
493 | 501 |
// dw.beginTrans(); |
494 | 502 |
} |
495 |
|
|
503 |
*/ |
|
496 | 504 |
/** |
497 | 505 |
* @throws DriverException |
498 | 506 |
* |
499 | 507 |
*/ |
500 |
public void cancelEditing() throws DriverException { |
|
508 |
/* public void cancelEditing() throws DriverException {
|
|
501 | 509 |
dw.rollBackTrans(); |
502 | 510 |
dw = null; |
503 | 511 |
} |
504 |
|
|
512 |
*/ |
|
505 | 513 |
/** |
506 | 514 |
* @throws DriverException |
507 | 515 |
* |
508 | 516 |
*/ |
509 |
public void stopEditing() throws DriverException { |
|
517 |
/* public void stopEditing() throws DriverException {
|
|
510 | 518 |
// dw.commitTrans(); |
511 | 519 |
// dw = null; |
512 | 520 |
// model.getModelo().stop(); |
513 | 521 |
// model.getModelo().start(); |
514 | 522 |
} |
515 |
|
|
523 |
*/ |
|
516 | 524 |
/** |
517 | 525 |
* @return |
518 | 526 |
*/ |
519 |
public boolean isEditing() { |
|
527 |
/* public boolean isEditing() {
|
|
520 | 528 |
return dw != null; |
521 | 529 |
} |
522 |
|
|
530 |
*/ |
|
523 | 531 |
/** |
524 | 532 |
* Quita los campos seleccionados |
525 | 533 |
*/ |
... | ... | |
554 | 562 |
} |
555 | 563 |
return values; |
556 | 564 |
} |
557 |
private void refresh() throws DriverException{ |
|
565 |
/* private void refresh() throws DriverException{
|
|
558 | 566 |
//dw.commitTrans(); |
559 | 567 |
//model.getModelo().stop(); |
560 | 568 |
//dw.beginTrans(); |
561 | 569 |
//DataSourceDataModel dsdm=(DataSourceDataModel)getTable().getModel(); |
562 | 570 |
//dsdm.fireTableDataChanged(); |
563 |
} |
|
564 |
public void addEmptyRow() throws DriverException{ |
|
571 |
}*/
|
|
572 |
/* public void addEmptyRow() throws DriverException{
|
|
565 | 573 |
ValueCollection valuePK=new ValueCollection(); |
566 | 574 |
valuePK.setValues(new Value[]{ValueFactory.createValue(dw.getRowCount())}); |
567 | 575 |
dw.insertEmptyRow(valuePK); |
568 | 576 |
refresh(); |
569 | 577 |
} |
570 |
|
|
571 |
public void copySelectedRows() throws DriverException{ |
|
578 |
*/ |
|
579 |
/* public void copySelectedRows() throws DriverException{
|
|
572 | 580 |
int[] sel=getSelectedRowIndices(); |
573 | 581 |
for(int i=0;i<sel.length;i++){ |
574 | 582 |
rowsCopied.add(getValueRow(sel[i])); |
575 | 583 |
} |
576 | 584 |
} |
577 |
|
|
578 |
public void addSelectionToEnd() throws DriverException { |
|
585 |
*/ |
|
586 |
/* public void addSelectionToEnd() throws DriverException {
|
|
579 | 587 |
for (int i=0;i<rowsCopied.size();i++){ |
580 | 588 |
dw.insertFilledRow((Value[])rowsCopied.get(i)); |
581 | 589 |
} |
582 | 590 |
refresh(); |
583 | 591 |
} |
584 |
public void delSelectionRow() throws DriverException{ |
|
592 |
*/ |
|
593 |
/*public void delSelectionRow() throws DriverException{ |
|
585 | 594 |
int[] sel=getSelectedRowIndices(); |
586 | 595 |
for(int i=sel.length-1;i>=0;i--){ |
587 | 596 |
dw.deleteRow(sel[i]); |
... | ... | |
589 | 598 |
refresh(); |
590 | 599 |
|
591 | 600 |
} |
592 |
public boolean isCopy(){ |
|
601 |
*/ |
|
602 |
/*public boolean isCopy(){ |
|
593 | 603 |
return !rowsCopied.isEmpty(); |
594 | 604 |
} |
605 |
*/ |
|
595 | 606 |
/* |
596 |
public void addSelectionToRow() throws DriverException {
|
|
607 |
public void addSelectionToRow() throws DriverException {
|
|
597 | 608 |
int[] sel=getSelectedRowIndices(); |
598 | 609 |
dw.insertFilledRow((Value[])rowsCopied.get(i),sel[0]); |
599 | 610 |
refresh(); |
600 | 611 |
} |
601 | 612 |
*/ |
602 | 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 |
} |
|
603 | 740 |
} |
Also available in: Unified diff