Statistics
| Revision:

svn-gvsig-desktop / branches / CatalogYNomenclator_v1_1_0_1005 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / ui / serverconnect / ServerConnectPanel.java @ 12758

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

    
45
import javax.swing.JPanel;
46

    
47
import org.gvsig.i18n.Messages;
48

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

    
52
import es.gva.cit.catalogClient.drivers.ICatalogServiceDriver;
53
import es.gva.cit.catalogClient.utils.CatalogDriverRegister;
54
import es.gva.cit.catalogClient.utils.CatalogConstants;
55

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

    
80
        /** Creates new form ServerConnectPanel */
81
        public ServerConnectPanel() {
82
                initComponents();
83
                initLabels();
84
                initButtonSize();        
85
                initDefaultValues();
86
        }
87

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

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

    
116
                setLayout(new java.awt.BorderLayout(0, 5));
117

    
118
                upperPanel.setLayout(new java.awt.GridBagLayout());
119

    
120
                serverPanel.setLayout(new java.awt.GridBagLayout());
121

    
122
                serverLabel.setText("jLabel1");
123
                gridBagConstraints = new java.awt.GridBagConstraints();
124
                gridBagConstraints.gridx = 0;
125
                gridBagConstraints.gridy = 0;
126
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
127
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 2, 2);
128
                serverPanel.add(serverLabel, gridBagConstraints);
129

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

    
140
                gridBagConstraints = new java.awt.GridBagConstraints();
141
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
142
                gridBagConstraints.ipadx = 23;
143
                gridBagConstraints.ipady = 3;
144
                gridBagConstraints.weightx = 0.3;
145
                upperPanel.add(serverPanel, gridBagConstraints);
146

    
147
                protocolPanel.setLayout(new java.awt.GridBagLayout());
148

    
149
                protocolLabel.setText("jLabel1");
150
                gridBagConstraints = new java.awt.GridBagConstraints();
151
                gridBagConstraints.gridx = 0;
152
                gridBagConstraints.gridy = 0;
153
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
154
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 2, 2);
155
                protocolPanel.add(protocolLabel, gridBagConstraints);
156

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

    
166
                gridBagConstraints = new java.awt.GridBagConstraints();
167
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
168
                gridBagConstraints.weightx = 0.3;
169
                gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 2);
170
                upperPanel.add(protocolPanel, gridBagConstraints);
171

    
172
                dataBasePanel.setLayout(new java.awt.GridBagLayout());
173

    
174
                dataBaseLabel.setText("jLabel1");
175
                gridBagConstraints = new java.awt.GridBagConstraints();
176
                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
177
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 2, 2);
178
                dataBasePanel.add(dataBaseLabel, gridBagConstraints);
179

    
180
                dataBaseText.setText("jTextField1");
181
                gridBagConstraints = new java.awt.GridBagConstraints();
182
                gridBagConstraints.gridx = 0;
183
                gridBagConstraints.gridy = 1;
184
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
185
                gridBagConstraints.weightx = 1.0;
186
                gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 2);
187
                dataBasePanel.add(dataBaseText, gridBagConstraints);
188

    
189
                gridBagConstraints = new java.awt.GridBagConstraints();
190
                gridBagConstraints.gridx = 0;
191
                gridBagConstraints.gridy = 1;
192
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
193
                gridBagConstraints.weightx = 0.3;
194
                upperPanel.add(dataBasePanel, gridBagConstraints);
195

    
196
                add(upperPanel, java.awt.BorderLayout.NORTH);
197

    
198
                centerPanel.setLayout(new java.awt.BorderLayout(2, 4));
199

    
200
                centerPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 2, 5));
201
                jScrollPane1.setViewportView(replyText);
202

    
203
                centerPanel.add(jScrollPane1, java.awt.BorderLayout.CENTER);
204

    
205
                replyLabel.setText("jLabel1");
206
                centerPanel.add(replyLabel, java.awt.BorderLayout.NORTH);
207

    
208
                add(centerPanel, java.awt.BorderLayout.CENTER);
209

    
210
                lowerPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 5, 0));
211

    
212
                lowerPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 5, 0));
213
                connectButton.setText("jButton1");
214
                lowerPanel.add(connectButton);
215

    
216
                searchButton.setText("jButton2");
217
                lowerPanel.add(searchButton);
218

    
219
                closeButton.setText("jButton3");
220
                lowerPanel.add(closeButton);
221

    
222
                add(lowerPanel, java.awt.BorderLayout.SOUTH);
223
        }// </editor-fold>   
224

    
225
        /**
226
         * Rewrite the labels
227
         */
228
        private void initLabels(){
229
                serverLabel.setText(Messages.getText("serverURLCat"));
230
                protocolLabel.setText(Messages.getText("protocols"));
231
                dataBaseLabel.setText(Messages.getText("database"));
232
                replyLabel.setText(Messages.getText("serverReply"));
233
                connectButton.setText(Messages.getText("connectButton"));
234
                searchButton.setText(Messages.getText("searchButton"));
235
                closeButton.setText(Messages.getText("close"));
236
        }
237
        
238
        /**
239
         * Initialize the default values
240
         */
241
        private void initDefaultValues(){
242
                dataBaseText.setText("");
243
                protocolCombo.removeAllItems();
244
                serverCombo.removeAllItems();
245
                serverCombo.setEditable(true);
246
        }
247

    
248
        /**
249
         * Initialize the buttons size
250
         */
251
        private void initButtonSize(){
252
                connectButton.setPreferredSize(CatalogConstants.BUTTON_SIZE);
253
                searchButton.setPreferredSize(CatalogConstants.BUTTON_SIZE);
254
                closeButton.setPreferredSize(CatalogConstants.BUTTON_SIZE);
255
        }
256

    
257
        /**
258
         * Set the database panel visible
259
         * @param isVisible
260
         */
261
        protected void setDatabaseVisible(boolean isVisible){
262
                dataBaseLabel.setVisible(false);
263
                dataBaseText.setVisible(false);
264
                dataBasePanel.setVisible(false);
265
        }
266
        
267
        /**
268
         * Adds a new server
269
         * @param serverData
270
         * Server to add
271
         */
272
        public void addServer(ServerData serverData){
273
                serverCombo.addItem(serverData);
274
        }
275

    
276
        /**
277
         * Load the drivers
278
         * @param drivers
279
         */
280
        public void loadDrivers(Object[] drivers){
281
                for (int i=0 ; i<drivers.length ; i++){
282
                        protocolCombo.addItem(drivers[i]);
283
                }
284
        }
285

    
286
        /**
287
         * Select a concrete protocol
288
         * @param protocol
289
         * Protocol to select
290
         */
291
        public void setProtocol(String protocol){
292
                ICatalogServiceDriver driver = CatalogDriverRegister.getInstance().getDriver(protocol);
293
                if (driver != null){
294
                        protocolCombo.setSelectedItem(driver);
295
                }
296
        }
297

    
298
        /**
299
         * @return the selected server
300
         */
301
        public ServerData getServer(){
302
                return serverCombo.getSelectedServer();        
303
        }
304

    
305
        /**
306
         * @return the selected driver by protocol
307
         */
308
        public Object getDriver(){
309
                return protocolCombo.getSelectedItem();
310
        }
311

    
312
        /**
313
         * @return the server address
314
         */
315
        public String getServerAddress(){
316
                return (String) serverCombo.getSelectedServer().getServerAddress();
317
        }
318
        
319
        /**
320
         * @return the server address
321
         */
322
        public String getDatabase(){
323
                return dataBaseText.getText();
324
        }
325

    
326
        /**
327
         * Set the server reply
328
         * @param text
329
         * Text to write
330
         */
331
        public void setServerReply(String text){
332
                replyText.setText(text);
333
        }
334

    
335
        /**
336
         * Adds a listener to manage the panel events 
337
         * @param listener
338
         * Listener to add
339
         */
340
        public void addActionListener(ActionListener listener){
341
                serverCombo.addActionListener(listener);
342
                serverCombo.setActionCommand(CatalogConstants.PROTOCOL_COMBO_ACTION_COMMAND);
343
                connectButton.addActionListener(listener);
344
                connectButton.setActionCommand(CatalogConstants.CONNECT_BUTTON_ACTION_COMMAND);
345
                searchButton.addActionListener(listener);
346
                searchButton.setActionCommand(CatalogConstants.SEARCH_BUTTON_ACTION_COMMAND);
347
                closeButton.addActionListener(listener);
348
                closeButton.setActionCommand(CatalogConstants.CLOSE_BUTTON_ACTION_COMMAND);
349
        }
350

    
351
        /**
352
         * Enable or disable the search button
353
         * @param isEnabled
354
         * If the search button has to be enabled
355
         */
356
        public void enableSearchButton(boolean isEnabled){
357
                searchButton.setEnabled(isEnabled);
358
        }
359
}