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 @ 44395
History | View | Annotate | Download (5.17 KB)
1 | 44263 | jjdelcerro | 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.FeatureStore; |
||
26 | import org.gvsig.tools.ToolsLocator; |
||
27 | import org.gvsig.tools.i18n.I18nManager; |
||
28 | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
||
29 | import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
||
30 | import org.slf4j.Logger; |
||
31 | import org.slf4j.LoggerFactory; |
||
32 | |||
33 | /**
|
||
34 | *
|
||
35 | * @author jjdelcerro
|
||
36 | */
|
||
37 | @SuppressWarnings("UseSpecificCatch") |
||
38 | public class ExportTable { |
||
39 | |||
40 | private static final Logger LOGGER = LoggerFactory.getLogger(ExportTable.class); |
||
41 | |||
42 | public ExportTable() {
|
||
43 | |||
44 | } |
||
45 | |||
46 | public void showExport(FeatureStore featureStore, Expression filter) { |
||
47 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
48 | ExportManager manager = ExportLocator.getManager(); |
||
49 | ExportSwingManager swingManager = ExportSwingLocator.getSwingManager(); |
||
50 | |||
51 | final ExportProcess process = manager.createProcess();
|
||
52 | process.setSourceFeatureStore(featureStore); |
||
53 | process.setContextProjection(null);
|
||
54 | process.setSourceProjection(null);
|
||
55 | process.setSourceTransformation(null);
|
||
56 | 44281 | jjdelcerro | process.setFilterExpression(filter); |
57 | 44263 | jjdelcerro | |
58 | JExportProcessPanel panel = swingManager.createJExportProcessPanel( |
||
59 | process, |
||
60 | new Filter<ExportServiceFactory>() { |
||
61 | @Override
|
||
62 | public boolean apply(ExportServiceFactory factory) { |
||
63 | return factory.hasTabularSupport();
|
||
64 | } |
||
65 | } |
||
66 | ); |
||
67 | panel.addFinishListener(new ExportFinishListenerAdapter() {
|
||
68 | @Override
|
||
69 | public void finished(JExportProcessPanel exportPanel) { |
||
70 | doAddTable(process); |
||
71 | } |
||
72 | }); |
||
73 | JComponent component = panel.asJComponent();
|
||
74 | component.setPreferredSize(new Dimension(component.getPreferredSize().width, 530)); |
||
75 | |||
76 | WindowManager winmgr = ToolsSwingLocator.getWindowManager(); |
||
77 | winmgr.showWindow( |
||
78 | panel.asJComponent(), |
||
79 | i18n.getTranslation("_Export_to"),
|
||
80 | WindowManager.MODE.WINDOW |
||
81 | ); |
||
82 | } |
||
83 | |||
84 | private void doAddTable(ExportProcess process) { |
||
85 | ApplicationManager application = ApplicationLocator.getManager(); |
||
86 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
87 | 44395 | omartinez | if (process.getTargetOpenStoreParameters()==null) { |
88 | return;
|
||
89 | } |
||
90 | 44263 | jjdelcerro | int n = application.confirmDialog(
|
91 | i18n.getTranslation("_Add_new_table_to_current_project"),
|
||
92 | i18n.getTranslation("_Export"),
|
||
93 | JOptionPane.YES_NO_OPTION,
|
||
94 | JOptionPane.QUESTION_MESSAGE,
|
||
95 | "AddExportedTableToProject"
|
||
96 | ); |
||
97 | if( n != JOptionPane.YES_OPTION ) { |
||
98 | return;
|
||
99 | } |
||
100 | try {
|
||
101 | DataManager dataManager = DALLocator.getDataManager(); |
||
102 | ProjectManager projectManager = application.getProjectManager(); |
||
103 | Project project = application.getCurrentProject(); |
||
104 | for (OpenDataStoreParameters params : process.getTargetOpenStoreParameters()) {
|
||
105 | FeatureStore store = (FeatureStore) dataManager.openStore( |
||
106 | params.getDataStoreName(), |
||
107 | params |
||
108 | ); |
||
109 | TableDocument tableDocument = (TableDocument) projectManager.createDocument( |
||
110 | TableManager.TYPENAME, |
||
111 | store.getName() |
||
112 | ); |
||
113 | tableDocument.setStore(store); |
||
114 | project.addDocument(tableDocument); |
||
115 | } |
||
116 | application.messageDialog( |
||
117 | i18n.getTranslation("_Table_added_to_project"),
|
||
118 | null,
|
||
119 | i18n.getTranslation("_Export"),
|
||
120 | JOptionPane.QUESTION_MESSAGE,
|
||
121 | "ExportedTableAddedToProject"
|
||
122 | ); |
||
123 | } catch (Exception ex) { |
||
124 | LOGGER.warn("Can't add exported layer to view",ex);
|
||
125 | application.messageDialog( |
||
126 | i18n.getTranslation("_Cant_add_exported_table_to_project"),
|
||
127 | null,
|
||
128 | i18n.getTranslation("_Export"),
|
||
129 | JOptionPane.WARNING_MESSAGE,
|
||
130 | "CantAddExportedTableToProject"
|
||
131 | ); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | } |