root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / ui / ServerConnectDialogPanel.java @ 2985
History | View | Annotate | Download (9.24 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package es.gva.cit.catalogClient.ui; |
42 |
|
43 |
import es.gva.cit.catalogClient.CatalogClient; |
44 |
|
45 |
import org.w3c.dom.Node; |
46 |
|
47 |
import java.awt.Dimension; |
48 |
import java.awt.FlowLayout; |
49 |
import java.awt.event.ActionEvent; |
50 |
import java.awt.event.ActionListener; |
51 |
|
52 |
import java.io.BufferedReader; |
53 |
import java.io.File; |
54 |
import java.io.FileNotFoundException; |
55 |
import java.io.FileReader; |
56 |
import java.io.IOException; |
57 |
|
58 |
import java.util.Iterator; |
59 |
import java.util.TreeMap; |
60 |
|
61 |
import javax.swing.BoxLayout; |
62 |
import javax.swing.JButton; |
63 |
import javax.swing.JPanel; |
64 |
|
65 |
|
66 |
/**
|
67 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
68 |
*/
|
69 |
public class ServerConnectDialogPanel extends JPanel implements ActionListener { |
70 |
private static TreeMap serverList = new TreeMap(); |
71 |
|
72 |
//Panels
|
73 |
JPanel ppalPanel = null; |
74 |
ServerConnectPanel controlsPanel = null;
|
75 |
JPanel buttonsPanel = null; |
76 |
|
77 |
//Buttons
|
78 |
JButton conectar = null; |
79 |
JButton buscar = null; |
80 |
|
81 |
//Others
|
82 |
CatalogClient cliente = null;
|
83 |
private String serversFile = "servers.txt"; |
84 |
private String currentServer = ""; |
85 |
|
86 |
public ServerConnectDialogPanel() {
|
87 |
ppalPanel = new JPanel(); |
88 |
ppalPanel.setLayout(new BoxLayout(ppalPanel, BoxLayout.Y_AXIS)); |
89 |
|
90 |
ppalPanel.add(getControlsPanel(), null);
|
91 |
ppalPanel.add(getButtonPanel(), null);
|
92 |
|
93 |
add(ppalPanel); |
94 |
|
95 |
setDefaultButtonListeners(); |
96 |
|
97 |
//Loads the servers
|
98 |
loadServerList(serversFile); |
99 |
} |
100 |
|
101 |
public JPanel getControlsPanel() { |
102 |
if (controlsPanel == null) { |
103 |
controlsPanel = new ServerConnectPanel();
|
104 |
controlsPanel.setSize(625, 230); |
105 |
controlsPanel.getZ3950Button().addActionListener(this);
|
106 |
controlsPanel.getSrwButton().addActionListener(this);
|
107 |
controlsPanel.getCswButton().addActionListener(this);
|
108 |
controlsPanel.getServidoresCombo().addActionListener(this);
|
109 |
} |
110 |
|
111 |
return controlsPanel;
|
112 |
} |
113 |
|
114 |
public JPanel getButtonPanel() { |
115 |
if (buttonsPanel == null) { |
116 |
buttonsPanel = new JPanel(new FlowLayout()); |
117 |
buttonsPanel.add(getConnectButton()); |
118 |
buttonsPanel.add(getSearchButton()); |
119 |
} |
120 |
|
121 |
return buttonsPanel;
|
122 |
} |
123 |
|
124 |
public JButton getConnectButton() { |
125 |
if (conectar == null) { |
126 |
conectar = new JButton("Conectar"); |
127 |
conectar.setSize(new Dimension(30, 20)); |
128 |
conectar.setActionCommand("Connect");
|
129 |
} |
130 |
|
131 |
return conectar;
|
132 |
} |
133 |
|
134 |
public JButton getSearchButton() { |
135 |
if (buscar == null) { |
136 |
buscar = new JButton("Buscar"); |
137 |
buscar.setSize(new Dimension(30, 20)); |
138 |
buscar.setActionCommand("Search");
|
139 |
buscar.setEnabled(false);
|
140 |
} |
141 |
|
142 |
return buscar;
|
143 |
} |
144 |
|
145 |
public static void addServer(String name) { |
146 |
if (ServerConnectDialogPanel.serverList == null) { |
147 |
ServerConnectDialogPanel.serverList = new TreeMap(); |
148 |
} |
149 |
|
150 |
if (!ServerConnectDialogPanel.serverList.containsKey(name)) {
|
151 |
ServerConnectDialogPanel.serverList.put(name, name); |
152 |
} |
153 |
} |
154 |
|
155 |
public void setDefaultButtonListeners() { |
156 |
getConnectButton().addActionListener(this);
|
157 |
getSearchButton().addActionListener(this);
|
158 |
} |
159 |
|
160 |
public void loadServerList(String sfile) { |
161 |
File file = null; |
162 |
|
163 |
try {
|
164 |
file = new File(sfile); |
165 |
|
166 |
// Cargo el fichero si existe
|
167 |
if (file.exists()) {
|
168 |
BufferedReader fr = new BufferedReader(new FileReader(file)); |
169 |
String s;
|
170 |
|
171 |
while ((s = fr.readLine()) != null) { |
172 |
ServerConnectDialogPanel.addServer(s); |
173 |
} |
174 |
} else {
|
175 |
System.out.println("No se encuentra el fichero '" + |
176 |
file.getPath() + "'");
|
177 |
} |
178 |
|
179 |
// Si hay servers en el TreeMap los cargo en el Combo
|
180 |
Iterator iter = ServerConnectDialogPanel.serverList.keySet()
|
181 |
.iterator(); |
182 |
|
183 |
while (iter.hasNext()) {
|
184 |
controlsPanel.getServerCombo().addItem((String) iter.next());
|
185 |
} |
186 |
} catch (FileNotFoundException e) { |
187 |
// TODO Auto-generated catch block
|
188 |
System.out.println("No se encuentra el fichero '" + file.getPath() + |
189 |
"'");
|
190 |
e.printStackTrace(); |
191 |
} catch (IOException e) { |
192 |
// TODO Auto-generated catch block
|
193 |
e.printStackTrace(); |
194 |
} |
195 |
} |
196 |
|
197 |
/* (non-Javadoc)
|
198 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
199 |
*/
|
200 |
public void actionPerformed(ActionEvent e) { |
201 |
//Connect
|
202 |
if (e.getActionCommand() == "Connect") { |
203 |
doConectar(); |
204 |
} |
205 |
|
206 |
//BUSCAR
|
207 |
if (e.getActionCommand() == "Search") { |
208 |
this.setEnabled(false); |
209 |
|
210 |
SearchDialog frame = new SearchDialog(cliente,true,""); |
211 |
} |
212 |
|
213 |
if ((e.getActionCommand() == "Z39.50") || |
214 |
(e.getActionCommand() == "SRU/SRW") ||
|
215 |
(e.getActionCommand() == "CS-W") ||
|
216 |
(e.getActionCommand() == "comboBoxChanged")) {
|
217 |
buscar.setEnabled(false);
|
218 |
} |
219 |
|
220 |
if (e.getActionCommand() == "Z39.50") { |
221 |
controlsPanel.getDbText().setEnabled(true);
|
222 |
} |
223 |
|
224 |
if ((e.getActionCommand() == "SRU/SRW") || |
225 |
(e.getActionCommand() == "CS-W")) {
|
226 |
controlsPanel.getDbText().setEnabled(false);
|
227 |
} |
228 |
} |
229 |
|
230 |
private void doConectar() { |
231 |
buscar.setEnabled(false);
|
232 |
|
233 |
//Create a new atalogClient
|
234 |
cliente = new CatalogClient(controlsPanel.getServer(),
|
235 |
controlsPanel.getProtocol(), controlsPanel.getDatabase()); |
236 |
|
237 |
String msg = ""; |
238 |
|
239 |
//try to connect
|
240 |
if (!cliente.serverReady()) {
|
241 |
msg = "No se encuentra el servidor";
|
242 |
} else if (!cliente.getLnkICatalogServerDriver().isProtocolSupported(cliente.getUrl())) { |
243 |
msg = "El servidor No soporta el protocolo especificado";
|
244 |
} else {
|
245 |
//getCapabilities
|
246 |
Node[] nodesCapabilities = cliente.getLnkICatalogServerDriver()
|
247 |
.getCapabilities(cliente.getUrl()); |
248 |
|
249 |
if (nodesCapabilities == null) { |
250 |
msg = "Error al hacer un GetCapabilities." +
|
251 |
"Esto puede ser debido a dos razones: " +
|
252 |
"O bien ha habido un error al intentar " +
|
253 |
"hacer la operaci?n, o bien el servidor " +
|
254 |
"no soporta el protocolo especificado";
|
255 |
} else {
|
256 |
//Configure the client
|
257 |
if (!cliente.getLnkICatalogServerDriver().setParameters(nodesCapabilities)) {
|
258 |
if (!(cliente.getLnkICatalogServerDriver()
|
259 |
.getServerAnswerReady().equals(""))) {
|
260 |
msg = cliente.getLnkICatalogServerDriver() |
261 |
.getServerAnswerReady(); |
262 |
} else {
|
263 |
msg = "Error al procesar la respuesta. " +
|
264 |
"Se ha encontrado el servidor, pero posiblemente" +
|
265 |
" no soporta el protocolo especificado";
|
266 |
} |
267 |
} else {
|
268 |
//Show the answer
|
269 |
msg = cliente.getLnkICatalogServerDriver() |
270 |
.getServerAnswerReady(); |
271 |
|
272 |
buscar.setEnabled(true);
|
273 |
currentServer = controlsPanel.getServer(); |
274 |
} |
275 |
} |
276 |
} |
277 |
|
278 |
controlsPanel.setRespuesta(msg); |
279 |
} |
280 |
|
281 |
/**
|
282 |
* @return Returns the serversFile.
|
283 |
*/
|
284 |
public String getServersFile() { |
285 |
return serversFile;
|
286 |
} |
287 |
|
288 |
/**
|
289 |
* @param serversFile The serversFile to set.
|
290 |
*/
|
291 |
public void setServersFile(String serversFile) { |
292 |
this.serversFile = serversFile;
|
293 |
} |
294 |
|
295 |
/**
|
296 |
* @return Returns the currentServer.
|
297 |
*/
|
298 |
public String getCurrentServer() { |
299 |
return currentServer;
|
300 |
} |
301 |
|
302 |
/**
|
303 |
* @return Returns the cliente.
|
304 |
*/
|
305 |
public CatalogClient getCliente() {
|
306 |
return cliente;
|
307 |
} |
308 |
} |