root / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / gui / panels / WFSSelectFeaturePanelListener.java @ 17791
History | View | Annotate | Download (7.04 KB)
1 |
package com.iver.cit.gvsig.gui.panels; |
---|---|
2 |
|
3 |
import java.net.URL; |
4 |
import java.util.ArrayList; |
5 |
|
6 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
7 |
import com.iver.andami.PluginServices; |
8 |
import com.iver.andami.messages.NotificationManager; |
9 |
import com.iver.andami.ui.mdiManager.IWindow; |
10 |
import com.iver.cit.gvsig.ProjectExtension; |
11 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
12 |
import com.iver.cit.gvsig.fmap.MapControl; |
13 |
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver; |
14 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
15 |
import com.iver.cit.gvsig.fmap.layers.FLyrWFS; |
16 |
import com.iver.cit.gvsig.fmap.layers.FLyrWFSFactory; |
17 |
import com.iver.cit.gvsig.fmap.rendering.IVectorLegend; |
18 |
import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
19 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
20 |
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
21 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
22 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
23 |
*
|
24 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
25 |
*
|
26 |
* This program is free software; you can redistribute it and/or
|
27 |
* modify it under the terms of the GNU General Public License
|
28 |
* as published by the Free Software Foundation; either version 2
|
29 |
* of the License, or (at your option) any later version.
|
30 |
*
|
31 |
* This program is distributed in the hope that it will be useful,
|
32 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
33 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
34 |
* GNU General Public License for more details.
|
35 |
*
|
36 |
* You should have received a copy of the GNU General Public License
|
37 |
* along with this program; if not, write to the Free Software
|
38 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
39 |
*
|
40 |
* For more information, contact:
|
41 |
*
|
42 |
* Generalitat Valenciana
|
43 |
* Conselleria d'Infraestructures i Transport
|
44 |
* Av. Blasco Ib??ez, 50
|
45 |
* 46010 VALENCIA
|
46 |
* SPAIN
|
47 |
*
|
48 |
* +34 963862235
|
49 |
* gvsig@gva.es
|
50 |
* www.gvsig.gva.es
|
51 |
*
|
52 |
* or
|
53 |
*
|
54 |
* IVER T.I. S.A
|
55 |
* Salamanca 50
|
56 |
* 46005 Valencia
|
57 |
* Spain
|
58 |
*
|
59 |
* +34 963163400
|
60 |
* dac@iver.es
|
61 |
*/
|
62 |
/* CVS MESSAGES:
|
63 |
*
|
64 |
* $Id$
|
65 |
* $Log$
|
66 |
*
|
67 |
*/
|
68 |
/**
|
69 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
70 |
*/
|
71 |
public class WFSSelectFeaturePanelListener{ |
72 |
public static final int CANCEL_BUTTON_ACTION_COMMAND = 0; |
73 |
public static final int APPLY_BUTTON_ACTION_COMMAND = 1; |
74 |
public static final int ACCEPT_BUTTON_ACTION_COMMAND = 2; |
75 |
|
76 |
private WFSParamsPanelData paramsPanel = null; |
77 |
private FLyrWFS layer = null; |
78 |
|
79 |
public WFSSelectFeaturePanelListener(WFSParamsPanelData paramsPanel) {
|
80 |
this.paramsPanel = paramsPanel;
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Exectutes the action
|
85 |
*/
|
86 |
public void actionPerformed(int actionEvent) { |
87 |
layer = (FLyrWFS)paramsPanel.getLayer(); |
88 |
//Accept or apply
|
89 |
try {
|
90 |
// Gets the driver
|
91 |
FMapWFSDriver driver = paramsPanel.getDriver(); |
92 |
|
93 |
// Sets the online resource
|
94 |
URL host = new URL(paramsPanel.getWizardData().getHost()); |
95 |
String onlineResource = paramsPanel.getWizardData().getOnlineResource();
|
96 |
|
97 |
// Tries to get the new layer
|
98 |
FLyrWFS newLayer = new FLyrWFSFactory().getFLyrWFS(layer, host, onlineResource, driver, true, false); |
99 |
|
100 |
// If can load the layer, update all data
|
101 |
|
102 |
if (newLayer != null) { |
103 |
// Removes the last project table if exists
|
104 |
removeProjectTable(layer); |
105 |
|
106 |
// Sets the legend
|
107 |
IVectorLegend legend = (IVectorLegend)layer.getLegend(); |
108 |
newLayer.setLegend(legend); |
109 |
|
110 |
//Apply button clicked
|
111 |
if (actionEvent == APPLY_BUTTON_ACTION_COMMAND) {
|
112 |
applyButtonActionPerformed(); |
113 |
refreshLayouts(); |
114 |
return;
|
115 |
} |
116 |
//Accept button clicked
|
117 |
if (actionEvent == ACCEPT_BUTTON_ACTION_COMMAND) {
|
118 |
acceptButtonActionPerformed(); |
119 |
refreshLayouts(); |
120 |
return;
|
121 |
} |
122 |
} |
123 |
} catch (Exception e1) { |
124 |
NotificationManager.addError(e1); |
125 |
} |
126 |
} |
127 |
|
128 |
/**
|
129 |
* Action for the apply button
|
130 |
* @throws LoadLayerException
|
131 |
*/
|
132 |
private void applyButtonActionPerformed() throws LoadLayerException{ |
133 |
// We can't 'apply' if there is a filter query and it's incorrect
|
134 |
if (paramsPanel.getFilterPanel().getQuery() != null) { |
135 |
String layerName = layer.getName();
|
136 |
BaseView activeView = (BaseView) PluginServices.getMDIManager().getActiveWindow(); |
137 |
MapControl mapCtrl = activeView.getMapControl(); |
138 |
mapCtrl.getMapContext().getLayers().replaceLayer(layerName, layer); |
139 |
mapCtrl.getMapContext().invalidate(); |
140 |
|
141 |
|
142 |
// Restores the private attribute of the area panel: hasUserDefinedAnArea
|
143 |
paramsPanel.getAreaPanel().setUserHasntDefineAnArea(); |
144 |
|
145 |
// If we load another layer, or the same but we've selected others fields -> notify it to the WFSFilter panel
|
146 |
if ((paramsPanel.getFilterPanel().getWFSFilterPanelIsAsTabForWFSLayersLoad()) ||
|
147 |
(paramsPanel.getFieldsPanel().getFieldsSelectedOfSameLayerHasChanged())) { |
148 |
paramsPanel.getFilterPanel().setWFSFilterPanelIsAsTabForWFSLayersLoad(false);
|
149 |
paramsPanel.getFieldsPanel().resetFieldsSelectedOfSameLayerHasChanged(); // reset that field
|
150 |
} |
151 |
|
152 |
// Update values associated to the current selected field
|
153 |
paramsPanel.getFilterPanel().updateFieldValues(); |
154 |
paramsPanel.getAreaPanel().updateWFSArea(); |
155 |
} |
156 |
} |
157 |
|
158 |
/**
|
159 |
* Action for the accept button
|
160 |
* @throws LoadLayerException
|
161 |
*/
|
162 |
private void acceptButtonActionPerformed() throws LoadLayerException{ |
163 |
// We can't 'apply' if there is a filter query and it's incorrect
|
164 |
if (paramsPanel.getFilterPanel().getQuery() != null) { |
165 |
String layerName = layer.getName();
|
166 |
BaseView vista = (BaseView) PluginServices.getMDIManager().getActiveWindow(); |
167 |
MapControl mapCtrl = vista.getMapControl(); |
168 |
mapCtrl.getMapContext().getLayers().replaceLayer(layerName, layer); |
169 |
mapCtrl.getMapContext().invalidate(); |
170 |
|
171 |
// Restores the private attribute of the area panel: hasUserDefinedAnArea
|
172 |
paramsPanel.getAreaPanel().setUserHasntDefineAnArea(); |
173 |
|
174 |
} |
175 |
|
176 |
// Update all fields and values known about the current layer loaded (and selected)
|
177 |
layer.setAllFieldsAndValuesKnown(paramsPanel.getFilterPanel().getAllFieldsAndValuesKnownOfCurrentLayer()); |
178 |
} |
179 |
|
180 |
/**
|
181 |
* It removes the associated project table
|
182 |
* @param flayer
|
183 |
* Flayer vercorial
|
184 |
*/
|
185 |
private void removeProjectTable(FLyrVect flayer){ |
186 |
//remove it
|
187 |
ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
188 |
ArrayList tables = ext.getProject().getDocumentsByType(ProjectTableFactory.registerName);
|
189 |
for (int i=0 ; i<tables.size() ; i++){ |
190 |
ProjectTable projectTable = (ProjectTable)tables.get(i); |
191 |
try {
|
192 |
Object obj = projectTable.getAssociatedTable().getRecordset();
|
193 |
if (flayer.getRecordset().equals(projectTable.getAssociatedTable().getRecordset())){
|
194 |
ext.getProject().delDocument(projectTable); |
195 |
} |
196 |
} catch (ReadDriverException e) {
|
197 |
//It doens't matter. The table will not deleted
|
198 |
} |
199 |
|
200 |
} |
201 |
} |
202 |
|
203 |
/**
|
204 |
* Refresh the layouts
|
205 |
*/
|
206 |
private void refreshLayouts(){ |
207 |
IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
|
208 |
for (int i=0 ; i<windows.length ; i++){ |
209 |
if (windows[i] instanceof Layout){ |
210 |
((Layout)windows[i]).getLayoutContext().fullRefresh(); |
211 |
} |
212 |
} |
213 |
} |
214 |
} |
215 |
|
216 |
|