Statistics
| Revision:

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 @ 44129

History | View | Annotate | Download (3.87 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 org.gvsig.andami.IconThemeHelper;
26
import org.gvsig.andami.plugins.Extension;
27
import org.gvsig.app.ApplicationLocator;
28
import org.gvsig.app.ApplicationManager;
29
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
import org.gvsig.app.project.documents.view.gui.IView;
34
import org.gvsig.tools.ToolsLocator;
35
import org.gvsig.tools.i18n.I18nManager;
36
import org.gvsig.tools.swing.api.ToolsSwingLocator;
37
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
38

    
39
import org.slf4j.Logger;
40
import org.slf4j.LoggerFactory;
41

    
42
/**
43
 * Extension that handles the selection tools, selection tools have sense on
44
 * vectorial layers only.
45
 *
46
 */
47
public class ViewSelectionByTheme extends Extension {
48

    
49
    private static final Logger logger = LoggerFactory
50
            .getLogger(ViewSelectionByTheme.class);
51

    
52
    public void initialize() {
53
        registerIcons();
54
    }
55

    
56
    private void registerIcons() {
57
        IconThemeHelper.registerIcon("action", "selection-select-by-layer", this);
58
    }
59

    
60
    public void execute(String actionCommand) {
61
        ApplicationManager application = ApplicationLocator.getManager();
62

    
63
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
64
        if (view == null) {
65
            return;
66
        }
67
        ViewDocument document = view.getViewDocument();
68
        I18nManager i18n = ToolsLocator.getI18nManager();
69
        if (actionCommand.equalsIgnoreCase("selection-select-by-layer")) {
70

    
71
            SelectionByTheme dlg = new SelectionByTheme();
72
            dlg.setModel(new DefaultSelectionByThemeModel());
73
            dlg.addSelectionListener(new MySelectionByThemeListener());
74
            ToolsSwingLocator.getWindowManager().showWindow(
75
                    dlg, 
76
                    i18n.getTranslation("Seleccion_por_capa"), 
77
                    WindowManager.MODE.TOOL
78
            );
79
            document.setModified(true);
80
        }
81
    }
82

    
83
    public boolean isEnabled() {
84
        ApplicationManager application = ApplicationLocator.getManager();
85

    
86
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
87
        if (view == null) {
88
            return false;
89
        }
90
        ViewDocument document = view.getViewDocument();
91

    
92
        return document.getMapContext().hasActiveVectorLayers();
93
    }
94

    
95
    public boolean isVisible() {
96
        ApplicationManager application = ApplicationLocator.getManager();
97

    
98
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
99
        if (view == null) {
100
            return false;
101
        }
102
        ViewDocument document = view.getViewDocument();
103

    
104
        return document.getMapContext().hasVectorLayers();
105
    }
106
}