Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / extension / ZoomToSelectExtension.java @ 40558

History | View | Annotate | Download (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
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.extension;
25

    
26
import org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.messages.NotificationManager;
29
import org.gvsig.andami.plugins.Extension;
30
import org.gvsig.andami.ui.mdiManager.IWindow;
31
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
32
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
33
import org.gvsig.fmap.dal.exception.DataException;
34
import org.gvsig.fmap.geom.primitive.Envelope;
35
import org.gvsig.fmap.mapcontext.MapContext;
36
import org.gvsig.tools.exception.BaseException;
37

    
38
/**
39
 * Extensi?n de zoom a lo seleccionado teniendo como ventana activa una tabla.
40
 * 
41
 * @author Vicente Caballero Navarro
42
 */
43
public class ZoomToSelectExtension extends Extension {
44

    
45
    public void execute(String s) {
46
            if( "view-navigation-zoom-to-selection-table".equalsIgnoreCase(s) ) {
47
                org.gvsig.andami.ui.mdiManager.IWindow f =
48
                    PluginServices.getMDIManager().getActiveWindow();
49
                MapContext mapa = null;
50
                Envelope selectedExtent = null;
51
                if (f instanceof FeatureTableDocumentPanel) {
52
                    FeatureTableDocumentPanel table = (FeatureTableDocumentPanel) f;
53
                    mapa = (table.getModel().getAssociatedLayer()).getMapContext();
54
                }
55
        
56
                try {
57
                    selectedExtent = mapa.getSelectionBounds();
58
                    mapa.getViewPort().setEnvelope(selectedExtent);
59
                } catch (BaseException e) {
60
                    NotificationManager.addError(e);
61
                }
62
            }
63
    }
64

    
65
    public boolean isVisible() {
66
        org.gvsig.andami.ui.mdiManager.IWindow window =
67
            PluginServices.getMDIManager().getActiveWindow();
68
        if (window instanceof FeatureTableDocumentPanel) {
69
            FeatureTableDocumentPanel featureTableDocumentPanel =
70
                (FeatureTableDocumentPanel) window;
71
            IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
72
            for (int i = 0; i < windows.length; i++) {
73
                if (windows[i] instanceof DefaultViewPanel) {
74
                    if (featureTableDocumentPanel.getModel()
75
                        .getAssociatedLayer() != null) {
76
                        if (((DefaultViewPanel) windows[i])
77
                            .getMapControl()
78
                            .getMapContext()
79
                            .equals(
80
                                (featureTableDocumentPanel.getModel()
81
                                    .getAssociatedLayer()).getMapContext())) {
82
                            return true;
83
                        }
84
                    }
85
                }
86
            }
87
        }
88
        return false;
89
    }
90

    
91
    public boolean isEnabled() {
92
        org.gvsig.andami.ui.mdiManager.IWindow f =
93
            PluginServices.getMDIManager().getActiveWindow();
94
        if (f == null) {
95
            return false;
96
        }
97
        if (f instanceof FeatureTableDocumentPanel) {
98
            FeatureTableDocumentPanel t = (FeatureTableDocumentPanel) f;
99
            IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
100
            for (int i = 0; i < windows.length; i++) {
101
                if (windows[i] instanceof DefaultViewPanel) {
102
                    if (((DefaultViewPanel) windows[i])
103
                        .getMapControl()
104
                        .getMapContext()
105
                        .equals(
106
                            (t.getModel().getAssociatedLayer()).getMapContext())) {
107
                        try {
108
                            if (!t.getModel().getStore().getFeatureSelection()
109
                                .isEmpty()) {
110
                                return true;
111
                            }
112
                        } catch (DataException e) {
113
                            NotificationManager.addError(e);
114
                            return false;
115
                        }
116
                    }
117
                }
118
            }
119

    
120
        }
121
        return false;
122
    }
123

    
124
    public void initialize() {
125
        registerIcons();
126
    }
127

    
128
    private void registerIcons() {
129
            IconThemeHelper.registerIcon("action", "view-navigation-zoom-to-selection", this);
130
    }
131
}