root / trunk / extensions / extPublish / src / org / gvsig / publish / gui / selectServer / SelectServerPanel.java @ 29308
History | View | Annotate | Download (9.87 KB)
1 |
/* 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 |
package org.gvsig.publish.gui.selectServer; |
42 |
|
43 |
|
44 |
import java.awt.event.ActionListener; |
45 |
import java.util.ArrayList; |
46 |
import java.util.EventListener; |
47 |
import java.util.Iterator; |
48 |
|
49 |
import javax.swing.JOptionPane; |
50 |
import javax.swing.JPanel; |
51 |
|
52 |
import org.gvsig.gui.beans.swing.JButton; |
53 |
import org.gvsig.publish.PublishRegister; |
54 |
|
55 |
import com.iver.andami.PluginServices; |
56 |
import com.iver.andami.persistence.serverData.ServerDataPersistence; |
57 |
import com.iver.utiles.swing.jcomboServer.JComboServer; |
58 |
import com.iver.utiles.swing.jcomboServer.ServerData; |
59 |
|
60 |
/**
|
61 |
* GUI for server and service selection
|
62 |
*
|
63 |
* @author jvhigon
|
64 |
*
|
65 |
*/
|
66 |
|
67 |
public class SelectServerPanel extends JPanel { |
68 |
|
69 |
/**
|
70 |
* Constructor
|
71 |
*/
|
72 |
public SelectServerPanel(){
|
73 |
super();
|
74 |
initComponents(); |
75 |
initCombos(); |
76 |
initLabels(); |
77 |
} |
78 |
private void initLabels(){ |
79 |
acceptButton.setText(PluginServices.getText(this,"publish_accept")); |
80 |
cancelButton.setText(PluginServices.getText(this,"publish_cancel")); |
81 |
selectionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(PluginServices.getText(this,"publish_select_server"))); |
82 |
labelservice.setText(PluginServices.getText(this,"publish_service")); |
83 |
labelurl.setText(PluginServices.getText(this, "publish_url")); |
84 |
labelserver.setText(PluginServices.getText(this, "publish_server")); |
85 |
} |
86 |
private void initComponents() { |
87 |
java.awt.GridBagConstraints gridBagConstraints; |
88 |
|
89 |
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 |
|
100 |
setLayout(new java.awt.BorderLayout());
|
101 |
|
102 |
buttonsPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
|
103 |
|
104 |
|
105 |
buttonsPanel.add(acceptButton); |
106 |
|
107 |
|
108 |
buttonsPanel.add(cancelButton); |
109 |
|
110 |
add(buttonsPanel, java.awt.BorderLayout.SOUTH); |
111 |
|
112 |
selectionPanel.setLayout(new java.awt.GridBagLayout());
|
113 |
|
114 |
|
115 |
|
116 |
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 |
|
122 |
|
123 |
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 |
|
130 |
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 |
|
139 |
|
140 |
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 |
|
147 |
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 |
|
156 |
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 |
|
167 |
add(selectionPanel, java.awt.BorderLayout.CENTER); |
168 |
|
169 |
}// </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 |
/**
|
186 |
* sets the listener for all the actions in the panel
|
187 |
*/
|
188 |
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 |
cancelButton.setActionCommand(SelectServerController.NEWSERVER_EVENT_CANCEL); |
194 |
serverurlcombo.addActionListener((ActionListener)listener);
|
195 |
serverurlcombo.setActionCommand(SelectServerController.COMBOSERVERURL_EVENT_CHANGE); |
196 |
servercombo.addActionListener((ActionListener)listener);
|
197 |
servercombo.setActionCommand(SelectServerController.COMBOSERVER_EVENT_CHANGE); |
198 |
} |
199 |
/**
|
200 |
* initialize combos
|
201 |
*/
|
202 |
public void initCombos(){ |
203 |
//remove items
|
204 |
servercombo.removeAllItems(); |
205 |
servicecombo.removeAllItems(); |
206 |
serverurlcombo.removeAllItems(); |
207 |
|
208 |
//initialize servercombo
|
209 |
initServerCombo(); |
210 |
|
211 |
ArrayList set = PublishRegister.register().getServerNames();
|
212 |
if (set == null){ |
213 |
JOptionPane.showMessageDialog(this, |
214 |
PluginServices.getText(this, "publish_no_servers_available"), |
215 |
PluginServices.getText(this,"ERROR"), |
216 |
JOptionPane.ERROR_MESSAGE);
|
217 |
return;
|
218 |
} |
219 |
Iterator i = set.iterator();
|
220 |
while (i.hasNext()){
|
221 |
servercombo.addItem(i.next()); |
222 |
} |
223 |
//initialice servicecombo
|
224 |
set = PublishRegister.register().getServicesNames(servercombo.getSelectedItem().toString()); |
225 |
i = set.iterator(); |
226 |
while (i.hasNext()){
|
227 |
servicecombo.addItem(i.next()); |
228 |
} |
229 |
} |
230 |
|
231 |
/**
|
232 |
* Initializes the serverComboURL with the saved servers
|
233 |
*/
|
234 |
private void initServerCombo(){ |
235 |
ServerDataPersistence persistence = new ServerDataPersistence(this,"publish_server_data"); |
236 |
ServerData[] servers = persistence.getArrayOfServerData();
|
237 |
|
238 |
for (int i=0 ; i<servers.length ; i++){ |
239 |
persistence.addServerData(servers[i]); |
240 |
} |
241 |
persistence.setPersistent(); |
242 |
serverurlcombo.setServerList(servers); |
243 |
} |
244 |
|
245 |
/**
|
246 |
* Saves the current selected server in the Andami
|
247 |
* persistence system
|
248 |
*/
|
249 |
protected void saveCurrentServer() { |
250 |
String host = null; |
251 |
Object obj = serverurlcombo.getSelectedItem();
|
252 |
if (obj instanceof ServerData){ |
253 |
host = ((ServerData)obj).getServerAddress(); |
254 |
}else{
|
255 |
host = ((String)obj).trim();
|
256 |
} |
257 |
String server = ((String)servercombo.getSelectedItem()); |
258 |
String service = ((String)servicecombo.getSelectedItem()); |
259 |
|
260 |
ServerDataPersistence persistence = new ServerDataPersistence(this,"publish_server_data"); |
261 |
persistence.addServerData(new ServerData(host, server, service));
|
262 |
} |
263 |
|
264 |
/**
|
265 |
* Updates the server and the service combo with the
|
266 |
* selected server url
|
267 |
*/
|
268 |
protected void updateCombos(){ |
269 |
ServerData server = serverurlcombo.getSelectedServer(); |
270 |
//Sets the server
|
271 |
for (int i=0 ; i<servercombo.getItemCount() ; i++){ |
272 |
if (server.getServiceType().compareTo(((String)servercombo.getSelectedItem()).toUpperCase()) == 0){ |
273 |
servercombo.setSelectedIndex(i); |
274 |
break;
|
275 |
} |
276 |
} |
277 |
//Sets the service
|
278 |
for (int i=0 ; i<servicecombo.getItemCount() ; i++){ |
279 |
if (server.getServiceSubType().compareTo(((String)servicecombo.getSelectedItem()).toUpperCase()) == 0){ |
280 |
servicecombo.setSelectedIndex(i); |
281 |
break;
|
282 |
} |
283 |
} |
284 |
} |
285 |
/**
|
286 |
* Updates the service combo when you select a server
|
287 |
*/
|
288 |
public void updateServiceCombo() { |
289 |
servicecombo.removeAllItems(); |
290 |
ArrayList set = PublishRegister.register().getServicesNames(servercombo.getSelectedItem().toString());
|
291 |
Iterator i = set.iterator();
|
292 |
while (i.hasNext()){
|
293 |
servicecombo.addItem(i.next()); |
294 |
} |
295 |
} |
296 |
|
297 |
|
298 |
public String getSelectedServer(){ |
299 |
return servercombo.getSelectedItem().toString();
|
300 |
} |
301 |
public String getSelectedService(){ |
302 |
return servicecombo.getSelectedItem().toString();
|
303 |
} |
304 |
public String getSelectedURL(){ |
305 |
return serverurlcombo.getSelectedItem().toString();
|
306 |
} |
307 |
} |