I found the solution... I have to use the following code:<br> //-------------Crear el dbf----------------------<br> DbaseFileHeaderNIO myHeader = DbaseFileHeaderNIO.createDbaseHeader(fields);<br> myHeader.setNumRecords(0);<br>
DbaseFileWriterNIO dbfWrite = new DbaseFileWriterNIO(myHeader, (FileChannel) getWriteChannel(tableFile.getAbsolutePath()));<br> dbfWrite.close();<br> //------------Aņadir el dbf al proyecto-------------- <br>
ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);<br> String name = tableFile.getName();<br> LayerFactory.getDataSourceFactory().addFileDataSource("gdbms dbf driver", name, tableFile.getAbsolutePath() );<br>
DataSource dataSource = LayerFactory.getDataSourceFactory().createRandomDataSource(name, DataSourceFactory.AUTOMATIC_OPENING);<br> dataSource.setDataSourceFactory(LayerFactory.getDataSourceFactory());<br>
SelectableDataSource sds = new SelectableDataSource(dataSource);<br> EditableAdapter auxea=new EditableAdapter();<br> auxea.setOriginalDataSource(sds);<br> ProjectTable projectTable = ProjectFactory.createTable(tableName, auxea);<br>
ext.getProject().addDocument(projectTable);<br><br>I hope this could help someone else..:)<br><br><div class="gmail_quote">2011/4/21 Flavio Pompermaier <span dir="ltr"><<a href="mailto:fla83tn@gmail.com">fla83tn@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi to all,<br>I don't know if I'm doing something wrong but I have a very strange problem in table creation.<br>
I want to create an alphanumeric table (DBF) from the scratch, and the code I use for doing this is:<br>
<br> Driver driver = LayerFactory.getDM().getDriver("gdbms dbf driver");<br> dsf.createFileDataSource(driver.getName(), tableName, tableFile.getAbsolutePath(), campos, fieldTypes);<br> <br>
DataSource dataSource = dsf.createRandomDataSource(tableName, DataSourceFactory.AUTOMATIC_OPENING);<br> dataSource.setDataSourceFactory(dsf);<br> SelectableDataSource sds = new SelectableDataSource(dataSource);<br>
EditableAdapter auxea = new EditableAdapter();<br> auxea.setOriginalDataSource(sds);<br> ProjectTable projectTables = ProjectFactory.createTable(tableName, auxea);<br> ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);<br>
ext.getProject().addDocument(projectTables);<br><br>The problem is that in this way, suppose that I have a fieldType = 4 (Integer), then in the created table I found a Double (fieldType=8)!!<br>To build correctly my table I have to:<br>
<br>1 - create an empty table:<br> dsf.createFileDataSource(driver.getName(), tableName, tableFile.getAbsolutePath(), new String[0], new int[0]);<br>2 - add a FieldDescription one at a time:<br> ....... <br>
auxea.setOriginalDataSource(sds);<br> auxea.startComplexRow();<br> for (int j = 0; j < fields.length; j++) {<br> FieldDescription field = fields[j];<br> auxea.addField(field);<br>
}<br> auxea.endComplexRow("Fix table creation");<br> ProjectTable projectTables = ProjectFactory.createTable(tableName, auxea);<br> ....... <br><br>Is this a bug??<br>
<br>Best regards,<br><font color="#888888">Flavio<br>
</font></blockquote></div><br>