Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toc / actions / LayersGroupTocMenuEntry.java @ 9532

History | View | Annotate | Download (3.91 KB)

1
package com.iver.cit.gvsig.project.documents.view.toc.actions;
2

    
3
import com.iver.andami.PluginServices;
4
import com.iver.cit.gvsig.ProjectExtension;
5
import com.iver.cit.gvsig.fmap.layers.FLayer;
6
import com.iver.cit.gvsig.fmap.layers.FLayers;
7
import com.iver.cit.gvsig.project.Project;
8
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction;
9
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
10
import com.iver.cit.gvsig.project.documents.view.toc.gui.ChangeName;
11

    
12
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
13
 *
14
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
29
 *
30
 * For more information, contact:
31
 *
32
 *  Generalitat Valenciana
33
 *   Conselleria d'Infraestructures i Transport
34
 *   Av. Blasco Ib??ez, 50
35
 *   46010 VALENCIA
36
 *   SPAIN
37
 *
38
 *      +34 963862235
39
 *   gvsig@gva.es
40
 *      www.gvsig.gva.es
41
 *
42
 *    or
43
 *
44
 *   IVER T.I. S.A
45
 *   Salamanca 50
46
 *   46005 Valencia
47
 *   Spain
48
 *
49
 *   +34 963163400
50
 *   dac@iver.es
51
 */
52
/* CVS MESSAGES:
53
 *
54
 * $Id: LayersGroupTocMenuEntry.java 9532 2007-01-04 07:24:32Z caballero $
55
 * $Log$
56
 * Revision 1.4  2007-01-04 07:24:31  caballero
57
 * isModified
58
 *
59
 * Revision 1.3  2006/10/02 13:52:34  jaume
60
 * organize impots
61
 *
62
 * Revision 1.2  2006/09/25 15:21:47  jmvivo
63
 * * Modificada la condicion de visibilidad, no permitir si no tienen el mismo padre.
64
 * * Modificada la implementacion.
65
 *
66
 * Revision 1.1  2006/09/15 10:41:30  caballero
67
 * extensibilidad de documentos
68
 *
69
 * Revision 1.1  2006/09/12 15:58:14  jorpiell
70
 * "Sacadas" las opcines del men? de FPopupMenu
71
 *
72
 *
73
 */
74
/**
75
 * Realiza una agrupaci?n de capas, a partir de las capas que se encuentren activas.
76
 *
77
 * @author Vicente Caballero Navarro
78
 */
79
public class LayersGroupTocMenuEntry extends AbstractTocContextMenuAction {
80
        public String getGroup() {
81
                return "group4"; //FIXME
82
        }
83

    
84
        public int getGroupOrder() {
85
                return 40;
86
        }
87

    
88
        public int getOrder() {
89
                return 0;
90
        }
91

    
92
        public String getText() {
93
                return PluginServices.getText(this, "agrupar_capas");
94
        }
95

    
96
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
97
                return selectedItems.length > 1;
98
        }
99

    
100
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
101
                if (selectedItems.length < 2) {
102
                        return false;
103
                }
104
                FLayers parent = selectedItems[0].getParentLayer();
105
                for (int i = 1; i < selectedItems.length;i++){
106
                        if (parent != selectedItems[i].getParentLayer()){
107
                                return false;
108
                        }
109
                }
110
                return true;
111

    
112
        }
113

    
114

    
115
        public void execute(ITocItem item, FLayer[] selectedItems) {
116
                //ITocItem tocItem = (ITocItem) getNodeUserObject();
117
                ChangeName changename=new ChangeName(null);
118
                PluginServices.getMDIManager().addWindow(changename);
119
                String nombre=changename.getName();
120

    
121
                if (nombre != null){
122

    
123
                        getMapContext().beginAtomicEvent();
124
                        FLayers parent = selectedItems[0].getParentLayer();
125
                        FLayers newGroup = new FLayers(getMapContext(),parent);
126
                        newGroup.setName(nombre);
127
                        for (int j=0;j < selectedItems.length;j++){
128
                                FLayer layer = selectedItems[j];
129
                                parent.removeLayer(layer);
130
                                newGroup.addLayer(layer);
131
                        }
132
                        parent.addLayer(newGroup);
133

    
134
                        getMapContext().endAtomicEvent();
135
                        // TRUCO PARA REFRESCAR.
136
                        getMapContext().invalidate();
137
                        Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
138
                        project.setModified(true);
139
                }
140
        }
141
}