root / branches / v10 / extensions / extPublish / src / org / gvsig / publish / gui / selectServer / SelectServerPanel.java @ 19419
History | View | Annotate | Download (9.61 KB)
1 | 13962 | jvhigon | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004-2006 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 Iba?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 | 14227 | jvhigon | package org.gvsig.publish.gui.selectServer; |
42 | 13962 | jvhigon | |
43 | 14376 | jvhigon | |
44 | 13962 | jvhigon | import java.awt.event.ActionListener; |
45 | 14404 | jvhigon | import java.util.ArrayList; |
46 | 13962 | jvhigon | import java.util.EventListener; |
47 | 14376 | jvhigon | import java.util.Iterator; |
48 | 13962 | jvhigon | |
49 | import javax.swing.JPanel; |
||
50 | |||
51 | 14376 | jvhigon | import org.gvsig.gui.beans.swing.JButton; |
52 | import org.gvsig.publish.PublishRegister; |
||
53 | 16215 | jvhigon | import org.gvsig.publish.serversmodel.Server; |
54 | 13962 | jvhigon | |
55 | 17788 | jvhigon | import com.iver.andami.PluginServices; |
56 | 14408 | jpiera | import com.iver.andami.persistence.serverData.ServerDataPersistence; |
57 | 14376 | jvhigon | import com.iver.utiles.swing.jcomboServer.JComboServer; |
58 | 14408 | jpiera | import com.iver.utiles.swing.jcomboServer.ServerData; |
59 | 13962 | jvhigon | |
60 | 19419 | jvhigon | /**
|
61 | * GUI for server and service selection
|
||
62 | *
|
||
63 | * @author jvhigon
|
||
64 | *
|
||
65 | */
|
||
66 | 14376 | jvhigon | |
67 | public class SelectServerPanel extends JPanel { |
||
68 | 14408 | jpiera | |
69 | 13962 | jvhigon | /**
|
70 | 14376 | jvhigon | * Constructor
|
71 | 13962 | jvhigon | */
|
72 | 14376 | jvhigon | public SelectServerPanel(){
|
73 | 13962 | jvhigon | super();
|
74 | 14376 | jvhigon | initComponents(); |
75 | initCombos(); |
||
76 | 17788 | jvhigon | initLabels(); |
77 | 13962 | jvhigon | } |
78 | 17788 | jvhigon | private void initLabels(){ |
79 | acceptButton.setText(PluginServices.getText(this,"accept")); |
||
80 | cancelButton.setText(PluginServices.getText(this,"cancel")); |
||
81 | selectionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(PluginServices.getText(this,"select_server"))); |
||
82 | labelservice.setText(PluginServices.getText(this,"service")); |
||
83 | labelurl.setText(PluginServices.getText(this, "url")); |
||
84 | labelserver.setText(PluginServices.getText(this, "server")); |
||
85 | } |
||
86 | 14376 | jvhigon | private void initComponents() { |
87 | 14408 | jpiera | java.awt.GridBagConstraints gridBagConstraints; |
88 | 14376 | jvhigon | |
89 | 14408 | jpiera | buttonsPanel = new javax.swing.JPanel();
|
90 | acceptButton = new JButton(); |
||
91 | cancelButton = new JButton(); |
||
92 | selectionPanel = new javax.swing.JPanel();
|
||
93 | labelservice = new javax.swing.JLabel();
|
||
94 | labelserver = new javax.swing.JLabel();
|
||
95 | servercombo = new javax.swing.JComboBox();
|
||
96 | labelurl = new javax.swing.JLabel();
|
||
97 | servicecombo = new javax.swing.JComboBox();
|
||
98 | serverurlcombo = new JComboServer();
|
||
99 | 14376 | jvhigon | |
100 | 14408 | jpiera | setLayout(new java.awt.BorderLayout());
|
101 | 14376 | jvhigon | |
102 | 14408 | jpiera | buttonsPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
|
103 | 14376 | jvhigon | |
104 | 17788 | jvhigon | |
105 | 14408 | jpiera | buttonsPanel.add(acceptButton); |
106 | 14376 | jvhigon | |
107 | 17788 | jvhigon | |
108 | 14408 | jpiera | buttonsPanel.add(cancelButton); |
109 | 14376 | jvhigon | |
110 | 14408 | jpiera | add(buttonsPanel, java.awt.BorderLayout.SOUTH); |
111 | 14376 | jvhigon | |
112 | 14408 | jpiera | selectionPanel.setLayout(new java.awt.GridBagLayout());
|
113 | 14376 | jvhigon | |
114 | 17788 | jvhigon | |
115 | |||
116 | 14408 | jpiera | gridBagConstraints = new java.awt.GridBagConstraints();
|
117 | gridBagConstraints.gridx = 2;
|
||
118 | gridBagConstraints.gridy = 1;
|
||
119 | gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); |
||
120 | selectionPanel.add(labelservice, gridBagConstraints); |
||
121 | 14376 | jvhigon | |
122 | 17788 | jvhigon | |
123 | 14408 | jpiera | gridBagConstraints = new java.awt.GridBagConstraints();
|
124 | gridBagConstraints.gridx = 0;
|
||
125 | gridBagConstraints.gridy = 1;
|
||
126 | gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; |
||
127 | gridBagConstraints.insets = new java.awt.Insets(2, 5, 5, 2); |
||
128 | selectionPanel.add(labelserver, gridBagConstraints); |
||
129 | 14376 | jvhigon | |
130 | 14408 | jpiera | servercombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); |
131 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
132 | gridBagConstraints.gridx = 1;
|
||
133 | gridBagConstraints.gridy = 1;
|
||
134 | gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
||
135 | gridBagConstraints.weightx = 0.5;
|
||
136 | gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); |
||
137 | selectionPanel.add(servercombo, gridBagConstraints); |
||
138 | 14376 | jvhigon | |
139 | 17788 | jvhigon | |
140 | 14408 | jpiera | gridBagConstraints = new java.awt.GridBagConstraints();
|
141 | gridBagConstraints.gridx = 0;
|
||
142 | gridBagConstraints.gridy = 0;
|
||
143 | gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; |
||
144 | gridBagConstraints.insets = new java.awt.Insets(5, 5, 2, 2); |
||
145 | selectionPanel.add(labelurl, gridBagConstraints); |
||
146 | 14376 | jvhigon | |
147 | 14408 | jpiera | servicecombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); |
148 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
149 | gridBagConstraints.gridx = 3;
|
||
150 | gridBagConstraints.gridy = 1;
|
||
151 | gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
||
152 | gridBagConstraints.weightx = 0.5;
|
||
153 | gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 5); |
||
154 | selectionPanel.add(servicecombo, gridBagConstraints); |
||
155 | 14376 | jvhigon | |
156 | 14408 | jpiera | serverurlcombo.setEditable(true);
|
157 | serverurlcombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); |
||
158 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
159 | gridBagConstraints.gridx = 1;
|
||
160 | gridBagConstraints.gridy = 0;
|
||
161 | gridBagConstraints.gridwidth = 3;
|
||
162 | gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
||
163 | gridBagConstraints.weightx = 1.0;
|
||
164 | gridBagConstraints.insets = new java.awt.Insets(5, 2, 2, 5); |
||
165 | selectionPanel.add(serverurlcombo, gridBagConstraints); |
||
166 | 14376 | jvhigon | |
167 | 14408 | jpiera | add(selectionPanel, java.awt.BorderLayout.CENTER); |
168 | 14376 | jvhigon | |
169 | 14408 | jpiera | }// </editor-fold>
|
170 | |||
171 | |||
172 | // Variables declaration - do not modify
|
||
173 | private JButton acceptButton; |
||
174 | private javax.swing.JPanel buttonsPanel;
|
||
175 | private JButton cancelButton; |
||
176 | private javax.swing.JLabel labelserver;
|
||
177 | private javax.swing.JLabel labelservice;
|
||
178 | private javax.swing.JLabel labelurl;
|
||
179 | private javax.swing.JPanel selectionPanel;
|
||
180 | private javax.swing.JComboBox servercombo;
|
||
181 | private JComboServer serverurlcombo;
|
||
182 | private javax.swing.JComboBox servicecombo;
|
||
183 | // End of variables declaration
|
||
184 | |||
185 | 19419 | jvhigon | /**
|
186 | * sets the listener for all the actions in the panel
|
||
187 | */
|
||
188 | 14376 | jvhigon | public void setListener(EventListener listener) { |
189 | //set listener into the buttons
|
||
190 | acceptButton.addActionListener((ActionListener)listener);
|
||
191 | acceptButton.setActionCommand(SelectServerController.NEWSERVER_EVENT_ACCEPT); |
||
192 | cancelButton.addActionListener((ActionListener)listener);
|
||
193 | 14408 | jpiera | cancelButton.setActionCommand(SelectServerController.NEWSERVER_EVENT_CANCEL); |
194 | serverurlcombo.addActionListener((ActionListener)listener);
|
||
195 | 19419 | jvhigon | serverurlcombo.setActionCommand(SelectServerController.COMBOSERVERURL_EVENT_CHANGE); |
196 | servercombo.addActionListener((ActionListener)listener);
|
||
197 | servercombo.setActionCommand(SelectServerController.COMBOSERVER_EVENT_CHANGE); |
||
198 | 13962 | jvhigon | } |
199 | 19419 | jvhigon | /**
|
200 | * initialize combos
|
||
201 | */
|
||
202 | 14376 | jvhigon | public void initCombos(){ |
203 | //remove items
|
||
204 | servercombo.removeAllItems(); |
||
205 | servicecombo.removeAllItems(); |
||
206 | serverurlcombo.removeAllItems(); |
||
207 | 14404 | jvhigon | |
208 | 14376 | jvhigon | //initialize servercombo
|
209 | 14408 | jpiera | initServerCombo(); |
210 | |||
211 | ArrayList set = PublishRegister.register().getServerNames();
|
||
212 | Iterator i = set.iterator();
|
||
213 | while (i.hasNext()){
|
||
214 | servercombo.addItem(i.next()); |
||
215 | } |
||
216 | //initialice servicecombo
|
||
217 | set = PublishRegister.register().getServicesNames(servercombo.getSelectedItem().toString()); |
||
218 | i = set.iterator(); |
||
219 | while (i.hasNext()){
|
||
220 | servicecombo.addItem(i.next()); |
||
221 | } |
||
222 | } |
||
223 | |||
224 | /**
|
||
225 | 19419 | jvhigon | * Initializes the serverComboURL with the saved servers
|
226 | 14408 | jpiera | */
|
227 | private void initServerCombo(){ |
||
228 | ServerDataPersistence persistence = new ServerDataPersistence(this,Server.PUBLISH_SERVERS); |
||
229 | ServerData[] servers = persistence.getArrayOfServerData();
|
||
230 | |||
231 | for (int i=0 ; i<servers.length ; i++){ |
||
232 | persistence.addServerData(servers[i]); |
||
233 | } |
||
234 | persistence.setPersistent(); |
||
235 | serverurlcombo.setServerList(servers); |
||
236 | } |
||
237 | |||
238 | /**
|
||
239 | * Saves the current selected server in the Andami
|
||
240 | * persistence system
|
||
241 | */
|
||
242 | protected void saveCurrentServer() { |
||
243 | String host = null; |
||
244 | Object obj = serverurlcombo.getSelectedItem();
|
||
245 | if (obj instanceof ServerData){ |
||
246 | host = ((ServerData)obj).getServerAddress(); |
||
247 | }else{
|
||
248 | host = ((String)obj).trim();
|
||
249 | } |
||
250 | String server = ((String)servercombo.getSelectedItem()); |
||
251 | String service = ((String)servicecombo.getSelectedItem()); |
||
252 | 14404 | jvhigon | |
253 | 14408 | jpiera | ServerDataPersistence persistence = new ServerDataPersistence(this,Server.PUBLISH_SERVERS); |
254 | persistence.addServerData(new ServerData(host, server, service));
|
||
255 | 13962 | jvhigon | } |
256 | |||
257 | 14408 | jpiera | /**
|
258 | 19419 | jvhigon | * Updates the server and the service combo with the
|
259 | * selected server url
|
||
260 | 14408 | jpiera | */
|
261 | protected void updateCombos(){ |
||
262 | ServerData server = serverurlcombo.getSelectedServer(); |
||
263 | //Sets the server
|
||
264 | for (int i=0 ; i<servercombo.getItemCount() ; i++){ |
||
265 | if (server.getServiceType().compareTo(((String)servercombo.getSelectedItem()).toUpperCase()) == 0){ |
||
266 | servercombo.setSelectedIndex(i); |
||
267 | break;
|
||
268 | } |
||
269 | } |
||
270 | //Sets the service
|
||
271 | for (int i=0 ; i<servicecombo.getItemCount() ; i++){ |
||
272 | if (server.getServiceSubType().compareTo(((String)servicecombo.getSelectedItem()).toUpperCase()) == 0){ |
||
273 | servicecombo.setSelectedIndex(i); |
||
274 | break;
|
||
275 | } |
||
276 | } |
||
277 | } |
||
278 | 19419 | jvhigon | /**
|
279 | * Updates the service combo when you select a server
|
||
280 | */
|
||
281 | public void updateServiceCombo() { |
||
282 | servicecombo.removeAllItems(); |
||
283 | ArrayList set = PublishRegister.register().getServicesNames(servercombo.getSelectedItem().toString());
|
||
284 | Iterator i = set.iterator();
|
||
285 | while (i.hasNext()){
|
||
286 | servicecombo.addItem(i.next()); |
||
287 | } |
||
288 | } |
||
289 | |||
290 | 14408 | jpiera | |
291 | 13962 | jvhigon | public String getSelectedServer(){ |
292 | 14376 | jvhigon | return servercombo.getSelectedItem().toString();
|
293 | 13962 | jvhigon | } |
294 | public String getSelectedService(){ |
||
295 | 14376 | jvhigon | return servicecombo.getSelectedItem().toString();
|
296 | 13962 | jvhigon | } |
297 | 14376 | jvhigon | public String getSelectedURL(){ |
298 | return serverurlcombo.getSelectedItem().toString();
|
||
299 | } |
||
300 | 13962 | jvhigon | } |