root / branches / v2_0_0_prep / extensions / extDataLocator / src / org / gvsig / datalocator / DataLocatorExtension.java @ 29628
History | View | Annotate | Download (6.68 KB)
1 |
/*
|
---|---|
2 |
* Created on 22-jun-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
package org.gvsig.datalocator; |
45 |
|
46 |
import java.util.prefs.Preferences; |
47 |
|
48 |
import org.gvsig.andami.PluginServices; |
49 |
import org.gvsig.andami.plugins.Extension; |
50 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
51 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
52 |
import org.gvsig.app.project.documents.view.IProjectView; |
53 |
import org.gvsig.app.project.documents.view.gui.View; |
54 |
import org.gvsig.datalocator.gui.DataSelectionPanel; |
55 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
56 |
import org.gvsig.fmap.mapcontext.MapContext; |
57 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
58 |
import org.gvsig.fmap.mapcontext.layers.LayersIterator; |
59 |
import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection; |
60 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
61 |
|
62 |
|
63 |
/**
|
64 |
* The DataLocatorExtension class allows to make a quick zoom based on an
|
65 |
* alphanumeric attribute.
|
66 |
*
|
67 |
* @author jmorell
|
68 |
*/
|
69 |
public class DataLocatorExtension extends Extension { |
70 |
|
71 |
IWindow iWDataSelection = null;
|
72 |
IWindow previousView = null;
|
73 |
|
74 |
/* (non-Javadoc)
|
75 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
76 |
*/
|
77 |
public void initialize() { |
78 |
registerIcons(); |
79 |
|
80 |
} |
81 |
|
82 |
private void registerIcons(){ |
83 |
//view-locator
|
84 |
PluginServices.getIconTheme().registerDefault( |
85 |
"view-locator",
|
86 |
this.getClass().getClassLoader().getResource("images/locator.png") |
87 |
); |
88 |
} |
89 |
|
90 |
/* (non-Javadoc)
|
91 |
* @see com.iver.andami.plugins.Extension#execute(java.lang.String)
|
92 |
*/
|
93 |
public void execute(String actionCommand) { |
94 |
View vista = (View)PluginServices.getMDIManager().getActiveWindow(); |
95 |
MapContext mapContext = vista.getModel().getMapContext(); |
96 |
DataSelectionPanel dataSelectionPanel = new DataSelectionPanel(mapContext);
|
97 |
WindowInfo vi = dataSelectionPanel.getWindowInfo(); |
98 |
vi.setX(Preferences.userRoot().getInt("gvSIG.DataLocator.x", vi.getX())); |
99 |
vi.setY(Preferences.userRoot().getInt("gvSIG.DataLocator.y", vi.getY())); |
100 |
// vi.setWidth(Preferences.userRoot().getInt("gvSIG.DataLocator.w", vi.getWidth()));
|
101 |
// vi.setHeight(Preferences.userRoot().getInt("gvSIG.DataLocator.h", vi.getHeight()));
|
102 |
|
103 |
PluginServices.getMDIManager().addWindow(dataSelectionPanel); |
104 |
iWDataSelection = dataSelectionPanel; |
105 |
iWDataSelection.getWindowInfo(); |
106 |
} |
107 |
|
108 |
/* (non-Javadoc)
|
109 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
110 |
*/
|
111 |
public boolean isEnabled() { |
112 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
113 |
.getActiveWindow(); |
114 |
if (f == null) { |
115 |
return false; |
116 |
} |
117 |
if (f.getClass() == View.class) { |
118 |
|
119 |
View vista = (View) f; |
120 |
IProjectView model = vista.getModel(); |
121 |
MapContext mapContext = model.getMapContext(); |
122 |
if (mapContext.getLayers().getLayersCount() > 0) { |
123 |
LayersIterator iter = newValidLayersIterator(mapContext.getLayers()); |
124 |
if (!iter.hasNext()) {
|
125 |
return false; |
126 |
} |
127 |
} else {
|
128 |
return false; |
129 |
} |
130 |
|
131 |
// Si la vista tiene el tema con el que est? configurado
|
132 |
// el DataLocator y el usuario ha decidido que se abra
|
133 |
// autom?ticamente, la abrimos inmediatamente.
|
134 |
if (iWDataSelection == null || (PluginServices.getMDIManager() |
135 |
.getWindowInfo(iWDataSelection).isClosed() && f!=previousView)) { |
136 |
int userOpen = Preferences.userRoot().getInt("gvSIG.DataLocator.open_first_time", -1); |
137 |
if (userOpen == 1) |
138 |
{ |
139 |
String layerName = Preferences.userRoot().get("LAYERNAME_FOR_DATA_LOCATION", ""); |
140 |
FLayer lyr = mapContext.getLayers().getLayer(layerName); |
141 |
if (lyr != null) |
142 |
{ |
143 |
DataSelectionPanel dataSelectionPanel = new DataSelectionPanel(mapContext);
|
144 |
WindowInfo vi = dataSelectionPanel.getWindowInfo(); |
145 |
vi.setX(Preferences.userRoot().getInt("gvSIG.DataLocator.x", vi.getX())); |
146 |
vi.setY(Preferences.userRoot().getInt("gvSIG.DataLocator.y", vi.getY())); |
147 |
// vi.setWidth(Preferences.userRoot().getInt("gvSIG.DataLocator.w", vi.getWidth()));
|
148 |
// vi.setHeight(Preferences.userRoot().getInt("gvSIG.DataLocator.h", vi.getHeight()));
|
149 |
|
150 |
PluginServices.getMDIManager().addWindow(dataSelectionPanel); |
151 |
iWDataSelection = dataSelectionPanel; |
152 |
iWDataSelection.getWindowInfo(); |
153 |
} |
154 |
} |
155 |
} |
156 |
previousView = f; |
157 |
} |
158 |
return true; |
159 |
} |
160 |
|
161 |
/* (non-Javadoc)
|
162 |
* @see com.iver.andami.plugins.Extension#isVisible()
|
163 |
*/
|
164 |
public boolean isVisible() { |
165 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
166 |
.getActiveWindow(); |
167 |
if (f == null) { |
168 |
return false; |
169 |
} |
170 |
if (f.getClass() == View.class) { |
171 |
View vista = (View) f; |
172 |
IProjectView model = vista.getModel(); |
173 |
MapContext mapContext = model.getMapContext(); |
174 |
return mapContext.getLayers().getLayersCount() > 0; |
175 |
} else {
|
176 |
return false; |
177 |
} |
178 |
} |
179 |
|
180 |
public static LayersIterator newValidLayersIterator(LayerCollection layer) { |
181 |
return new LayersIterator((FLayer)layer){ |
182 |
public boolean evaluate(FLayer layer) { |
183 |
if (!(layer instanceof FLyrVect)) |
184 |
return false; |
185 |
|
186 |
FeatureStore featureStore; |
187 |
try {
|
188 |
featureStore = ((FLyrVect)layer).getFeatureStore(); |
189 |
if (featureStore.getDefaultFeatureType().size() < 1) |
190 |
return false; |
191 |
|
192 |
} catch (Exception e) { |
193 |
return false; |
194 |
} |
195 |
return true; |
196 |
} |
197 |
}; |
198 |
} |
199 |
} |