svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.daltransform.app / org.gvsig.daltransform.app.mainplugin / src / main / java / org / gvsig / daltransform / swing / impl / SelectDataStoreWizardPanel.java @ 40558
History | View | Annotate | Download (7.26 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 |
* 2009 {Iver T.I.} {Task}
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.daltransform.swing.impl; |
30 |
|
31 |
import java.util.List; |
32 |
|
33 |
import javax.swing.DefaultListModel; |
34 |
import javax.swing.JList; |
35 |
import javax.swing.JScrollPane; |
36 |
|
37 |
import org.gvsig.andami.PluginServices; |
38 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
39 |
import org.gvsig.app.project.ProjectManager; |
40 |
import org.gvsig.app.project.documents.Document; |
41 |
import org.gvsig.app.project.documents.table.TableDocument; |
42 |
import org.gvsig.app.project.documents.table.TableManager; |
43 |
import org.gvsig.app.project.documents.view.gui.IView; |
44 |
import org.gvsig.daltransform.swing.DataTransformGui; |
45 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
46 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
47 |
import org.gvsig.fmap.mapcontext.layers.LayersIterator; |
48 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
49 |
|
50 |
|
51 |
/**
|
52 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
53 |
*/
|
54 |
public class SelectDataStoreWizardPanel extends AbstractDataTransformWizardPanel{ |
55 |
private static final long serialVersionUID = -1841990357325903449L; |
56 |
private JList dataStoreList; |
57 |
private JScrollPane dataStoreScrollPane; |
58 |
|
59 |
/**
|
60 |
* @param wizardComponents
|
61 |
*/
|
62 |
public SelectDataStoreWizardPanel() {
|
63 |
super();
|
64 |
initComponents(); |
65 |
} |
66 |
|
67 |
private void initComponents() { |
68 |
java.awt.GridBagConstraints gridBagConstraints; |
69 |
|
70 |
dataStoreScrollPane = new javax.swing.JScrollPane();
|
71 |
dataStoreList = new javax.swing.JList();
|
72 |
|
73 |
setLayout(new java.awt.GridBagLayout());
|
74 |
|
75 |
dataStoreScrollPane.setViewportView(dataStoreList); |
76 |
|
77 |
dataStoreList.setModel(new DefaultListModel()); |
78 |
|
79 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
80 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
81 |
gridBagConstraints.weightx = 1.0;
|
82 |
gridBagConstraints.weighty = 1.0;
|
83 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); |
84 |
add(dataStoreScrollPane, gridBagConstraints); |
85 |
} |
86 |
|
87 |
public void removeFeatureStore(FeatureStore featureStore){ |
88 |
DefaultListModel model =( DefaultListModel)dataStoreList.getModel(); |
89 |
for (int i=model.getSize()-1 ; i>=0 ; i--){ |
90 |
if (((FeatureStoreCombo)model.get(i)).getFeatureStore().equals(featureStore)){
|
91 |
model.remove(i); |
92 |
break;
|
93 |
} |
94 |
} |
95 |
} |
96 |
|
97 |
/**
|
98 |
* Adding the objects
|
99 |
*/
|
100 |
private void addDataStores(){ |
101 |
((DefaultListModel)dataStoreList.getModel()).removeAllElements();
|
102 |
DataTransformGui dataTransformGui = |
103 |
getDataTransformWizard().getDataTransformGui(); |
104 |
|
105 |
//Add all the tables
|
106 |
List<Document> tables = ProjectManager.getInstance().getCurrentProject() |
107 |
.getDocuments(TableManager.TYPENAME); |
108 |
for (Document table : tables) { |
109 |
if (dataTransformGui.accept(((TableDocument)table).getStore())){
|
110 |
((DefaultListModel)dataStoreList.getModel()).addElement(
|
111 |
new FeatureStoreCombo(
|
112 |
table.getName(), |
113 |
((TableDocument)table).getStore(), |
114 |
false
|
115 |
) |
116 |
); |
117 |
} |
118 |
} |
119 |
|
120 |
//Add the layers from the current view
|
121 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
122 |
if (window instanceof IView){ |
123 |
IView view = (IView)window; |
124 |
LayersIterator it = new LayersIterator(
|
125 |
view.getMapControl().getMapContext().getLayers()); |
126 |
while(it.hasNext()){
|
127 |
FLayer layer = it.nextLayer(); |
128 |
if (layer instanceof FLyrVect){ |
129 |
FLyrVect layerVect = (FLyrVect)layer; |
130 |
FeatureStore featureStore = layerVect.getFeatureStore(); |
131 |
boolean found = false; |
132 |
for (int i=0 ; i<tables.size() ; i++){ |
133 |
TableDocument table = (TableDocument)tables.get(i); |
134 |
if (table.getStore().equals(featureStore)) {
|
135 |
found = true;
|
136 |
} |
137 |
} |
138 |
if (!found){
|
139 |
if (dataTransformGui.accept(featureStore)){
|
140 |
((DefaultListModel)dataStoreList.getModel()).addElement(
|
141 |
new FeatureStoreCombo(layerVect.getName(),
|
142 |
featureStore, |
143 |
true));
|
144 |
} |
145 |
} |
146 |
} |
147 |
} |
148 |
} |
149 |
} |
150 |
|
151 |
|
152 |
/**
|
153 |
* @return the selected feature store
|
154 |
*/
|
155 |
public FeatureStore getSelectedFeatureStore(){
|
156 |
Object obj = dataStoreList.getSelectedValue();
|
157 |
if (obj != null){ |
158 |
return ((FeatureStoreCombo)obj).getFeatureStore();
|
159 |
} |
160 |
return null; |
161 |
} |
162 |
|
163 |
/* (non-Javadoc)
|
164 |
* @see org.gvsig.app.daltransform.impl.AbstractDataTransformWizardPanel#getFeatureStore()
|
165 |
*/
|
166 |
@Override
|
167 |
public FeatureStore getFeatureStore() {
|
168 |
return getSelectedFeatureStore();
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* @return the selected feature store
|
173 |
*/
|
174 |
public boolean isSelectedFeatureStoreLoaded(){ |
175 |
Object obj = dataStoreList.getSelectedValue();
|
176 |
if (obj != null){ |
177 |
return ((FeatureStoreCombo)obj).isLoaded();
|
178 |
} |
179 |
return false; |
180 |
} |
181 |
|
182 |
/**
|
183 |
* Used to fill the combo
|
184 |
* @author jpiera
|
185 |
*/
|
186 |
private class FeatureStoreCombo{ |
187 |
private FeatureStore featureStore = null; |
188 |
private String name = null; |
189 |
private boolean isLoaded = false; |
190 |
|
191 |
public FeatureStoreCombo(String name, FeatureStore featureStore, boolean isLoaded) { |
192 |
super();
|
193 |
this.name = name;
|
194 |
this.featureStore = featureStore;
|
195 |
this.isLoaded = isLoaded;
|
196 |
} |
197 |
|
198 |
/**
|
199 |
* @return the isLoaded
|
200 |
*/
|
201 |
public boolean isLoaded() { |
202 |
return isLoaded;
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* @return the featureStore
|
207 |
*/
|
208 |
public FeatureStore getFeatureStore() {
|
209 |
return featureStore;
|
210 |
} |
211 |
|
212 |
/* (non-Javadoc)
|
213 |
* @see java.lang.Object#toString()
|
214 |
*/
|
215 |
public String toString() { |
216 |
return name;
|
217 |
} |
218 |
} |
219 |
|
220 |
/*
|
221 |
* (non-Javadoc)
|
222 |
* @see org.gvsig.app.daltransform.gui.FeatureTransformWizard#getPanelTitle()
|
223 |
*/
|
224 |
public String getPanelTitle() { |
225 |
return PluginServices.getText(this, "transform_datastore_selection"); |
226 |
} |
227 |
|
228 |
/* (non-Javadoc)
|
229 |
* @see org.gvsig.app.daltransform.DataTransformWizard#updatePanel()
|
230 |
*/
|
231 |
public void updatePanel() { |
232 |
addDataStores(); |
233 |
if (dataStoreList.getSelectedIndex() == -1){ |
234 |
if (dataStoreList.getModel().getSize() > 0){ |
235 |
dataStoreList.setSelectedIndex(0);
|
236 |
getDataTransformWizard().setApplicable(true);
|
237 |
}else{
|
238 |
getDataTransformWizard().setApplicable(false);
|
239 |
} |
240 |
} |
241 |
} |
242 |
|
243 |
/**
|
244 |
* @return
|
245 |
*/
|
246 |
public boolean isFeatureStoreLayer() { |
247 |
Object obj = dataStoreList.getSelectedValue();
|
248 |
if (obj != null){ |
249 |
return ((FeatureStoreCombo)obj).isLoaded;
|
250 |
} |
251 |
return false; |
252 |
} |
253 |
|
254 |
/* (non-Javadoc)
|
255 |
* @see org.gvsig.app.daltransform.impl.AbstractDataTransformWizardPanel#nextPanel()
|
256 |
*/
|
257 |
@Override
|
258 |
public void nextPanel() { |
259 |
getDataTransformWizard().updateGui(); |
260 |
} |
261 |
|
262 |
|
263 |
} |
264 |
|