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 @ 40596
History | View | Annotate | Download (3.69 KB)
1 |
/**
|
---|---|
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 |
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 |
/**
|
40 |
* Realiza una agrupaci?n de capas, a partir de las capas que se encuentren activas.
|
41 |
*
|
42 |
* @author Vicente Caballero Navarro
|
43 |
*/
|
44 |
public class LayersGroupTocMenuEntry extends AbstractTocContextMenuAction { |
45 |
/**
|
46 |
* Useful for debug the problems during the implementation.
|
47 |
*/
|
48 |
private static Logger logger = LoggerFactory.getLogger(LayersGroupTocMenuEntry.class); |
49 |
|
50 |
public String getGroup() { |
51 |
return "group4"; //FIXME |
52 |
} |
53 |
|
54 |
public int getGroupOrder() { |
55 |
return 40; |
56 |
} |
57 |
|
58 |
public int getOrder() { |
59 |
return 0; |
60 |
} |
61 |
|
62 |
public String getText() { |
63 |
return PluginServices.getText(this, "agrupar_capas"); |
64 |
} |
65 |
|
66 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
67 |
return selectedItems.length > 1; |
68 |
} |
69 |
|
70 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
71 |
if (selectedItems.length < 2) { |
72 |
return false; |
73 |
} |
74 |
FLayers parent = selectedItems[0].getParentLayer();
|
75 |
for (int i = 1; i < selectedItems.length;i++){ |
76 |
if (parent != selectedItems[i].getParentLayer()){
|
77 |
return false; |
78 |
} |
79 |
} |
80 |
return true; |
81 |
|
82 |
} |
83 |
|
84 |
|
85 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
86 |
//ITocItem tocItem = (ITocItem) getNodeUserObject();
|
87 |
ChangeName changename=new ChangeName(null); |
88 |
PluginServices.getMDIManager().addWindow(changename); |
89 |
if (!changename.isAccepted())
|
90 |
return;
|
91 |
String nombre=changename.getName();
|
92 |
|
93 |
if (nombre != null){ |
94 |
|
95 |
getMapContext().beginAtomicEvent(); |
96 |
FLayers parent = selectedItems[0].getParentLayer();
|
97 |
FLayers newGroup = getMapContext().getNewGroupLayer(parent); |
98 |
|
99 |
newGroup.setProjection(getMapContext().getProjection()); |
100 |
newGroup.setName(nombre); |
101 |
|
102 |
int pos=0; |
103 |
for (int i=0;i<parent.getLayersCount();i++){ |
104 |
if (parent.getLayer(i).equals(selectedItems[0])){ |
105 |
pos=i; |
106 |
continue;
|
107 |
} |
108 |
} |
109 |
for (int j=0;j < selectedItems.length;j++){ |
110 |
FLayer layer = selectedItems[j]; |
111 |
parent.move(layer, newGroup); |
112 |
} |
113 |
parent.addLayer(pos,newGroup); |
114 |
newGroup.dispose(); |
115 |
getMapContext().endAtomicEvent(); |
116 |
// TRUCO PARA REFRESCAR.
|
117 |
getMapContext().invalidate(); |
118 |
Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
119 |
project.setModified(true);
|
120 |
} |
121 |
} |
122 |
} |