svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / daltransform / gui / SelectDataStoreWizard.java @ 28666
History | View | Annotate | Download (6.21 KB)
1 | 28666 | jpiera | /* 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.app.daltransform.gui; |
||
29 | |||
30 | import java.util.ArrayList; |
||
31 | |||
32 | import javax.swing.DefaultListModel; |
||
33 | import javax.swing.JList; |
||
34 | import javax.swing.JScrollPane; |
||
35 | |||
36 | import jwizardcomponent.JWizardComponents; |
||
37 | import jwizardcomponent.JWizardPanel; |
||
38 | |||
39 | import org.gvsig.fmap.dal.exception.ReadException; |
||
40 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
41 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
42 | import org.gvsig.fmap.mapcontext.layers.LayersIterator; |
||
43 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
44 | import org.gvsig.project.document.table.FeatureTableDocument; |
||
45 | import org.gvsig.project.document.table.FeatureTableDocumentFactory; |
||
46 | import org.slf4j.Logger; |
||
47 | import org.slf4j.LoggerFactory; |
||
48 | |||
49 | import com.iver.andami.PluginServices; |
||
50 | import com.iver.andami.ui.mdiManager.IWindow; |
||
51 | import com.iver.cit.gvsig.ProjectExtension; |
||
52 | import com.iver.cit.gvsig.project.documents.ProjectDocument; |
||
53 | import com.iver.cit.gvsig.project.documents.view.gui.IView; |
||
54 | |||
55 | /**
|
||
56 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
||
57 | */
|
||
58 | public class SelectDataStoreWizard extends JWizardPanel{ |
||
59 | private static final long serialVersionUID = -1841990357325903449L; |
||
60 | private static final Logger logger = LoggerFactory.getLogger(SelectDataStoreWizard.class); |
||
61 | private JList dataStoreList; |
||
62 | private JScrollPane dataStoreScrollPane; |
||
63 | |||
64 | /**
|
||
65 | * @param wizardComponents
|
||
66 | */
|
||
67 | public SelectDataStoreWizard(JWizardComponents wizardComponents) {
|
||
68 | super(wizardComponents);
|
||
69 | initComponents(); |
||
70 | initLabels(); |
||
71 | addDataStores(); |
||
72 | } |
||
73 | |||
74 | private void initLabels(){ |
||
75 | setBorder(javax.swing.BorderFactory.createTitledBorder(PluginServices.getText(this, "transform_datastore_selection"))); |
||
76 | } |
||
77 | |||
78 | private void initComponents() { |
||
79 | java.awt.GridBagConstraints gridBagConstraints; |
||
80 | |||
81 | dataStoreScrollPane = new javax.swing.JScrollPane();
|
||
82 | dataStoreList = new javax.swing.JList();
|
||
83 | |||
84 | setLayout(new java.awt.GridBagLayout());
|
||
85 | |||
86 | dataStoreScrollPane.setViewportView(dataStoreList); |
||
87 | |||
88 | dataStoreList.setModel(new DefaultListModel()); |
||
89 | |||
90 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
91 | gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
||
92 | gridBagConstraints.weightx = 1.0;
|
||
93 | gridBagConstraints.weighty = 1.0;
|
||
94 | gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); |
||
95 | add(dataStoreScrollPane, gridBagConstraints); |
||
96 | } |
||
97 | |||
98 | /**
|
||
99 | * Adding the objects
|
||
100 | */
|
||
101 | private void addDataStores(){ |
||
102 | //Add all the tables
|
||
103 | ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
||
104 | ArrayList<ProjectDocument> tables = ext.getProject().getDocumentsByType(FeatureTableDocumentFactory.registerName);
|
||
105 | for (int i=0 ; i<tables.size() ; i++){ |
||
106 | FeatureTableDocument table = (FeatureTableDocument)tables.get(i); |
||
107 | ((DefaultListModel)dataStoreList.getModel()).addElement(
|
||
108 | new FeatureStoreCombo(table.getName(),
|
||
109 | table.getStore(), |
||
110 | false));
|
||
111 | } |
||
112 | //Add the layers from the current view
|
||
113 | IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
||
114 | if (window instanceof IView){ |
||
115 | IView view = (IView)window; |
||
116 | LayersIterator it = new LayersIterator(
|
||
117 | view.getMapControl().getMapContext().getLayers()); |
||
118 | while(it.hasNext()){
|
||
119 | FLayer layer = it.nextLayer(); |
||
120 | if (layer instanceof FLyrVect){ |
||
121 | try {
|
||
122 | FLyrVect layerVect = (FLyrVect)layer; |
||
123 | FeatureStore featureStore = layerVect.getFeatureStore(); |
||
124 | boolean found = false; |
||
125 | for (int i=0 ; i<tables.size() ; i++){ |
||
126 | FeatureTableDocument table = (FeatureTableDocument)tables.get(i); |
||
127 | if (table.getStore().equals(featureStore)) {
|
||
128 | found = true;
|
||
129 | } |
||
130 | } |
||
131 | if (!found){
|
||
132 | ((DefaultListModel)dataStoreList.getModel()).addElement(
|
||
133 | new FeatureStoreCombo(layerVect.getName(),
|
||
134 | featureStore, |
||
135 | true));
|
||
136 | } |
||
137 | } catch (ReadException e) {
|
||
138 | logger.error("It is not possible to read the FeatureStore", e);
|
||
139 | } |
||
140 | } |
||
141 | } |
||
142 | } |
||
143 | } |
||
144 | |||
145 | /* (non-Javadoc)
|
||
146 | * @see jwizardcomponent.JWizardPanel#update()
|
||
147 | */
|
||
148 | public void update() { |
||
149 | if (dataStoreList.getModel().getSize() > 0){ |
||
150 | dataStoreList.setSelectedIndex(0);
|
||
151 | }else{
|
||
152 | getWizardComponents().getNextButton().setEnabled(false);
|
||
153 | } |
||
154 | } |
||
155 | |||
156 | |||
157 | /**
|
||
158 | * @return the selected feature store
|
||
159 | */
|
||
160 | public FeatureStore getSelectedFeatureStore(){
|
||
161 | Object obj = dataStoreList.getSelectedValue();
|
||
162 | if (obj != null){ |
||
163 | return ((FeatureStoreCombo)obj).getFeatureStore();
|
||
164 | } |
||
165 | return null; |
||
166 | } |
||
167 | |||
168 | /**
|
||
169 | * @return the selected feature store
|
||
170 | */
|
||
171 | public boolean isSelectedFeatureStoreLoaded(){ |
||
172 | Object obj = dataStoreList.getSelectedValue();
|
||
173 | if (obj != null){ |
||
174 | return ((FeatureStoreCombo)obj).isLoaded();
|
||
175 | } |
||
176 | return false; |
||
177 | } |
||
178 | |||
179 | /**
|
||
180 | * Used to fill the combo
|
||
181 | * @author jpiera
|
||
182 | */
|
||
183 | private class FeatureStoreCombo{ |
||
184 | private FeatureStore featureStore = null; |
||
185 | private String name = null; |
||
186 | private boolean isLoaded = false; |
||
187 | |||
188 | public FeatureStoreCombo(String name, FeatureStore featureStore, boolean isLoaded) { |
||
189 | super();
|
||
190 | this.name = name;
|
||
191 | this.featureStore = featureStore;
|
||
192 | this.isLoaded = isLoaded;
|
||
193 | } |
||
194 | |||
195 | /**
|
||
196 | * @return the isLoaded
|
||
197 | */
|
||
198 | public boolean isLoaded() { |
||
199 | return isLoaded;
|
||
200 | } |
||
201 | |||
202 | /**
|
||
203 | * @return the featureStore
|
||
204 | */
|
||
205 | public FeatureStore getFeatureStore() {
|
||
206 | return featureStore;
|
||
207 | } |
||
208 | |||
209 | /* (non-Javadoc)
|
||
210 | * @see java.lang.Object#toString()
|
||
211 | */
|
||
212 | public String toString() { |
||
213 | return name;
|
||
214 | } |
||
215 | } |
||
216 | } |