Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extPublish / src / org / gvsig / publish / ProjectPublication.java @ 22616

History | View | Annotate | Download (6.33 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;
42

    
43
import java.util.Iterator;
44

    
45
import org.gvsig.publish.gui.properties.PublicationPropertiesController;
46
import org.gvsig.publish.gui.publish.PublishController;
47
import org.gvsig.publish.gui.selectServer.SelectServerController;
48
import org.gvsig.publish.infoproject.IProjectInfo;
49
import org.gvsig.publish.infoproject.ProjectInfoFactory;
50
import org.gvsig.publish.serversmodel.Publication;
51

    
52
import com.iver.andami.PluginServices;
53
import com.iver.andami.ui.mdiManager.IWindow;
54
import com.iver.cit.gvsig.fmap.DriverException;
55
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
56
import com.iver.cit.gvsig.fmap.layers.XMLException;
57
import com.iver.cit.gvsig.project.Project;
58
import com.iver.cit.gvsig.project.documents.ProjectDocument;
59
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
60
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
61
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory;
62
import com.iver.utiles.XMLEntity;
63

    
64
public class ProjectPublication extends ProjectDocument {
65
        /**
66
         * 
67
         */
68
        private static final long serialVersionUID = 5784873591226633893L;
69
        /*
70
         * Dependences
71
         * xxx
72
         */
73
        private Publication publication = null;
74
        private PublishController publishCtrl = null;
75
        //private AddResourceController addResourceCtrl = null;
76
        private SelectServerController slcSrvCtrl = null;
77
        private PublicationPropertiesController ppc = null;
78
                        
79
        /**
80
         * Creates all the controllers and sets the relations.
81
         * It's invoked when a new publication is created (new button)
82
         * @see ProjectDocument#setProject(Project, int)
83
         */
84
        public void setProject(Project project, int index) {
85
                super.setProject(project, index);                                                        
86
        }
87
        /**
88
         * 
89
         * @return the publication of the document
90
         */
91
        private Publication getPublication(){
92
                if (publication == null){
93
                        publication = new Publication();
94
                }
95
                return publication;
96
        }
97
        
98
        /**
99
         * @see ProjectDocument#afterAdd()
100
         */
101
        public void afterAdd() {                
102
        
103
        }
104
        /**
105
         * @see ProjectDocument#afterRemove()
106
         */
107
        public void afterRemove() {
108
                // TODO Auto-generated method stub
109
                
110
        }
111
        /**
112
         * This method is called when I open the document 
113
         * @return
114
         * @see {@linkProjectDocument#createWindow()}
115
         */
116
        public IWindow createWindow() {
117
                                 
118
                IProjectInfo projectInfo = ProjectInfoFactory.getProjectInfo(getProject());
119
                Iterator it= getPublication().setProjectInfo(projectInfo).iterator();
120
                String message="";
121
                while (it.hasNext()){
122
                        message=message +" " +it.next().toString();
123
                }                                
124
                //create controllers 
125
                publishCtrl = new PublishController();
126
                slcSrvCtrl = new SelectServerController();
127
                //initial message
128
                if (!message.equals("")){
129
                        String aux = PluginServices.getText(this, "publish_layerinfo_not_available");
130
                        message = aux + message;
131
                        publishCtrl.setInitialMessage(message);
132
                }                                
133
                
134
                //Add observers
135
                getPublication().addObserver(publishCtrl);
136
                                
137
                //sets the publication in the controllers
138
                //addResourceCtrl.setPublication(publication);
139
                publishCtrl.setPublication(getPublication());
140
                slcSrvCtrl.setPublication(getPublication());
141
                
142
                
143

    
144
                //If the publication is new, I must select the server
145
                if (getPublication().getServer() == null){
146
                        publishCtrl.showWindow();
147
                        return slcSrvCtrl.getWindow();
148
                }                
149
                return publishCtrl.getWindow();
150
                //return null;
151
        }
152
        /**
153
         * 
154
         * @param root
155
         * @param project
156
         * @throws SaveException
157
         * @see {@link ProjectDocument#exportToXML(XMLEntity, Project)}
158
         */
159
        public void exportToXML(XMLEntity root, Project project)
160
                        throws SaveException {
161
                XMLEntity tableRoot = project.getExportXMLTypeRootNode(root,ProjectTableFactory.registerName);
162
                tableRoot.addChild(this.getXMLEntity());
163
        }
164
        /**
165
         * This method is invoked when the properties button is pressed
166
         * 
167
         * @return
168
         * @see {@link ProjectDocument#getProperties()}
169
         */
170
        public IWindow getProperties() {                
171
                if (ppc == null){
172
                        ppc = new PublicationPropertiesController(getPublication());
173
                }
174
                return ppc.getWindow();
175
        }
176
        /**
177
         * 
178
         * @param root
179
         * @param typeRoot
180
         * @param elementIndex
181
         * @param project
182
         * @param removeDocumentsFromRoot
183
         * @throws XMLException
184
         * @throws DriverException
185
         * @throws OpenException
186
         * @see {@link ProjectDocument#importFromXML(XMLEntity, XMLEntity, int, Project, boolean)}
187
         */  
188
        public void importFromXML(XMLEntity root, XMLEntity typeRoot,
189
                        int elementIndex, Project project, boolean removeDocumentsFromRoot)
190
                        throws XMLException, DriverException, OpenException {
191
                XMLEntity element = typeRoot.getChild(elementIndex);
192
                try {
193
                        this.setXMLEntity(element);
194
                } catch (DriverIOException e) {                        
195
                        PublishLogger.getLog().error("ERROR ProjectPublication: importXML", e);
196
                }
197
                if (removeDocumentsFromRoot) {
198
                        typeRoot.removeChild(elementIndex);
199
                }
200
                project.addDocument(this);
201
                
202
        }
203
        /**
204
         * @see ProjectDocument#getXMLEntity()
205
        */
206
        public XMLEntity getXMLEntity() throws SaveException {
207
                XMLEntity xml= super.getXMLEntity();
208
                xml.addChild(getPublication().getXMLEntity());                
209
                return xml;
210
        }
211
        /**
212
         * @see ProjectDocument#getXMLEntity()
213
         */
214
        public void setXMLEntity(XMLEntity xml) throws XMLException,
215
                        DriverException, DriverIOException, OpenException {
216
                super.setXMLEntity(xml);
217
                getPublication().setXMLEntity(xml.getChild(0));        
218
        }
219
        
220
        
221
}