svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / ViewSelectionByTheme.java @ 44601
History | View | Annotate | Download (4.5 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 modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.app.extension; |
24 |
|
25 |
import java.util.List; |
26 |
import org.gvsig.andami.IconThemeHelper; |
27 |
import org.gvsig.andami.plugins.Extension; |
28 |
import org.gvsig.app.ApplicationLocator; |
29 |
import org.gvsig.app.ApplicationManager; |
30 |
import org.gvsig.app.gui.selectionByTheme.DefaultSelectionByThemeModel; |
31 |
import org.gvsig.app.gui.selectionByTheme.MySelectionByThemeListener; |
32 |
import org.gvsig.app.gui.selectionByTheme.SelectionByTheme; |
33 |
import org.gvsig.app.project.documents.view.ViewDocument; |
34 |
import org.gvsig.app.project.documents.view.gui.IView; |
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
36 |
import org.gvsig.fmap.dal.feature.FeatureType; |
37 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
38 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
39 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
40 |
import org.gvsig.tools.ToolsLocator; |
41 |
import org.gvsig.tools.i18n.I18nManager; |
42 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
43 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
44 |
|
45 |
import org.slf4j.Logger; |
46 |
import org.slf4j.LoggerFactory; |
47 |
|
48 |
/**
|
49 |
* Extension that handles the selection tools, selection tools have sense on
|
50 |
* vectorial layers only.
|
51 |
*
|
52 |
*/
|
53 |
public class ViewSelectionByTheme extends Extension { |
54 |
|
55 |
private static final Logger logger = LoggerFactory |
56 |
.getLogger(ViewSelectionByTheme.class); |
57 |
|
58 |
public void initialize() { |
59 |
registerIcons(); |
60 |
} |
61 |
|
62 |
private void registerIcons() { |
63 |
IconThemeHelper.registerIcon("action", "selection-select-by-layer", this); |
64 |
} |
65 |
|
66 |
public void execute(String actionCommand) { |
67 |
ApplicationManager application = ApplicationLocator.getManager(); |
68 |
|
69 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
70 |
if (view == null) { |
71 |
return;
|
72 |
} |
73 |
ViewDocument document = view.getViewDocument(); |
74 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
75 |
if (actionCommand.equalsIgnoreCase("selection-select-by-layer")) { |
76 |
|
77 |
SelectionByTheme dlg = new SelectionByTheme();
|
78 |
dlg.setModel(new DefaultSelectionByThemeModel());
|
79 |
dlg.addSelectionListener(new MySelectionByThemeListener());
|
80 |
ToolsSwingLocator.getWindowManager().showWindow( |
81 |
dlg, |
82 |
i18n.getTranslation("Seleccion_por_capa"),
|
83 |
WindowManager.MODE.TOOL |
84 |
); |
85 |
document.setModified(true);
|
86 |
} |
87 |
} |
88 |
|
89 |
@Override
|
90 |
public boolean isEnabled() { |
91 |
ApplicationManager application = ApplicationLocator.getManager(); |
92 |
|
93 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
94 |
if (view == null) { |
95 |
return false; |
96 |
} |
97 |
ViewDocument document = view.getViewDocument(); |
98 |
if( document == null ) { |
99 |
return false; |
100 |
} |
101 |
List<FLayer> layers = document.getMapContext().getLayers().getLayers(
|
102 |
FLayers.LAYER_ACTIVE |
103 |
.and(FLayers.LAYER_AVALAIBLE) |
104 |
.and(FLayers.LAYER_SELECTION_AVAILABLE) |
105 |
); |
106 |
if (layers.size()>=1) { |
107 |
return true; |
108 |
} |
109 |
return false; |
110 |
} |
111 |
|
112 |
public boolean isVisible() { |
113 |
ApplicationManager application = ApplicationLocator.getManager(); |
114 |
|
115 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
116 |
if (view == null) { |
117 |
return false; |
118 |
} |
119 |
ViewDocument document = view.getViewDocument(); |
120 |
|
121 |
return document.getMapContext().hasVectorLayers();
|
122 |
} |
123 |
} |