gvsig-publish / org.gvsig.publish / trunk / org.gvsig.publish / org.gvsig.publish.swing / org.gvsig.publish.swing.impl / src / main / java / org / gvsig / publish / swing / impl / gui / DefaultJPublishPanel.java @ 123
History | View | Annotate | Download (13.7 KB)
1 |
package org.gvsig.publish.swing.impl.gui; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.FlowLayout; |
6 |
import java.awt.event.ActionEvent; |
7 |
import java.awt.event.ActionListener; |
8 |
import java.io.File; |
9 |
import java.io.IOException; |
10 |
import java.security.SecureRandom; |
11 |
import java.security.cert.CertificateException; |
12 |
import java.security.cert.X509Certificate; |
13 |
import java.util.ArrayList; |
14 |
import java.util.Iterator; |
15 |
import java.util.List; |
16 |
|
17 |
import javax.net.ssl.SSLContext; |
18 |
import javax.net.ssl.TrustManager; |
19 |
import javax.net.ssl.X509TrustManager; |
20 |
import javax.swing.BoxLayout; |
21 |
import javax.swing.JButton; |
22 |
import javax.swing.JCheckBox; |
23 |
import javax.swing.JDialog; |
24 |
import javax.swing.JOptionPane; |
25 |
import javax.swing.JPanel; |
26 |
import javax.swing.JTabbedPane; |
27 |
import javax.swing.border.EmptyBorder; |
28 |
import javax.swing.border.TitledBorder; |
29 |
|
30 |
import org.apache.commons.lang.StringUtils; |
31 |
import org.apache.http.conn.ssl.SSLSocketFactory; |
32 |
import org.gvsig.andami.PluginServices; |
33 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
34 |
import org.gvsig.publish.PublishProperties; |
35 |
import org.gvsig.publish.swing.PublishSwingManager; |
36 |
import org.gvsig.publish.swing.gui.JPublishOptionPanel; |
37 |
import org.gvsig.publish.swing.gui.JPublishPanel; |
38 |
import org.gvsig.publish.swing.impl.gui.panels.JGeneralOptionsPanel; |
39 |
import org.gvsig.publish.swing.impl.gui.panels.JMapCacheOptionsPanel; |
40 |
import org.gvsig.publish.swing.impl.gui.panels.JMapProxyOptionsPanel; |
41 |
import org.gvsig.publish.swing.impl.gui.panels.JPublishRemoteOptionsPanel; |
42 |
import org.gvsig.publish.swing.impl.gui.panels.JServiceOptionsPanel; |
43 |
import org.gvsig.publish.swing.impl.gui.panels.JTinyOWSOptionsPanel; |
44 |
import org.gvsig.publish.swing.impl.gui.utils.JFileField; |
45 |
import org.gvsig.tools.ToolsLocator; |
46 |
import org.gvsig.tools.i18n.I18nManager; |
47 |
import org.gvsig.tools.observer.Observable; |
48 |
import org.gvsig.tools.observer.Observer; |
49 |
import org.slf4j.Logger; |
50 |
import org.slf4j.LoggerFactory; |
51 |
|
52 |
import com.googlecode.sardine.Sardine; |
53 |
import com.googlecode.sardine.impl.SardineImpl; |
54 |
|
55 |
public class DefaultJPublishPanel extends JPanel implements JPublishPanel, Observer{ |
56 |
|
57 |
/**
|
58 |
*
|
59 |
*/
|
60 |
private static final long serialVersionUID = -7691929833669579018L; |
61 |
private Logger logger = LoggerFactory.getLogger(DefaultJPublishPanel.class); |
62 |
|
63 |
private PublishSwingManager swingManager;
|
64 |
private JFileField jFileField;
|
65 |
private JCheckBox options; |
66 |
private JPanel optionPanel; |
67 |
private JButton acceptButton; |
68 |
private JButton cancelButton; |
69 |
private boolean isAccepted; |
70 |
|
71 |
private static final String WMS_PATH = "wms"; |
72 |
private static final String WFS_PATH = "wfs"; |
73 |
private static final String WCS_PATH = "wcs"; |
74 |
private static final String WFST_PATH = "wfst"; |
75 |
private static final String WMTS_PATH = "wmts"; |
76 |
private static final String MAPPROXY_PATH = "wmts"; |
77 |
|
78 |
private JDialog dialogParent; |
79 |
|
80 |
|
81 |
private List<JPublishOptionPanel> panels = null; |
82 |
private PublishProperties properties;
|
83 |
private JTabbedPane tabbed; |
84 |
private JPanel blankPanel; |
85 |
private I18nManager i18nManager;
|
86 |
|
87 |
public DefaultJPublishPanel(PublishSwingManager manager, PublishProperties props){
|
88 |
this(manager);
|
89 |
|
90 |
if(props != null){ |
91 |
this.properties = props;
|
92 |
loadData(); |
93 |
refreshPanel(); |
94 |
} |
95 |
} |
96 |
|
97 |
public DefaultJPublishPanel(PublishSwingManager manager){
|
98 |
this.swingManager = manager;
|
99 |
|
100 |
this.panels = new ArrayList<JPublishOptionPanel>(); |
101 |
|
102 |
initialize(); |
103 |
refreshPanel(); |
104 |
} |
105 |
|
106 |
private void initialize() { |
107 |
setLayout(new BorderLayout()); |
108 |
JPanel centerPanel = new JPanel(new BorderLayout()); |
109 |
|
110 |
JPanel fileContainer = new JPanel(); |
111 |
fileContainer.setLayout(new BoxLayout(fileContainer,BoxLayout.Y_AXIS)); |
112 |
fileContainer.setBorder(new TitledBorder(this.swingManager.getTranslation("Output_folder"))); |
113 |
fileContainer.add(getJFileField()); |
114 |
|
115 |
JPanel statusPanel = new JPanel(); |
116 |
statusPanel.setPreferredSize(new Dimension(450, 25)); |
117 |
options = new JCheckBox(this.swingManager.getTranslation("Advanced_options")); |
118 |
options.setSelected(getPublishProperties().onlyUploadFolderContent()); |
119 |
options.setEnabled(!getPublishProperties().onlyUploadFolderContent()); |
120 |
options.setBorder(new EmptyBorder(0, 0, 0, 300)); |
121 |
options.addActionListener(new ActionListener() { |
122 |
public void actionPerformed(ActionEvent arg0) { |
123 |
refreshPanel(); |
124 |
} |
125 |
}); |
126 |
statusPanel.add(options); |
127 |
fileContainer.add(statusPanel); |
128 |
|
129 |
centerPanel.add(fileContainer, BorderLayout.NORTH);
|
130 |
|
131 |
blankPanel = new JPanel(); |
132 |
centerPanel.add(blankPanel,BorderLayout.CENTER);
|
133 |
centerPanel.add(getOptionPanel(), BorderLayout.SOUTH);
|
134 |
|
135 |
add(centerPanel, BorderLayout.CENTER);
|
136 |
add(getButtonsPanel(), BorderLayout.PAGE_END);
|
137 |
setBorder(new EmptyBorder(10, 10, 0, 10)); |
138 |
|
139 |
} |
140 |
|
141 |
private JPanel getButtonsPanel() { |
142 |
JPanel buttonPanel = new JPanel(); |
143 |
buttonPanel.setLayout(new FlowLayout(FlowLayout.TRAILING)); |
144 |
acceptButton = new JButton(this.swingManager.getTranslation("accept")); |
145 |
acceptButton.setEnabled(!StringUtils.isBlank(getJFileField().getSelectedFilePath())); |
146 |
acceptButton.addActionListener(new ActionListener() { |
147 |
public void actionPerformed(ActionEvent arg0) { |
148 |
if(!acceptForm()){
|
149 |
//JOptionPane.showMessageDialog(getAsJComponent(), "Some errors.....");
|
150 |
}else{
|
151 |
updateData(); |
152 |
isAccepted = true;
|
153 |
closeMainWindow(); |
154 |
} |
155 |
} |
156 |
|
157 |
}); |
158 |
cancelButton = new JButton(this.swingManager.getTranslation("cancel")); |
159 |
cancelButton.addActionListener(new ActionListener() { |
160 |
public void actionPerformed(ActionEvent arg0) { |
161 |
isAccepted = false;
|
162 |
closeMainWindow(); |
163 |
} |
164 |
}); |
165 |
buttonPanel.add(cancelButton); |
166 |
buttonPanel.add(acceptButton); |
167 |
buttonPanel.setBorder(new EmptyBorder(10,0,0,0)); |
168 |
return buttonPanel;
|
169 |
} |
170 |
|
171 |
private boolean acceptForm() { |
172 |
boolean success = accept();
|
173 |
|
174 |
Iterator<JPublishOptionPanel> it = panels.iterator();
|
175 |
while(it.hasNext()){
|
176 |
JPublishOptionPanel p = (JPublishOptionPanel) it.next(); |
177 |
success = success && p.accept(); |
178 |
} |
179 |
|
180 |
return success;
|
181 |
} |
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
private boolean accept(){ |
188 |
String servicePath = ""; |
189 |
File file = new File(this.jFileField.getSelectedFilePath() |
190 |
+servicePath |
191 |
+File.separator+"mapfile.map"); |
192 |
boolean fileExists = file.exists();
|
193 |
|
194 |
if(!fileExists && getPublishProperties().isWMSService()){
|
195 |
servicePath = File.separator + WMS_PATH;
|
196 |
file = new File(this.jFileField.getSelectedFilePath() |
197 |
+servicePath |
198 |
+File.separator+"mapfile.map"); |
199 |
fileExists = fileExists || file.exists(); |
200 |
} |
201 |
if(!fileExists && getPublishProperties().isWFSService()){
|
202 |
servicePath = File.separator + WFS_PATH;
|
203 |
file = new File(this.jFileField.getSelectedFilePath() |
204 |
+servicePath |
205 |
+File.separator+"mapfile.map"); |
206 |
fileExists = fileExists || file.exists(); |
207 |
} |
208 |
if(!fileExists && getPublishProperties().isWCSService()){
|
209 |
servicePath = File.separator + WCS_PATH;
|
210 |
file = new File(this.jFileField.getSelectedFilePath() |
211 |
+servicePath |
212 |
+File.separator+"mapfile.map"); |
213 |
fileExists = fileExists || file.exists(); |
214 |
} |
215 |
if(!fileExists && getPublishProperties().isWFSTService()){
|
216 |
servicePath = File.separator + WFST_PATH;
|
217 |
file = new File(this.jFileField.getSelectedFilePath() |
218 |
+servicePath |
219 |
+File.separator+"mapfile.map"); |
220 |
fileExists = fileExists || file.exists(); |
221 |
} |
222 |
if(!fileExists && getPublishProperties().isWMTSService()){
|
223 |
servicePath = File.separator + WMTS_PATH;
|
224 |
file = new File(this.jFileField.getSelectedFilePath() |
225 |
+servicePath |
226 |
+File.separator+"mapfile.map"); |
227 |
fileExists = fileExists || file.exists(); |
228 |
} |
229 |
if(!fileExists && getPublishProperties().isMapProxyService()){
|
230 |
servicePath = File.separator + MAPPROXY_PATH;
|
231 |
file = new File(this.jFileField.getSelectedFilePath() |
232 |
+servicePath |
233 |
+File.separator+"mapfile.map"); |
234 |
fileExists = fileExists || file.exists(); |
235 |
} |
236 |
|
237 |
if(fileExists && !getPublishProperties().onlyUploadFolderContent()){
|
238 |
if(getPublishProperties().allowMerge() && !getPublishProperties().onlyUploadFolderContent()){
|
239 |
Object[] options = { |
240 |
this.swingManager.getTranslation("override"), |
241 |
this.swingManager.getTranslation("join_to_current"), |
242 |
// this.swingManager.getTranslation("merge_with_current"),
|
243 |
this.swingManager.getTranslation("cancel")}; |
244 |
int n = JOptionPane.showOptionDialog(this, |
245 |
this.swingManager.getTranslation("file_exists3")+"\n"+ |
246 |
this.swingManager.getTranslation("file_exists2"), |
247 |
this.swingManager.getTranslation("file_exists"), |
248 |
JOptionPane.YES_NO_OPTION,
|
249 |
JOptionPane.WARNING_MESSAGE,
|
250 |
null,
|
251 |
options, |
252 |
options[0]);
|
253 |
if(n==0){ |
254 |
this.getPublishProperties().setOverrideCurrentProject(true); |
255 |
return true; |
256 |
} |
257 |
if(n==1){ |
258 |
this.getPublishProperties().setOverrideCurrentProject(false); |
259 |
this.getPublishProperties().setJoinToCurrent(true); |
260 |
return true; |
261 |
} |
262 |
if(n==2){ |
263 |
// this.getPublishProperties().setOverrideCurrentProject(false);
|
264 |
// this.getPublishProperties().setJoinToCurrent(true);
|
265 |
// }
|
266 |
// if(n==3){
|
267 |
return false; |
268 |
} |
269 |
}else{
|
270 |
Object[] options = { |
271 |
this.swingManager.getTranslation("accept"), |
272 |
this.swingManager.getTranslation("cancel")}; |
273 |
int n = JOptionPane.showOptionDialog(this, |
274 |
this.swingManager.getTranslation("file_exists3")+"\n"+ |
275 |
this.swingManager.getTranslation("file_exists2"), |
276 |
this.swingManager.getTranslation("file_exists"), |
277 |
JOptionPane.YES_NO_OPTION,
|
278 |
JOptionPane.WARNING_MESSAGE,
|
279 |
null,
|
280 |
options, |
281 |
options[0]);
|
282 |
if(n==1){ |
283 |
return false; |
284 |
} |
285 |
} |
286 |
} |
287 |
this.getPublishProperties().setOverrideCurrentProject(true); |
288 |
return true; |
289 |
} |
290 |
|
291 |
protected void closeMainWindow() { |
292 |
if(this.dialogParent!=null){ |
293 |
this.dialogParent.dispose();
|
294 |
}else{
|
295 |
PluginServices.getMDIManager().closeWindow(this);
|
296 |
} |
297 |
} |
298 |
|
299 |
public PublishProperties getPublishProperties(){
|
300 |
if(this.properties==null){ |
301 |
this.properties = getSwingManager().getPublishManager().createProperties("Mapserver"); |
302 |
} |
303 |
return this.properties; |
304 |
} |
305 |
|
306 |
private JPanel getOptionPanel() { |
307 |
if(this.optionPanel == null){ |
308 |
initializeOptionPanels(); |
309 |
|
310 |
this.optionPanel = new JPanel(); |
311 |
this.optionPanel.setBorder(new TitledBorder(this.swingManager.getTranslation("Advanced_options")+":")); |
312 |
this.optionPanel.setPreferredSize(new Dimension(464, 250)); |
313 |
tabbed = new JTabbedPane(); |
314 |
Iterator<JPublishOptionPanel> it = panels.iterator();
|
315 |
while(it.hasNext()){
|
316 |
JPublishOptionPanel p = (JPublishOptionPanel) it.next(); |
317 |
tabbed.add(p.getName(), p.getAsJComponent()); |
318 |
} |
319 |
this.optionPanel.add(tabbed);
|
320 |
this.optionPanel.setVisible(false); |
321 |
} |
322 |
return optionPanel;
|
323 |
} |
324 |
|
325 |
public JTabbedPane getTabPanel(){ |
326 |
return tabbed;
|
327 |
} |
328 |
|
329 |
private void initializeOptionPanels() { |
330 |
if(!getPublishProperties().onlyUploadFolderContent()){
|
331 |
panels.add(new JServiceOptionsPanel(getSwingManager()));
|
332 |
panels.add(new JTinyOWSOptionsPanel((getSwingManager())));
|
333 |
panels.add(new JMapCacheOptionsPanel((getSwingManager())));
|
334 |
panels.add(new JMapProxyOptionsPanel((getSwingManager())));
|
335 |
panels.add(new JGeneralOptionsPanel(getSwingManager()));
|
336 |
}else{
|
337 |
panels.add(new JPublishRemoteOptionsPanel(getSwingManager()));
|
338 |
panels.add(new JGeneralOptionsPanel(getSwingManager()));
|
339 |
options.setVisible(false);
|
340 |
} |
341 |
} |
342 |
|
343 |
|
344 |
private JFileField getJFileField(){
|
345 |
if(this.jFileField==null){ |
346 |
jFileField = new JFileField(null, "..."); |
347 |
jFileField.setMode(JFileField.MODE_OPEN); |
348 |
jFileField.getFileChooser().setCurrentDirectory(new File(System.getProperty("user.home"))); |
349 |
jFileField.addObserver(this);
|
350 |
} |
351 |
return this.jFileField; |
352 |
} |
353 |
|
354 |
public void update(Observable observable, Object notification) { |
355 |
if(observable instanceof JFileField){ |
356 |
acceptButton.setEnabled(true);
|
357 |
} |
358 |
} |
359 |
|
360 |
public PublishSwingManager getSwingManager() {
|
361 |
return this.swingManager; |
362 |
} |
363 |
|
364 |
public void setParentDialog(JDialog parent){ |
365 |
this.dialogParent = parent;
|
366 |
} |
367 |
|
368 |
private void loadData() { |
369 |
if(!StringUtils.isBlank(getPublishProperties().getMapFile())){
|
370 |
this.jFileField.setFile(getPublishProperties().getMapFile());
|
371 |
this.acceptButton.setEnabled(true); |
372 |
} |
373 |
|
374 |
Iterator<JPublishOptionPanel> it = panels.iterator();
|
375 |
while(it.hasNext()){
|
376 |
JPublishOptionPanel p = (JPublishOptionPanel) it.next(); |
377 |
p.loadData(); |
378 |
} |
379 |
|
380 |
} |
381 |
|
382 |
private void updateData(){ |
383 |
getPublishProperties().setMapFile(this.jFileField.getSelectedFilePath());
|
384 |
|
385 |
Iterator<JPublishOptionPanel> it = panels.iterator();
|
386 |
while(it.hasNext()){
|
387 |
JPublishOptionPanel p = (JPublishOptionPanel) it.next(); |
388 |
p.updateData(); |
389 |
} |
390 |
|
391 |
} |
392 |
|
393 |
public void addPublishServicePropertiesPanel(JPublishOptionPanel panel){ |
394 |
panels.add(panel); |
395 |
tabbed.add(panel.getName(), panel.getAsJComponent()); |
396 |
refreshPanel(); |
397 |
} |
398 |
|
399 |
private void refreshPanel() { |
400 |
this.optionPanel.setVisible(options.isSelected());
|
401 |
optionPanel.setEnabled(options.isSelected()); |
402 |
tabbed.setEnabled(options.isSelected()); |
403 |
|
404 |
Iterator<JPublishOptionPanel> it = panels.iterator();
|
405 |
while(it.hasNext()){
|
406 |
JPublishOptionPanel p = (JPublishOptionPanel) it.next(); |
407 |
p.refreshPanel(options.isSelected()); |
408 |
} |
409 |
|
410 |
if(dialogParent != null){ |
411 |
if(options.isSelected()){
|
412 |
this.blankPanel.setBorder(new EmptyBorder(10,0,0,0)); |
413 |
this.dialogParent.setSize(510, 500); |
414 |
this.dialogParent.pack();
|
415 |
}else{
|
416 |
this.blankPanel.setBorder(new EmptyBorder(0,0,0,0)); |
417 |
this.dialogParent.setSize(510, 150); |
418 |
this.dialogParent.pack();
|
419 |
} |
420 |
} |
421 |
|
422 |
this.getAsJComponent().repaint();
|
423 |
this.getAsJComponent().revalidate();
|
424 |
} |
425 |
|
426 |
public JPanel getAsJComponent() { |
427 |
return this; |
428 |
} |
429 |
|
430 |
public WindowInfo getWindowInfo() {
|
431 |
WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG
|
432 |
| WindowInfo.RESIZABLE); |
433 |
m_viewinfo |
434 |
.setTitle(PluginServices.getText(this, this.swingManager.getTranslation("_publish_resource"))); |
435 |
m_viewinfo.setWidth(510);
|
436 |
m_viewinfo.setHeight(560);
|
437 |
return m_viewinfo;
|
438 |
} |
439 |
|
440 |
public Object getWindowProfile() { |
441 |
return WindowInfo.PROPERTIES_PROFILE;
|
442 |
} |
443 |
|
444 |
public boolean isAccepted() { |
445 |
return this.isAccepted; |
446 |
} |
447 |
|
448 |
} |