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 @ 40596
History | View | Annotate | Download (5.05 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 |
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 |
|
55 |
public class FilesystemExplorerTableWizardPanel extends |
56 |
FilesystemExplorerWizardPanel { |
57 |
|
58 |
private static final long serialVersionUID = 8469934188826417698L; |
59 |
private static final Logger LOG = LoggerFactory.getLogger( |
60 |
FilesystemExplorerTableWizardPanel.class); |
61 |
|
62 |
private PrepareContext prepareDSContext = null; |
63 |
|
64 |
@Override
|
65 |
public void execute() { |
66 |
executeWizard(); |
67 |
} |
68 |
|
69 |
public Object executeWizard() { |
70 |
FeatureStore store; |
71 |
TableDocument table; |
72 |
|
73 |
ApplicationManager manager = ApplicationLocator.getManager(); |
74 |
Project project = manager.getCurrentProject(); |
75 |
|
76 |
PrepareContext context = this.getPrepareDataStoreContext();
|
77 |
DataStoreParameters[] parameters = this.getParameters(); |
78 |
List<TableDocument> tabledocs =
|
79 |
new ArrayList<TableDocument>(parameters.length); |
80 |
|
81 |
Set<String> not_valid = new HashSet<String>(); |
82 |
|
83 |
for (DataStoreParameters params : parameters) {
|
84 |
store = null;
|
85 |
|
86 |
/*
|
87 |
* Try to validate.
|
88 |
*/
|
89 |
try {
|
90 |
params.validate(); |
91 |
} catch (ValidateDataParametersException ecx) {
|
92 |
LOG.info("Unable to validate params: " + params.getDataStoreName());
|
93 |
not_valid.add(params.getDataStoreName()); |
94 |
continue;
|
95 |
} |
96 |
|
97 |
try {
|
98 |
|
99 |
DataManager dataManager = DALLocator.getDataManager(); |
100 |
store = |
101 |
(FeatureStore) dataManager.openStore( |
102 |
params.getDataStoreName(), params); |
103 |
manager.pepareOpenDataSource(store, context); |
104 |
|
105 |
table = |
106 |
(TableDocument) ProjectManager.getInstance() |
107 |
.createDocument(TableManager.TYPENAME); |
108 |
table.setName(store.getName()); |
109 |
table.setStore(store); |
110 |
|
111 |
// project.add(table);
|
112 |
tabledocs.add(table); |
113 |
} catch (Exception e) { |
114 |
if (store != null) { |
115 |
store.dispose(); |
116 |
} |
117 |
NotificationManager.addError(e); |
118 |
} |
119 |
|
120 |
} |
121 |
|
122 |
if (not_valid.size() > 0) { |
123 |
String not_str = not_valid.toString();
|
124 |
JOptionPane.showMessageDialog(
|
125 |
this,
|
126 |
Messages.getText("_These_sources_were_not_loaded")
|
127 |
+ ": " + not_str, // not_valid, |
128 |
Messages.getText("_Load_error"),
|
129 |
JOptionPane.WARNING_MESSAGE);
|
130 |
} |
131 |
return tabledocs;
|
132 |
} |
133 |
|
134 |
@Override
|
135 |
protected PrepareContext getPrepareDataStoreContext() {
|
136 |
if (this.prepareDSContext == null) { |
137 |
this.prepareDSContext = new PrepareContext() { |
138 |
|
139 |
public Window getOwnerWindow() { |
140 |
return null; |
141 |
} |
142 |
|
143 |
public IProjection getViewProjection() {
|
144 |
return null; |
145 |
} |
146 |
|
147 |
}; |
148 |
} |
149 |
return this.prepareDSContext; |
150 |
} |
151 |
|
152 |
public String getTabName() { |
153 |
return PluginServices.getText(this, "File"); |
154 |
} |
155 |
|
156 |
} |