gvsig-publish / org.gvsig.publish / trunk / org.gvsig.publish / org.gvsig.publish.app / org.gvsig.publish.app.mainplugin / src / main / java / org / gvsig / publish / app / mainplugin / PublishClientExtension.java @ 121
History | View | Annotate | Download (5.96 KB)
1 |
/* OSM layers for gvSIG.
|
---|---|
2 |
* Geographic Information System of the Valencian Government
|
3 |
*
|
4 |
*
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.publish.app.mainplugin; |
23 |
|
24 |
import javax.swing.JDialog; |
25 |
import javax.swing.JOptionPane; |
26 |
|
27 |
import org.apache.commons.lang3.StringUtils; |
28 |
import org.gvsig.andami.IconThemeHelper; |
29 |
import org.gvsig.andami.PluginServices; |
30 |
import org.gvsig.andami.PluginsLocator; |
31 |
import org.gvsig.andami.PluginsManager; |
32 |
import org.gvsig.andami.plugins.Extension; |
33 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
34 |
import org.gvsig.app.ApplicationLocator; |
35 |
import org.gvsig.app.ApplicationManager; |
36 |
import org.gvsig.app.project.documents.view.gui.IView; |
37 |
import org.gvsig.publish.PublishProperties; |
38 |
import org.gvsig.publish.PublishService; |
39 |
import org.gvsig.publish.swing.PublishSwingLocator; |
40 |
import org.gvsig.publish.swing.PublishSwingManager; |
41 |
import org.gvsig.publish.swing.gui.JPublishPanel; |
42 |
import org.gvsig.tools.ToolsLocator; |
43 |
import org.gvsig.tools.dynobject.DynObject; |
44 |
import org.gvsig.tools.task.SimpleTaskStatus; |
45 |
import org.slf4j.Logger; |
46 |
import org.slf4j.LoggerFactory; |
47 |
|
48 |
/**
|
49 |
* Publish Extension to gvSIG.
|
50 |
* @author Jos? Bad?a (jbadia@scolab.es)
|
51 |
*/
|
52 |
public class PublishClientExtension extends Extension { |
53 |
private Logger log = LoggerFactory.getLogger(PublishClientExtension.class); |
54 |
private static boolean isRunning=false; |
55 |
|
56 |
private PublishSwingManager swingManager;
|
57 |
|
58 |
private static final String ACTION_ADDRESOURCE = "add_resource"; |
59 |
private static final String ACTION_UPLOADRESOURCE = "upload_resource"; |
60 |
|
61 |
public void initialize() { |
62 |
registerIcons(); |
63 |
} |
64 |
|
65 |
private void registerIcons() { |
66 |
IconThemeHelper.registerIcon("publish", "publish-service", this); |
67 |
IconThemeHelper.registerIcon("publish", "publish-server", this); |
68 |
} |
69 |
|
70 |
/*
|
71 |
* (non-Javadoc)
|
72 |
* @see org.gvsig.andami.plugins.Extension#postInitialize()
|
73 |
*/
|
74 |
public void postInitialize() { |
75 |
|
76 |
|
77 |
} |
78 |
|
79 |
public PublishSwingManager getSwingManager() {
|
80 |
if(swingManager == null){ |
81 |
swingManager = PublishSwingLocator.getSwingServiceManager().getPublishSwingManager(); |
82 |
} |
83 |
return swingManager;
|
84 |
} |
85 |
|
86 |
public void execute(String actionCommand) { |
87 |
if (ACTION_ADDRESOURCE.equalsIgnoreCase(actionCommand) ||
|
88 |
ACTION_UPLOADRESOURCE.equalsIgnoreCase(actionCommand)){ |
89 |
|
90 |
boolean onlyUploadContent = ACTION_UPLOADRESOURCE.equalsIgnoreCase(actionCommand);
|
91 |
|
92 |
PublishProperties props = getSwingManager().getPublishManager().createProperties("Mapserver");
|
93 |
|
94 |
PluginsManager pmanager = PluginsLocator.getManager(); |
95 |
PluginServices plugin = pmanager.getPlugin(PublishClientExtension.class); |
96 |
DynObject config = plugin.getPluginProperties(); |
97 |
|
98 |
if(StringUtils.isBlank(props.getUrl())){
|
99 |
props.setUrl((String) config.getDynValue("server_url")); |
100 |
props.setUser((String) config.getDynValue("server_user")); |
101 |
props.setPassword((String) config.getDynValue("server_password")); |
102 |
if(config.hasDynValue("default_srs")){ |
103 |
props.setDefaultSRS((String) config.getDynValue("default_srs")); |
104 |
} |
105 |
} |
106 |
props.setOnlyUploadFolderContent(onlyUploadContent); |
107 |
props.setRemoteConfiguration(onlyUploadContent); |
108 |
|
109 |
final JPublishPanel windowPanel =
|
110 |
getSwingManager().createPublishOptionsPanel(props); |
111 |
|
112 |
|
113 |
JDialog dlg = new JDialog(); |
114 |
if(!onlyUploadContent){
|
115 |
dlg.setTitle(this.swingManager.getTranslation("_publish_resource")); |
116 |
}else{
|
117 |
dlg.setTitle(this.swingManager.getTranslation("upload_resource")); |
118 |
} |
119 |
dlg.setResizable(true);
|
120 |
windowPanel.setParentDialog(dlg); |
121 |
dlg.getContentPane().add(windowPanel.getAsJComponent()); |
122 |
dlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
123 |
|
124 |
dlg.setSize(510, 560); |
125 |
dlg.setModal(true);
|
126 |
dlg.pack(); |
127 |
dlg.setLocationRelativeTo(null);
|
128 |
dlg.setVisible(true);
|
129 |
|
130 |
if(windowPanel.isAccepted()){
|
131 |
Runnable run = new Runnable() { |
132 |
public void run() { |
133 |
isRunning = true;
|
134 |
SimpleTaskStatus task = ToolsLocator.getTaskStatusManager() |
135 |
.createDefaultSimpleTaskStatus(swingManager.getTranslation("publishing_"));
|
136 |
task.setAutoremove(true);
|
137 |
task.add(); |
138 |
PublishService service = getSwingManager().getPublishManager() |
139 |
.createService("Mapserver", windowPanel.getPublishProperties());
|
140 |
boolean result = service.publish();
|
141 |
|
142 |
isRunning = false;
|
143 |
service.resetToDefaults(); |
144 |
task.remove(); |
145 |
|
146 |
if(result){
|
147 |
if(!(windowPanel.getPublishProperties().onlyUploadFolderContent() &&
|
148 |
!windowPanel.getPublishProperties().getRemoteConfiguration())){ |
149 |
JOptionPane.showMessageDialog(
|
150 |
null,
|
151 |
getSwingManager().getTranslation("succesfull_message"),
|
152 |
getSwingManager().getTranslation("succesfull_message_title"),
|
153 |
JOptionPane.INFORMATION_MESSAGE);
|
154 |
} |
155 |
}else{
|
156 |
JOptionPane.showMessageDialog(
|
157 |
null,
|
158 |
getSwingManager().getTranslation("unsuccesfull_message"),
|
159 |
getSwingManager().getTranslation("unsuccesfull_message_title"),
|
160 |
JOptionPane.ERROR_MESSAGE);
|
161 |
} |
162 |
} |
163 |
}; |
164 |
Thread th = new Thread(run); |
165 |
th.start(); |
166 |
} |
167 |
|
168 |
return;
|
169 |
}else{
|
170 |
|
171 |
} |
172 |
} |
173 |
|
174 |
public boolean isEnabled() { |
175 |
return true; |
176 |
} |
177 |
|
178 |
public boolean isVisible() { |
179 |
ApplicationManager application = ApplicationLocator.getManager(); |
180 |
IWindow f = application.getActiveWindow(); |
181 |
if (f == null) { |
182 |
return false; |
183 |
} |
184 |
|
185 |
if (f instanceof IView) { |
186 |
return true; |
187 |
} |
188 |
return false; |
189 |
} |
190 |
|
191 |
} |