Statistics
| Revision:

root / trunk / applications / appCatalogAndGazetteerClient / src / es / gva / cit / catalog / ui / serverconnect / ServerConnectPanel.java @ 15558

History | View | Annotate | Download (13.8 KB)

1

    
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42
package es.gva.cit.catalog.ui.serverconnect;
43
import java.awt.event.ActionListener;
44

    
45
import javax.swing.ImageIcon;
46
import javax.swing.JPanel;
47

    
48
import org.gvsig.i18n.Messages;
49

    
50
import com.iver.utiles.swing.jcomboServer.JComboServer;
51
import com.iver.utiles.swing.jcomboServer.ServerData;
52

    
53
import es.gva.cit.catalog.drivers.ICatalogServiceDriver;
54
import es.gva.cit.catalog.drivers.IDiscoveryServiceDriver;
55
import es.gva.cit.catalog.utils.CatalogConstants;
56
import es.gva.cit.catalog.utils.CatalogDriverRegister;
57

    
58
/**
59
 * Panel de conexi?n con los servers de cat?logo.
60
 * @author Jorge Piera Llodra (piera_jor@gva.es)
61
 */
62
public class ServerConnectPanel extends JPanel {
63
        private javax.swing.JPanel centerPanel;
64
        private javax.swing.JButton closeButton;
65
        private javax.swing.JButton connectButton;
66
        private javax.swing.JLabel dataBaseLabel;
67
        private javax.swing.JPanel dataBasePanel;
68
        private javax.swing.JTextField dataBaseText;
69
        private javax.swing.JScrollPane jScrollPane1;
70
        private javax.swing.JPanel lowerPanel;
71
        protected javax.swing.JComboBox protocolCombo;
72
        private javax.swing.JLabel protocolLabel;
73
        private javax.swing.JPanel protocolPanel;
74
        private javax.swing.JLabel replyLabel;
75
        private javax.swing.JEditorPane replyText;
76
        private javax.swing.JButton searchButton;
77
        private JComboServer serverCombo;
78
        private javax.swing.JLabel serverLabel;
79
        private javax.swing.JPanel serverPanel;
80
        private javax.swing.JButton serverPropertiesButton;
81
        private javax.swing.JPanel upperPanel;
82

    
83
        /** Creates new form ServerConnectPanel */
84
        public ServerConnectPanel() {
85
                initComponents();
86
                initLabels();
87
                initButtonSize();        
88
                initDefaultValues();
89
        }
90

    
91
        /** This method is called from within the constructor to
92
         * initialize the form.
93
         * WARNING: Do NOT modify this code. The content of this method is
94
         * always regenerated by the Form Editor.
95
         */
96
        // <editor-fold defaultstate="collapsed" desc=" C?digo Generado  ">                          
97
        private void initComponents() {
98
        java.awt.GridBagConstraints gridBagConstraints;
99

    
100
        upperPanel = new javax.swing.JPanel();
101
        serverPanel = new javax.swing.JPanel();
102
        serverLabel = new javax.swing.JLabel();
103
        serverCombo = new JComboServer();
104
        protocolPanel = new javax.swing.JPanel();
105
        protocolLabel = new javax.swing.JLabel();
106
        protocolCombo = new javax.swing.JComboBox();
107
        serverPropertiesButton = new javax.swing.JButton();
108
        dataBasePanel = new javax.swing.JPanel();
109
        dataBaseLabel = new javax.swing.JLabel();
110
        dataBaseText = new javax.swing.JTextField();
111
        centerPanel = new javax.swing.JPanel();
112
        jScrollPane1 = new javax.swing.JScrollPane();
113
        replyText = new javax.swing.JEditorPane();
114
        replyLabel = new javax.swing.JLabel();
115
        lowerPanel = new javax.swing.JPanel();
116
        connectButton = new javax.swing.JButton();
117
        searchButton = new javax.swing.JButton();
118
        closeButton = new javax.swing.JButton();
119

    
120
        setLayout(new java.awt.BorderLayout(0, 5));
121

    
122
        upperPanel.setLayout(new java.awt.GridBagLayout());
123

    
124
        serverPanel.setLayout(new java.awt.GridBagLayout());
125

    
126
        serverLabel.setText("jLabel1");
127
        gridBagConstraints = new java.awt.GridBagConstraints();
128
        gridBagConstraints.gridx = 0;
129
        gridBagConstraints.gridy = 0;
130
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
131
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 2, 2);
132
        serverPanel.add(serverLabel, gridBagConstraints);
133

    
134
        serverCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Art\u00edculo 1", "Art\u00edculo 2", "Art\u00edculo 3", "Art\u00edculo 4" }));
135
        gridBagConstraints = new java.awt.GridBagConstraints();
136
        gridBagConstraints.gridx = 0;
137
        gridBagConstraints.gridy = 1;
138
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
139
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
140
        gridBagConstraints.weightx = 1.0;
141
        gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 2);
142
        serverPanel.add(serverCombo, gridBagConstraints);
143

    
144
        gridBagConstraints = new java.awt.GridBagConstraints();
145
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
146
        gridBagConstraints.ipadx = 23;
147
        gridBagConstraints.ipady = 3;
148
        gridBagConstraints.weightx = 0.3;
149
        upperPanel.add(serverPanel, gridBagConstraints);
150

    
151
        protocolPanel.setLayout(new java.awt.GridBagLayout());
152

    
153
        protocolLabel.setText("jLabel1");
154
        gridBagConstraints = new java.awt.GridBagConstraints();
155
        gridBagConstraints.gridx = 0;
156
        gridBagConstraints.gridy = 0;
157
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
158
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 2, 2);
159
        protocolPanel.add(protocolLabel, gridBagConstraints);
160

    
161
        protocolCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Art\u00edculo 1", "Art\u00edculo 2", "Art\u00edculo 3", "Art\u00edculo 4" }));
162
        gridBagConstraints = new java.awt.GridBagConstraints();
163
        gridBagConstraints.gridx = 0;
164
        gridBagConstraints.gridy = 1;
165
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
166
        gridBagConstraints.weightx = 1.0;
167
        gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 4);
168
        protocolPanel.add(protocolCombo, gridBagConstraints);
169

    
170
        serverPropertiesButton.setPreferredSize(new java.awt.Dimension(25, 25));
171
        gridBagConstraints = new java.awt.GridBagConstraints();
172
        gridBagConstraints.gridx = 1;
173
        gridBagConstraints.gridy = 1;
174
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 3);
175
        protocolPanel.add(serverPropertiesButton, gridBagConstraints);
176

    
177
        gridBagConstraints = new java.awt.GridBagConstraints();
178
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
179
        gridBagConstraints.weightx = 0.3;
180
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 2);
181
        upperPanel.add(protocolPanel, gridBagConstraints);
182

    
183
        dataBasePanel.setLayout(new java.awt.GridBagLayout());
184

    
185
        dataBaseLabel.setText("jLabel1");
186
        gridBagConstraints = new java.awt.GridBagConstraints();
187
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
188
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 2, 2);
189
        dataBasePanel.add(dataBaseLabel, gridBagConstraints);
190

    
191
        dataBaseText.setText("jTextField1");
192
        gridBagConstraints = new java.awt.GridBagConstraints();
193
        gridBagConstraints.gridx = 0;
194
        gridBagConstraints.gridy = 1;
195
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
196
        gridBagConstraints.weightx = 1.0;
197
        gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 2);
198
        dataBasePanel.add(dataBaseText, gridBagConstraints);
199

    
200
        gridBagConstraints = new java.awt.GridBagConstraints();
201
        gridBagConstraints.gridx = 0;
202
        gridBagConstraints.gridy = 1;
203
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
204
        gridBagConstraints.weightx = 0.3;
205
        upperPanel.add(dataBasePanel, gridBagConstraints);
206

    
207
        add(upperPanel, java.awt.BorderLayout.NORTH);
208

    
209
        centerPanel.setLayout(new java.awt.BorderLayout(2, 4));
210

    
211
        centerPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 2, 5));
212
        jScrollPane1.setViewportView(replyText);
213

    
214
        centerPanel.add(jScrollPane1, java.awt.BorderLayout.CENTER);
215

    
216
        replyLabel.setText("jLabel1");
217
        centerPanel.add(replyLabel, java.awt.BorderLayout.NORTH);
218

    
219
        add(centerPanel, java.awt.BorderLayout.CENTER);
220

    
221
        lowerPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 5, 0));
222

    
223
        lowerPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 5, 0));
224
        connectButton.setText("jButton1");
225
        lowerPanel.add(connectButton);
226

    
227
        searchButton.setText("jButton2");
228
        lowerPanel.add(searchButton);
229

    
230
        closeButton.setText("jButton3");
231
        lowerPanel.add(closeButton);
232

    
233
        add(lowerPanel, java.awt.BorderLayout.SOUTH);
234
        }// </editor-fold>   
235

    
236
        /**
237
         * Rewrite the labels
238
         */
239
        private void initLabels(){
240
                serverLabel.setText(Messages.getText("serverURL"));
241
                protocolLabel.setText(Messages.getText("protocols"));
242
                dataBaseLabel.setText(Messages.getText("database"));
243
                replyLabel.setText(Messages.getText("serverReply"));
244
                connectButton.setText(Messages.getText("connectButton"));
245
                searchButton.setText(Messages.getText("searchButton"));
246
                closeButton.setText(Messages.getText("close"));
247
                serverPropertiesButton
248
                .setIcon(new ImageIcon("./gvSIG/extensiones/es.gva.cit.gvsig.catalogClient/images/serverProperties.png"));
249
        }
250

    
251
        /**
252
         * Initialize the default values
253
         */
254
        private void initDefaultValues(){
255
                dataBaseText.setText("");
256
                protocolCombo.removeAllItems();
257
                serverCombo.removeAllItems();
258
                serverCombo.setEditable(true);
259
                replyText.setEditable(false);
260
        }
261

    
262
        /**
263
         * Initialize the buttons size
264
         */
265
        private void initButtonSize(){
266
                connectButton.setPreferredSize(CatalogConstants.BUTTON_SIZE);
267
                searchButton.setPreferredSize(CatalogConstants.BUTTON_SIZE);
268
                closeButton.setPreferredSize(CatalogConstants.BUTTON_SIZE);
269
        }
270

    
271
        /**
272
         * Set the database panel visible
273
         * @param isVisible
274
         */
275
        protected void setDatabaseVisible(boolean isVisible){
276
                dataBaseLabel.setVisible(false);
277
                dataBaseText.setVisible(false);
278
                dataBasePanel.setVisible(false);
279
        }
280

    
281
        /**
282
         * Adds a new server
283
         * @param serverData
284
         * Server to add
285
         */
286
        public void addServer(ServerData serverData){
287
                serverCombo.addServer(serverData);
288
        }
289

    
290
        /**
291
         * Load the drivers
292
         * @param drivers
293
         */
294
        public void loadDrivers(Object[] drivers){
295
                for (int i=0 ; i<drivers.length ; i++){
296
                        protocolCombo.addItem(drivers[i]);
297
                }
298
        }
299

    
300
        /**
301
         * Select a concrete protocol
302
         * @param protocol
303
         * Protocol to select
304
         */
305
        public void setProtocol(String protocol){
306
                ICatalogServiceDriver driver = CatalogDriverRegister.getInstance().getDriver(protocol);
307
                if (driver != null){
308
                        for (int i=0 ; i<protocolCombo.getItemCount() ; i++){
309
                                IDiscoveryServiceDriver auxDriver = (IDiscoveryServiceDriver)protocolCombo.getItemAt(i);
310
                                if (auxDriver.getServiceName().toLowerCase().compareTo(driver.getServiceName().toLowerCase()) == 0){
311
                                        protocolCombo.setSelectedItem(auxDriver);
312
                                }
313
                        }
314
                }
315
        }
316
        
317
        /**
318
         * Updates the protocl combo
319
         */
320
        public void updateProtocol(){
321
                ServerData server = getServer();
322
                if (server != null){
323
                        setProtocol(server.getServiceSubType());
324
                }
325
        }
326

    
327
        /**
328
         * @return the selected server
329
         */
330
        public ServerData getServer(){
331
                return serverCombo.getSelectedServer();        
332
        }
333

    
334
        /**
335
         * @return the selected driver by protocol
336
         */
337
        public Object getDriver(){
338
                return protocolCombo.getSelectedItem();
339
        }
340

    
341
        /**
342
         * @return the server address
343
         */
344
        public String getServerAddress(){
345
                return (String) serverCombo.getSelectedServer().getServerAddress();
346
        }
347

    
348
        /**
349
         * @return the server address
350
         */
351
        public String getDatabase(){
352
                return dataBaseText.getText();
353
        }
354

    
355
        /**
356
         * Set the server reply
357
         * @param text
358
         * Text to write
359
         */
360
        public void setServerReply(String text){
361
                replyText.setText(text);
362
        }
363

    
364
        /**
365
         * Adds a listener to manage the panel events 
366
         * @param listener
367
         * Listener to add
368
         */
369
        public void addActionListener(ActionListener listener){
370
                serverCombo.addActionListener(listener);
371
                serverCombo.setActionCommand(CatalogConstants.SERVER_COMBO_ACTION_COMMAND);
372
                protocolCombo.addActionListener(listener);
373
                protocolCombo.setActionCommand(CatalogConstants.PROTOCOL_COMBO_ACTION_COMMAND);
374
                connectButton.addActionListener(listener);
375
                connectButton.setActionCommand(CatalogConstants.CONNECT_BUTTON_ACTION_COMMAND);
376
                searchButton.addActionListener(listener);
377
                searchButton.setActionCommand(CatalogConstants.SEARCH_BUTTON_ACTION_COMMAND);
378
                closeButton.addActionListener(listener);
379
                closeButton.setActionCommand(CatalogConstants.CLOSE_BUTTON_ACTION_COMMAND);
380
                serverPropertiesButton.addActionListener(listener);
381
                serverPropertiesButton.setActionCommand(CatalogConstants.SERVERPROPERTIES_BUTTON_ACTION_COMMAND);
382
                
383
        }
384

    
385
        /**
386
         * Enable or disable the search button
387
         * @param isEnabled
388
         * If the search button has to be enabled
389
         */
390
        public void enableSearchButton(boolean isEnabled){
391
                searchButton.setEnabled(isEnabled);
392
        }
393
        
394
        /**
395
         * Enable or disable the server properties button
396
         * @param isEnabled
397
         * If the search button has to be enabled
398
         */
399
        public void enableServerPropertiesButton(boolean isEnabled){
400
                serverPropertiesButton.setEnabled(isEnabled);
401
        }
402
        
403
        /**
404
         * Set visible the properties button
405
         * @param isVisible
406
         * If the properties button has to be visible
407
         */
408
        public void setServerPropertiesButtonVisible(boolean isVisible){
409
                serverPropertiesButton.setVisible(isVisible);
410
        }
411
}