svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.datalocator.app / org.gvsig.datalocator.app.mainplugin / src / main / java / org / gvsig / datalocator / DataLocatorExtension.java @ 40558
History | View | Annotate | Download (6.55 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.datalocator; |
25 |
|
26 |
import java.util.prefs.Preferences; |
27 |
|
28 |
import org.gvsig.andami.IconThemeHelper; |
29 |
import org.gvsig.andami.PluginServices; |
30 |
import org.gvsig.andami.plugins.Extension; |
31 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
32 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
33 |
import org.gvsig.app.project.documents.view.ViewDocument; |
34 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
35 |
import org.gvsig.datalocator.gui.DataSelectionPanel; |
36 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
37 |
import org.gvsig.fmap.mapcontext.MapContext; |
38 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
39 |
import org.gvsig.fmap.mapcontext.layers.LayersIterator; |
40 |
import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection; |
41 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
42 |
|
43 |
|
44 |
/**
|
45 |
* The DataLocatorExtension class allows to make a quick zoom based on an
|
46 |
* alphanumeric attribute.
|
47 |
*
|
48 |
* @author jmorell
|
49 |
*/
|
50 |
public class DataLocatorExtension extends Extension { |
51 |
|
52 |
IWindow iWDataSelection = null;
|
53 |
IWindow previousView = null;
|
54 |
|
55 |
/* (non-Javadoc)
|
56 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
57 |
*/
|
58 |
public void initialize() { |
59 |
registerIcons(); |
60 |
|
61 |
} |
62 |
|
63 |
private void registerIcons(){ |
64 |
IconThemeHelper.registerIcon("action", "view-navigation-locator-by-attribute", this); |
65 |
} |
66 |
|
67 |
/* (non-Javadoc)
|
68 |
* @see com.iver.andami.plugins.Extension#execute(java.lang.String)
|
69 |
*/
|
70 |
public void execute(String actionCommand) { |
71 |
if( "view-navigation-locator-by-attribute".equalsIgnoreCase(actionCommand)) { |
72 |
DefaultViewPanel vista = (DefaultViewPanel)PluginServices.getMDIManager().getActiveWindow(); |
73 |
MapContext mapContext = vista.getViewDocument().getMapContext(); |
74 |
DataSelectionPanel dataSelectionPanel = new DataSelectionPanel(mapContext);
|
75 |
WindowInfo vi = dataSelectionPanel.getWindowInfo(); |
76 |
vi.setX(Preferences.userRoot().getInt("gvSIG.DataLocator.x", vi.getX())); |
77 |
vi.setY(Preferences.userRoot().getInt("gvSIG.DataLocator.y", vi.getY())); |
78 |
// vi.setWidth(Preferences.userRoot().getInt("gvSIG.DataLocator.w", vi.getWidth()));
|
79 |
// vi.setHeight(Preferences.userRoot().getInt("gvSIG.DataLocator.h", vi.getHeight()));
|
80 |
|
81 |
PluginServices.getMDIManager().addWindow(dataSelectionPanel); |
82 |
iWDataSelection = dataSelectionPanel; |
83 |
iWDataSelection.getWindowInfo(); |
84 |
} |
85 |
} |
86 |
|
87 |
/* (non-Javadoc)
|
88 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
89 |
*/
|
90 |
public boolean isEnabled() { |
91 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
92 |
.getActiveWindow(); |
93 |
if (f == null) { |
94 |
return false; |
95 |
} |
96 |
if (f.getClass() == DefaultViewPanel.class) {
|
97 |
|
98 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
99 |
ViewDocument model = vista.getModel(); |
100 |
MapContext mapContext = model.getMapContext(); |
101 |
if (mapContext.getLayers().getLayersCount() > 0) { |
102 |
LayersIterator iter = newValidLayersIterator(mapContext.getLayers()); |
103 |
if (!iter.hasNext()) {
|
104 |
return false; |
105 |
} |
106 |
} else {
|
107 |
return false; |
108 |
} |
109 |
|
110 |
// Si la vista tiene el tema con el que est? configurado
|
111 |
// el DataLocator y el usuario ha decidido que se abra
|
112 |
// autom?ticamente, la abrimos inmediatamente.
|
113 |
if (iWDataSelection == null || (PluginServices.getMDIManager() |
114 |
.getWindowInfo(iWDataSelection).isClosed() && f!=previousView)) { |
115 |
int userOpen = Preferences.userRoot().getInt("gvSIG.DataLocator.open_first_time", -1); |
116 |
if (userOpen == 1) |
117 |
{ |
118 |
String layerName = Preferences.userRoot().get("LAYERNAME_FOR_DATA_LOCATION", ""); |
119 |
FLayer lyr = mapContext.getLayers().getLayer(layerName); |
120 |
if (lyr != null) |
121 |
{ |
122 |
DataSelectionPanel dataSelectionPanel = new DataSelectionPanel(mapContext);
|
123 |
WindowInfo vi = dataSelectionPanel.getWindowInfo(); |
124 |
vi.setX(Preferences.userRoot().getInt("gvSIG.DataLocator.x", vi.getX())); |
125 |
vi.setY(Preferences.userRoot().getInt("gvSIG.DataLocator.y", vi.getY())); |
126 |
// vi.setWidth(Preferences.userRoot().getInt("gvSIG.DataLocator.w", vi.getWidth()));
|
127 |
// vi.setHeight(Preferences.userRoot().getInt("gvSIG.DataLocator.h", vi.getHeight()));
|
128 |
|
129 |
PluginServices.getMDIManager().addWindow(dataSelectionPanel); |
130 |
iWDataSelection = dataSelectionPanel; |
131 |
iWDataSelection.getWindowInfo(); |
132 |
} |
133 |
} |
134 |
} |
135 |
previousView = f; |
136 |
} |
137 |
return true; |
138 |
} |
139 |
|
140 |
/* (non-Javadoc)
|
141 |
* @see com.iver.andami.plugins.Extension#isVisible()
|
142 |
*/
|
143 |
public boolean isVisible() { |
144 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
145 |
.getActiveWindow(); |
146 |
if (f == null) { |
147 |
return false; |
148 |
} |
149 |
if (f.getClass() == DefaultViewPanel.class) {
|
150 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
151 |
ViewDocument model = vista.getModel(); |
152 |
MapContext mapContext = model.getMapContext(); |
153 |
return mapContext.getLayers().getLayersCount() > 0; |
154 |
} else {
|
155 |
return false; |
156 |
} |
157 |
} |
158 |
|
159 |
public static LayersIterator newValidLayersIterator(LayerCollection layer) { |
160 |
return new LayersIterator((FLayer)layer){ |
161 |
public boolean evaluate(FLayer layer) { |
162 |
if (!(layer instanceof FLyrVect)) |
163 |
return false; |
164 |
|
165 |
FeatureStore featureStore; |
166 |
try {
|
167 |
featureStore = ((FLyrVect)layer).getFeatureStore(); |
168 |
if (featureStore.getDefaultFeatureType().size() < 1) |
169 |
return false; |
170 |
|
171 |
} catch (Exception e) { |
172 |
return false; |
173 |
} |
174 |
return true; |
175 |
} |
176 |
}; |
177 |
} |
178 |
} |