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 @ 40558
History | View | Annotate | Download (5.12 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* 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 |
*
|
16 |
* 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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
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 |
*/
|
24 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2008 IVER T.I. S.A. {{Task}}
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.fmap.dal.serverexplorer.filesystem.swing; |
30 |
|
31 |
import java.awt.Window; |
32 |
import java.util.ArrayList; |
33 |
import java.util.HashSet; |
34 |
import java.util.List; |
35 |
import java.util.Set; |
36 |
|
37 |
import javax.swing.JOptionPane; |
38 |
|
39 |
import org.cresques.cts.IProjection; |
40 |
import org.slf4j.Logger; |
41 |
import org.slf4j.LoggerFactory; |
42 |
|
43 |
import org.gvsig.andami.PluginServices; |
44 |
import org.gvsig.andami.messages.NotificationManager; |
45 |
import org.gvsig.app.ApplicationLocator; |
46 |
import org.gvsig.app.ApplicationManager; |
47 |
import org.gvsig.app.prepareAction.PrepareContext; |
48 |
import org.gvsig.app.project.Project; |
49 |
import org.gvsig.app.project.ProjectManager; |
50 |
import org.gvsig.app.project.documents.table.TableDocument; |
51 |
import org.gvsig.app.project.documents.table.TableManager; |
52 |
import org.gvsig.fmap.dal.DALLocator; |
53 |
import org.gvsig.fmap.dal.DataManager; |
54 |
import org.gvsig.fmap.dal.DataStoreParameters; |
55 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
56 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
57 |
import org.gvsig.i18n.Messages; |
58 |
|
59 |
public class FilesystemExplorerTableWizardPanel extends |
60 |
FilesystemExplorerWizardPanel { |
61 |
|
62 |
private static final long serialVersionUID = 8469934188826417698L; |
63 |
private static final Logger LOG = LoggerFactory.getLogger( |
64 |
FilesystemExplorerTableWizardPanel.class); |
65 |
|
66 |
private PrepareContext prepareDSContext = null; |
67 |
|
68 |
@Override
|
69 |
public void execute() { |
70 |
executeWizard(); |
71 |
} |
72 |
|
73 |
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 |
new ArrayList<TableDocument>(parameters.length); |
84 |
|
85 |
Set<String> not_valid = new HashSet<String>(); |
86 |
|
87 |
for (DataStoreParameters params : parameters) {
|
88 |
store = null;
|
89 |
|
90 |
/*
|
91 |
* Try to validate.
|
92 |
*/
|
93 |
try {
|
94 |
params.validate(); |
95 |
} catch (ValidateDataParametersException ecx) {
|
96 |
LOG.info("Unable to validate params: " + params.getDataStoreName());
|
97 |
not_valid.add(params.getDataStoreName()); |
98 |
continue;
|
99 |
} |
100 |
|
101 |
try {
|
102 |
|
103 |
DataManager dataManager = DALLocator.getDataManager(); |
104 |
store = |
105 |
(FeatureStore) dataManager.openStore( |
106 |
params.getDataStoreName(), params); |
107 |
manager.pepareOpenDataSource(store, context); |
108 |
|
109 |
table = |
110 |
(TableDocument) ProjectManager.getInstance() |
111 |
.createDocument(TableManager.TYPENAME); |
112 |
table.setName(store.getName()); |
113 |
table.setStore(store); |
114 |
|
115 |
// project.add(table);
|
116 |
tabledocs.add(table); |
117 |
} catch (Exception e) { |
118 |
if (store != null) { |
119 |
store.dispose(); |
120 |
} |
121 |
NotificationManager.addError(e); |
122 |
} |
123 |
|
124 |
} |
125 |
|
126 |
if (not_valid.size() > 0) { |
127 |
String not_str = not_valid.toString();
|
128 |
JOptionPane.showMessageDialog(
|
129 |
this,
|
130 |
Messages.getText("_These_sources_were_not_loaded")
|
131 |
+ ": " + not_str, // not_valid, |
132 |
Messages.getText("_Load_error"),
|
133 |
JOptionPane.WARNING_MESSAGE);
|
134 |
} |
135 |
return tabledocs;
|
136 |
} |
137 |
|
138 |
@Override
|
139 |
protected PrepareContext getPrepareDataStoreContext() {
|
140 |
if (this.prepareDSContext == null) { |
141 |
this.prepareDSContext = new PrepareContext() { |
142 |
|
143 |
public Window getOwnerWindow() { |
144 |
return null; |
145 |
} |
146 |
|
147 |
public IProjection getViewProjection() {
|
148 |
return null; |
149 |
} |
150 |
|
151 |
}; |
152 |
} |
153 |
return this.prepareDSContext; |
154 |
} |
155 |
|
156 |
public String getTabName() { |
157 |
return PluginServices.getText(this, "File"); |
158 |
} |
159 |
|
160 |
} |