Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extPublish / src / org / gvsig / publish / gui / addResource / AddResourceController.java @ 19900

History | View | Annotate | Download (4.48 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.addResource;
42

    
43
import java.awt.event.ActionEvent;
44
import java.awt.event.ActionListener;
45

    
46
import javax.swing.event.TreeSelectionEvent;
47
import javax.swing.event.TreeSelectionListener;
48

    
49
import org.gvsig.publish.PublishLogger;
50
import org.gvsig.publish.infoproject.ILayerInfo;
51
import org.gvsig.publish.infoproject.IProjectInfo;
52
import org.gvsig.publish.infoproject.IViewInfo;
53
import org.gvsig.publish.serversmodel.Publication;
54

    
55

    
56
public class AddResourceController implements ActionListener,TreeSelectionListener {
57
        /*
58
         * Events
59
         */
60
        public static final String ADDRESOURCE_EVENT_ACCEPT="accept_add_resource";
61
        public static final String ADDRESOURCE_EVENT_CANCEL="cancel_add_resource";
62
        /*
63
         *Dependencies 
64
         */
65
        private Publication publication = null;
66
        //private IProjectInfo projectInfo = null;
67
        private AddResourceWindow window = null;
68
        private Object resourceToAdd = null;
69
        /**
70
         * Constructor:
71
         * <p>
72
         * Creates the window and sets the listener itself.
73
         */
74
        public AddResourceController(){
75
                        window = new AddResourceWindow();        
76
                        window.setListener(this);                                                                
77
        }
78
        /**
79
         * Shows the window in order to add resources
80
         * TODO: At the moment only gets the project information from the first service (it can be filtered)
81
         * If we want multiservice support, we must have an "activeservice" in this class in order to show 
82
         * the suitable projectinfo tree
83
         */
84
        public void showWindow(){
85
                //window.setModel(publication.getProjectInfo());
86
                window.setModel(publication.getServer().getService(0).getProjectInfo());
87
                //show the window
88
                window.showWindow();
89
        }
90
        /**
91
         * Get actions from the controls panel
92
         */
93
        public void actionPerformed(ActionEvent e) {
94
                if (e.getActionCommand().equals(AddResourceController.ADDRESOURCE_EVENT_CANCEL)){                        
95
                        window.closeWindow();
96
                        return;
97
                }
98
                if (e.getActionCommand().equals(AddResourceController.ADDRESOURCE_EVENT_ACCEPT)){                        
99
                        window.closeWindow();
100
                        if (resourceToAdd instanceof IProjectInfo){
101
                                IProjectInfo projectInfo = (IProjectInfo)resourceToAdd;                                
102
                                publication.getServer().setProjectInfo(projectInfo);
103
                        }
104
                        if (resourceToAdd instanceof IViewInfo){
105
                                IViewInfo viewInfo = (IViewInfo)resourceToAdd;
106
                                publication.getServer().addInfo(viewInfo);                                
107
                        }
108
                        if (resourceToAdd instanceof ILayerInfo){
109
                                ILayerInfo layerInfo = (ILayerInfo)resourceToAdd;        
110
                                publication.getServer().addInfo(layerInfo);                        
111
                        }
112
                }
113
        }
114
        /**
115
         * It finds out the resource to add
116
         * TODO: I don't know why sometimes getNewLeadSelectionPath is null !!
117
         */
118
        public void valueChanged(TreeSelectionEvent e) {
119
                Object source = null;
120
                if (e.getNewLeadSelectionPath() == null){
121
                        source = e.getOldLeadSelectionPath().getLastPathComponent();
122
                }else{
123
                        source = e.getNewLeadSelectionPath().getLastPathComponent();
124
                }
125
                                        
126
                if (source instanceof IProjectInfo){                        
127
                        resourceToAdd = source;
128
                }
129
                if (source instanceof IViewInfo){
130
                        resourceToAdd = source;                        
131
                }
132
                if (source instanceof ILayerInfo){        
133
                        resourceToAdd = source;                        
134
                }
135
        }
136
        
137
        /**
138
         * Sets the publication 
139
         */
140
        public void setPublication(Publication publi){
141
                if (publi == null){
142
                        PublishLogger.getLog().error("ERROR AddresourceController : the publication can't be nulll");
143
                }else{
144
                        publication = publi;
145
                }
146
        }
147
        /**
148
         * Gets the controller's panel
149
         */
150
        public AddResourcePanel getWindow(){
151
                return this.window;
152
        }
153
}