gvsig-raster / org.gvsig.raster.reproject / branches / org.gvsig.raster.reproject_dataaccess_refactoring / org.gvsig.raster.reproject.app.reprojectclient / src / main / java / org / gvsig / raster / reproject / app / ReprojectExtension.java @ 2388
History | View | Annotate | Download (4.82 KB)
1 | 1947 | nbrodin | /* 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.ApplicationLocator; |
||
29 | import org.gvsig.app.ApplicationManager; |
||
30 | import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
||
31 | import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
||
32 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
33 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
34 | import org.gvsig.raster.fmap.layers.FLyrRaster; |
||
35 | import org.gvsig.raster.fmap.layers.ILayerState; |
||
36 | import org.gvsig.raster.fmap.layers.IRasterLayerActions; |
||
37 | 2388 | nbrodin | import org.gvsig.raster.reproject.app.toolbox.ToolboxReprojectLoader; |
38 | 1947 | nbrodin | import org.gvsig.tools.ToolsLocator; |
39 | import org.gvsig.tools.extensionpoint.ExtensionBuilder; |
||
40 | import org.gvsig.tools.extensionpoint.ExtensionPoint; |
||
41 | import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
||
42 | |||
43 | /**
|
||
44 | * Extension for adding grid netcdf support to gvSIG.
|
||
45 | * @author Nacho Brodin (nachobrodin@gmail.com)
|
||
46 | */
|
||
47 | public class ReprojectExtension extends Extension { |
||
48 | private ExtensionPoint genericToolBarMenuExtensionPoint = null; |
||
49 | private static String action = "Reproject"; |
||
50 | |||
51 | public void initialize() { |
||
52 | IconThemeHelper.registerIcon("action", "tools-raster-reproject", this); |
||
53 | |||
54 | ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
||
55 | ExtensionPoint point = extensionPoints.add("GenericToolBarMenu");
|
||
56 | point.append(action, "", ReprojectTocMenuEntry.getSingleton());
|
||
57 | |||
58 | ApplicationManager appGvSigMan = ApplicationLocator.getManager(); |
||
59 | appGvSigMan.registerPrepareOpenLayer(new PrepareLayerAskProjection());
|
||
60 | appGvSigMan.registerPrepareOpenDataStoreParameters(new PrepareLayerAskProjection());
|
||
61 | } |
||
62 | 2388 | nbrodin | |
63 | public void postInitialize() { |
||
64 | new ToolboxReprojectLoader().registerTool();
|
||
65 | } |
||
66 | 1947 | nbrodin | |
67 | public void execute(String actionCommand) { |
||
68 | //Las entradas en GenericToolBarModule est?n registradas con la misma etiqueta que la del actionCommand
|
||
69 | //De esta forma pueden recuperarse los TocMenuEntry del punto de extensi?n y ejecutar la acci?n a
|
||
70 | //trav?s de este.
|
||
71 | ExtensionBuilder ext = getGenericToolBarMenuExtensionPoint().get(actionCommand).getBuilder(); |
||
72 | if(ext != null && ext instanceof AbstractTocContextMenuAction) { |
||
73 | IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
||
74 | if(w instanceof AbstractViewPanel) { |
||
75 | FLayers lyrs = ((AbstractViewPanel)w).getMapControl().getMapContext().getLayers(); |
||
76 | FLayer[] actives = lyrs.getActives();
|
||
77 | ((AbstractTocContextMenuAction)ext).execute(null, actives);
|
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | |||
82 | public boolean isEnabled() { |
||
83 | IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
||
84 | if(w instanceof AbstractViewPanel) { |
||
85 | FLayers lyrs = ((AbstractViewPanel)w).getMapControl().getMapContext().getLayers(); |
||
86 | FLayer[] actives = lyrs.getActives();
|
||
87 | if(actives != null && actives.length > 0) { |
||
88 | for (int i = 0; i < actives.length; i++) { |
||
89 | if(actives[i] instanceof FLyrRaster && ((ILayerState)actives[i]).isOpen()) { |
||
90 | return true; |
||
91 | } |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 | return false; |
||
96 | } |
||
97 | |||
98 | public boolean isVisible() { |
||
99 | IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
||
100 | if(w instanceof AbstractViewPanel) { |
||
101 | FLayers lyrs = ((AbstractViewPanel)w).getMapControl().getMapContext().getLayers(); |
||
102 | FLayer[] actives = lyrs.getActives();
|
||
103 | if(actives != null && actives.length > 0) { |
||
104 | for (int i = 0; i < actives.length; i++) { |
||
105 | if(actives[i] instanceof FLyrRaster && |
||
106 | ((IRasterLayerActions)actives[i]).isActionEnabled(IRasterLayerActions.REPROJECT)) { |
||
107 | return true; |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | } |
||
112 | return false; |
||
113 | } |
||
114 | |||
115 | public ExtensionPoint getGenericToolBarMenuExtensionPoint() {
|
||
116 | if(genericToolBarMenuExtensionPoint == null) { |
||
117 | ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
||
118 | genericToolBarMenuExtensionPoint = extensionPoints.get("GenericToolBarMenu");
|
||
119 | } |
||
120 | return genericToolBarMenuExtensionPoint;
|
||
121 | } |
||
122 | } |