svn-gvsig-desktop / branches / v10 / extensions / extPublish / src / org / gvsig / publish / gui / publish / PublishController.java @ 22616
History | View | Annotate | Download (6.11 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.publish; |
42 |
|
43 |
import java.awt.event.ActionEvent; |
44 |
import java.awt.event.ActionListener; |
45 |
import java.util.Observable; |
46 |
import java.util.Observer; |
47 |
|
48 |
import javax.swing.JOptionPane; |
49 |
import javax.swing.JPanel; |
50 |
|
51 |
import org.gvsig.publish.PublishLogger; |
52 |
import org.gvsig.publish.PublishRegister; |
53 |
import org.gvsig.publish.exceptions.PublishException; |
54 |
import org.gvsig.publish.serversmodel.Publication; |
55 |
|
56 |
import com.iver.andami.PluginServices; |
57 |
|
58 |
/**
|
59 |
* This class represents the controller for the publish use case
|
60 |
* <p>
|
61 |
* Responsabilities:
|
62 |
* <p>
|
63 |
* To create the publish window
|
64 |
* <p>
|
65 |
* To get the actions from the window
|
66 |
*
|
67 |
* @author Jos? Vicente Hig?n (josevicente.higon@iver.es)
|
68 |
*
|
69 |
*/
|
70 |
public class PublishController implements ActionListener, Observer { |
71 |
//events
|
72 |
public static final String PUBLISH_EVENT_ACCEPT="accept_publish"; |
73 |
public static final String PUBLISH_EVENT_CANCEL="cancel_publish"; |
74 |
//associations
|
75 |
private PublishWindow window = null; |
76 |
private Publication publication = null; |
77 |
private IPublishPluginController pluginCtrl = null; |
78 |
private String initialMessage=null; |
79 |
|
80 |
|
81 |
/**
|
82 |
* Constructor
|
83 |
*/
|
84 |
public PublishController(){
|
85 |
window = new PublishWindow();
|
86 |
window.setListener(this);
|
87 |
} |
88 |
/**
|
89 |
*
|
90 |
* @return publication active
|
91 |
*/
|
92 |
public Publication getPublication(){
|
93 |
return publication;
|
94 |
} |
95 |
/**
|
96 |
* The publication class needs a IWindow
|
97 |
* @return IWindow
|
98 |
*/
|
99 |
public PublishWindow getWindow(){
|
100 |
if (getInitialMessage() != null){ |
101 |
JOptionPane.showMessageDialog(window,
|
102 |
getInitialMessage(), |
103 |
PluginServices.getText(this,"publish_publication_has_changed"), |
104 |
JOptionPane.WARNING_MESSAGE);
|
105 |
} |
106 |
updateWindow(); |
107 |
return window;
|
108 |
} |
109 |
/**
|
110 |
* Shown the controller's window.
|
111 |
* Preconditions: first you must call setPublication
|
112 |
*/
|
113 |
public void showWindow(){ |
114 |
window.showWindow(); |
115 |
} |
116 |
/**
|
117 |
* Sets the controller's publication
|
118 |
*
|
119 |
* @param publication
|
120 |
*/
|
121 |
public void setPublication(Publication publication){ |
122 |
//if there isn't publications it creates one
|
123 |
if (publication==null){ |
124 |
//TODO I need to throw an exception
|
125 |
//PublishLogger.getLog().error("ERROR: PublishController, the active publication is null ", new PublishException());
|
126 |
PublishLogger.getLog().error("ERROR: PublishController, the active publication is null");
|
127 |
}else{
|
128 |
this.publication = publication;
|
129 |
} |
130 |
} |
131 |
|
132 |
/**
|
133 |
* Actions from publish window
|
134 |
*/
|
135 |
public void actionPerformed(ActionEvent e) { |
136 |
if (e.getActionCommand().equals(PublishController.PUBLISH_EVENT_CANCEL)){
|
137 |
window.closeWindow(); |
138 |
} |
139 |
if (e.getActionCommand().equals(PublishController.PUBLISH_EVENT_ACCEPT)){
|
140 |
try {
|
141 |
//TODO: I don't know if this is the best method
|
142 |
//I'm forcing to do a GetModel()
|
143 |
//Why I can't use the plugincontroller instead?
|
144 |
//window.getActivePublication();
|
145 |
pluginCtrl.getModel(); |
146 |
String aux = publication.getServer().publish();
|
147 |
JOptionPane.showMessageDialog(window,
|
148 |
PluginServices.getText(this,aux),
|
149 |
PluginServices.getText(this,"publish_correct_publication"), |
150 |
JOptionPane.INFORMATION_MESSAGE);
|
151 |
} catch (PublishException e1) {
|
152 |
PublishLogger.getLog().error("ERROR PublishController: error_publishing");
|
153 |
//show a dialog
|
154 |
JOptionPane.showMessageDialog(window,
|
155 |
PluginServices.getText(this, e1.getMessage()),
|
156 |
PluginServices.getText(this,"publish_error_publishing"), |
157 |
JOptionPane.ERROR_MESSAGE);
|
158 |
return;
|
159 |
} |
160 |
window.closeWindow(); |
161 |
} |
162 |
} |
163 |
/**
|
164 |
* @see java.util.Observer#update(Observable, Object)
|
165 |
*/
|
166 |
public void update(Observable o, Object arg) { |
167 |
if (o instanceof Publication){ |
168 |
setPublication((Publication)o); |
169 |
updateWindow(); |
170 |
}else{
|
171 |
PublishLogger.getLog().error("ERROR PublishController: The observable object must be a publication" );
|
172 |
} |
173 |
} |
174 |
private void updateWindow() { |
175 |
if (publication ==null){ |
176 |
PublishLogger.getLog().error("ERROR " + getClass().getName() + " I can't update the window, publication is null!!"); |
177 |
return;
|
178 |
} |
179 |
//get active publication
|
180 |
if (publication.getServer()==null){ |
181 |
return;
|
182 |
} |
183 |
String key = publication.getServer().getRegisterTag();
|
184 |
//get controller
|
185 |
pluginCtrl = (IPublishPluginController) PublishRegister.register().getController(key); |
186 |
if (pluginCtrl == null){ |
187 |
PublishLogger.getLog().error("ERROR " + getClass().getName() + "The gui controller has not been loaded!!"); |
188 |
window.closeWindow(); |
189 |
return;
|
190 |
} |
191 |
pluginCtrl.setModel(publication); |
192 |
//TODO: check casting
|
193 |
IPublishPluginPanel publishPanel = pluginCtrl.getPanel(); |
194 |
JPanel panel = null; |
195 |
try{
|
196 |
panel = (JPanel) publishPanel;
|
197 |
}catch(ClassCastException e){ |
198 |
PublishLogger.getLog().error("ERROR Publish Controller",e);
|
199 |
} |
200 |
window.setPublicationPanel(panel); |
201 |
} |
202 |
/**
|
203 |
* @return the initialMessage
|
204 |
*/
|
205 |
public String getInitialMessage() { |
206 |
return initialMessage;
|
207 |
} |
208 |
/**
|
209 |
* @param initialMessage the initialMessage to set
|
210 |
*/
|
211 |
public void setInitialMessage(String initialMessage) { |
212 |
this.initialMessage = initialMessage;
|
213 |
} |
214 |
|
215 |
} |