root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / gazetteer / ui / serverConnect / ServerConnectDialogPanel.java @ 3229
History | View | Annotate | Download (9.86 KB)
1 | 3214 | jorpiell | /* 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.gazetteer.ui.serverConnect; |
||
42 | |||
43 | import es.gva.cit.catalogClient.metadataXML.XMLNode; |
||
44 | 3229 | jorpiell | import es.gva.cit.catalogClient.traductor.ITranslator; |
45 | import es.gva.cit.catalogClient.traductor.Translator; |
||
46 | 3227 | jorpiell | import es.gva.cit.catalogClient.utils.comboServer.ServerData; |
47 | 3214 | jorpiell | import es.gva.cit.gazetteer.GazetteerClient; |
48 | import es.gva.cit.gazetteer.ui.search.SearchDialog; |
||
49 | |||
50 | import java.awt.Dimension; |
||
51 | import java.awt.FlowLayout; |
||
52 | import java.awt.event.ActionEvent; |
||
53 | import java.awt.event.ActionListener; |
||
54 | |||
55 | import java.io.BufferedReader; |
||
56 | import java.io.File; |
||
57 | import java.io.FileNotFoundException; |
||
58 | import java.io.FileReader; |
||
59 | import java.io.IOException; |
||
60 | |||
61 | import java.util.Iterator; |
||
62 | import java.util.TreeMap; |
||
63 | |||
64 | import javax.swing.BoxLayout; |
||
65 | import javax.swing.JButton; |
||
66 | import javax.swing.JPanel; |
||
67 | |||
68 | |||
69 | /**
|
||
70 | * @author Jorge Piera Llodra (piera_jor@gva.es)
|
||
71 | */
|
||
72 | public class ServerConnectDialogPanel extends JPanel implements ActionListener { |
||
73 | private static TreeMap serverList = new TreeMap(); |
||
74 | |||
75 | //Panels
|
||
76 | JPanel ppalPanel = null; |
||
77 | ServerConnectPanel controlsPanel = null;
|
||
78 | JPanel buttonsPanel = null; |
||
79 | |||
80 | //Buttons
|
||
81 | JButton connect = null; |
||
82 | JButton search = null; |
||
83 | |||
84 | //Others
|
||
85 | protected GazetteerClient client = null; |
||
86 | protected String serversFile = "GazServers.txt"; |
||
87 | protected String currentServer = ""; |
||
88 | 3229 | jorpiell | private ITranslator translator = null; |
89 | 3214 | jorpiell | |
90 | 3229 | jorpiell | public ServerConnectDialogPanel(ITranslator translator) {
|
91 | this.translator = translator;
|
||
92 | 3214 | jorpiell | ppalPanel = new JPanel(); |
93 | ppalPanel.setLayout(new BoxLayout(ppalPanel, BoxLayout.Y_AXIS)); |
||
94 | |||
95 | ppalPanel.add(getControlsPanel(), null);
|
||
96 | ppalPanel.add(getButtonPanel(), null);
|
||
97 | |||
98 | add(ppalPanel); |
||
99 | |||
100 | setDefaultButtonListeners(); |
||
101 | |||
102 | //Loads the servers
|
||
103 | loadServerList(serversFile); |
||
104 | } |
||
105 | |||
106 | public JPanel getControlsPanel() { |
||
107 | if (controlsPanel == null) { |
||
108 | 3229 | jorpiell | controlsPanel = new ServerConnectPanel(translator);
|
109 | 3214 | jorpiell | controlsPanel.getWFSGButton().addActionListener(this);
|
110 | controlsPanel.getADLButton().addActionListener(this);
|
||
111 | controlsPanel.getServidoresCombo().addActionListener(this);
|
||
112 | } |
||
113 | |||
114 | return controlsPanel;
|
||
115 | } |
||
116 | |||
117 | public JPanel getButtonPanel() { |
||
118 | if (buttonsPanel == null) { |
||
119 | buttonsPanel = new JPanel(new FlowLayout()); |
||
120 | buttonsPanel.add(getConnectButton()); |
||
121 | buttonsPanel.add(getSearchButton()); |
||
122 | } |
||
123 | |||
124 | return buttonsPanel;
|
||
125 | } |
||
126 | |||
127 | public JButton getConnectButton() { |
||
128 | if (connect == null) { |
||
129 | 3229 | jorpiell | connect = new JButton(Translator.getText(translator,"connectButton")); |
130 | 3214 | jorpiell | connect.setSize(new Dimension(30, 20)); |
131 | connect.setActionCommand("Connect");
|
||
132 | } |
||
133 | |||
134 | return connect;
|
||
135 | } |
||
136 | |||
137 | public JButton getSearchButton() { |
||
138 | if (search == null) { |
||
139 | 3229 | jorpiell | search = new JButton(Translator.getText(translator,"searchButton")); |
140 | 3214 | jorpiell | search.setSize(new Dimension(30, 20)); |
141 | search.setActionCommand("Search");
|
||
142 | search.setEnabled(false);
|
||
143 | } |
||
144 | |||
145 | return search;
|
||
146 | } |
||
147 | |||
148 | 3227 | jorpiell | /**
|
149 | * It adds a server in the TreeMap Object
|
||
150 | * @param name
|
||
151 | */
|
||
152 | public static void addTreeMapServer(ServerData server) { |
||
153 | 3214 | jorpiell | if (ServerConnectDialogPanel.serverList == null) { |
154 | ServerConnectDialogPanel.serverList = new TreeMap(); |
||
155 | } |
||
156 | |||
157 | 3227 | jorpiell | serverList.put(server.getServerAddress(), server); |
158 | |||
159 | 3214 | jorpiell | } |
160 | |||
161 | 3227 | jorpiell | /**
|
162 | * Sets the listeners
|
||
163 | */
|
||
164 | 3214 | jorpiell | public void setDefaultButtonListeners() { |
165 | getConnectButton().addActionListener(this);
|
||
166 | getSearchButton().addActionListener(this);
|
||
167 | } |
||
168 | |||
169 | 3227 | jorpiell | /**
|
170 | * This method loads a server list in the combo
|
||
171 | * @param sfile
|
||
172 | */
|
||
173 | 3214 | jorpiell | public void loadServerList(String sfile) { |
174 | 3227 | jorpiell | loadServersFromFile(sfile); |
175 | |||
176 | Iterator iter = serverList.keySet().iterator();
|
||
177 | while (iter.hasNext()) {
|
||
178 | ServerData server = (ServerData) serverList.get((String) iter.next());
|
||
179 | controlsPanel.getServerCombo().addServer(server); |
||
180 | } |
||
181 | } |
||
182 | |||
183 | /**
|
||
184 | * It loads a server list from a text file
|
||
185 | * @param file
|
||
186 | */
|
||
187 | public void loadServersFromFile(String sfile){ |
||
188 | 3214 | jorpiell | File file = null; |
189 | try {
|
||
190 | file = new File(sfile); |
||
191 | |||
192 | if (file.exists()) {
|
||
193 | BufferedReader fr = new BufferedReader(new FileReader(file)); |
||
194 | String s;
|
||
195 | |||
196 | while ((s = fr.readLine()) != null) { |
||
197 | 3227 | jorpiell | addTreeMapServer(new ServerData(s,0,0)); |
198 | 3214 | jorpiell | } |
199 | } else {
|
||
200 | System.out.println("No se encuentra el fichero '" + |
||
201 | file.getPath() + "'");
|
||
202 | } |
||
203 | } catch (FileNotFoundException e) { |
||
204 | System.out.println("No se encuentra el fichero '" + file.getPath() + |
||
205 | "'");
|
||
206 | 3227 | jorpiell | //e.printStackTrace();
|
207 | 3214 | jorpiell | } catch (IOException e) { |
208 | 3227 | jorpiell | System.out.println("Error de entrada salida en la lectura del fichero"); |
209 | //e.printStackTrace();
|
||
210 | 3214 | jorpiell | } |
211 | 3227 | jorpiell | |
212 | 3214 | jorpiell | } |
213 | /* (non-Javadoc)
|
||
214 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||
215 | */
|
||
216 | public void actionPerformed(ActionEvent e) { |
||
217 | //Connect
|
||
218 | if (e.getActionCommand() == "Connect") { |
||
219 | connectButtonActionPerformed(); |
||
220 | } |
||
221 | |||
222 | //BUSCAR
|
||
223 | if (e.getActionCommand() == "Search") { |
||
224 | searchButtonActionPerformed(); |
||
225 | } |
||
226 | |||
227 | if ((e.getActionCommand() == "WFS-G") || |
||
228 | (e.getActionCommand() == "ADL") ||
|
||
229 | (e.getActionCommand() == "comboBoxChanged")) {
|
||
230 | search.setEnabled(false);
|
||
231 | } |
||
232 | 3227 | jorpiell | |
233 | if (e.getActionCommand() == "servidoresCombo"){ |
||
234 | try {
|
||
235 | controlsPanel.setProtocol(controlsPanel.getServer().getServiceSubType()); |
||
236 | }catch(NullPointerException ex){ |
||
237 | //The server is not loaded
|
||
238 | } |
||
239 | |||
240 | } |
||
241 | 3214 | jorpiell | |
242 | |||
243 | } |
||
244 | public void searchButtonActionPerformed(){ |
||
245 | setEnabled(false);
|
||
246 | SearchDialog frame = new SearchDialog(client);
|
||
247 | } |
||
248 | |||
249 | public void connectButtonActionPerformed(){ |
||
250 | doConectar(); |
||
251 | } |
||
252 | |||
253 | private void doConectar() { |
||
254 | search.setEnabled(false);
|
||
255 | |||
256 | //Create a new atalogClient
|
||
257 | 3227 | jorpiell | client = new GazetteerClient(controlsPanel.getServerAddress(),
|
258 | 3214 | jorpiell | controlsPanel.getProtocol()); |
259 | |||
260 | String msg = ""; |
||
261 | |||
262 | //try to connect
|
||
263 | if (!client.serverReady()) {
|
||
264 | msg = "No se encuentra el servidor";
|
||
265 | } else if (!client.getLnkIGazetteerDriver().isProtocolSupported(client.getUrl())) { |
||
266 | msg = "El servidor No soporta el protocolo especificado";
|
||
267 | } else {
|
||
268 | //getCapabilities
|
||
269 | XMLNode[] nodesCapabilities = client.getLnkIGazetteerDriver()
|
||
270 | .getCapabilities(client.getUrl()); |
||
271 | |||
272 | if (nodesCapabilities == null) { |
||
273 | msg = "Error al hacer un GetCapabilities." +
|
||
274 | "Esto puede ser debido a dos razones: " +
|
||
275 | "O bien ha habido un error al intentar " +
|
||
276 | "hacer la operaci?n, o bien el servidor " +
|
||
277 | "no soporta el protocolo especificado";
|
||
278 | } else {
|
||
279 | //Configure the client
|
||
280 | if (!client.getLnkIGazetteerDriver().setParameters(nodesCapabilities)) {
|
||
281 | if (!(client.getLnkIGazetteerDriver()
|
||
282 | .getServerAnswerReady().equals(""))) {
|
||
283 | msg = client.getLnkIGazetteerDriver() |
||
284 | .getServerAnswerReady(); |
||
285 | } else {
|
||
286 | msg = "Error al procesar la respuesta. " +
|
||
287 | "Se ha encontrado el servidor, pero posiblemente" +
|
||
288 | " no soporta el protocolo especificado";
|
||
289 | } |
||
290 | } else {
|
||
291 | //Show the answer
|
||
292 | msg = client.getLnkIGazetteerDriver() |
||
293 | .getServerAnswerReady(); |
||
294 | |||
295 | search.setEnabled(true);
|
||
296 | 3227 | jorpiell | currentServer = controlsPanel.getServerAddress(); |
297 | 3214 | jorpiell | } |
298 | } |
||
299 | } |
||
300 | controlsPanel.setRespuesta(msg); |
||
301 | } |
||
302 | |||
303 | /**
|
||
304 | * @return Returns the serversFile.
|
||
305 | */
|
||
306 | public String getServersFile() { |
||
307 | return serversFile;
|
||
308 | } |
||
309 | |||
310 | /**
|
||
311 | * @param serversFile The serversFile to set.
|
||
312 | */
|
||
313 | public void setServersFile(String serversFile) { |
||
314 | this.serversFile = serversFile;
|
||
315 | } |
||
316 | |||
317 | /**
|
||
318 | * @return Returns the currentServer.
|
||
319 | */
|
||
320 | public String getCurrentServer() { |
||
321 | return currentServer;
|
||
322 | } |
||
323 | |||
324 | /**
|
||
325 | * @return Returns the client.
|
||
326 | */
|
||
327 | public GazetteerClient getCliente() {
|
||
328 | return client;
|
||
329 | } |
||
330 | } |