Statistics
| Revision:

gvsig-attributeeditor / org.gvsig.attributeeditor / trunk / org.gvsig.attributeeditor / org.gvsig.attributeeditor.app / org.gvsig.attributeeditor.app.mainplugin / src / main / java / org / gvsig / app / mainplugin / extension / AttributeEditorExtension.java @ 100

History | View | Annotate | Download (3.35 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2014 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.app.mainplugin.extension;
24

    
25
import org.slf4j.Logger;
26
import org.slf4j.LoggerFactory;
27

    
28
import org.gvsig.andami.IconThemeHelper;
29
import org.gvsig.andami.plugins.Extension;
30
import org.gvsig.app.ApplicationLocator;
31
import org.gvsig.app.project.documents.view.ViewDocument;
32
import org.gvsig.app.project.documents.view.ViewManager;
33
import org.gvsig.app.project.documents.view.gui.IView;
34
import org.gvsig.fmap.mapcontrol.MapControl;
35
import org.gvsig.fmap.mapcontrol.tools.Listeners.AttributeEditorBehavior;
36
import org.gvsig.fmap.mapcontrol.tools.Listeners.AttributeEditorPointListener;
37

    
38
/**
39
 * @author fdiaz
40
 *
41
 */
42
public class AttributeEditorExtension extends Extension {
43

    
44
    private static final Logger logger = LoggerFactory.getLogger(AttributeEditorExtension.class);
45

    
46
    @Override
47
    public void execute(String actionCommand) {
48
        if (actionCommand.compareToIgnoreCase("attribute-editor") != 0) {
49
            return;
50
        }
51
        IView view = (IView) ApplicationLocator.getManager().getActiveComponent(ViewDocument.class);
52
        if (view != null) {
53
            MapControl mapControl = view.getMapControl();
54
            if( mapControl.getMapContext().hasActiveVectorLayers() ) {
55
                if (!mapControl.hasTool(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME)) {
56
                    AttributeEditorBehavior attributeEditorBehavior = new AttributeEditorBehavior(mapControl);
57
                    mapControl.addBehavior(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME, attributeEditorBehavior);
58
                }
59
                mapControl.setTool(AttributeEditorPointListener.ATTRIBUTE_EDITOR_TOOL_NAME);
60
            }
61
        }
62

    
63
    }
64

    
65
    @Override
66
    public void initialize() {
67
        IconThemeHelper.registerIcon("action", "attribute-editor", this);
68
    }
69

    
70
    @Override
71
    public boolean isEnabled() {
72
        /*
73
         * It's enabled if there is exactly one vector layer in the active view
74
         * and it has a selection
75
         */
76
        ViewDocument viewDoc = actWin();
77
        if (viewDoc == null) {
78
            return false;
79
        }
80
        return viewDoc.getMapContext().hasActiveVectorLayers();
81
    }
82

    
83
    @Override
84
    public boolean isVisible() {
85
        return actWin() != null;
86
    }
87

    
88
    /**
89
     * Gets active window
90
     *
91
     * @return
92
     */
93
    private ViewDocument actWin() {
94
        return (ViewDocument) ApplicationLocator.getManager().getActiveDocument(ViewManager.TYPENAME);
95
    }
96
}