Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appCatalog / src / org / gvsig / catalog / ui / serverconnect / ServerConnectPanel.java @ 28434

History | View | Annotate | Download (14 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 org.gvsig.catalog.ui.serverconnect;
43
import java.awt.event.ActionListener;
44

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

    
48
import org.gvsig.catalog.CatalogLocator;
49
import org.gvsig.catalog.CatalogManager;
50
import org.gvsig.catalog.drivers.ICatalogServiceDriver;
51
import org.gvsig.catalog.drivers.IDiscoveryServiceDriver;
52
import org.gvsig.catalog.utils.CatalogConstants;
53
import org.gvsig.i18n.Messages;
54

    
55
import com.iver.utiles.swing.jcomboServer.JComboServer;
56
import com.iver.utiles.swing.jcomboServer.ServerData;
57

    
58

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

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

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

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

    
122
        setLayout(new java.awt.BorderLayout(0, 5));
123

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

    
126
        serverPanel.setLayout(new java.awt.GridBagLayout());
127

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

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

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

    
153
        protocolPanel.setLayout(new java.awt.GridBagLayout());
154

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

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

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

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

    
185
        dataBasePanel.setLayout(new java.awt.GridBagLayout());
186

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

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

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

    
209
        add(upperPanel, java.awt.BorderLayout.NORTH);
210

    
211
        centerPanel.setLayout(new java.awt.BorderLayout(2, 4));
212

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

    
216
        centerPanel.add(jScrollPane1, java.awt.BorderLayout.CENTER);
217

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

    
221
        add(centerPanel, java.awt.BorderLayout.CENTER);
222

    
223
        lowerPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 5, 0));
224

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

    
229
        searchButton.setText("jButton2");
230
        lowerPanel.add(searchButton);
231

    
232
        closeButton.setText("jButton3");
233
        lowerPanel.add(closeButton);
234

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

    
238
        /**
239
         * Rewrite the labels
240
         */
241
        private void initLabels(){
242
                serverLabel.setText(Messages.getText("serverURL"));
243
                protocolLabel.setText(Messages.getText("protocols"));
244
                dataBaseLabel.setText(Messages.getText("database"));
245
                replyLabel.setText(Messages.getText("serverReply"));
246
                connectButton.setText(Messages.getText("connectButton"));
247
                searchButton.setText(Messages.getText("searchButton"));
248
                closeButton.setText(Messages.getText("close"));                
249
        }
250
        
251
        public void setPropertiesIcon(Icon icon){
252
                serverPropertiesButton
253
                .setIcon(icon);
254
        }
255

    
256
        /**
257
         * Initialize the default values
258
         */
259
        private void initDefaultValues(){
260
                dataBaseText.setText("");
261
                protocolCombo.removeAllItems();
262
                serverCombo.removeAllItems();
263
                serverCombo.setEditable(true);
264
                replyText.setEditable(false);
265
        }
266

    
267
        /**
268
         * Initialize the buttons size
269
         */
270
        private void initButtonSize(){
271
                connectButton.setPreferredSize(CatalogConstants.BUTTON_SIZE);
272
                searchButton.setPreferredSize(CatalogConstants.BUTTON_SIZE);
273
                closeButton.setPreferredSize(CatalogConstants.BUTTON_SIZE);
274
        }
275

    
276
        /**
277
         * Set the database panel visible
278
         * @param isVisible
279
         */
280
        protected void setDatabaseVisible(boolean isVisible){
281
                dataBaseLabel.setVisible(false);
282
                dataBaseText.setVisible(false);
283
                dataBasePanel.setVisible(false);
284
        }
285

    
286
        /**
287
         * Adds a new server
288
         * @param serverData
289
         * Server to add
290
         */
291
        public void addServer(ServerData serverData){
292
                serverCombo.addServer(serverData);
293
        }
294

    
295
        /**
296
         * Load the drivers
297
         * @param drivers
298
         */
299
        public void loadDrivers(Object[] drivers){
300
                for (int i=0 ; i<drivers.length ; i++){
301
                        protocolCombo.addItem(drivers[i]);
302
                }
303
        }
304

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

    
332
        /**
333
         * @return the selected server
334
         */
335
        public ServerData getServer(){
336
                return serverCombo.getSelectedServer();        
337
        }
338
        
339
        public ServerData[] getAllServers(){
340
                return serverCombo.getAllServers();
341
        }
342

    
343
        /**
344
         * @return the selected driver by protocol
345
         */
346
        public Object getDriver(){
347
                return protocolCombo.getSelectedItem();
348
        }
349

    
350
        /**
351
         * @return the server address
352
         */
353
        public String getServerAddress(){
354
                return (String) serverCombo.getSelectedServer().getServerAddress();
355
        }
356

    
357
        /**
358
         * @return the server address
359
         */
360
        public String getDatabase(){
361
                return dataBaseText.getText();
362
        }
363

    
364
        /**
365
         * Set the server reply
366
         * @param text
367
         * Text to write
368
         */
369
        public void setServerReply(String text){
370
                replyText.setText(text);
371
        }
372

    
373
        /**
374
         * Adds a listener to manage the panel events 
375
         * @param listener
376
         * Listener to add
377
         */
378
        public void addActionListener(ActionListener listener){
379
                serverCombo.addActionListener(listener);
380
                serverCombo.setActionCommand(CatalogConstants.SERVER_COMBO_ACTION_COMMAND);
381
                protocolCombo.addActionListener(listener);
382
                protocolCombo.setActionCommand(CatalogConstants.PROTOCOL_COMBO_ACTION_COMMAND);
383
                connectButton.addActionListener(listener);
384
                connectButton.setActionCommand(CatalogConstants.CONNECT_BUTTON_ACTION_COMMAND);
385
                searchButton.addActionListener(listener);
386
                searchButton.setActionCommand(CatalogConstants.SEARCH_BUTTON_ACTION_COMMAND);
387
                closeButton.addActionListener(listener);
388
                closeButton.setActionCommand(CatalogConstants.CLOSE_BUTTON_ACTION_COMMAND);
389
                serverPropertiesButton.addActionListener(listener);
390
                serverPropertiesButton.setActionCommand(CatalogConstants.SERVERPROPERTIES_BUTTON_ACTION_COMMAND);
391
                
392
        }
393

    
394
        /**
395
         * Enable or disable the search button
396
         * @param isEnabled
397
         * If the search button has to be enabled
398
         */
399
        public void enableSearchButton(boolean isEnabled){
400
                searchButton.setEnabled(isEnabled);
401
        }
402
        
403
        /**
404
         * Enable or disable the server properties button
405
         * @param isEnabled
406
         * If the search button has to be enabled
407
         */
408
        public void enableServerPropertiesButton(boolean isEnabled){
409
                serverPropertiesButton.setEnabled(isEnabled);
410
        }
411
        
412
        /**
413
         * Set visible the properties button
414
         * @param isVisible
415
         * If the properties button has to be visible
416
         */
417
        public void setServerPropertiesButtonVisible(boolean isVisible){
418
                serverPropertiesButton.setVisible(isVisible);
419
        }
420
        
421
        public void setServerTextEnabled(boolean isEnabled){
422
                serverCombo.setEnabled(isEnabled);
423
        }
424
}