svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.exportto.app / org.gvsig.exportto.app.mainplugin / src / main / java / org / gvsig / export / app / extension / ExportTable.java @ 45627
History | View | Annotate | Download (5.51 KB)
1 |
package org.gvsig.export.app.extension; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import javax.swing.JComponent; |
5 |
import javax.swing.JOptionPane; |
6 |
import org.gvsig.app.ApplicationLocator; |
7 |
import org.gvsig.app.ApplicationManager; |
8 |
import org.gvsig.app.project.Project; |
9 |
import org.gvsig.app.project.ProjectManager; |
10 |
import org.gvsig.app.project.documents.table.TableDocument; |
11 |
import org.gvsig.app.project.documents.table.TableManager; |
12 |
import org.gvsig.export.ExportLocator; |
13 |
import org.gvsig.export.ExportManager; |
14 |
import org.gvsig.export.ExportProcess; |
15 |
import org.gvsig.export.Filter; |
16 |
import org.gvsig.export.spi.ExportServiceFactory; |
17 |
import org.gvsig.export.swing.ExportFinishListenerAdapter; |
18 |
import org.gvsig.export.swing.ExportSwingLocator; |
19 |
import org.gvsig.export.swing.ExportSwingManager; |
20 |
import org.gvsig.export.swing.JExportProcessPanel; |
21 |
import org.gvsig.expressionevaluator.Expression; |
22 |
import org.gvsig.fmap.dal.DALLocator; |
23 |
import org.gvsig.fmap.dal.DataManager; |
24 |
import org.gvsig.fmap.dal.OpenDataStoreParameters; |
25 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
26 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
27 |
import org.gvsig.tools.ToolsLocator; |
28 |
import org.gvsig.tools.i18n.I18nManager; |
29 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
30 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
31 |
import org.slf4j.Logger; |
32 |
import org.slf4j.LoggerFactory; |
33 |
|
34 |
/**
|
35 |
*
|
36 |
* @author jjdelcerro
|
37 |
*/
|
38 |
@SuppressWarnings("UseSpecificCatch") |
39 |
public class ExportTable { |
40 |
|
41 |
private static final Logger LOGGER = LoggerFactory.getLogger(ExportTable.class); |
42 |
|
43 |
public ExportTable() {
|
44 |
|
45 |
} |
46 |
|
47 |
public void showExport(FeatureStore featureStore, FeatureQuery query) { |
48 |
showExport(featureStore, query, WindowManager.MODE.WINDOW); |
49 |
} |
50 |
|
51 |
public void showExport(FeatureStore featureStore, FeatureQuery query, WindowManager.MODE mode) { |
52 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
53 |
ExportManager manager = ExportLocator.getManager(); |
54 |
ExportSwingManager swingManager = ExportSwingLocator.getSwingManager(); |
55 |
|
56 |
final ExportProcess process = manager.createProcess();
|
57 |
process.setSourceFeatureStore(featureStore); |
58 |
process.setContextProjection(null);
|
59 |
process.setSourceProjection(featureStore.getDefaultFeatureTypeQuietly().getDefaultSRS()); |
60 |
process.setSourceTransformation(null);
|
61 |
process.setFeatureQuery(query); |
62 |
process.setFilterExpression(query==null? null:query.getExpressionFilter()); |
63 |
|
64 |
JExportProcessPanel panel = swingManager.createJExportProcessPanel( |
65 |
process, |
66 |
new Filter<ExportServiceFactory>() { |
67 |
@Override
|
68 |
public boolean apply(ExportServiceFactory factory) { |
69 |
return factory.hasTabularSupport();
|
70 |
} |
71 |
} |
72 |
); |
73 |
panel.addFinishListener(new ExportFinishListenerAdapter() {
|
74 |
@Override
|
75 |
public void finished(JExportProcessPanel exportPanel) { |
76 |
doAddStore(process); |
77 |
} |
78 |
}); |
79 |
JComponent component = panel.asJComponent();
|
80 |
component.setPreferredSize(new Dimension(component.getPreferredSize().width, 530)); |
81 |
|
82 |
WindowManager winmgr = ToolsSwingLocator.getWindowManager(); |
83 |
winmgr.showWindow( |
84 |
panel.asJComponent(), |
85 |
i18n.getTranslation("_Export_to"),
|
86 |
mode |
87 |
); |
88 |
} |
89 |
|
90 |
|
91 |
public void doAddStore(ExportProcess process) { |
92 |
ApplicationManager application = ApplicationLocator.getManager(); |
93 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
94 |
if (process.getTargetOpenStoreParameters()==null) { |
95 |
return;
|
96 |
} |
97 |
int n = application.confirmDialog(
|
98 |
i18n.getTranslation("_Add_new_table_to_current_project"),
|
99 |
i18n.getTranslation("_Export"),
|
100 |
JOptionPane.YES_NO_OPTION,
|
101 |
JOptionPane.QUESTION_MESSAGE,
|
102 |
"AddExportedTableToProject"
|
103 |
); |
104 |
if( n != JOptionPane.YES_OPTION ) { |
105 |
return;
|
106 |
} |
107 |
try {
|
108 |
DataManager dataManager = DALLocator.getDataManager(); |
109 |
ProjectManager projectManager = application.getProjectManager(); |
110 |
Project project = application.getCurrentProject(); |
111 |
for (OpenDataStoreParameters params : process.getTargetOpenStoreParameters()) {
|
112 |
FeatureStore store = (FeatureStore) dataManager.openStore( |
113 |
params.getDataStoreName(), |
114 |
params |
115 |
); |
116 |
TableDocument tableDocument = (TableDocument) projectManager.createDocument( |
117 |
TableManager.TYPENAME, |
118 |
store.getName() |
119 |
); |
120 |
tableDocument.setStore(store); |
121 |
project.addDocument(tableDocument); |
122 |
} |
123 |
application.messageDialog( |
124 |
i18n.getTranslation("_Table_added_to_project"),
|
125 |
null,
|
126 |
i18n.getTranslation("_Export"),
|
127 |
JOptionPane.QUESTION_MESSAGE,
|
128 |
"ExportedTableAddedToProject"
|
129 |
); |
130 |
} catch (Exception ex) { |
131 |
LOGGER.warn("Can't add exported layer to view",ex);
|
132 |
application.messageDialog( |
133 |
i18n.getTranslation("_Cant_add_exported_table_to_project"),
|
134 |
null,
|
135 |
i18n.getTranslation("_Export"),
|
136 |
JOptionPane.WARNING_MESSAGE,
|
137 |
"CantAddExportedTableToProject"
|
138 |
); |
139 |
} |
140 |
} |
141 |
|
142 |
} |