Revision 36613
tags/v1_12_0_Build_1402/extTableExport/.project | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>extTableExport</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
<buildCommand> |
|
9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
10 |
<arguments> |
|
11 |
</arguments> |
|
12 |
</buildCommand> |
|
13 |
</buildSpec> |
|
14 |
<natures> |
|
15 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
16 |
</natures> |
|
17 |
</projectDescription> |
|
0 | 18 |
tags/v1_12_0_Build_1402/extTableExport/config/text_tr.properties | ||
---|---|---|
1 |
#Translations for language [tr] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=D\u0131\u015fa aktar |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=Dosya zaten var, devam edeyim mi? |
|
7 |
guardar=Kaydet |
|
8 |
Tabla=Tablo |
tags/v1_12_0_Build_1402/extTableExport/config/text_ru.properties | ||
---|---|---|
1 |
#Translations for language [ru] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=\u042d\u043a\u0441\u043f\u043e\u0440\u0442 |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=\u0424\u0430\u0439\u043b \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442. \u0417\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0444\u0430\u0439\u043b? |
|
7 |
guardar=\u0421\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c |
|
8 |
Tabla=\u0422\u0430\u0431\u043b\u0438\u0446\u0430 |
tags/v1_12_0_Build_1402/extTableExport/config/text_de.properties | ||
---|---|---|
1 |
#Translations for language [de] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=Exportieren |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=Diese Datei existiert bereits. Soll sie \u00fcberschrieben werden? |
|
7 |
guardar=Speichern |
|
8 |
Tabla=Tabelle |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/config/text_sw.properties | ||
---|---|---|
1 |
#Translations for language [sw] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=Toa Nje ya Mfumo wa sasa. |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=Faili hili tayari lipo, je wataka kuendelea? |
|
7 |
guardar=Weka Akiba |
|
8 |
Tabla=Jedwali |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/config/text_el.properties | ||
---|---|---|
1 |
#Translations for language [el] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=\u0395\u03be\u03b1\u03b3\u03c9\u03b3\u03ae |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=\u03a4\u03bf \u03b1\u03c1\u03c7\u03b5\u03af\u03bf \u03c5\u03c0\u03ac\u03c1\u03c7\u03b5\u03b9 \u03ae\u03b4\u03b7, \u03b8\u03ad\u03bb\u03b5\u03c4\u03b5 \u03bd\u03b1 \u03c3\u03c5\u03bd\u03b5\u03c7\u03af\u03c3\u03b5\u03c4\u03b5; |
|
7 |
guardar=\u0391\u03c0\u03bf\u03b8\u03ae\u03ba\u03b5\u03c5\u03c3\u03b7 |
|
8 |
Tabla=\u03a0\u03af\u03bd\u03b1\u03ba\u03b1\u03c2 |
tags/v1_12_0_Build_1402/extTableExport/config/text_en.properties | ||
---|---|---|
1 |
#Translations for language [en] |
|
2 |
#Mon Sep 21 10:02:12 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=Export |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=The file already exists, do you want to continue? |
|
7 |
guardar=Save |
|
8 |
Tabla=Table |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/config/text_gl.properties | ||
---|---|---|
1 |
#Translations for language [gl] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=Exportar |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=O arquivo xa existe, \u00bfdesexa continuar? |
|
7 |
guardar=Gardar |
|
8 |
Tabla=T\u00e1boa |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/config/config.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<plugin-config> |
|
3 |
<libraries library-dir="."/> |
|
4 |
<depends plugin-name="com.iver.cit.gvsig"/> |
|
5 |
<resourceBundle name="text"/> |
|
6 |
<extensions> |
|
7 |
<extension class-name="org.gvsig.tableExport.xls.ExportTableToExcelExtension" |
|
8 |
description="Export a table to excel file." |
|
9 |
active="true" |
|
10 |
priority="30"> |
|
11 |
<menu text="Tabla/export/Excel" |
|
12 |
position="11500"/> |
|
13 |
</extension> |
|
14 |
<extension class-name="org.gvsig.tableExport.ExportTableToFileExtension" |
|
15 |
description="Export table to a file" |
|
16 |
active="true" |
|
17 |
priority="30"> |
|
18 |
<menu text="Tabla/export/DBF" |
|
19 |
position="11505" action-command="gdbms dbf driver|dbf|dbf file"/> |
|
20 |
</extension> |
|
21 |
</extensions> |
|
22 |
</plugin-config> |
|
0 | 23 |
tags/v1_12_0_Build_1402/extTableExport/config/text_cs.properties | ||
---|---|---|
1 |
#Translations for language [cs] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=Exportovat |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=Soubor u\u017e existuje, chcete pokra\u010dovat? |
|
7 |
guardar=Ulo\u017eit |
|
8 |
Tabla=Tabulka |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/config/text_pt_BR.properties | ||
---|---|---|
1 |
#Translations for language [pt_BR] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=Exportar |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=O arquivo ja existe. Deseja continuar? |
|
7 |
guardar=Salvar |
|
8 |
Tabla=Tabela |
tags/v1_12_0_Build_1402/extTableExport/config/text_fr.properties | ||
---|---|---|
1 |
#Translations for language [fr] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=Exporter |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=Le fichier existe d\u00e9j\u00e0, \u00eates-vous s\u00fbr de vouloir continuer ? |
|
7 |
guardar=Enregistrer |
|
8 |
Tabla=Table |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/config/text_nl.properties | ||
---|---|---|
1 |
#Translations for language [nl] |
|
2 |
#Tue Aug 11 10:49:15 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export= |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo= |
|
7 |
guardar= |
|
8 |
Tabla= |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/config/text_eu.properties | ||
---|---|---|
1 |
#Translations for language [eu] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=Esportatu |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=Fitxategia lehendik ere badago, jarraitu nahi duzu? |
|
7 |
guardar=Gorde |
|
8 |
Tabla=Taula |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/config/text_en_US.properties | ||
---|---|---|
1 |
#Translations for language [en_US] |
|
2 |
#Mon Sep 21 10:02:12 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=Export to |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=The file already exists. Do you want to continue? |
|
7 |
guardar=Save |
|
8 |
Tabla=Table |
tags/v1_12_0_Build_1402/extTableExport/config/text_pl.properties | ||
---|---|---|
1 |
#Translations for language [pl] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export= |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=Plik ju\u017c istnieje, czy chcesz kontynuowac? |
|
7 |
guardar=Zapisz |
|
8 |
Tabla= |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/config/text_it.properties | ||
---|---|---|
1 |
#Translations for language [it] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=Esporta |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=Il file esiste gi\u00e0, continuare? |
|
7 |
guardar=Salva |
|
8 |
Tabla=Tabella |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/config/text_ro.properties | ||
---|---|---|
1 |
#Translations for language [ro] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=Export\u0103 |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=Fi\u015fier deja existent. Dori\u0163i s\u0103 continua\u0163i? |
|
7 |
guardar=Salveaz\u0103 |
|
8 |
Tabla=Tabel |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/config/text.properties | ||
---|---|---|
1 |
#Translations for language [es] |
|
2 |
#Mon Sep 21 10:02:12 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=Exportar |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=El fichero ya existe, \u00bfdesea continuar? |
|
7 |
guardar=Guardar |
|
8 |
Tabla=Tabla |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/config/text_zh.properties | ||
---|---|---|
1 |
#Translations for language [zh] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=\u8f93\u51fa |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=\u6587\u4ef6\u5df2\u5b58\u5728\uff0c\u60a8\u8981\u7ee7\u7eed\u5417? |
|
7 |
guardar=\u5b58\u76d8 |
|
8 |
Tabla=\u8868\u683c |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/config/text_ca.properties | ||
---|---|---|
1 |
#Translations for language [ca] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=Exportar |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=El fitxer ja existix, voleu continuar? |
|
7 |
guardar=Guardar |
|
8 |
Tabla=Taula |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/config/text_pt.properties | ||
---|---|---|
1 |
#Translations for language [pt] |
|
2 |
#Mon Sep 21 10:02:13 CEST 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=Exportar |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=O ficheiro j\u00e1 existe, deseja continuar? |
|
7 |
guardar=Guardar |
|
8 |
Tabla=Tabela |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/config/text_sr.properties | ||
---|---|---|
1 |
#Translations for language [sr] |
|
2 |
#Mon Nov 02 08:36:03 CET 2009 |
|
3 |
DBF= |
|
4 |
Excel= |
|
5 |
export=Eksportovanje |
|
6 |
fichero_ya_existe_seguro_desea_guardarlo=Datoteka ve\u0107 postoji. \u017delite li da nastavite? |
|
7 |
guardar=Sa\u010duvaj |
|
8 |
Tabla=Tabela |
|
0 | 9 |
tags/v1_12_0_Build_1402/extTableExport/package.info | ||
---|---|---|
1 |
|
|
2 |
state=devel |
|
3 |
name=org.gvsig.tableExport |
|
4 |
official=true |
|
5 |
code=org.gvsig.tableExport |
|
6 |
operating-system=all |
|
7 |
architecture=all |
|
8 |
java-version=j1_5 |
|
9 |
gvSIG-version=1.12.0 |
|
10 |
version=1.12.0 |
|
11 |
type=plugin |
|
12 |
description=gvSIG basic extensions |
|
13 |
build=1402 |
|
14 |
buildNumber=1402 |
|
15 |
model-version=1.0.0 |
|
16 |
|
tags/v1_12_0_Build_1402/extTableExport/build.number | ||
---|---|---|
1 |
#Build Number for ANT. Do not edit! |
|
2 |
#Wed Sep 21 10:36:11 CEST 2011 |
|
3 |
build.number=1475 |
tags/v1_12_0_Build_1402/extTableExport/src/org/gvsig/tableExport/xls/ExportTableToExcelExtension.java | ||
---|---|---|
1 |
package org.gvsig.tableExport.xls; |
|
2 |
|
|
3 |
|
|
4 |
import java.awt.Component; |
|
5 |
import java.io.File; |
|
6 |
import java.util.Iterator; |
|
7 |
import java.util.NoSuchElementException; |
|
8 |
|
|
9 |
import javax.swing.JFileChooser; |
|
10 |
import javax.swing.JOptionPane; |
|
11 |
|
|
12 |
import jxl.JXLException; |
|
13 |
import jxl.Workbook; |
|
14 |
import jxl.write.Label; |
|
15 |
import jxl.write.Number; |
|
16 |
import jxl.write.NumberFormats; |
|
17 |
import jxl.write.WritableCell; |
|
18 |
import jxl.write.WritableCellFormat; |
|
19 |
import jxl.write.WritableSheet; |
|
20 |
import jxl.write.WritableWorkbook; |
|
21 |
|
|
22 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
23 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
|
24 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
|
25 |
import com.hardcode.gdbms.engine.values.FloatValue; |
|
26 |
import com.hardcode.gdbms.engine.values.NullValue; |
|
27 |
import com.hardcode.gdbms.engine.values.NumericValue; |
|
28 |
import com.hardcode.gdbms.engine.values.Value; |
|
29 |
import com.iver.andami.PluginServices; |
|
30 |
import com.iver.andami.messages.NotificationManager; |
|
31 |
import com.iver.andami.plugins.Extension; |
|
32 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
33 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
|
34 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
|
35 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
|
36 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
|
37 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
|
38 |
import com.iver.utiles.GenericFileFilter; |
|
39 |
|
|
40 |
public class ExportTableToExcelExtension extends Extension { |
|
41 |
|
|
42 |
private WritableCellFormat floatFormat = new WritableCellFormat (NumberFormats.FLOAT); |
|
43 |
private WritableCellFormat intFormat = new WritableCellFormat (NumberFormats.INTEGER); |
|
44 |
/** |
|
45 |
* @see com.iver.andami.plugins.IExtension#initialize() |
|
46 |
*/ |
|
47 |
public void initialize() { |
|
48 |
} |
|
49 |
|
|
50 |
/** |
|
51 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String) |
|
52 |
*/ |
|
53 |
public void execute(String actionCommand) { |
|
54 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
|
55 |
Table table = (Table) v; |
|
56 |
try { |
|
57 |
exportToXLS(table); |
|
58 |
} catch (Exception e) { |
|
59 |
NotificationManager.showMessageError("error_en_el_proceso", e); |
|
60 |
} |
|
61 |
|
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* DOCUMENT ME! |
|
66 |
*/ |
|
67 |
public void exportToXLS(Table table) throws Exception{ |
|
68 |
File file = this.askForFileName("xls","Excel"); |
|
69 |
if (file == null){ |
|
70 |
return; |
|
71 |
} |
|
72 |
exportToFile(table,file); |
|
73 |
} |
|
74 |
|
|
75 |
public void exportToFile(Table table,File trgfile) throws Exception{ |
|
76 |
SelectableDataSource source; |
|
77 |
ITableDefinition orgDef; |
|
78 |
try { |
|
79 |
source = table.getModel().getModelo().getRecordset(); |
|
80 |
source.start(); |
|
81 |
orgDef = table.getModel().getModelo().getTableDefinition(); |
|
82 |
} catch (Exception e) { |
|
83 |
throw new Exception("Error preparando la fuente", e); // TODO intenacionalizacion?? |
|
84 |
} |
|
85 |
|
|
86 |
|
|
87 |
File file = new File(trgfile.getAbsoluteFile()+".tmp"); |
|
88 |
|
|
89 |
WritableWorkbook workbook = Workbook.createWorkbook(file); |
|
90 |
WritableSheet sheet = workbook.createSheet("First Sheet", 0); |
|
91 |
|
|
92 |
writeHeader(sheet,orgDef); |
|
93 |
|
|
94 |
|
|
95 |
try { |
|
96 |
SourceIterator iter = new SourceIterator(source); |
|
97 |
Value[] values; |
|
98 |
Value value; |
|
99 |
int row=1; |
|
100 |
int col; |
|
101 |
while (iter.hasNext()){ |
|
102 |
values = iter.nextValues(); |
|
103 |
for (col=0;col<values.length;col++){ |
|
104 |
value = values[col]; |
|
105 |
if (!(value instanceof NullValue)){ |
|
106 |
sheet.addCell(getCell(row,col,value)); |
|
107 |
} |
|
108 |
} |
|
109 |
row++; |
|
110 |
|
|
111 |
} |
|
112 |
|
|
113 |
workbook.write(); |
|
114 |
|
|
115 |
workbook.close(); |
|
116 |
|
|
117 |
} catch (Exception e) { |
|
118 |
throw new Exception("Error generando fichero", e); // TODO intenacionalizacion?? |
|
119 |
|
|
120 |
} |
|
121 |
|
|
122 |
file.renameTo(trgfile); |
|
123 |
|
|
124 |
try { |
|
125 |
source.stop(); |
|
126 |
|
|
127 |
} catch (Exception e) { |
|
128 |
throw new Exception("Error cerrando ficheros", e); // TODO intenacionalizacion?? |
|
129 |
} |
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
} |
|
134 |
|
|
135 |
private WritableCell getCell(int row, int col, Value value) { |
|
136 |
if (value instanceof NumericValue){ |
|
137 |
if (value instanceof DoubleValue || value instanceof FloatValue){ |
|
138 |
return new Number(col,row,((NumericValue)value).doubleValue(),floatFormat); |
|
139 |
} else { |
|
140 |
return new Number(col,row,((NumericValue)value).longValue(),intFormat); |
|
141 |
} |
|
142 |
} else{ |
|
143 |
return new Label(col,row,value.toString()); |
|
144 |
} |
|
145 |
|
|
146 |
} |
|
147 |
|
|
148 |
private void writeHeader(WritableSheet sheet, ITableDefinition orgDef) throws JXLException { |
|
149 |
FieldDescription[] fields = orgDef.getFieldsDesc(); |
|
150 |
FieldDescription field; |
|
151 |
Label cell; |
|
152 |
int col; |
|
153 |
for (col=0;col<fields.length;col++){ |
|
154 |
field = fields[col]; |
|
155 |
cell=new Label(col,0,field.getFieldName()); |
|
156 |
sheet.addCell(cell); |
|
157 |
} |
|
158 |
} |
|
159 |
|
|
160 |
private File askForFileName(String ext,String extDescription){ |
|
161 |
JFileChooser jfc = new JFileChooser(); |
|
162 |
jfc.addChoosableFileFilter(new GenericFileFilter(ext, |
|
163 |
extDescription)); |
|
164 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
|
165 |
File file=jfc.getSelectedFile(); |
|
166 |
if (file == null){ |
|
167 |
return null; |
|
168 |
} |
|
169 |
if (file.exists()){ |
|
170 |
int resp = JOptionPane.showConfirmDialog( |
|
171 |
(Component) PluginServices.getMainFrame(),PluginServices.getText(this,"fichero_ya_existe_seguro_desea_guardarlo"), |
|
172 |
PluginServices.getText(this,"guardar"), JOptionPane.YES_NO_OPTION); |
|
173 |
if (resp != JOptionPane.YES_OPTION) { |
|
174 |
return null; |
|
175 |
} |
|
176 |
} |
|
177 |
String name = file.getAbsolutePath(); |
|
178 |
if (!name.toLowerCase().endsWith("." +ext.toLowerCase())){ |
|
179 |
file = new File(name + "."+ext); |
|
180 |
} |
|
181 |
return file; |
|
182 |
} else{ |
|
183 |
return null; |
|
184 |
} |
|
185 |
|
|
186 |
} |
|
187 |
|
|
188 |
|
|
189 |
/** |
|
190 |
* @see com.iver.andami.plugins.IExtension#isEnabled() |
|
191 |
*/ |
|
192 |
public boolean isEnabled() { |
|
193 |
return true; |
|
194 |
} |
|
195 |
|
|
196 |
/** |
|
197 |
* @see com.iver.andami.plugins.IExtension#isVisible() |
|
198 |
*/ |
|
199 |
public boolean isVisible() { |
|
200 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
|
201 |
|
|
202 |
if (v == null) { |
|
203 |
return false; |
|
204 |
} else if (v instanceof Table) { |
|
205 |
return true; |
|
206 |
} else { |
|
207 |
return false; |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
private class SourceIterator implements Iterator{ |
|
212 |
private int index; |
|
213 |
private long count; |
|
214 |
private FBitSet selection = null; |
|
215 |
private SelectableDataSource source; |
|
216 |
|
|
217 |
public SourceIterator(SelectableDataSource source) throws DriverException, ReadDriverException{ |
|
218 |
this.source = source; |
|
219 |
if (source.getSelection().cardinality()== 0){ |
|
220 |
this.selection = null; |
|
221 |
this.index=0; |
|
222 |
this.count = source.getRowCount(); |
|
223 |
} else{ |
|
224 |
this.selection = source.getSelection(); |
|
225 |
this.index=selection.nextSetBit(0); |
|
226 |
this.count = selection.cardinality(); |
|
227 |
} |
|
228 |
|
|
229 |
} |
|
230 |
|
|
231 |
public void remove() { |
|
232 |
throw new UnsupportedOperationException(); |
|
233 |
} |
|
234 |
|
|
235 |
public boolean hasNext() { |
|
236 |
if (this.selection == null) |
|
237 |
return this.index < this.count; |
|
238 |
return this.index >= 0; |
|
239 |
} |
|
240 |
|
|
241 |
public Object next() { |
|
242 |
try { |
|
243 |
if (!hasNext()){ |
|
244 |
throw new NoSuchElementException(); |
|
245 |
} |
|
246 |
return this.nextValues(); |
|
247 |
} catch (DriverException e) { |
|
248 |
throw new RuntimeException(e); |
|
249 |
} catch (ReadDriverException e) { |
|
250 |
throw new RuntimeException(e); |
|
251 |
} |
|
252 |
} |
|
253 |
|
|
254 |
public Value[] nextValues() throws DriverException, ReadDriverException { |
|
255 |
|
|
256 |
Value[] values = this.source.getRow(this.index); |
|
257 |
if (this.selection == null){ |
|
258 |
this.index++; |
|
259 |
} else { |
|
260 |
this.index = this.selection.nextSetBit(this.index + 1); |
|
261 |
} |
|
262 |
return values; |
|
263 |
|
|
264 |
} |
|
265 |
|
|
266 |
public long count(){ |
|
267 |
return this.count; |
|
268 |
} |
|
269 |
|
|
270 |
} |
|
271 |
|
|
272 |
} |
|
0 | 273 |
tags/v1_12_0_Build_1402/extTableExport/src/org/gvsig/tableExport/ExportTableToFileExtension.java | ||
---|---|---|
1 |
package org.gvsig.tableExport; |
|
2 |
|
|
3 |
|
|
4 |
import java.awt.Component; |
|
5 |
import java.io.File; |
|
6 |
import java.io.IOException; |
|
7 |
import java.sql.Types; |
|
8 |
import java.util.Iterator; |
|
9 |
|
|
10 |
import javax.swing.JFileChooser; |
|
11 |
import javax.swing.JOptionPane; |
|
12 |
|
|
13 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
14 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
|
15 |
import com.hardcode.gdbms.engine.data.driver.FileDriver; |
|
16 |
import com.hardcode.gdbms.engine.values.Value; |
|
17 |
import com.iver.andami.PluginServices; |
|
18 |
import com.iver.andami.messages.NotificationManager; |
|
19 |
import com.iver.andami.plugins.Extension; |
|
20 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
21 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
|
22 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
|
23 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
|
24 |
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
|
25 |
import com.iver.cit.gvsig.fmap.edition.IWriteable; |
|
26 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
|
27 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
|
28 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
|
29 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
|
30 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
|
31 |
import com.iver.utiles.GenericFileFilter; |
|
32 |
|
|
33 |
|
|
34 |
/** |
|
35 |
* Extensi?n que permite exportar una tabla a cualquier |
|
36 |
* driver de fichero que soporte escritura. |
|
37 |
* |
|
38 |
* @author jmvivo |
|
39 |
*/ |
|
40 |
public class ExportTableToFileExtension extends Extension { |
|
41 |
/** |
|
42 |
* @see com.iver.andami.plugins.IExtension#initialize() |
|
43 |
*/ |
|
44 |
public void initialize() { |
|
45 |
} |
|
46 |
|
|
47 |
/** |
|
48 |
* @param actionCommand Debe de estar compuesto por tres par?mentros |
|
49 |
* separados por '|' d?nde el primero es el nombre |
|
50 |
* del driver, el segundo la extensi?n de los ficheros |
|
51 |
* y el tercero el nombre del tipo. Ejemplo:<br> |
|
52 |
* "gdbms dbf driver|dbf|dbf file" |
|
53 |
* |
|
54 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String) |
|
55 |
*/ |
|
56 |
public void execute(String actionCommand) { |
|
57 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
|
58 |
Table table = (Table) v; |
|
59 |
|
|
60 |
String[] params=actionCommand.split("[|]"); |
|
61 |
|
|
62 |
if (params.length != 3){ |
|
63 |
NotificationManager.showMessageError("Parametros no validos: "+actionCommand, null); |
|
64 |
return; |
|
65 |
|
|
66 |
} |
|
67 |
|
|
68 |
|
|
69 |
try { |
|
70 |
exportToFile(table,params[0],params[1],params[2]); |
|
71 |
} catch (Exception e) { |
|
72 |
NotificationManager.showMessageError("error_en_el_proceso", e); |
|
73 |
} |
|
74 |
|
|
75 |
} |
|
76 |
|
|
77 |
public void exportToFile(Table table, String driverName,String fileExtension,String fileDescription) throws Exception{ |
|
78 |
FileDriver driver = (FileDriver)LayerFactory.getDM().getDriver(driverName); |
|
79 |
if (driver == null){ |
|
80 |
throw new Exception("Driver '"+driverName+"' Not Found"); |
|
81 |
} |
|
82 |
File file = this.askForFileName(fileExtension,fileDescription); |
|
83 |
if (file == null){ |
|
84 |
return; |
|
85 |
} |
|
86 |
exportToFile(table,driver,file); |
|
87 |
} |
|
88 |
|
|
89 |
public void exportToFile(Table table, FileDriver driver,String fileExtension,String fileDescription) throws Exception{ |
|
90 |
File file = this.askForFileName(fileExtension,fileDescription); |
|
91 |
exportToFile(table,driver,file); |
|
92 |
} |
|
93 |
|
|
94 |
public void exportToFile(Table table, FileDriver driver,File file) throws Exception{ |
|
95 |
SelectableDataSource source; |
|
96 |
ITableDefinition orgDef; |
|
97 |
try { |
|
98 |
source = table.getModel().getModelo().getRecordset(); |
|
99 |
source.start(); |
|
100 |
orgDef = table.getModel().getModelo().getTableDefinition(); |
|
101 |
} catch (Exception e) { |
|
102 |
throw new Exception("Error preparando la fuente", e); // TODO intenacionalizacion?? |
|
103 |
} |
|
104 |
|
|
105 |
|
|
106 |
try { |
|
107 |
if (!file.exists()){ |
|
108 |
|
|
109 |
//Builds a valid empty dbf file. We need it for call to the method Driver.open |
|
110 |
driver.createSource(file.getAbsolutePath(),new String[] {"0"},new int[] {Types.INTEGER} ); |
|
111 |
file.createNewFile(); |
|
112 |
|
|
113 |
} |
|
114 |
|
|
115 |
driver.open(file); |
|
116 |
} catch (IOException e) { |
|
117 |
throw new Exception("Error preparando el fichero destino", e); // TODO intenacionalizacion?? |
|
118 |
} |
|
119 |
|
|
120 |
IWriter writer = ((IWriteable)driver).getWriter(); |
|
121 |
try { |
|
122 |
writer.initialize(orgDef); |
|
123 |
writer.preProcess(); |
|
124 |
SourceIterator iter = new SourceIterator(source); |
|
125 |
IFeature feature; |
|
126 |
int i=0; |
|
127 |
while (iter.hasNext()){ |
|
128 |
feature = iter.nextFeature(); |
|
129 |
|
|
130 |
DefaultRowEdited edRow = new DefaultRowEdited(feature, |
|
131 |
DefaultRowEdited.STATUS_ADDED, i); |
|
132 |
writer.process(edRow); |
|
133 |
i++; |
|
134 |
|
|
135 |
} |
|
136 |
writer.postProcess(); |
|
137 |
|
|
138 |
|
|
139 |
} catch (Exception e) { |
|
140 |
throw new Exception("Error generando fichero", e); // TODO intenacionalizacion?? |
|
141 |
|
|
142 |
} |
|
143 |
|
|
144 |
try { |
|
145 |
source.stop(); |
|
146 |
driver.close(); |
|
147 |
} catch (Exception e) { |
|
148 |
throw new Exception("Error cerrando ficheros", e); // TODO intenacionalizacion?? |
|
149 |
} |
|
150 |
|
|
151 |
|
|
152 |
} |
|
153 |
|
|
154 |
private File askForFileName(String ext,String extDescription){ |
|
155 |
JFileChooser jfc = new JFileChooser(); |
|
156 |
jfc.addChoosableFileFilter(new GenericFileFilter(ext, |
|
157 |
extDescription)); |
|
158 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
|
159 |
File file=jfc.getSelectedFile(); |
|
160 |
if (file==null){ |
|
161 |
return null; |
|
162 |
} |
|
163 |
if (file.exists()){ |
|
164 |
int resp = JOptionPane.showConfirmDialog( |
|
165 |
(Component) PluginServices.getMainFrame(),PluginServices.getText(this,"fichero_ya_existe_seguro_desea_guardarlo"), |
|
166 |
PluginServices.getText(this,"guardar"), JOptionPane.YES_NO_OPTION); |
|
167 |
if (resp != JOptionPane.YES_OPTION) { |
|
168 |
return null; |
|
169 |
} |
|
170 |
} |
|
171 |
String name = file.getAbsolutePath(); |
|
172 |
if (!name.toLowerCase().endsWith("." +ext.toLowerCase())){ |
|
173 |
file = new File(name + "."+ext); |
|
174 |
} |
|
175 |
return file; |
|
176 |
} else{ |
|
177 |
return null; |
|
178 |
} |
|
179 |
|
|
180 |
} |
|
181 |
|
|
182 |
|
|
183 |
/** |
|
184 |
* @see com.iver.andami.plugins.IExtension#isEnabled() |
|
185 |
*/ |
|
186 |
public boolean isEnabled() { |
|
187 |
return true; |
|
188 |
} |
|
189 |
|
|
190 |
/** |
|
191 |
* @see com.iver.andami.plugins.IExtension#isVisible() |
|
192 |
*/ |
|
193 |
public boolean isVisible() { |
|
194 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
|
195 |
|
|
196 |
if (v == null) { |
|
197 |
return false; |
|
198 |
} else if (v instanceof Table) { |
|
199 |
return true; |
|
200 |
} else { |
|
201 |
return false; |
|
202 |
} |
|
203 |
} |
|
204 |
|
|
205 |
private class SourceIterator implements Iterator{ |
|
206 |
private int index; |
|
207 |
private long count; |
|
208 |
private FBitSet selection = null; |
|
209 |
private SelectableDataSource source; |
|
210 |
|
|
211 |
public SourceIterator(SelectableDataSource source) throws DriverException, ReadDriverException{ |
|
212 |
this.source = source; |
|
213 |
if (source.getSelection().cardinality()== 0){ |
|
214 |
this.selection = null; |
|
215 |
this.index=0; |
|
216 |
this.count = source.getRowCount(); |
|
217 |
} else{ |
|
218 |
this.selection = source.getSelection(); |
|
219 |
this.index=selection.nextSetBit(0); |
|
220 |
this.count = selection.cardinality(); |
|
221 |
} |
|
222 |
|
|
223 |
} |
|
224 |
|
|
225 |
public void remove() { |
|
226 |
throw new UnsupportedOperationException(); |
|
227 |
} |
|
228 |
|
|
229 |
public boolean hasNext() { |
|
230 |
if (this.selection == null) |
|
231 |
return this.index < this.count; |
|
232 |
return this.index >= 0; |
|
233 |
} |
|
234 |
|
|
235 |
public Object next() { |
|
236 |
try { |
|
237 |
return this.nextFeature(); |
|
238 |
} catch (DriverException e) { |
|
239 |
throw new RuntimeException(e); |
|
240 |
} catch (ReadDriverException e) { |
|
241 |
throw new RuntimeException(e); |
|
242 |
} |
|
243 |
} |
|
244 |
|
|
245 |
public IFeature nextFeature() throws DriverException, ReadDriverException { |
|
246 |
|
|
247 |
Value[] values = this.source.getRow(this.index); |
|
248 |
IFeature feat = new DefaultFeature(null, values, "" + this.index); |
|
249 |
if (this.selection == null){ |
|
250 |
this.index++; |
|
251 |
} else { |
|
252 |
this.index = this.selection.nextSetBit(this.index + 1); |
|
253 |
} |
|
254 |
return feat; |
|
255 |
|
|
256 |
} |
|
257 |
|
|
258 |
public long count(){ |
|
259 |
return this.count; |
|
260 |
} |
|
261 |
|
|
262 |
} |
|
263 |
} |
|
0 | 264 |
tags/v1_12_0_Build_1402/extTableExport/.settings/org.eclipse.jdt.core.prefs | ||
---|---|---|
1 |
#Tue May 20 09:22:19 CEST 2008 |
|
2 |
eclipse.preferences.version=1 |
|
3 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
4 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 |
|
5 |
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve |
|
6 |
org.eclipse.jdt.core.compiler.compliance=1.5 |
|
7 |
org.eclipse.jdt.core.compiler.debug.lineNumber=generate |
|
8 |
org.eclipse.jdt.core.compiler.debug.localVariable=generate |
|
9 |
org.eclipse.jdt.core.compiler.debug.sourceFile=generate |
|
10 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
|
11 |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
|
12 |
org.eclipse.jdt.core.compiler.source=1.5 |
|
0 | 13 |
tags/v1_12_0_Build_1402/extTableExport/build.xml | ||
---|---|---|
1 |
<project name="extTableExport" default="dist" basedir="."> |
|
2 |
<description> |
|
3 |
Instala el plugin |
|
4 |
</description> |
|
5 |
<!-- set global properties for this build --> |
|
6 |
<import file="../binaries/ant/utilities.xml"/> |
|
7 |
<property name="src" location="src"/> |
|
8 |
<property name="src-test" location="src-test"/> |
|
9 |
<property name="lib" location="../_fwAndami/lib"/> |
|
10 |
<property name="build" location="bin"/> |
|
11 |
<property name="build-test" location="bin-test"/> |
|
12 |
<property name="dist" location="dist"/> |
|
13 |
<property name="plugin" value="org.gvsig.tableExport"/> |
|
14 |
<property name="targetDir" location="../_fwAndami/gvSIG/extensiones"/> |
|
15 |
|
|
16 |
|
|
17 |
<target name="init"> |
|
18 |
<!-- Create the time stamp --> |
|
19 |
<tstamp/> |
|
20 |
<echo> |
|
21 |
Compiling ${ant.project.name}...</echo> |
|
22 |
<!-- create the build.number file --> |
|
23 |
<buildnumber/> |
|
24 |
<!-- Create the build directory structure used by compile --> |
|
25 |
<mkdir dir="${build}"/> |
|
26 |
</target> |
|
27 |
|
|
28 |
<target name="dist" description="generate the distribution" |
|
29 |
depends="create-jar,copy-libs,copy-data-files,move-to-andami" /> |
|
30 |
|
|
31 |
<target name="batch-build" |
|
32 |
description="compile the sources, create the jar file" |
|
33 |
depends="init,compile,create-jar,copy-libs,copy-data-files,move-to-andami"> |
|
34 |
</target> |
|
35 |
|
|
36 |
<target name="compile" description="compile the source" > |
|
37 |
<!-- Compile the Java code from ${src} to ${build} --> |
|
38 |
<mkdir dir="${build}" /> |
|
39 |
<loadEclipseClasspath project="${basedir}"/> |
|
40 |
<gvSIG-javac |
|
41 |
classpath="${eclipseClasspath}" |
|
42 |
/> |
|
43 |
</target> |
|
44 |
|
|
45 |
<target name="copy-libs"> |
|
46 |
<copy todir="${dist}"> |
|
47 |
<fileset dir="lib" includes="*.jar"/> |
|
48 |
</copy> |
|
49 |
</target> |
|
50 |
|
|
51 |
<target name="copy-data-files" depends="make-package-info"> |
|
52 |
<copy file="config/config.xml" todir="${dist}"/> |
|
53 |
<copy file="build.number" todir="${dist}"/> |
|
54 |
<!-- <copy file="config/about.htm" todir="${dist}" overwrite="yes"/> |
|
55 |
<loadproperties srcFile="build.number"/> |
|
56 |
<replace casesensitive="true" |
|
57 |
file="${dist}/about.htm" |
|
58 |
token="#build.number#" |
|
59 |
value="${build.number}"> |
|
60 |
</replace>--> |
|
61 |
<copy file="package.info" todir="${dist}"/> |
|
62 |
<copy todir="${dist}"> |
|
63 |
<fileset dir="config" includes="text*.properties"/> |
|
64 |
</copy> |
|
65 |
<copy todir="${dist}/images"> |
|
66 |
<fileset dir="images/" includes="*"/> |
|
67 |
</copy> |
|
68 |
<copy todir="${dist}"> |
|
69 |
<fileset dir="." includes="*.jar"/> |
|
70 |
</copy> |
|
71 |
</target> |
|
72 |
|
|
73 |
<target name="move-to-andami" description="Moves the build directory to andami"> |
|
74 |
<move todir="${targetDir}/${plugin}/"> |
|
75 |
<fileset dir="${dist}" includes="**/**"/> |
|
76 |
</move> |
|
77 |
</target> |
|
78 |
|
|
79 |
<target name="create-jar" description="Crea el jar de la aplicacion"> |
|
80 |
<mkdir dir="${dist}"/> |
|
81 |
<jar jarfile="${dist}/${plugin}.jar" basedir="${build}"/> |
|
82 |
</target> |
|
83 |
|
|
84 |
<target name="clean" description="clean up" > |
|
85 |
<!-- Delete the ${build} and ${dist} directory trees --> |
|
86 |
<delete dir="${build}"/> |
|
87 |
<delete dir="${dist}"/> |
|
88 |
</target> |
|
89 |
|
|
90 |
<target name="run-tests" depends="batch-build,compile-tests"> |
|
91 |
<antcall target="generic-run-tests"> |
|
92 |
<param name="TestSuite.Name" value="com.iver.core.AllTests"/> |
|
93 |
</antcall> |
|
94 |
</target> |
|
95 |
</project> |
|
96 |
|
|
0 | 97 |
tags/v1_12_0_Build_1402/extTableExport/.classpath | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<classpath> |
|
3 |
<classpathentry kind="src" path="src"/> |
|
4 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
|
5 |
<classpathentry combineaccessrules="false" kind="src" path="/_fwAndami"/> |
|
6 |
<classpathentry combineaccessrules="false" kind="src" path="/appgvSIG"/> |
|
7 |
<classpathentry combineaccessrules="false" kind="src" path="/libFMap"/> |
|
8 |
<classpathentry combineaccessrules="false" kind="src" path="/libGDBMS"/> |
|
9 |
<classpathentry kind="lib" path="/_fwAndami/lib/iver-utiles.jar" sourcepath="/libIverUtiles"/> |
|
10 |
<classpathentry kind="lib" path="/_fwAndami/lib/org.gvsig.exceptions.jar" sourcepath="/libExceptions/src"/> |
|
11 |
<classpathentry kind="lib" path="/libFMap/lib/driver-manager-1.1.jar" sourcepath="/libDriverManager"/> |
|
12 |
<classpathentry kind="lib" path="lib/jxl-2.6.6.jar"/> |
|
13 |
<classpathentry kind="output" path="bin"/> |
|
14 |
</classpath> |
|
0 | 15 |
Also available in: Unified diff