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 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | 41248 | jjdelcerro | * 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 | 40435 | jjdelcerro | *
|
11 | 41248 | jjdelcerro | * 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 | 40435 | jjdelcerro | *
|
16 | 41248 | jjdelcerro | * 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 | 40435 | jjdelcerro | *
|
20 | 41248 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40435 | jjdelcerro | */
|
23 | package org.gvsig.app.extension; |
||
24 | |||
25 | 44601 | omartinez | import java.util.List; |
26 | 42227 | mcompany | import org.gvsig.andami.IconThemeHelper; |
27 | 40435 | jjdelcerro | import org.gvsig.andami.plugins.Extension; |
28 | 41248 | jjdelcerro | import org.gvsig.app.ApplicationLocator; |
29 | import org.gvsig.app.ApplicationManager; |
||
30 | 40435 | jjdelcerro | 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 | 41264 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.IView; |
35 | 44437 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureStore; |
36 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
37 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
38 | 44601 | omartinez | import org.gvsig.fmap.mapcontext.layers.FLayers; |
39 | 44437 | jjdelcerro | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
40 | 43704 | jjdelcerro | 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 | 42227 | mcompany | |
45 | 40435 | jjdelcerro | 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 | 41248 | jjdelcerro | |
55 | 40435 | jjdelcerro | private static final Logger logger = LoggerFactory |
56 | .getLogger(ViewSelectionByTheme.class); |
||
57 | |||
58 | 41248 | jjdelcerro | public void initialize() { |
59 | 42227 | mcompany | registerIcons(); |
60 | } |
||
61 | 40435 | jjdelcerro | |
62 | 42227 | mcompany | private void registerIcons() { |
63 | IconThemeHelper.registerIcon("action", "selection-select-by-layer", this); |
||
64 | 41248 | jjdelcerro | } |
65 | 40435 | jjdelcerro | |
66 | 41248 | jjdelcerro | public void execute(String actionCommand) { |
67 | ApplicationManager application = ApplicationLocator.getManager(); |
||
68 | 40435 | jjdelcerro | |
69 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
70 | if (view == null) { |
||
71 | 41248 | jjdelcerro | return;
|
72 | } |
||
73 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
74 | 43704 | jjdelcerro | I18nManager i18n = ToolsLocator.getI18nManager(); |
75 | 41248 | jjdelcerro | if (actionCommand.equalsIgnoreCase("selection-select-by-layer")) { |
76 | 40435 | jjdelcerro | |
77 | 41248 | jjdelcerro | SelectionByTheme dlg = new SelectionByTheme();
|
78 | dlg.setModel(new DefaultSelectionByThemeModel());
|
||
79 | dlg.addSelectionListener(new MySelectionByThemeListener());
|
||
80 | 43704 | jjdelcerro | ToolsSwingLocator.getWindowManager().showWindow( |
81 | dlg, |
||
82 | i18n.getTranslation("Seleccion_por_capa"),
|
||
83 | WindowManager.MODE.TOOL |
||
84 | ); |
||
85 | 41248 | jjdelcerro | document.setModified(true);
|
86 | } |
||
87 | } |
||
88 | 40435 | jjdelcerro | |
89 | 44437 | jjdelcerro | @Override
|
90 | 41248 | jjdelcerro | public boolean isEnabled() { |
91 | ApplicationManager application = ApplicationLocator.getManager(); |
||
92 | 40435 | jjdelcerro | |
93 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
94 | if (view == null) { |
||
95 | 41248 | jjdelcerro | return false; |
96 | } |
||
97 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
98 | 44437 | jjdelcerro | if( document == null ) { |
99 | return false; |
||
100 | } |
||
101 | 44601 | omartinez | 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 | 44437 | jjdelcerro | } |
109 | 44601 | omartinez | return false; |
110 | 41248 | jjdelcerro | } |
111 | 40435 | jjdelcerro | |
112 | 41248 | jjdelcerro | public boolean isVisible() { |
113 | ApplicationManager application = ApplicationLocator.getManager(); |
||
114 | |||
115 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
116 | if (view == null) { |
||
117 | 41248 | jjdelcerro | return false; |
118 | } |
||
119 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
120 | |||
121 | 41248 | jjdelcerro | return document.getMapContext().hasVectorLayers();
|
122 | } |
||
123 | 40435 | jjdelcerro | } |