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