Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / dialog / RasterPropertiesTocMenuEntry.java @ 12154

History | View | Annotate | Download (3.83 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.rastertools.properties.dialog;
20

    
21
import java.util.ArrayList;
22
import java.util.Iterator;
23

    
24
import org.gvsig.fmap.layers.FLyrRasterSE;
25

    
26
import com.iver.andami.PluginServices;
27
import com.iver.cit.gvsig.fmap.layers.FLayer;
28
import com.iver.cit.gvsig.gui.panels.IRasterPropertiesRegistrable;
29
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction;
30
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
31
import com.iver.utiles.extensionPoints.ExtensionPoint;
32
import com.iver.utiles.extensionPoints.ExtensionPoints;
33
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
34
/**
35
 * Entrada en del men? contextual del TOC correspondiente al cuadro de 
36
 * propiedades del raster
37
 * 
38
 * @author Nacho Brodin (nachobrodin@gmail.com)
39
 */
40
public class RasterPropertiesTocMenuEntry extends AbstractTocContextMenuAction {
41
        private PropertiesRasterRegistrableDialog properties = null;
42
        private ArrayList                         listeners  = new ArrayList();
43
        private FLayer                            lyr        = null;
44

    
45
        public String getGroup() {
46
                return "raster";
47
        }
48

    
49
        public int getGroupOrder() {
50
                return 60;
51
        }
52

    
53
        public int getOrder() {
54
                return 0;
55
        }
56

    
57
        public String getText() {
58
                return PluginServices.getText(this, "propiedades_raster");
59
        }
60

    
61
        /**
62
         * Los objetos que quieren que se ejecute su listerner deben ser registrados a
63
         * traves de este m?todo. Cuando se ejecute el actionPerformed se buscar?
64
         * todos los objetos registrados y ejecutar? el actionPerformed de cada uno,
65
         *
66
         * @param obj Objeto a registrar
67
         */
68
        public void register(Object obj) {
69
                if (obj instanceof IRasterPropertiesRegistrable)
70
                        listeners.add(obj);
71
        }
72

    
73
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
74
                return selectedItems.length == 1;
75
        }
76

    
77
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
78
                if (isTocItemBranch(item))
79
                        return (getNodeLayer(item) instanceof FLyrRasterSE);
80
                return false;
81
        }
82

    
83
        /**
84
         * Gestiona la apertura del dialogo de propiedades de raster cuando se pulsa
85
         * la opci?n asignando a este las propiedades iniciales.
86
         */
87
        public void execute(ITocItem item, FLayer[] selectedItems) {
88
                if (selectedItems.length == 1 )
89
                        lyr = selectedItems[0];
90
                else
91
                        return;
92

    
93
                if (properties == null)
94
                        properties = new PropertiesRasterRegistrableDialog();
95

    
96
                //Asigna la capa a cada panel registrado para que puedan operar
97
                ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
98
                ExtensionPoint extensionPoint = (ExtensionPoint)extensionPoints.get("RasterSEPropertiesDialog");
99
                if (extensionPoint == null)
100
                        return;
101
                Iterator iterator = extensionPoint.keySet().iterator();
102
                while (iterator.hasNext()) {
103
                        try {
104
                                String key = (String) iterator.next();
105
                                Object obj = extensionPoint.get(key);
106
                                if (obj instanceof IRegistrablePanel)
107
                                        ((IRegistrablePanel) obj).setLayer(lyr);
108
                        } catch (ClassCastException e) {
109
                                //No se a?ade el panel y se sigue con el siguiente
110
                                continue;
111
                        }
112
                }
113

    
114
                PluginServices.getMDIManager().addWindow(properties);
115
        }
116
}