root / branches / v2_0_0_prep / extensions / extDataLocator / src / org / gvsig / datalocator / DataLocatorExtension.java @ 38564
History | View | Annotate | Download (6.86 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.IconThemeHelper; |
49 |
import org.gvsig.andami.PluginServices; |
50 |
import org.gvsig.andami.plugins.Extension; |
51 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
52 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
53 |
import org.gvsig.app.project.documents.view.ViewDocument; |
54 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
55 |
import org.gvsig.datalocator.gui.DataSelectionPanel; |
56 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
57 |
import org.gvsig.fmap.mapcontext.MapContext; |
58 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
59 |
import org.gvsig.fmap.mapcontext.layers.LayersIterator; |
60 |
import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection; |
61 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
62 |
|
63 |
|
64 |
/**
|
65 |
* The DataLocatorExtension class allows to make a quick zoom based on an
|
66 |
* alphanumeric attribute.
|
67 |
*
|
68 |
* @author jmorell
|
69 |
*/
|
70 |
public class DataLocatorExtension extends Extension { |
71 |
|
72 |
IWindow iWDataSelection = null;
|
73 |
IWindow previousView = null;
|
74 |
|
75 |
/* (non-Javadoc)
|
76 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
77 |
*/
|
78 |
public void initialize() { |
79 |
registerIcons(); |
80 |
|
81 |
} |
82 |
|
83 |
private void registerIcons(){ |
84 |
IconThemeHelper.registerIcon("action", "view-navigation-locator-by-attribute", this); |
85 |
} |
86 |
|
87 |
/* (non-Javadoc)
|
88 |
* @see com.iver.andami.plugins.Extension#execute(java.lang.String)
|
89 |
*/
|
90 |
public void execute(String actionCommand) { |
91 |
if( "view-navigation-locator-by-attribute".equalsIgnoreCase(actionCommand)) { |
92 |
DefaultViewPanel vista = (DefaultViewPanel)PluginServices.getMDIManager().getActiveWindow(); |
93 |
MapContext mapContext = vista.getViewDocument().getMapContext(); |
94 |
DataSelectionPanel dataSelectionPanel = new DataSelectionPanel(mapContext);
|
95 |
WindowInfo vi = dataSelectionPanel.getWindowInfo(); |
96 |
vi.setX(Preferences.userRoot().getInt("gvSIG.DataLocator.x", vi.getX())); |
97 |
vi.setY(Preferences.userRoot().getInt("gvSIG.DataLocator.y", vi.getY())); |
98 |
// vi.setWidth(Preferences.userRoot().getInt("gvSIG.DataLocator.w", vi.getWidth()));
|
99 |
// vi.setHeight(Preferences.userRoot().getInt("gvSIG.DataLocator.h", vi.getHeight()));
|
100 |
|
101 |
PluginServices.getMDIManager().addWindow(dataSelectionPanel); |
102 |
iWDataSelection = dataSelectionPanel; |
103 |
iWDataSelection.getWindowInfo(); |
104 |
} |
105 |
} |
106 |
|
107 |
/* (non-Javadoc)
|
108 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
109 |
*/
|
110 |
public boolean isEnabled() { |
111 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
112 |
.getActiveWindow(); |
113 |
if (f == null) { |
114 |
return false; |
115 |
} |
116 |
if (f.getClass() == DefaultViewPanel.class) {
|
117 |
|
118 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
119 |
ViewDocument model = vista.getModel(); |
120 |
MapContext mapContext = model.getMapContext(); |
121 |
if (mapContext.getLayers().getLayersCount() > 0) { |
122 |
LayersIterator iter = newValidLayersIterator(mapContext.getLayers()); |
123 |
if (!iter.hasNext()) {
|
124 |
return false; |
125 |
} |
126 |
} else {
|
127 |
return false; |
128 |
} |
129 |
|
130 |
// Si la vista tiene el tema con el que est? configurado
|
131 |
// el DataLocator y el usuario ha decidido que se abra
|
132 |
// autom?ticamente, la abrimos inmediatamente.
|
133 |
if (iWDataSelection == null || (PluginServices.getMDIManager() |
134 |
.getWindowInfo(iWDataSelection).isClosed() && f!=previousView)) { |
135 |
int userOpen = Preferences.userRoot().getInt("gvSIG.DataLocator.open_first_time", -1); |
136 |
if (userOpen == 1) |
137 |
{ |
138 |
String layerName = Preferences.userRoot().get("LAYERNAME_FOR_DATA_LOCATION", ""); |
139 |
FLayer lyr = mapContext.getLayers().getLayer(layerName); |
140 |
if (lyr != null) |
141 |
{ |
142 |
DataSelectionPanel dataSelectionPanel = new DataSelectionPanel(mapContext);
|
143 |
WindowInfo vi = dataSelectionPanel.getWindowInfo(); |
144 |
vi.setX(Preferences.userRoot().getInt("gvSIG.DataLocator.x", vi.getX())); |
145 |
vi.setY(Preferences.userRoot().getInt("gvSIG.DataLocator.y", vi.getY())); |
146 |
// vi.setWidth(Preferences.userRoot().getInt("gvSIG.DataLocator.w", vi.getWidth()));
|
147 |
// vi.setHeight(Preferences.userRoot().getInt("gvSIG.DataLocator.h", vi.getHeight()));
|
148 |
|
149 |
PluginServices.getMDIManager().addWindow(dataSelectionPanel); |
150 |
iWDataSelection = dataSelectionPanel; |
151 |
iWDataSelection.getWindowInfo(); |
152 |
} |
153 |
} |
154 |
} |
155 |
previousView = f; |
156 |
} |
157 |
return true; |
158 |
} |
159 |
|
160 |
/* (non-Javadoc)
|
161 |
* @see com.iver.andami.plugins.Extension#isVisible()
|
162 |
*/
|
163 |
public boolean isVisible() { |
164 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
165 |
.getActiveWindow(); |
166 |
if (f == null) { |
167 |
return false; |
168 |
} |
169 |
if (f.getClass() == DefaultViewPanel.class) {
|
170 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
171 |
ViewDocument model = vista.getModel(); |
172 |
MapContext mapContext = model.getMapContext(); |
173 |
return mapContext.getLayers().getLayersCount() > 0; |
174 |
} else {
|
175 |
return false; |
176 |
} |
177 |
} |
178 |
|
179 |
public static LayersIterator newValidLayersIterator(LayerCollection layer) { |
180 |
return new LayersIterator((FLayer)layer){ |
181 |
public boolean evaluate(FLayer layer) { |
182 |
if (!(layer instanceof FLyrVect)) |
183 |
return false; |
184 |
|
185 |
FeatureStore featureStore; |
186 |
try {
|
187 |
featureStore = ((FLyrVect)layer).getFeatureStore(); |
188 |
if (featureStore.getDefaultFeatureType().size() < 1) |
189 |
return false; |
190 |
|
191 |
} catch (Exception e) { |
192 |
return false; |
193 |
} |
194 |
return true; |
195 |
} |
196 |
}; |
197 |
} |
198 |
} |