Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / extension / ZoomToSelectExtension.java @ 38564

History | View | Annotate | Download (4.96 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.app.extension;
23

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

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

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

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

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

    
118
        }
119
        return false;
120
    }
121

    
122
    public void initialize() {
123
        registerIcons();
124
    }
125

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