Statistics
| Revision:

gvsig-raster / org.gvsig.raster.reproject / trunk / org.gvsig.raster.reproject / org.gvsig.raster.reproject.app / org.gvsig.raster.reproject.app.reprojectclient / src / main / java / org / gvsig / raster / reproject / app / ReprojectExtension.java @ 1876

History | View | Annotate | Download (4.37 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.raster.reproject.app;
23

    
24
import org.gvsig.andami.IconThemeHelper;
25
import org.gvsig.andami.PluginServices;
26
import org.gvsig.andami.plugins.Extension;
27
import org.gvsig.andami.ui.mdiManager.IWindow;
28
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
29
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
30
import org.gvsig.fmap.mapcontext.layers.FLayer;
31
import org.gvsig.fmap.mapcontext.layers.FLayers;
32
import org.gvsig.raster.fmap.layers.FLyrRaster;
33
import org.gvsig.raster.fmap.layers.ILayerState;
34
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
35
import org.gvsig.tools.ToolsLocator;
36
import org.gvsig.tools.extensionpoint.ExtensionBuilder;
37
import org.gvsig.tools.extensionpoint.ExtensionPoint;
38
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
39

    
40
/**
41
 * Extension for adding grid netcdf support to gvSIG.
42
 * @author Nacho Brodin (nachobrodin@gmail.com)
43
 */
44
public class ReprojectExtension extends Extension {
45
        private ExtensionPoint      genericToolBarMenuExtensionPoint  = null;
46
        private static String       action                            = "Reproject";
47

    
48
        public void initialize() {
49
                IconThemeHelper.registerIcon("action", "tools-raster-reproject", this);
50
                
51
                ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
52
                ExtensionPoint point = extensionPoints.add("GenericToolBarMenu");
53
                point.append(action, "", ReprojectTocMenuEntry.getSingleton());
54
        }
55

    
56
        public void execute(String actionCommand) {
57
                //Las entradas en GenericToolBarModule est?n registradas con la misma etiqueta que la del actionCommand
58
                //De esta forma pueden recuperarse los TocMenuEntry del punto de extensi?n y ejecutar la acci?n a
59
                //trav?s de este.
60
                ExtensionBuilder ext = getGenericToolBarMenuExtensionPoint().get(actionCommand).getBuilder();
61
                if(ext != null && ext instanceof AbstractTocContextMenuAction) {
62
                        IWindow w = PluginServices.getMDIManager().getActiveWindow();
63
                        if(w instanceof AbstractViewPanel) {
64
                                FLayers lyrs = ((AbstractViewPanel)w).getMapControl().getMapContext().getLayers();
65
                                FLayer[] actives = lyrs.getActives();
66
                                ((AbstractTocContextMenuAction)ext).execute(null, actives);
67
                        }
68
                }
69
        }
70

    
71
        public boolean isEnabled() {
72
                IWindow w = PluginServices.getMDIManager().getActiveWindow();
73
                if(w instanceof AbstractViewPanel) {
74
                        FLayers lyrs = ((AbstractViewPanel)w).getMapControl().getMapContext().getLayers();
75
                        FLayer[] actives = lyrs.getActives();
76
                        if(actives != null && actives.length > 0) {
77
                                for (int i = 0; i < actives.length; i++) {
78
                                        if(actives[i] instanceof FLyrRaster && ((ILayerState)actives[i]).isOpen()) {
79
                                                return true;
80
                                        }
81
                                }
82
                        }
83
                }
84
                return false;
85
        }
86

    
87
        public boolean isVisible() {
88
                IWindow w = PluginServices.getMDIManager().getActiveWindow();
89
                if(w instanceof AbstractViewPanel) {
90
                        FLayers lyrs = ((AbstractViewPanel)w).getMapControl().getMapContext().getLayers();
91
                        FLayer[] actives = lyrs.getActives();
92
                        if(actives != null && actives.length > 0) {
93
                                for (int i = 0; i < actives.length; i++) {
94
                                        if(actives[i] instanceof FLyrRaster && 
95
                                                ((IRasterLayerActions)actives[i]).isActionEnabled(IRasterLayerActions.REPROJECT)) {
96
                                                return true;
97
                                        }
98
                                }
99
                        }
100
                }
101
                return false;
102
        }
103
        
104
        public ExtensionPoint getGenericToolBarMenuExtensionPoint() {
105
                if(genericToolBarMenuExtensionPoint == null) {
106
                        ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
107
                        genericToolBarMenuExtensionPoint = extensionPoints.get("GenericToolBarMenu");
108
                }
109
                return genericToolBarMenuExtensionPoint;
110
        }
111
}