Revision 21132 branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/table/ProjectTable.java
ProjectTable.java | ||
---|---|---|
44 | 44 |
import java.util.ArrayList; |
45 | 45 |
import java.util.Date; |
46 | 46 |
|
47 |
import org.gvsig.fmap.datasources.SelectableDataSource; |
|
48 |
import org.gvsig.fmap.drivers.writing.IEditableSource; |
|
49 |
import org.gvsig.fmap.drivers.writing.adapters.EditableAdapter; |
|
50 |
import org.gvsig.fmap.drivers.writing.adapters.VectorialEditableAdapter; |
|
47 |
import org.gvsig.data.ReadException; |
|
48 |
import org.gvsig.data.vectorial.FeatureStore; |
|
51 | 49 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
52 | 50 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
53 | 51 |
import org.gvsig.fmap.mapcontext.layers.LayerFactory; |
... | ... | |
58 | 56 |
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend; |
59 | 57 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
60 | 58 |
|
61 |
import com.hardcode.driverManager.DriverLoadException; |
|
62 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
63 |
import com.hardcode.gdbms.engine.data.DataSource; |
|
64 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
|
65 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
|
66 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
|
67 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
|
68 | 59 |
import com.iver.andami.messages.NotificationManager; |
69 | 60 |
import com.iver.andami.ui.mdiManager.IWindow; |
70 | 61 |
import com.iver.cit.gvsig.project.Project; |
... | ... | |
86 | 77 |
public class ProjectTable extends ProjectDocument { |
87 | 78 |
//public static int numTables = 0; |
88 | 79 |
|
89 |
private IEditableSource esModel;
|
|
80 |
private FeatureStore esModel;
|
|
90 | 81 |
|
91 |
private IEditableSource original;
|
|
82 |
private FeatureStore original;
|
|
92 | 83 |
|
93 | 84 |
private String linkTable; |
94 | 85 |
|
... | ... | |
143 | 134 |
* |
144 | 135 |
* @return |
145 | 136 |
*/ |
146 |
public IEditableSource getModelo() {
|
|
137 |
public FeatureStore getModelo() {
|
|
147 | 138 |
return esModel; |
148 | 139 |
} |
149 | 140 |
|
... | ... | |
368 | 359 |
return xml; |
369 | 360 |
} |
370 | 361 |
|
371 |
/** |
|
372 |
* DOCUMENT ME! |
|
373 |
* |
|
374 |
* @param xml |
|
375 |
* DOCUMENT ME! |
|
376 |
* @param p |
|
377 |
* DOCUMENT ME! |
|
378 |
* |
|
379 |
* @throws XMLException |
|
380 |
* @throws ReadDriverException |
|
381 |
* @throws DriverException |
|
382 |
* |
|
383 |
* @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity) |
|
384 |
*/ |
|
385 |
public void setXMLEntity03(XMLEntity xml) |
|
386 |
throws XMLException, ReadDriverException{ |
|
387 |
super.setXMLEntity03(xml); |
|
388 |
int numTables = xml.getIntProperty("numTables"); |
|
389 |
ProjectDocument.NUMS.put(ProjectTableFactory.registerName,new Integer(numTables)); |
|
390 |
|
|
391 |
if (xml.getStringProperty("type").equals("otherDriverFile")) { |
|
392 |
LayerFactory.getDataSourceFactory().addFileDataSource( |
|
393 |
xml.getStringProperty("driverName"), |
|
394 |
xml.getStringProperty("gdbmsname"), |
|
395 |
xml.getStringProperty("file")); |
|
396 |
|
|
397 |
setSelectableDataSource03(xml); |
|
398 |
} else if (xml.getStringProperty("type").equals("sameDriverFile")) { |
|
399 |
String layerName = xml.getStringProperty("layerName"); |
|
400 |
|
|
401 |
ProjectView vista =(ProjectView) project.getProjectDocumentByName(xml |
|
402 |
.getStringProperty("viewName"), ProjectViewFactory.registerName); |
|
403 |
FLayer layer = vista.getMapContext().getLayers() |
|
404 |
.getLayer(layerName); |
|
405 |
|
|
406 |
setTheModel((VectorialEditableAdapter) ((FLyrVect) layer).getSource()); |
|
407 |
associatedTable = (AlphanumericData) layer; |
|
408 |
|
|
409 |
LayerFactory.getDataSourceFactory().addDataSource( |
|
410 |
(ObjectDriver) ((SingleLayer) layer).getSource() |
|
411 |
.getDriver(), xml.getStringProperty("gdbmsname")); |
|
412 |
} else if (xml.getStringProperty("type").equals("db")) { |
|
413 |
LayerFactory.getDataSourceFactory().addDBDataSourceByTable( |
|
414 |
xml.getStringProperty("gdbmsname"), |
|
415 |
xml.getStringProperty("host"), xml.getIntProperty("port"), |
|
416 |
xml.getStringProperty("user"), |
|
417 |
xml.getStringProperty("password"), |
|
418 |
xml.getStringProperty("dbName"), |
|
419 |
xml.getStringProperty("tableName"), |
|
420 |
xml.getStringProperty("driverInfo")); |
|
421 |
|
|
422 |
setSelectableDataSource03(xml); |
|
423 |
} |
|
424 |
|
|
425 |
setName(xml.getStringProperty("name")); |
|
426 |
} |
|
427 |
|
|
428 | 362 |
private void fillAsEmpty(){ |
429 | 363 |
this.esModel = null; |
430 | 364 |
mapping = new int[0]; |
... | ... | |
447 | 381 |
* @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity) |
448 | 382 |
*/ |
449 | 383 |
public void setXMLEntity(XMLEntity xml) throws XMLException, |
450 |
ReadDriverException, OpenException {
|
|
384 |
ReadException, OpenException { |
|
451 | 385 |
try { |
452 | 386 |
super.setXMLEntity(xml); |
453 | 387 |
backupXMLEntity = xml; |
... | ... | |
463 | 397 |
} |
464 | 398 |
try{ |
465 | 399 |
setSelectableDataSource(xml); |
466 |
} catch (ReadDriverException e){
|
|
400 |
} catch (ReadException e){ |
|
467 | 401 |
fillAsEmpty(); |
468 | 402 |
throw e; |
469 | 403 |
} |
... | ... | |
539 | 473 |
* @throws DriverException |
540 | 474 |
* DOCUMENT ME! |
541 | 475 |
*/ |
542 |
private void setSelectableDataSource03(XMLEntity xml) throws XMLException { |
|
543 |
String layerName = null; |
|
544 |
|
|
545 |
if (xml.contains("layerName")) { |
|
546 |
layerName = xml.getStringProperty("layerName"); |
|
547 |
} |
|
548 |
|
|
549 |
if (layerName == null) { |
|
550 |
DataSource dataSource; |
|
551 |
|
|
552 |
try { |
|
553 |
dataSource = LayerFactory.getDataSourceFactory() |
|
554 |
.createRandomDataSource( |
|
555 |
xml.getStringProperty("gdbmsname"), |
|
556 |
DataSourceFactory.AUTOMATIC_OPENING); |
|
557 |
|
|
558 |
SelectableDataSource sds = new SelectableDataSource(dataSource); |
|
559 |
|
|
560 |
sds.setXMLEntity03(xml.getChild(0)); |
|
561 |
EditableAdapter auxea = new EditableAdapter(); |
|
562 |
auxea.setOriginalDataSource(sds); |
|
563 |
setDataSource(auxea); |
|
564 |
} catch (NoSuchTableException e) { |
|
565 |
throw new XMLException(e); |
|
566 |
} catch (DriverLoadException e) { |
|
567 |
throw new XMLException(e); |
|
568 |
} catch (ReadDriverException e) { |
|
569 |
throw new XMLException(e); |
|
570 |
} |
|
571 |
|
|
572 |
} else { |
|
573 |
ProjectView vista = (ProjectView) project.getProjectDocumentByName(xml |
|
574 |
.getStringProperty("viewName"), ProjectViewFactory.registerName); |
|
575 |
FLayer layer = vista.getMapContext().getLayers() |
|
576 |
.getLayer(layerName); |
|
577 |
|
|
578 |
setTheModel((VectorialEditableAdapter) ((FLyrVect) layer).getSource()); |
|
579 |
associatedTable = (AlphanumericData) layer; |
|
580 |
} |
|
581 |
} |
|
582 |
|
|
583 |
/** |
|
584 |
* DOCUMENT ME! |
|
585 |
* |
|
586 |
* @param xml |
|
587 |
* DOCUMENT ME! |
|
588 |
* |
|
589 |
* @throws XMLException |
|
590 |
* DOCUMENT ME! |
|
591 |
* @throws DriverException |
|
592 |
* DOCUMENT ME! |
|
593 |
*/ |
|
594 | 476 |
private void setSelectableDataSource(XMLEntity xml) throws ReadDriverException { |
595 | 477 |
String layerName = null; |
596 | 478 |
boolean bNeedToReplace = false; |
... | ... | |
696 | 578 |
* |
697 | 579 |
* @return Returns the original. |
698 | 580 |
*/ |
699 |
public IEditableSource getOriginal() {
|
|
581 |
public FeatureStore getOriginal() {
|
|
700 | 582 |
return original; |
701 | 583 |
} |
702 | 584 |
|
... | ... | |
749 | 631 |
* listener que sean del tipo: LinkSelectionListenr |
750 | 632 |
*/ |
751 | 633 |
public void removeLinkTable() { |
752 |
linkTable = null; |
|
753 |
try { |
|
754 |
getModelo().getRecordset() |
|
755 |
.removeLinksSelectionListener(); |
|
756 |
} catch (ReadDriverException e) { |
|
757 |
e.printStackTrace(); |
|
758 |
} |
|
634 |
//TODO |
|
635 |
// linkTable = null; |
|
636 |
// try { |
|
637 |
// getModelo().getRecordset() |
|
638 |
// .removeLinksSelectionListener(); |
|
639 |
// } catch (ReadDriverException e) { |
|
640 |
// e.printStackTrace(); |
|
641 |
// } |
|
759 | 642 |
} |
760 | 643 |
|
761 | 644 |
public String[] getAliases() { |
... | ... | |
780 | 663 |
this.mapping = mapping; |
781 | 664 |
} |
782 | 665 |
|
783 |
public void setModel(IEditableSource ies) {
|
|
784 |
setTheModel(ies);
|
|
666 |
protected void setModel(FeatureStore fstore) {
|
|
667 |
setTheModel(FeatureStore);
|
|
785 | 668 |
try { |
786 | 669 |
if (mapping==null) { |
787 | 670 |
createAlias(); |
788 | 671 |
} |
789 |
} catch (ReadDriverException e) {
|
|
672 |
} catch (ReadException e) { |
|
790 | 673 |
e.printStackTrace(); |
791 | 674 |
NotificationManager.addError(e); |
792 | 675 |
} |
... | ... | |
831 | 714 |
|
832 | 715 |
} |
833 | 716 |
|
834 |
private void setTheModel(IEditableSource es) {
|
|
835 |
this.esModel = es;
|
|
717 |
private void setTheModel(FeatureStore fs) {
|
|
718 |
this.esModel = fs;
|
|
836 | 719 |
|
837 | 720 |
} |
838 | 721 |
|
839 | 722 |
public void exportToXML(XMLEntity root, Project project) throws SaveException { |
840 |
XMLEntity tableRoot = project.getExportXMLTypeRootNode(root,ProjectTableFactory.registerName); |
|
841 |
try { |
|
842 |
project.exportToXMLDataSource(root,this.getModelo().getRecordset().getName()); |
|
843 |
} catch (ReadDriverException e) { |
|
844 |
throw new SaveException(); |
|
845 |
} |
|
846 |
tableRoot.addChild(this.getXMLEntity()); |
|
723 |
//TODO |
|
724 |
// XMLEntity tableRoot = project.getExportXMLTypeRootNode(root,ProjectTableFactory.registerName); |
|
725 |
// try { |
|
726 |
// project.exportToXMLDataSource(root,this.getModelo().getRecordset().getName()); |
|
727 |
// } catch (ReadDriverException e) { |
|
728 |
// throw new SaveException(); |
|
729 |
// } |
|
730 |
// tableRoot.addChild(this.getXMLEntity()); |
|
847 | 731 |
} |
848 | 732 |
|
849 |
public void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project, boolean removeDocumentsFromRoot) throws XMLException, ReadDriverException, OpenException { |
|
850 |
XMLEntity element = typeRoot.getChild(elementIndex); |
|
851 |
this.setXMLEntity(element); |
|
852 |
if (removeDocumentsFromRoot) { |
|
853 |
typeRoot.removeChild(elementIndex); |
|
854 |
} |
|
855 |
project.addDocument(this); |
|
733 |
public void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project, boolean removeDocumentsFromRoot) throws XMLException, ReadException, OpenException { |
|
734 |
//TODO |
|
735 |
// XMLEntity element = typeRoot.getChild(elementIndex); |
|
736 |
// this.setXMLEntity(element); |
|
737 |
// if (removeDocumentsFromRoot) { |
|
738 |
// typeRoot.removeChild(elementIndex); |
|
739 |
// } |
|
740 |
// project.addDocument(this); |
|
856 | 741 |
|
857 | 742 |
} |
858 | 743 |
|
Also available in: Unified diff