svn-gvsig-desktop / branches / v10 / extensions / extPublish / src / org / gvsig / publish / gui / addResource / AddResourceController.java @ 22616
History | View | Annotate | Download (4.76 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 |
import java.util.HashSet; |
46 |
import java.util.Iterator; |
47 |
|
48 |
import javax.swing.JOptionPane; |
49 |
import javax.swing.event.TreeSelectionEvent; |
50 |
import javax.swing.event.TreeSelectionListener; |
51 |
import javax.swing.tree.TreePath; |
52 |
|
53 |
import org.gvsig.publish.PublishLogger; |
54 |
import org.gvsig.publish.exceptions.InvalidRemoteResourceException; |
55 |
import org.gvsig.publish.infoproject.FilterProjectInfo; |
56 |
import org.gvsig.publish.infoproject.ILayerInfo; |
57 |
import org.gvsig.publish.infoproject.IProjectInfo; |
58 |
import org.gvsig.publish.infoproject.IViewInfo; |
59 |
import org.gvsig.publish.serversmodel.Publication; |
60 |
|
61 |
import com.iver.andami.PluginServices; |
62 |
|
63 |
|
64 |
public class AddResourceController implements ActionListener,TreeSelectionListener { |
65 |
/*
|
66 |
* Events
|
67 |
*/
|
68 |
public static final String ADDRESOURCE_EVENT_ACCEPT="accept_add_resource"; |
69 |
public static final String ADDRESOURCE_EVENT_CANCEL="cancel_add_resource"; |
70 |
/*
|
71 |
*Dependencies
|
72 |
*/
|
73 |
private Publication publication = null; |
74 |
//private IProjectInfo projectInfo = null;
|
75 |
private AddResourceWindow window = null; |
76 |
|
77 |
private HashSet resourcesToAdd = new HashSet(); |
78 |
/**
|
79 |
* Constructor:
|
80 |
* <p>
|
81 |
* Creates the window and sets the listener itself.
|
82 |
*/
|
83 |
public AddResourceController(){
|
84 |
window = new AddResourceWindow();
|
85 |
window.setListener(this);
|
86 |
} |
87 |
/**
|
88 |
* Shows the window in order to add resources
|
89 |
* TODO: At the moment only gets the project information from the first service (it can be filtered)
|
90 |
* If we want multiservice support, we must have an "activeservice" in this class in order to show
|
91 |
* the suitable projectinfo tree
|
92 |
*/
|
93 |
public void showWindow(){ |
94 |
//window.setModel(publication.getProjectInfo());
|
95 |
FilterProjectInfo filter = publication.getServer().getService(0).getFilter();
|
96 |
IProjectInfo pi = publication.getProjectInfo(); |
97 |
pi.setFilter(filter); |
98 |
window.setModel(pi); |
99 |
//show the window
|
100 |
window.showWindow(); |
101 |
} |
102 |
/**
|
103 |
* Get actions from the controls panel
|
104 |
*/
|
105 |
public void actionPerformed(ActionEvent e) { |
106 |
if (e.getActionCommand().equals(AddResourceController.ADDRESOURCE_EVENT_CANCEL)){
|
107 |
resourcesToAdd.clear(); |
108 |
window.closeWindow(); |
109 |
return;
|
110 |
} |
111 |
if (e.getActionCommand().equals(AddResourceController.ADDRESOURCE_EVENT_ACCEPT)){
|
112 |
Iterator i = resourcesToAdd.iterator();
|
113 |
while (i.hasNext()){
|
114 |
try {
|
115 |
Object o = i.next();
|
116 |
if (o instanceof IViewInfo){ |
117 |
IViewInfo viewInfo = (IViewInfo)o; |
118 |
publication.getServer().addInfo(viewInfo); |
119 |
} |
120 |
if (o instanceof ILayerInfo){ |
121 |
ILayerInfo layerInfo = (ILayerInfo)o; |
122 |
publication.getServer().addInfo(layerInfo); |
123 |
} |
124 |
}catch (InvalidRemoteResourceException ex){
|
125 |
JOptionPane.showMessageDialog(window,
|
126 |
ex.getMessage(), |
127 |
PluginServices.getText(this,"publish_invalid_remote_resource"), |
128 |
JOptionPane.ERROR_MESSAGE);
|
129 |
} |
130 |
} |
131 |
window.closeWindow(); |
132 |
} |
133 |
} |
134 |
/**
|
135 |
* Tree selection event
|
136 |
*/
|
137 |
public void valueChanged(TreeSelectionEvent e) { |
138 |
TreePath[] paths = e.getPaths(); |
139 |
for (int i = 0; i < paths.length; i++){ |
140 |
if (e.isAddedPath(paths[i])){
|
141 |
resourcesToAdd.add(paths[i].getLastPathComponent()); |
142 |
}else{
|
143 |
resourcesToAdd.remove(paths[i].getLastPathComponent()); |
144 |
} |
145 |
} |
146 |
} |
147 |
|
148 |
/**
|
149 |
* Sets the publication
|
150 |
*/
|
151 |
public void setPublication(Publication publi){ |
152 |
if (publi == null){ |
153 |
PublishLogger.getLog().error("ERROR AddresourceController : the publication can't be nulll");
|
154 |
}else{
|
155 |
publication = publi; |
156 |
} |
157 |
} |
158 |
/**
|
159 |
* Gets the controller's panel
|
160 |
*/
|
161 |
public AddResourcePanel getWindow(){
|
162 |
return this.window; |
163 |
} |
164 |
} |