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