gvsig-raster / org.gvsig.raster.principalcomponents / branches / org.gvsig.raster.principalcomponents_dataaccess_refactoring / org.gvsig.raster.principalcomponents.app.principalcomponentsclient / src / main / java / org / gvsig / raster / principalcomponents / app / toolbox / AbstractToolboxAction.java @ 2379
History | View | Annotate | Download (3.82 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2012 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 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 |
* 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 |
|
25 |
package org.gvsig.raster.principalcomponents.app.toolbox; |
26 |
|
27 |
import org.gvsig.andami.PluginServices; |
28 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
29 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
30 |
import org.gvsig.fmap.mapcontext.MapContext; |
31 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
32 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.FLyrRasterIRasterLayer; |
33 |
import org.gvsig.i18n.Messages; |
34 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
35 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
36 |
|
37 |
import es.unex.sextante.dataObjects.IRasterLayer; |
38 |
import es.unex.sextante.gui.core.SextanteGUI; |
39 |
import es.unex.sextante.gui.core.ToolboxAction; |
40 |
|
41 |
/**
|
42 |
* Base class for toolBox actions
|
43 |
*
|
44 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
45 |
*/
|
46 |
public abstract class AbstractToolboxAction extends ToolboxAction { |
47 |
protected FLyrRaster lyr = null; |
48 |
|
49 |
@Override
|
50 |
public String getGroup() { |
51 |
return Messages.getText("group_tools"); |
52 |
} |
53 |
|
54 |
|
55 |
@Override
|
56 |
public boolean isActive() { |
57 |
IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
|
58 |
for (int i = 0; i < windows.length; i++) { |
59 |
if(windows[i] instanceof AbstractViewPanel) { |
60 |
FLayers lyrs = ((AbstractViewPanel)windows[i]).getMapControl().getMapContext().getLayers(); |
61 |
for (int j = 0; j < lyrs.getLayersCount(); j++) { |
62 |
if(lyrs.getLayer(j) instanceof FLyrRaster) |
63 |
return true; |
64 |
} |
65 |
} |
66 |
} |
67 |
return false; |
68 |
} |
69 |
|
70 |
/**
|
71 |
* Returns true if the plugin which gives the functionality is installed
|
72 |
* in gvSIG
|
73 |
* @return
|
74 |
*/
|
75 |
public abstract boolean isPluginInstalled(); |
76 |
|
77 |
/**
|
78 |
* Loads the raster layer for the tool
|
79 |
* @return
|
80 |
*/
|
81 |
public boolean loadLayer() { |
82 |
if(!isPluginInstalled()) {
|
83 |
RasterSwingLibrary.messageBoxError(Messages.getText("plugin_not_installed"), null); |
84 |
return false; |
85 |
} |
86 |
|
87 |
if(!isActive()) {
|
88 |
RasterSwingLibrary.messageBoxError(Messages.getText("layer_not_valid"), null); |
89 |
return false; |
90 |
} |
91 |
|
92 |
boolean existsRasterButNotActive = false; |
93 |
lyr = null;
|
94 |
IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
|
95 |
MapContext mapCtx = null;
|
96 |
for (int i = 0; i < windows.length; i++) { |
97 |
if(windows[i] instanceof AbstractViewPanel) { |
98 |
mapCtx = ((AbstractViewPanel)windows[i]).getMapControl().getMapContext(); |
99 |
break;
|
100 |
} |
101 |
} |
102 |
|
103 |
IRasterLayer[] layers = SextanteGUI.getInputFactory().getRasterLayers();
|
104 |
for (int i = 0; i < layers.length; i++) { |
105 |
FLyrRaster l = (FLyrRaster)((FLyrRasterIRasterLayer)layers[i]).getBaseDataObject(); |
106 |
existsRasterButNotActive = true;
|
107 |
if(l.isActive() && mapCtx == l.getMapContext()) {
|
108 |
existsRasterButNotActive = false;
|
109 |
lyr = l; |
110 |
break;
|
111 |
} |
112 |
} |
113 |
|
114 |
if(existsRasterButNotActive) {
|
115 |
RasterSwingLibrary.messageBoxError(Messages.getText("raster_layer_not_active"), null); |
116 |
return false; |
117 |
} |
118 |
|
119 |
return true; |
120 |
} |
121 |
|
122 |
} |