root / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / dal / swing / datastore / DefaultDataStoreParametersCreationPanel.java @ 35342
History | View | Annotate | Download (11.4 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 |
package org.gvsig.fmap.mapcontrol.dal.swing.datastore; |
23 |
|
24 |
import java.awt.Dimension; |
25 |
import java.awt.GridBagConstraints; |
26 |
import java.awt.GridBagLayout; |
27 |
import java.awt.Insets; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
import java.util.Iterator; |
31 |
import java.util.List; |
32 |
|
33 |
import javax.swing.JButton; |
34 |
import javax.swing.JComboBox; |
35 |
|
36 |
import org.slf4j.Logger; |
37 |
import org.slf4j.LoggerFactory; |
38 |
|
39 |
import org.gvsig.fmap.dal.DALLocator; |
40 |
import org.gvsig.fmap.dal.DataManager; |
41 |
import org.gvsig.fmap.dal.DataServerExplorer; |
42 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
43 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
44 |
import org.gvsig.fmap.dal.exception.InitializeException; |
45 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
46 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
47 |
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor; |
48 |
import org.gvsig.tools.service.ServiceException; |
49 |
|
50 |
|
51 |
/**
|
52 |
* @author gvSIG Team
|
53 |
* @version $Id$
|
54 |
*
|
55 |
*/
|
56 |
public class DefaultDataStoreParametersCreationPanel extends DataStoreParametersCreationPanel implements ActionListener{ |
57 |
private static final long serialVersionUID = -1453149638996485029L; |
58 |
|
59 |
private static final Logger LOG = |
60 |
LoggerFactory.getLogger(DefaultDataStoreParametersCreationPanel.class); |
61 |
|
62 |
private static final DataManager DATA_MANAGER = DALLocator.getDataManager(); |
63 |
|
64 |
private static final int FORM_HEIGTH = 18; |
65 |
|
66 |
private DataServerExplorer dataServerExplorer = null; |
67 |
private DataServerExplorerParameters dataServerExplorerParameters = null; |
68 |
|
69 |
private NewDataStoreParameters dataStoreParameters = null; |
70 |
|
71 |
private JButton explorersButton; |
72 |
private JComboBox explorersComboBox; |
73 |
private JButton providersButton; |
74 |
private JComboBox providersComboBox; |
75 |
|
76 |
public DefaultDataStoreParametersCreationPanel() {
|
77 |
super();
|
78 |
initComponents(); |
79 |
populateExplorerCombo(); |
80 |
initListeners(); |
81 |
enableExplorerControls(false);
|
82 |
} |
83 |
|
84 |
private void initListeners() { |
85 |
this.explorersComboBox.addActionListener(this); |
86 |
this.explorersButton.addActionListener(this); |
87 |
this.providersComboBox.addActionListener(this); |
88 |
this.providersButton.addActionListener(this); |
89 |
} |
90 |
|
91 |
@SuppressWarnings("rawtypes") |
92 |
private void populateExplorerCombo(){ |
93 |
explorersComboBox.addItem(null);
|
94 |
|
95 |
Iterator it = DATA_MANAGER.getExplorerProviders().iterator();
|
96 |
|
97 |
while(it.hasNext()) {
|
98 |
String explorer = (String)it.next(); |
99 |
explorersComboBox.addItem(explorer); |
100 |
} |
101 |
} |
102 |
|
103 |
private void initComponents() { |
104 |
GridBagConstraints gridBagConstraints;
|
105 |
|
106 |
explorersComboBox = new JComboBox(); |
107 |
providersComboBox = new JComboBox(); |
108 |
explorersButton = new JButton(); |
109 |
providersButton = new JButton(); |
110 |
|
111 |
setLayout(new GridBagLayout()); |
112 |
|
113 |
explorersComboBox.setPreferredSize(new Dimension(0, FORM_HEIGTH)); |
114 |
gridBagConstraints = new GridBagConstraints(); |
115 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
116 |
gridBagConstraints.weightx = 1.0;
|
117 |
gridBagConstraints.insets = new Insets(0, 2, 0, 2); |
118 |
add(explorersComboBox, gridBagConstraints); |
119 |
|
120 |
explorersButton.setText("...");
|
121 |
explorersButton.setPreferredSize(new Dimension(25, FORM_HEIGTH)); |
122 |
gridBagConstraints = new GridBagConstraints(); |
123 |
gridBagConstraints.gridx = 1;
|
124 |
gridBagConstraints.gridy = 0;
|
125 |
gridBagConstraints.insets = new Insets(0, 2, 0, 2); |
126 |
add(explorersButton, gridBagConstraints); |
127 |
|
128 |
providersComboBox.setPreferredSize(new Dimension(0, FORM_HEIGTH)); |
129 |
gridBagConstraints = new GridBagConstraints(); |
130 |
gridBagConstraints.gridx = 2;
|
131 |
gridBagConstraints.gridy = 0;
|
132 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
133 |
gridBagConstraints.weightx = 1.0;
|
134 |
gridBagConstraints.insets = new Insets(0, 2, 0, 2); |
135 |
add(providersComboBox, gridBagConstraints); |
136 |
|
137 |
providersButton.setText("...");
|
138 |
providersButton.setPreferredSize(new Dimension(25, FORM_HEIGTH)); |
139 |
gridBagConstraints = new GridBagConstraints(); |
140 |
gridBagConstraints.gridx = 3;
|
141 |
gridBagConstraints.gridy = 0;
|
142 |
gridBagConstraints.insets = new Insets(0, 2, 0, 2); |
143 |
add(providersButton, gridBagConstraints); |
144 |
} |
145 |
|
146 |
@Override
|
147 |
public NewDataStoreParameters getDataStoreParameters(){
|
148 |
return dataStoreParameters;
|
149 |
} |
150 |
|
151 |
@Override
|
152 |
public DataServerExplorer getDataServerExplorer() {
|
153 |
return dataServerExplorer;
|
154 |
} |
155 |
|
156 |
public void actionPerformed(ActionEvent e) { |
157 |
if (e.getSource().equals(explorersButton)) {
|
158 |
explorersButtonClicked(); |
159 |
}else if (e.getSource().equals(providersButton)) { |
160 |
providersButtonClicked(); |
161 |
}else if (e.getSource().equals(explorersComboBox)) { |
162 |
explorersComboSelectionChanged(); |
163 |
}else if (e.getSource().equals(providersComboBox)) { |
164 |
providersComboSelectionChanged(); |
165 |
} |
166 |
} |
167 |
|
168 |
private void explorersComboSelectionChanged(){ |
169 |
String explorerName = (String)explorersComboBox.getSelectedItem(); |
170 |
if (explorerName == null){ |
171 |
dataServerExplorerParameters = null;
|
172 |
dataServerExplorer = null;
|
173 |
removeProvidersCombo(); |
174 |
enableExplorerControls(false);
|
175 |
}else{
|
176 |
//Only update the explorer if the selection is different
|
177 |
if ((dataServerExplorer == null) || (!explorerName.equals(dataServerExplorer.getProviderName()))){ |
178 |
dataServerExplorerParameters = null;
|
179 |
|
180 |
//Remove all the previous providers
|
181 |
removeProvidersCombo(); |
182 |
|
183 |
//Disable all the components and enable the explorer button
|
184 |
this.enableExplorerControls(false); |
185 |
this.explorersButton.setEnabled(true); |
186 |
//Sometimes is possible to create an explorer without parameters (e.g: filesystem explorer"
|
187 |
try {
|
188 |
dataServerExplorerParameters = |
189 |
DATA_MANAGER.createServerExplorerParameters(explorerName); |
190 |
dataServerExplorer = |
191 |
DATA_MANAGER.openServerExplorer(explorerName, dataServerExplorerParameters); |
192 |
populateProvidersCombo(); |
193 |
this.providersComboBox.setEnabled(true); |
194 |
} catch (InitializeException e) {
|
195 |
LOG.error("Error creating the explorer parameters", e);
|
196 |
} catch (ProviderNotRegisteredException e) {
|
197 |
LOG.error("The explorer has not been registeger", e);
|
198 |
} catch (ValidateDataParametersException e) {
|
199 |
LOG.error("Error creating the explorer", e);
|
200 |
} |
201 |
} |
202 |
} |
203 |
} |
204 |
|
205 |
private void enableExplorerControls(boolean isEnabled){ |
206 |
this.explorersButton.setEnabled(isEnabled);
|
207 |
this.providersComboBox.setEnabled(isEnabled);
|
208 |
this.providersButton.setEnabled(isEnabled);
|
209 |
} |
210 |
|
211 |
private void enableProviderControls(boolean isEnabled){ |
212 |
this.providersButton.setEnabled(isEnabled);
|
213 |
} |
214 |
|
215 |
private void explorersButtonClicked(){ |
216 |
dataServerExplorer = null;
|
217 |
String explorerName = (String)explorersComboBox.getSelectedItem(); |
218 |
if (explorerName != null){ |
219 |
try {
|
220 |
if ((dataServerExplorerParameters == null) || (!dataServerExplorerParameters.getExplorerName().equals(explorerName))){ |
221 |
dataServerExplorerParameters = |
222 |
DATA_MANAGER.createServerExplorerParameters(explorerName); |
223 |
} |
224 |
DynObjectEditor dynObjectEditor = new DynObjectEditor(dataServerExplorerParameters);
|
225 |
dynObjectEditor.editObject(true);
|
226 |
dataServerExplorer = |
227 |
DATA_MANAGER.openServerExplorer(explorerName, dataServerExplorerParameters); |
228 |
//Remove all the previous providers
|
229 |
removeProvidersCombo(); |
230 |
populateProvidersCombo(); |
231 |
this.providersComboBox.setEnabled(true); |
232 |
} catch (InitializeException e) {
|
233 |
LOG.error("Error creating the explorer parameters", e);
|
234 |
} catch (ProviderNotRegisteredException e) {
|
235 |
LOG.error("The explorer has not been registered", e);
|
236 |
} catch (ServiceException e) {
|
237 |
LOG.error("Error creating the explorer panel", e);
|
238 |
} catch (ValidateDataParametersException e) {
|
239 |
LOG.error("Error creating the explorer", e);
|
240 |
} |
241 |
} |
242 |
} |
243 |
|
244 |
@SuppressWarnings("rawtypes") |
245 |
private void populateProvidersCombo(){ |
246 |
providersComboBox.addItem(null);
|
247 |
if (dataServerExplorer != null){ |
248 |
List providerNames = dataServerExplorer.getDataStoreProviderNames();
|
249 |
for (int i=0 ; i<providerNames.size() ; i++){ |
250 |
providersComboBox.addItem(providerNames.get(i)); |
251 |
} |
252 |
} |
253 |
} |
254 |
|
255 |
private void removeProvidersCombo(){ |
256 |
providersComboBox.removeAllItems(); |
257 |
} |
258 |
|
259 |
private void providersComboSelectionChanged(){ |
260 |
dataStoreParameters = null;
|
261 |
String providerName = (String)providersComboBox.getSelectedItem(); |
262 |
if ((dataServerExplorer != null) && (providerName != null)){ |
263 |
enableProviderControls(true);
|
264 |
}else{
|
265 |
enableProviderControls(false);
|
266 |
} |
267 |
} |
268 |
|
269 |
private void providersButtonClicked(){ |
270 |
String providerName = (String)providersComboBox.getSelectedItem(); |
271 |
if ((dataServerExplorer != null) && (providerName != null)){ |
272 |
try {
|
273 |
dataStoreParameters = |
274 |
DATA_MANAGER.createNewStoreParameters(dataServerExplorer.getProviderName(), providerName); |
275 |
DynObjectEditor dynObjectEditor = new DynObjectEditor(dataStoreParameters);
|
276 |
dynObjectEditor.editObject(true);
|
277 |
} catch (InitializeException e) {
|
278 |
LOG.error("Error creating the store parameters", e);
|
279 |
} catch (ProviderNotRegisteredException e) {
|
280 |
LOG.error("The provider has not been registered", e);
|
281 |
} catch (ServiceException e) {
|
282 |
LOG.error("Error creating the store panel", e);
|
283 |
} |
284 |
} |
285 |
} |
286 |
} |