svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / fmap / dal / serverexplorer / filesystem / swing / FilesystemExplorerTableWizardPanel.java @ 43152
History | View | Annotate | Download (6.51 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40558 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40558 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * This program is distributed in the hope that it will be useful,
|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | 40558 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * You should have received a copy of the GNU General Public License
|
17 | * along with this program; if not, write to the Free Software
|
||
18 | 40558 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 40435 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40558 | jjdelcerro | *
|
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | |||
25 | package org.gvsig.fmap.dal.serverexplorer.filesystem.swing; |
||
26 | |||
27 | import java.awt.Window; |
||
28 | import java.util.ArrayList; |
||
29 | import java.util.HashSet; |
||
30 | import java.util.List; |
||
31 | import java.util.Set; |
||
32 | |||
33 | import javax.swing.JOptionPane; |
||
34 | |||
35 | import org.cresques.cts.IProjection; |
||
36 | import org.slf4j.Logger; |
||
37 | import org.slf4j.LoggerFactory; |
||
38 | |||
39 | import org.gvsig.andami.PluginServices; |
||
40 | import org.gvsig.andami.messages.NotificationManager; |
||
41 | import org.gvsig.app.ApplicationLocator; |
||
42 | import org.gvsig.app.ApplicationManager; |
||
43 | import org.gvsig.app.prepareAction.PrepareContext; |
||
44 | import org.gvsig.app.project.Project; |
||
45 | import org.gvsig.app.project.ProjectManager; |
||
46 | import org.gvsig.app.project.documents.table.TableDocument; |
||
47 | import org.gvsig.app.project.documents.table.TableManager; |
||
48 | import org.gvsig.fmap.dal.DALLocator; |
||
49 | import org.gvsig.fmap.dal.DataManager; |
||
50 | import org.gvsig.fmap.dal.DataStoreParameters; |
||
51 | import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
||
52 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
53 | import org.gvsig.i18n.Messages; |
||
54 | 42775 | jjdelcerro | import org.gvsig.tools.dynobject.DynObject; |
55 | 41205 | jjdelcerro | import org.gvsig.tools.dynobject.exception.DynFieldRequiredValueException; |
56 | import org.gvsig.tools.dynobject.exception.DynObjectValidateException; |
||
57 | 40435 | jjdelcerro | |
58 | public class FilesystemExplorerTableWizardPanel extends |
||
59 | FilesystemExplorerWizardPanel { |
||
60 | |||
61 | private static final long serialVersionUID = 8469934188826417698L; |
||
62 | private static final Logger LOG = LoggerFactory.getLogger( |
||
63 | FilesystemExplorerTableWizardPanel.class); |
||
64 | |||
65 | private PrepareContext prepareDSContext = null; |
||
66 | |||
67 | @Override
|
||
68 | public void execute() { |
||
69 | executeWizard(); |
||
70 | } |
||
71 | |||
72 | 42775 | jjdelcerro | @Override
|
73 | 40435 | jjdelcerro | public Object executeWizard() { |
74 | FeatureStore store; |
||
75 | TableDocument table; |
||
76 | |||
77 | ApplicationManager manager = ApplicationLocator.getManager(); |
||
78 | Project project = manager.getCurrentProject(); |
||
79 | |||
80 | PrepareContext context = this.getPrepareDataStoreContext();
|
||
81 | DataStoreParameters[] parameters = this.getParameters(); |
||
82 | List<TableDocument> tabledocs =
|
||
83 | 42775 | jjdelcerro | new ArrayList<>(parameters.length); |
84 | 43152 | fdiaz | |
85 | 42775 | jjdelcerro | Set<String> not_valid = new HashSet<>(); |
86 | 43152 | fdiaz | |
87 | 40435 | jjdelcerro | for (DataStoreParameters params : parameters) {
|
88 | store = null;
|
||
89 | 43152 | fdiaz | |
90 | 40435 | jjdelcerro | /*
|
91 | * Try to validate.
|
||
92 | */
|
||
93 | try {
|
||
94 | params.validate(); |
||
95 | } catch (ValidateDataParametersException ecx) {
|
||
96 | 41205 | jjdelcerro | StringBuffer buffer = new StringBuffer(); |
97 | if( ecx.getCause() instanceof DynObjectValidateException ) { |
||
98 | DynObjectValidateException exceptions = (DynObjectValidateException) ecx.getCause(); |
||
99 | for( int i=0; i<exceptions.size(); i++ ) { |
||
100 | if( exceptions.get(i) instanceof DynFieldRequiredValueException ) { |
||
101 | DynFieldRequiredValueException exx = (DynFieldRequiredValueException) exceptions.get(i); |
||
102 | if( buffer.length()>0 ) { |
||
103 | buffer.append(", ");
|
||
104 | } |
||
105 | buffer.append(exx.getMessage()); |
||
106 | } |
||
107 | 43152 | fdiaz | |
108 | 41205 | jjdelcerro | } |
109 | } |
||
110 | String msg = params.getDataStoreName();
|
||
111 | if( buffer.length()>0 ) { |
||
112 | msg = msg + ": "+buffer.toString();
|
||
113 | } |
||
114 | LOG.info("Unable to validate params: " + msg);
|
||
115 | not_valid.add(msg); |
||
116 | 40435 | jjdelcerro | continue;
|
117 | } |
||
118 | 43152 | fdiaz | |
119 | 40435 | jjdelcerro | try {
|
120 | |||
121 | DataManager dataManager = DALLocator.getDataManager(); |
||
122 | store = |
||
123 | (FeatureStore) dataManager.openStore( |
||
124 | params.getDataStoreName(), params); |
||
125 | manager.pepareOpenDataSource(store, context); |
||
126 | |||
127 | table = |
||
128 | (TableDocument) ProjectManager.getInstance() |
||
129 | .createDocument(TableManager.TYPENAME); |
||
130 | table.setName(store.getName()); |
||
131 | table.setStore(store); |
||
132 | |||
133 | // project.add(table);
|
||
134 | tabledocs.add(table); |
||
135 | } catch (Exception e) { |
||
136 | if (store != null) { |
||
137 | store.dispose(); |
||
138 | } |
||
139 | NotificationManager.addError(e); |
||
140 | } |
||
141 | |||
142 | } |
||
143 | 43152 | fdiaz | |
144 | 40435 | jjdelcerro | if (not_valid.size() > 0) { |
145 | String not_str = not_valid.toString();
|
||
146 | JOptionPane.showMessageDialog(
|
||
147 | this,
|
||
148 | Messages.getText("_These_sources_were_not_loaded")
|
||
149 | + ": " + not_str, // not_valid, |
||
150 | Messages.getText("_Load_error"),
|
||
151 | JOptionPane.WARNING_MESSAGE);
|
||
152 | } |
||
153 | return tabledocs;
|
||
154 | } |
||
155 | |||
156 | @Override
|
||
157 | protected PrepareContext getPrepareDataStoreContext() {
|
||
158 | if (this.prepareDSContext == null) { |
||
159 | this.prepareDSContext = new PrepareContext() { |
||
160 | |||
161 | 42775 | jjdelcerro | @Override
|
162 | 40435 | jjdelcerro | public Window getOwnerWindow() { |
163 | return null; |
||
164 | } |
||
165 | 43152 | fdiaz | |
166 | 42775 | jjdelcerro | @Override
|
167 | 40435 | jjdelcerro | public IProjection getViewProjection() {
|
168 | return null; |
||
169 | } |
||
170 | |||
171 | }; |
||
172 | } |
||
173 | return this.prepareDSContext; |
||
174 | } |
||
175 | |||
176 | 42775 | jjdelcerro | @Override
|
177 | 40435 | jjdelcerro | public String getTabName() { |
178 | return PluginServices.getText(this, "File"); |
||
179 | } |
||
180 | |||
181 | 42775 | jjdelcerro | |
182 | @Override
|
||
183 | protected void showPropertiesDialog(final DynObject parameters) { |
||
184 | FilesystemExplorerPropertiesPanelManager manager = ApplicationLocator.getFilesystemExplorerPropertiesPanelManager(); |
||
185 | 43152 | fdiaz | FilesystemExplorerPropertiesPanel panel = manager.createPanel(parameters); |
186 | 42775 | jjdelcerro | panel.setExcludeGeometryOptions(true);
|
187 | manager.showPropertiesDialog(parameters, panel); |
||
188 | } |
||
189 | 43152 | fdiaz | |
190 | |||
191 | 40435 | jjdelcerro | } |