Statistics
| Revision:

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

History | View | Annotate | Download (4.08 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
         */
81
        public void showWindow(){
82
                window.setModel(publication.getProjectInfo());
83
                //show the window
84
                window.showWindow();
85
        }
86
        /**
87
         * Get actions from the controls panel
88
         */
89
        public void actionPerformed(ActionEvent e) {
90
                if (e.getActionCommand().equals(AddResourceController.ADDRESOURCE_EVENT_CANCEL)){                        
91
                        window.closeWindow();
92
                        return;
93
                }
94
                if (e.getActionCommand().equals(AddResourceController.ADDRESOURCE_EVENT_ACCEPT)){                        
95
                        window.closeWindow();
96
                        if (resourceToAdd instanceof IProjectInfo){
97
                                IProjectInfo projectInfo = (IProjectInfo)resourceToAdd;                                
98
                                publication.getServer().setProjectInfo(projectInfo);
99
                        }
100
                        if (resourceToAdd instanceof IViewInfo){
101
                                IViewInfo viewInfo = (IViewInfo)resourceToAdd;
102
                                publication.getServer().addInfo(viewInfo);                                
103
                        }
104
                        if (resourceToAdd instanceof ILayerInfo){
105
                                ILayerInfo layerInfo = (ILayerInfo)resourceToAdd;        
106
                                publication.getServer().addInfo(layerInfo);                        
107
                        }
108
                }
109
        }
110
        /**
111
         * It finds out about the resource to add
112
         * TODO: I don't know why sometimes getNewLeadSelectionPath is null !!
113
         */
114
        public void valueChanged(TreeSelectionEvent e) {
115
                Object source = null;
116
                if (e.getNewLeadSelectionPath() == null){
117
                        source = e.getOldLeadSelectionPath().getLastPathComponent();
118
                }else{
119
                        source = e.getNewLeadSelectionPath().getLastPathComponent();
120
                }
121
                                        
122
                if (source instanceof IProjectInfo){                        
123
                        resourceToAdd = source;
124
                }
125
                if (source instanceof IViewInfo){
126
                        resourceToAdd = source;                        
127
                }
128
                if (source instanceof ILayerInfo){        
129
                        resourceToAdd = source;                        
130
                }
131
        }
132
        
133
        /**
134
         * Sets the publication 
135
         */
136
        public void setPublication(Publication publi){
137
                if (publi == null){
138
                        PublishLogger.getLog().error("ERROR AddresourceController : the publication can't be nulll");
139
                }else{
140
                        publication = publi;
141
                }
142
        }
143
}