Statistics
| Revision:

root / trunk / extensions / extPublish / src / org / gvsig / publish / gui / selectServer / SelectServerController.java @ 29308

History | View | Annotate | Download (4.74 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
import java.awt.event.ActionEvent;
44
import java.awt.event.ActionListener;
45
import java.net.MalformedURLException;
46
import java.net.URL;
47

    
48
import javax.swing.JOptionPane;
49

    
50
import org.gvsig.publish.PublishLogger;
51
import org.gvsig.publish.PublishRegister;
52
import org.gvsig.publish.serversmodel.Publication;
53
import org.gvsig.publish.serversmodel.Server;
54
import org.gvsig.publish.serversmodel.Service;
55

    
56
import com.iver.andami.ui.mdiManager.IWindow;
57

    
58
/**
59
 * This class represents the controller for the "add server" use case.
60
 * It adds a server into a publication
61
 * <p>
62
 * 
63
 * @author Jos? Vicente Hig?n (josevicente.higon@iver.es)
64
 *
65
 */
66
public class SelectServerController implements ActionListener {
67
        /**
68
         * Events
69
         */
70
        public static final String NEWSERVER_EVENT_ACCEPT="accept_new_server";
71
        public static final String NEWSERVER_EVENT_CANCEL="cancel_new_server";
72
        public static final String COMBOSERVERURL_EVENT_CHANGE = "change_combo_serverurl";
73
        public static final String COMBOSERVER_EVENT_CHANGE = "change_combo_server";
74
        /**
75
         * dependences
76
         */
77
        //PublishController publishController = null;
78
        Publication publication = null;
79
        
80
        private SelectServerWindow window = null;
81
        /**
82
         * Constructor:
83
         * <p>
84
         * Creates the window and sets the listener itself.
85
         */
86
        public SelectServerController(){
87
                window = new SelectServerWindow();        
88
                window.setListener(this);                
89
        }
90
        /**
91
         * Sets the publication 
92
         * @param publi
93
         */
94
        public void setPublication(Publication publi){
95
                if (publi == null){
96
                        PublishLogger.getLog().error("ERROR AddresourceController : the publication can't be nulll");
97
                }else{
98
                        publication = publi;
99
                }
100
        }
101
        /**
102
         * Shows the window
103
         */
104
        public void showWindow(){
105
                window.showWindow();
106
        }
107
        /**
108
         * Get actions from the window
109
         */
110
        public void actionPerformed(ActionEvent e) {
111
                if (e.getActionCommand().equals(SelectServerController.NEWSERVER_EVENT_CANCEL)){                        
112
                        window.closeWindow();
113
                        return;
114
                }
115
                if (e.getActionCommand().equals(SelectServerController.NEWSERVER_EVENT_ACCEPT)){
116
                        String serverName = window.getSelectedServer();
117
                        String serviceName = window.getSelectedService();
118
                        String serverUrl = window.getSelectedURL();
119
                        
120
                        //Saves the selected server 
121
                        window.saveCurrentServer();
122
                        
123
                        //Creates the new Server and sets url
124
                        Server server = PublishRegister.register().getServer(serverName);
125
                        URL url;
126
                        try {
127
                                url = new URL (serverUrl);
128
                        } catch (MalformedURLException e1) {
129
                                JOptionPane.showMessageDialog(window,"malformed_url","ERROR",JOptionPane.ERROR_MESSAGE);
130
                                return;
131
                        }
132
                        server.setServerURL(url);
133
                        
134
                        //Creates the new Service
135
                        Service service = PublishRegister.register().getService(server, serviceName);
136
                        
137
                        //Adds the service into the server
138
                        server.addService(service);
139
                        
140
                        //adds the new server into the publication
141
                        //then publication state changes and notify observers
142
                        publication.setServer(server);
143
                        
144
                        //closes the add server window and shows the publication windows
145
                        window.closeWindow();
146
                        //I've changed byt the observer/observable pattern
147
                        //publishController.showWindow();
148
                }else if(e.getActionCommand().equals(SelectServerController.COMBOSERVERURL_EVENT_CHANGE)){
149
                        window.updateCombos();
150
                        return;
151
                }
152
                if (e.getActionCommand().equals(SelectServerController.COMBOSERVER_EVENT_CHANGE)){                        
153
                        window.updateServiceCombo();
154
                        return;
155
                }
156
        }
157
        /**
158
         * Maybe is better to return the panel and do the cast in the other side. Then I won't have
159
         * the dependency with gvSIG (IWindow) into the controller 
160
         * @return
161
         */
162
        public IWindow getWindow() {                
163
                return window;
164
        }
165
        
166
}