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 / LayersUngroupTocMenuEntry.java @ 40558
History | View | Annotate | Download (4.34 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.andami.messages.NotificationManager; |
28 |
import org.gvsig.app.extension.ProjectExtension; |
29 |
import org.gvsig.app.project.Project; |
30 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
31 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
32 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
33 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
34 |
import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection; |
35 |
import org.gvsig.fmap.mapcontext.layers.operations.LayerNotFoundInCollectionException; |
36 |
import org.slf4j.Logger; |
37 |
import org.slf4j.LoggerFactory; |
38 |
|
39 |
|
40 |
|
41 |
/* CVS MESSAGES:
|
42 |
*
|
43 |
* $Id: LayersUngroupTocMenuEntry.java 39575 2013-01-09 12:28:47Z jldominguez $
|
44 |
* $Log$
|
45 |
* Revision 1.6 2007-01-04 07:24:31 caballero
|
46 |
* isModified
|
47 |
*
|
48 |
* Revision 1.5 2006/10/02 13:52:34 jaume
|
49 |
* organize impots
|
50 |
*
|
51 |
* Revision 1.4 2006/09/25 15:24:26 jmvivo
|
52 |
* * Modificada la implementacion.
|
53 |
*
|
54 |
* Revision 1.3 2006/09/20 12:01:24 jaume
|
55 |
* *** empty log message ***
|
56 |
*
|
57 |
* Revision 1.2 2006/09/20 11:41:20 jaume
|
58 |
* *** empty log message ***
|
59 |
*
|
60 |
* Revision 1.1 2006/09/15 10:41:30 caballero
|
61 |
* extensibilidad de documentos
|
62 |
*
|
63 |
* Revision 1.1 2006/09/12 15:58:14 jorpiell
|
64 |
* "Sacadas" las opcines del men? de FPopupMenu
|
65 |
*
|
66 |
*
|
67 |
*/
|
68 |
/**
|
69 |
* Realiza una desagrupaci?n de capas, a partir de las capas que se encuentren activas.
|
70 |
*
|
71 |
* @author Vicente Caballero Navarro
|
72 |
*/
|
73 |
public class LayersUngroupTocMenuEntry extends AbstractTocContextMenuAction { |
74 |
/**
|
75 |
* Useful for debug the problems during the implementation.
|
76 |
*/
|
77 |
private static Logger logger = LoggerFactory.getLogger(LayersUngroupTocMenuEntry.class); |
78 |
|
79 |
public String getGroup() { |
80 |
return "group4"; //FIXME |
81 |
} |
82 |
|
83 |
public int getGroupOrder() { |
84 |
return 40; |
85 |
} |
86 |
|
87 |
public int getOrder() { |
88 |
return 1; |
89 |
} |
90 |
|
91 |
public String getText() { |
92 |
return PluginServices.getText(this, "desagrupar_capas"); |
93 |
} |
94 |
|
95 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
96 |
return true; |
97 |
} |
98 |
|
99 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
100 |
FLayer lyr = getNodeLayer(item); |
101 |
if (!(lyr instanceof FLayers) || (lyr instanceof FLayers && lyr.getParentLayer() == null)){ |
102 |
return false; |
103 |
} |
104 |
return true; |
105 |
|
106 |
} |
107 |
|
108 |
|
109 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
110 |
if (isTocItemBranch(item)){
|
111 |
FLayers agrupa = (FLayers)getNodeLayer(item); |
112 |
FLayers parent=agrupa.getParentLayer(); |
113 |
|
114 |
if (parent!=null){ |
115 |
getMapContext().beginAtomicEvent(); |
116 |
|
117 |
int insert_pos = getPositionForUngrouped(agrupa);
|
118 |
parent.removeLayer(agrupa); |
119 |
|
120 |
while (agrupa.getLayersCount() > 0) { |
121 |
FLayer layer = agrupa.getLayer(0);
|
122 |
agrupa.removeLayer(layer); |
123 |
parent.addLayer(insert_pos, layer); |
124 |
insert_pos++; |
125 |
} |
126 |
|
127 |
getMapContext().endAtomicEvent(); |
128 |
|
129 |
// TRUCO PARA REFRESCAR.
|
130 |
getMapContext().invalidate(); |
131 |
Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
132 |
project.setModified(true);
|
133 |
|
134 |
} |
135 |
} |
136 |
} |
137 |
|
138 |
/**
|
139 |
* Tells the starting position of children when FLayers provided is ungrouped
|
140 |
* @param agrupa
|
141 |
* @return
|
142 |
*/
|
143 |
private int getPositionForUngrouped(FLayers lyr) { |
144 |
|
145 |
FLayers pare = lyr.getParentLayer(); |
146 |
for (int i=0; i<pare.getLayersCount(); i++) { |
147 |
if (pare.getLayer(i) == lyr) {
|
148 |
return i;
|
149 |
} |
150 |
} |
151 |
return 0; |
152 |
} |
153 |
} |