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 @ 44535
History | View | Annotate | Download (4.7 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 | 42227 | mcompany | import org.gvsig.andami.IconThemeHelper; |
26 | 40435 | jjdelcerro | import org.gvsig.andami.plugins.Extension; |
27 | 41248 | jjdelcerro | import org.gvsig.app.ApplicationLocator; |
28 | import org.gvsig.app.ApplicationManager; |
||
29 | 40435 | jjdelcerro | import org.gvsig.app.gui.selectionByTheme.DefaultSelectionByThemeModel; |
30 | import org.gvsig.app.gui.selectionByTheme.MySelectionByThemeListener; |
||
31 | import org.gvsig.app.gui.selectionByTheme.SelectionByTheme; |
||
32 | import org.gvsig.app.project.documents.view.ViewDocument; |
||
33 | 41264 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.IView; |
34 | 44437 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureStore; |
35 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
36 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
37 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
38 | 43704 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
39 | import org.gvsig.tools.i18n.I18nManager; |
||
40 | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
||
41 | import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
||
42 | 42227 | mcompany | |
43 | 40435 | jjdelcerro | import org.slf4j.Logger; |
44 | import org.slf4j.LoggerFactory; |
||
45 | |||
46 | /**
|
||
47 | * Extension that handles the selection tools, selection tools have sense on
|
||
48 | * vectorial layers only.
|
||
49 | *
|
||
50 | */
|
||
51 | public class ViewSelectionByTheme extends Extension { |
||
52 | 41248 | jjdelcerro | |
53 | 40435 | jjdelcerro | private static final Logger logger = LoggerFactory |
54 | .getLogger(ViewSelectionByTheme.class); |
||
55 | |||
56 | 41248 | jjdelcerro | public void initialize() { |
57 | 42227 | mcompany | registerIcons(); |
58 | } |
||
59 | 40435 | jjdelcerro | |
60 | 42227 | mcompany | private void registerIcons() { |
61 | IconThemeHelper.registerIcon("action", "selection-select-by-layer", this); |
||
62 | 41248 | jjdelcerro | } |
63 | 40435 | jjdelcerro | |
64 | 41248 | jjdelcerro | public void execute(String actionCommand) { |
65 | ApplicationManager application = ApplicationLocator.getManager(); |
||
66 | 40435 | jjdelcerro | |
67 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
68 | if (view == null) { |
||
69 | 41248 | jjdelcerro | return;
|
70 | } |
||
71 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
72 | 43704 | jjdelcerro | I18nManager i18n = ToolsLocator.getI18nManager(); |
73 | 41248 | jjdelcerro | if (actionCommand.equalsIgnoreCase("selection-select-by-layer")) { |
74 | 40435 | jjdelcerro | |
75 | 41248 | jjdelcerro | SelectionByTheme dlg = new SelectionByTheme();
|
76 | dlg.setModel(new DefaultSelectionByThemeModel());
|
||
77 | dlg.addSelectionListener(new MySelectionByThemeListener());
|
||
78 | 43704 | jjdelcerro | ToolsSwingLocator.getWindowManager().showWindow( |
79 | dlg, |
||
80 | i18n.getTranslation("Seleccion_por_capa"),
|
||
81 | WindowManager.MODE.TOOL |
||
82 | ); |
||
83 | 41248 | jjdelcerro | document.setModified(true);
|
84 | } |
||
85 | } |
||
86 | 40435 | jjdelcerro | |
87 | 44437 | jjdelcerro | @Override
|
88 | 41248 | jjdelcerro | public boolean isEnabled() { |
89 | ApplicationManager application = ApplicationLocator.getManager(); |
||
90 | 40435 | jjdelcerro | |
91 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
92 | if (view == null) { |
||
93 | 41248 | jjdelcerro | return false; |
94 | } |
||
95 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
96 | 44437 | jjdelcerro | if( document == null ) { |
97 | return false; |
||
98 | } |
||
99 | boolean hasActiveVectorLayers = false; |
||
100 | for (FLayer layer : document.getMapContext().getLayers()) {
|
||
101 | if( layer.isActive() && layer.isAvailable() && layer instanceof FLyrVect ) { |
||
102 | try {
|
||
103 | hasActiveVectorLayers = true;
|
||
104 | FeatureStore store = ((FLyrVect)layer).getFeatureStore(); |
||
105 | if( !store.getFeatureSelection().isAvailable() ) {
|
||
106 | return false; |
||
107 | } |
||
108 | } catch (Exception ex) { |
||
109 | } |
||
110 | } |
||
111 | } |
||
112 | return hasActiveVectorLayers;
|
||
113 | 41248 | jjdelcerro | } |
114 | 40435 | jjdelcerro | |
115 | 41248 | jjdelcerro | public boolean isVisible() { |
116 | ApplicationManager application = ApplicationLocator.getManager(); |
||
117 | |||
118 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
119 | if (view == null) { |
||
120 | 41248 | jjdelcerro | return false; |
121 | } |
||
122 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
123 | |||
124 | 41248 | jjdelcerro | return document.getMapContext().hasVectorLayers();
|
125 | } |
||
126 | 40435 | jjdelcerro | } |