Revision 47676

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/ZoomToSelectExtension.java
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 javax.swing.JOptionPane;
26
import org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.plugins.Extension;
28
import org.gvsig.app.ApplicationLocator;
29
import org.gvsig.app.ApplicationManager;
30
import org.gvsig.app.project.documents.view.ViewDocument;
31
import org.gvsig.app.project.documents.view.gui.IView;
32
import org.gvsig.fmap.dal.feature.FeatureSelection;
33
import org.gvsig.fmap.dal.feature.FeatureStore;
34
import org.gvsig.fmap.geom.primitive.Envelope;
35
import org.gvsig.fmap.mapcontext.MapContext;
36
import org.gvsig.fmap.mapcontext.layers.FLayer;
37
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
38
import org.gvsig.tools.exception.BaseException;
39

  
40
/**
41
 * Extensi?n de zoom a lo seleccionado teniendo como ventana activa una vista.
42
 *
43
 */
44
@SuppressWarnings("UseSpecificCatch")
45
public class ZoomToSelectExtension extends Extension {
46

  
47
//    private static final Logger logger = LoggerFactory.getLogger(ZoomToSelectExtension.class);
48

  
49
    @Override
50
    public void initialize() {
51
        IconThemeHelper.registerIcon("action", "view-navigation-zoom-to-selection", this);
52
    }
53

  
54
    @Override
55
    public void execute(String s) {
56
        ApplicationManager application = ApplicationLocator.getManager();
57

  
58
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
59
        if (view == null) {
60
            return;
61
        }
62
        ViewDocument document = view.getViewDocument();
63
        MapContext mapa = document.getMapContext();
64
        Envelope selectedExtent;
65
        try {
66
            selectedExtent = mapa.getSelectionBounds();
67
            mapa.zoomToEnvelope(selectedExtent);
68
        } catch (BaseException e) {
69
            String msg = "Can't zoom to the seleccion.";
70
            logger.warn(msg, e);
71
            application.message(msg, JOptionPane.WARNING_MESSAGE);
72
        }
73
    }
74

  
75
    @Override
76
    public boolean isVisible() {
77
        ApplicationManager application = ApplicationLocator.getManager();
78

  
79
        ViewDocument document = (ViewDocument) application.getActiveDocument(ViewDocument.class);
80
        if (document == null) {
81
            return false;
82
        }
83
        return document.getMapContext().getLayers().getLayersCount() > 0;
84
    }
85

  
86
    @Override
87
    public boolean isEnabled() {
88
        ApplicationManager application = ApplicationLocator.getManager();
89

  
90
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
91
        if (view == null) {
92
            return false;
93
        }
94
        ViewDocument document = view.getViewDocument();
95
        if( document == null ) {
96
            return false;
97
        }
98
        boolean hasActiveVectorLayers = false;
99
        boolean hasSelection = 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
                    FeatureSelection selection = store.getFeatureSelection();
106
                    if( !selection.isAvailable() ) {
107
                        return false;
108
                    }
109
                    if( !selection.isEmpty() ) {
110
                        hasSelection = true;
111
                    }
112
                } catch (Exception ex) {
113
                }
114
            }
115
        }
116
        return hasActiveVectorLayers && hasSelection;
117
    }
118

  
119
}
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/ZoomToSelectViewExtension.java
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 javax.swing.JOptionPane;
26
import org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.plugins.Extension;
28
import org.gvsig.app.ApplicationLocator;
29
import org.gvsig.app.ApplicationManager;
30
import org.gvsig.app.project.documents.view.ViewDocument;
31
import org.gvsig.app.project.documents.view.gui.IView;
32
import org.gvsig.fmap.dal.feature.FeatureSelection;
33
import org.gvsig.fmap.dal.feature.FeatureStore;
34
import org.gvsig.fmap.geom.primitive.Envelope;
35
import org.gvsig.fmap.mapcontext.MapContext;
36
import org.gvsig.fmap.mapcontext.layers.FLayer;
37
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
38
import org.gvsig.tools.exception.BaseException;
39

  
40
/**
41
 * Extensi?n de zoom a lo seleccionado teniendo como ventana activa una vista.
42
 *
43
 */
44
@SuppressWarnings("UseSpecificCatch")
45
public class ZoomToSelectViewExtension extends Extension {
46

  
47
//    private static final Logger logger = LoggerFactory.getLogger(ZoomToSelectExtension.class);
48

  
49
    @Override
50
    public void initialize() {
51
        IconThemeHelper.registerIcon("action", "view-navigation-zoom-to-selection", this);
52
    }
53

  
54
    @Override
55
    public void execute(String s) {
56
        ApplicationManager application = ApplicationLocator.getManager();
57

  
58
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
59
        if (view == null) {
60
            return;
61
        }
62
        ViewDocument document = view.getViewDocument();
63
        MapContext mapa = document.getMapContext();
64
        Envelope selectedExtent;
65
        try {
66
            selectedExtent = mapa.getSelectionBounds();
67
            mapa.zoomToEnvelope(selectedExtent);
68
        } catch (BaseException e) {
69
            String msg = "Can't zoom to the seleccion.";
70
            logger.warn(msg, e);
71
            application.message(msg, JOptionPane.WARNING_MESSAGE);
72
        }
73
    }
74

  
75
    @Override
76
    public boolean isVisible() {
77
        ApplicationManager application = ApplicationLocator.getManager();
78

  
79
        ViewDocument document = (ViewDocument) application.getActiveDocument(ViewDocument.class);
80
        if (document == null) {
81
            return false;
82
        }
83
        return document.getMapContext().getLayers().getLayersCount() > 0;
84
    }
85

  
86
    @Override
87
    public boolean isEnabled() {
88
        ApplicationManager application = ApplicationLocator.getManager();
89

  
90
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
91
        if (view == null) {
92
            return false;
93
        }
94
        ViewDocument document = view.getViewDocument();
95
        if( document == null ) {
96
            return false;
97
        }
98
        boolean hasActiveVectorLayers = false;
99
        boolean hasSelection = false;
100
        for (FLayer layer : document.getMapContext().getLayers().getActives()) {
101
            if( layer.isActive() && layer.isAvailable() && layer instanceof FLyrVect ) {
102
                try {
103
                    hasActiveVectorLayers = true;
104
                    FeatureStore store = ((FLyrVect)layer).getFeatureStore();
105
                    if( store.isFeatureSelectionAvailable()) {
106
                        if( !store.isFeatureSelectionEmpty() ) {
107
                            hasSelection = true;
108
                        }
109
                    }
110
                } catch (Exception ex) {
111
                }
112
            }
113
        }
114
        return hasActiveVectorLayers && hasSelection;
115
    }
116

  
117
}
0 118

  
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/resources-plugin/config.xml
901 901

  
902 902
    </extension>
903 903
   
904
    <extension class-name="org.gvsig.app.extension.ZoomToSelectExtension"
904
    <extension class-name="org.gvsig.app.extension.ZoomToSelectViewExtension"
905 905
      description="Extensi?n encargada de gestionar los eventos realizados sobre una capa."
906 906
      active="true">
907 907

  
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
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
}
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/ZoomToSelectTableExtension.java
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 ZoomToSelectTableExtension 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
}
0 132

  
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/resources-plugin/config.xml
657 657
            </tool-bar>
658 658
        </extension>
659 659

  
660
        <extension class-name="org.gvsig.app.extension.ZoomToSelectExtension"
660
        <extension class-name="org.gvsig.app.extension.ZoomToSelectTableExtension"
661 661
                   description="Extensi?n encargada de gestionar los eventos realizados sobre una capa."
662 662
                   active="true">
663 663
            <action

Also available in: Unified diff