Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extPublish / src / org / gvsig / publish / gui / selectServer / SelectServerController.java @ 14407

History | View | Annotate | Download (4.24 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

    
46
import org.gvsig.publish.PublishLogger;
47
import org.gvsig.publish.PublishRegister;
48
import org.gvsig.publish.serversModel.Publication;
49
import org.gvsig.publish.serversModel.Server;
50
import org.gvsig.publish.serversModel.Service;
51

    
52
import com.iver.andami.ui.mdiManager.IWindow;
53
import com.iver.utiles.swing.jcomboServer.ServerData;
54

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