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 @ 43534
History | View | Annotate | Download (6.79 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 | 43209 | jjdelcerro | import org.gvsig.fmap.dal.swing.DALSwingLocator; |
54 | import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanel; |
||
55 | import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanelManager; |
||
56 | 40435 | jjdelcerro | import org.gvsig.i18n.Messages; |
57 | 42775 | jjdelcerro | import org.gvsig.tools.dynobject.DynObject; |
58 | 41205 | jjdelcerro | import org.gvsig.tools.dynobject.exception.DynFieldRequiredValueException; |
59 | import org.gvsig.tools.dynobject.exception.DynObjectValidateException; |
||
60 | 40435 | jjdelcerro | |
61 | public class FilesystemExplorerTableWizardPanel extends |
||
62 | FilesystemExplorerWizardPanel { |
||
63 | |||
64 | private static final long serialVersionUID = 8469934188826417698L; |
||
65 | private static final Logger LOG = LoggerFactory.getLogger( |
||
66 | FilesystemExplorerTableWizardPanel.class); |
||
67 | |||
68 | private PrepareContext prepareDSContext = null; |
||
69 | |||
70 | 43534 | jjdelcerro | public FilesystemExplorerTableWizardPanel() {
|
71 | super(true); |
||
72 | } |
||
73 | |||
74 | 40435 | jjdelcerro | @Override
|
75 | public void execute() { |
||
76 | executeWizard(); |
||
77 | } |
||
78 | |||
79 | 42775 | jjdelcerro | @Override
|
80 | 40435 | jjdelcerro | public Object executeWizard() { |
81 | FeatureStore store; |
||
82 | TableDocument table; |
||
83 | |||
84 | ApplicationManager manager = ApplicationLocator.getManager(); |
||
85 | Project project = manager.getCurrentProject(); |
||
86 | |||
87 | PrepareContext context = this.getPrepareDataStoreContext();
|
||
88 | DataStoreParameters[] parameters = this.getParameters(); |
||
89 | List<TableDocument> tabledocs =
|
||
90 | 42775 | jjdelcerro | new ArrayList<>(parameters.length); |
91 | 43152 | fdiaz | |
92 | 42775 | jjdelcerro | Set<String> not_valid = new HashSet<>(); |
93 | 43152 | fdiaz | |
94 | 40435 | jjdelcerro | for (DataStoreParameters params : parameters) {
|
95 | store = null;
|
||
96 | 43152 | fdiaz | |
97 | 40435 | jjdelcerro | /*
|
98 | * Try to validate.
|
||
99 | */
|
||
100 | try {
|
||
101 | params.validate(); |
||
102 | } catch (ValidateDataParametersException ecx) {
|
||
103 | 41205 | jjdelcerro | StringBuffer buffer = new StringBuffer(); |
104 | if( ecx.getCause() instanceof DynObjectValidateException ) { |
||
105 | DynObjectValidateException exceptions = (DynObjectValidateException) ecx.getCause(); |
||
106 | for( int i=0; i<exceptions.size(); i++ ) { |
||
107 | if( exceptions.get(i) instanceof DynFieldRequiredValueException ) { |
||
108 | DynFieldRequiredValueException exx = (DynFieldRequiredValueException) exceptions.get(i); |
||
109 | if( buffer.length()>0 ) { |
||
110 | buffer.append(", ");
|
||
111 | } |
||
112 | buffer.append(exx.getMessage()); |
||
113 | } |
||
114 | 43152 | fdiaz | |
115 | 41205 | jjdelcerro | } |
116 | } |
||
117 | String msg = params.getDataStoreName();
|
||
118 | if( buffer.length()>0 ) { |
||
119 | msg = msg + ": "+buffer.toString();
|
||
120 | } |
||
121 | LOG.info("Unable to validate params: " + msg);
|
||
122 | not_valid.add(msg); |
||
123 | 40435 | jjdelcerro | continue;
|
124 | } |
||
125 | 43152 | fdiaz | |
126 | 40435 | jjdelcerro | try {
|
127 | |||
128 | DataManager dataManager = DALLocator.getDataManager(); |
||
129 | store = |
||
130 | (FeatureStore) dataManager.openStore( |
||
131 | params.getDataStoreName(), params); |
||
132 | manager.pepareOpenDataSource(store, context); |
||
133 | |||
134 | table = |
||
135 | (TableDocument) ProjectManager.getInstance() |
||
136 | .createDocument(TableManager.TYPENAME); |
||
137 | table.setName(store.getName()); |
||
138 | table.setStore(store); |
||
139 | |||
140 | // project.add(table);
|
||
141 | tabledocs.add(table); |
||
142 | } catch (Exception e) { |
||
143 | if (store != null) { |
||
144 | store.dispose(); |
||
145 | } |
||
146 | NotificationManager.addError(e); |
||
147 | } |
||
148 | |||
149 | } |
||
150 | 43152 | fdiaz | |
151 | 40435 | jjdelcerro | if (not_valid.size() > 0) { |
152 | String not_str = not_valid.toString();
|
||
153 | JOptionPane.showMessageDialog(
|
||
154 | this,
|
||
155 | Messages.getText("_These_sources_were_not_loaded")
|
||
156 | + ": " + not_str, // not_valid, |
||
157 | Messages.getText("_Load_error"),
|
||
158 | JOptionPane.WARNING_MESSAGE);
|
||
159 | } |
||
160 | return tabledocs;
|
||
161 | } |
||
162 | |||
163 | @Override
|
||
164 | protected PrepareContext getPrepareDataStoreContext() {
|
||
165 | if (this.prepareDSContext == null) { |
||
166 | this.prepareDSContext = new PrepareContext() { |
||
167 | |||
168 | 42775 | jjdelcerro | @Override
|
169 | 40435 | jjdelcerro | public Window getOwnerWindow() { |
170 | return null; |
||
171 | } |
||
172 | 43152 | fdiaz | |
173 | 42775 | jjdelcerro | @Override
|
174 | 40435 | jjdelcerro | public IProjection getViewProjection() {
|
175 | return null; |
||
176 | } |
||
177 | |||
178 | }; |
||
179 | } |
||
180 | return this.prepareDSContext; |
||
181 | } |
||
182 | |||
183 | 42775 | jjdelcerro | @Override
|
184 | 40435 | jjdelcerro | public String getTabName() { |
185 | return PluginServices.getText(this, "File"); |
||
186 | } |
||
187 | |||
188 | 42775 | jjdelcerro | |
189 | @Override
|
||
190 | protected void showPropertiesDialog(final DynObject parameters) { |
||
191 | 43209 | jjdelcerro | DataStoreParametersPanelManager manager = DALSwingLocator.getDataStoreParametersPanelManager(); |
192 | DataStoreParametersPanel panel = manager.createDataStoreParametersPanel(parameters); |
||
193 | 42775 | jjdelcerro | panel.setExcludeGeometryOptions(true);
|
194 | manager.showPropertiesDialog(parameters, panel); |
||
195 | } |
||
196 | 43152 | fdiaz | |
197 | |||
198 | 40435 | jjdelcerro | } |