svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / toc / actions / LayersGroupTocMenuEntry.java @ 40558
History | View | Annotate | Download (5.69 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 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 3
|
||
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 | 40435 | jjdelcerro | package org.gvsig.app.project.documents.view.toc.actions; |
25 | |||
26 | import org.gvsig.andami.PluginServices; |
||
27 | import org.gvsig.app.extension.ProjectExtension; |
||
28 | import org.gvsig.app.project.Project; |
||
29 | import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
||
30 | import org.gvsig.app.project.documents.view.toc.ITocItem; |
||
31 | import org.gvsig.app.project.documents.view.toc.gui.ChangeName; |
||
32 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
33 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
34 | import org.gvsig.fmap.mapcontext.layers.operations.LayerNotFoundInCollectionException; |
||
35 | import org.slf4j.Logger; |
||
36 | import org.slf4j.LoggerFactory; |
||
37 | |||
38 | |||
39 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
40 | *
|
||
41 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
42 | *
|
||
43 | * This program is free software; you can redistribute it and/or
|
||
44 | * modify it under the terms of the GNU General Public License
|
||
45 | * as published by the Free Software Foundation; either version 2
|
||
46 | * of the License, or (at your option) any later version.
|
||
47 | *
|
||
48 | * This program is distributed in the hope that it will be useful,
|
||
49 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
50 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
51 | * GNU General Public License for more details.
|
||
52 | *
|
||
53 | * You should have received a copy of the GNU General Public License
|
||
54 | * along with this program; if not, write to the Free Software
|
||
55 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
56 | *
|
||
57 | * For more information, contact:
|
||
58 | *
|
||
59 | * Generalitat Valenciana
|
||
60 | * Conselleria d'Infraestructures i Transport
|
||
61 | * Av. Blasco Ib??ez, 50
|
||
62 | * 46010 VALENCIA
|
||
63 | * SPAIN
|
||
64 | *
|
||
65 | * +34 963862235
|
||
66 | * gvsig@gva.es
|
||
67 | * www.gvsig.gva.es
|
||
68 | *
|
||
69 | * or
|
||
70 | *
|
||
71 | * IVER T.I. S.A
|
||
72 | * Salamanca 50
|
||
73 | * 46005 Valencia
|
||
74 | * Spain
|
||
75 | *
|
||
76 | * +34 963163400
|
||
77 | * dac@iver.es
|
||
78 | */
|
||
79 | /* CVS MESSAGES:
|
||
80 | *
|
||
81 | * $Id: LayersGroupTocMenuEntry.java 39285 2012-11-21 11:44:13Z jldominguez $
|
||
82 | * $Log$
|
||
83 | * Revision 1.7 2007-06-19 08:42:17 jcampos
|
||
84 | * New method to get new group layers
|
||
85 | *
|
||
86 | * Revision 1.6 2007/02/15 11:04:54 caballero
|
||
87 | * cancelar agrupaci?n
|
||
88 | *
|
||
89 | * Revision 1.5 2007/02/14 17:09:43 caballero
|
||
90 | * posici?n layerGroup
|
||
91 | *
|
||
92 | * Revision 1.4 2007/01/04 07:24:31 caballero
|
||
93 | * isModified
|
||
94 | *
|
||
95 | * Revision 1.3 2006/10/02 13:52:34 jaume
|
||
96 | * organize impots
|
||
97 | *
|
||
98 | * Revision 1.2 2006/09/25 15:21:47 jmvivo
|
||
99 | * * Modificada la condicion de visibilidad, no permitir si no tienen el mismo padre.
|
||
100 | * * Modificada la implementacion.
|
||
101 | *
|
||
102 | * Revision 1.1 2006/09/15 10:41:30 caballero
|
||
103 | * extensibilidad de documentos
|
||
104 | *
|
||
105 | * Revision 1.1 2006/09/12 15:58:14 jorpiell
|
||
106 | * "Sacadas" las opcines del men? de FPopupMenu
|
||
107 | *
|
||
108 | *
|
||
109 | */
|
||
110 | /**
|
||
111 | * Realiza una agrupaci?n de capas, a partir de las capas que se encuentren activas.
|
||
112 | *
|
||
113 | * @author Vicente Caballero Navarro
|
||
114 | */
|
||
115 | public class LayersGroupTocMenuEntry extends AbstractTocContextMenuAction { |
||
116 | /**
|
||
117 | * Useful for debug the problems during the implementation.
|
||
118 | */
|
||
119 | private static Logger logger = LoggerFactory.getLogger(LayersGroupTocMenuEntry.class); |
||
120 | |||
121 | public String getGroup() { |
||
122 | return "group4"; //FIXME |
||
123 | } |
||
124 | |||
125 | public int getGroupOrder() { |
||
126 | return 40; |
||
127 | } |
||
128 | |||
129 | public int getOrder() { |
||
130 | return 0; |
||
131 | } |
||
132 | |||
133 | public String getText() { |
||
134 | return PluginServices.getText(this, "agrupar_capas"); |
||
135 | } |
||
136 | |||
137 | public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
||
138 | return selectedItems.length > 1; |
||
139 | } |
||
140 | |||
141 | public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
||
142 | if (selectedItems.length < 2) { |
||
143 | return false; |
||
144 | } |
||
145 | FLayers parent = selectedItems[0].getParentLayer();
|
||
146 | for (int i = 1; i < selectedItems.length;i++){ |
||
147 | if (parent != selectedItems[i].getParentLayer()){
|
||
148 | return false; |
||
149 | } |
||
150 | } |
||
151 | return true; |
||
152 | |||
153 | } |
||
154 | |||
155 | |||
156 | public void execute(ITocItem item, FLayer[] selectedItems) { |
||
157 | //ITocItem tocItem = (ITocItem) getNodeUserObject();
|
||
158 | ChangeName changename=new ChangeName(null); |
||
159 | PluginServices.getMDIManager().addWindow(changename); |
||
160 | if (!changename.isAccepted())
|
||
161 | return;
|
||
162 | String nombre=changename.getName();
|
||
163 | |||
164 | if (nombre != null){ |
||
165 | |||
166 | getMapContext().beginAtomicEvent(); |
||
167 | FLayers parent = selectedItems[0].getParentLayer();
|
||
168 | FLayers newGroup = getMapContext().getNewGroupLayer(parent); |
||
169 | |||
170 | newGroup.setProjection(getMapContext().getProjection()); |
||
171 | newGroup.setName(nombre); |
||
172 | |||
173 | int pos=0; |
||
174 | for (int i=0;i<parent.getLayersCount();i++){ |
||
175 | if (parent.getLayer(i).equals(selectedItems[0])){ |
||
176 | pos=i; |
||
177 | continue;
|
||
178 | } |
||
179 | } |
||
180 | for (int j=0;j < selectedItems.length;j++){ |
||
181 | FLayer layer = selectedItems[j]; |
||
182 | parent.move(layer, newGroup); |
||
183 | } |
||
184 | parent.addLayer(pos,newGroup); |
||
185 | newGroup.dispose(); |
||
186 | getMapContext().endAtomicEvent(); |
||
187 | // TRUCO PARA REFRESCAR.
|
||
188 | getMapContext().invalidate(); |
||
189 | Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
||
190 | project.setModified(true);
|
||
191 | } |
||
192 | } |
||
193 | } |