root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / toc / actions / EliminarCapaTocMenuEntry.java @ 29598
History | View | Annotate | Download (6.54 KB)
1 |
package org.gvsig.app.project.documents.view.toc.actions; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.util.ArrayList; |
5 |
|
6 |
import javax.swing.JOptionPane; |
7 |
|
8 |
import org.gvsig.andami.PluginServices; |
9 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
10 |
import org.gvsig.app.extension.ProjectExtension; |
11 |
import org.gvsig.app.project.Project; |
12 |
import org.gvsig.app.project.documents.ProjectDocument; |
13 |
import org.gvsig.app.project.documents.table.FeatureTableDocument; |
14 |
import org.gvsig.app.project.documents.table.FeatureTableDocumentFactory; |
15 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
16 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
17 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
18 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
19 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
20 |
|
21 |
|
22 |
|
23 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
24 |
*
|
25 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
26 |
*
|
27 |
* This program is free software; you can redistribute it and/or
|
28 |
* modify it under the terms of the GNU General Public License
|
29 |
* as published by the Free Software Foundation; either version 2
|
30 |
* of the License, or (at your option) any later version.
|
31 |
*
|
32 |
* This program is distributed in the hope that it will be useful,
|
33 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
34 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
35 |
* GNU General Public License for more details.
|
36 |
*
|
37 |
* You should have received a copy of the GNU General Public License
|
38 |
* along with this program; if not, write to the Free Software
|
39 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
40 |
*
|
41 |
* For more information, contact:
|
42 |
*
|
43 |
* Generalitat Valenciana
|
44 |
* Conselleria d'Infraestructures i Transport
|
45 |
* Av. Blasco Ib??ez, 50
|
46 |
* 46010 VALENCIA
|
47 |
* SPAIN
|
48 |
*
|
49 |
* +34 963862235
|
50 |
* gvsig@gva.es
|
51 |
* www.gvsig.gva.es
|
52 |
*
|
53 |
* or
|
54 |
*
|
55 |
* IVER T.I. S.A
|
56 |
* Salamanca 50
|
57 |
* 46005 Valencia
|
58 |
* Spain
|
59 |
*
|
60 |
* +34 963163400
|
61 |
* dac@iver.es
|
62 |
*/
|
63 |
/* CVS MESSAGES:
|
64 |
*
|
65 |
* $Id: EliminarCapaTocMenuEntry.java 29598 2009-06-29 16:09:14Z jpiera $
|
66 |
* $Log$
|
67 |
* Revision 1.8 2007-08-29 10:52:01 nacho
|
68 |
* Bug en eliminar capa
|
69 |
*
|
70 |
* Revision 1.7 2007/08/29 10:44:00 nacho
|
71 |
* Comprobaci?n de null para que no salte la consola en caso de que la capa no est? seleccionada
|
72 |
*
|
73 |
* Revision 1.6 2007/08/21 11:47:26 nacho
|
74 |
* Cerrar cuadros asociados a la capa al eliminar esta
|
75 |
*
|
76 |
* Revision 1.5 2007/06/06 15:53:09 jmvivo
|
77 |
* Added check for edition layers: It cannot be removed
|
78 |
*
|
79 |
* Revision 1.4 2007/03/06 16:37:08 caballero
|
80 |
* Exceptions
|
81 |
*
|
82 |
* Revision 1.3 2007/01/04 07:24:31 caballero
|
83 |
* isModified
|
84 |
*
|
85 |
* Revision 1.2 2006/12/19 09:09:07 jmvivo
|
86 |
* Faltaba un beginAtomicEvent para que no refrescase cada vez
|
87 |
*
|
88 |
* Revision 1.1 2006/09/15 10:41:30 caballero
|
89 |
* extensibilidad de documentos
|
90 |
*
|
91 |
* Revision 1.1 2006/09/12 15:58:14 jorpiell
|
92 |
* "Sacadas" las opcines del men? de FPopupMenu
|
93 |
*
|
94 |
*
|
95 |
*/
|
96 |
public class EliminarCapaTocMenuEntry extends AbstractTocContextMenuAction { |
97 |
public String getGroup() { |
98 |
return "group3"; //FIXME |
99 |
} |
100 |
|
101 |
public int getGroupOrder() { |
102 |
return 30; |
103 |
} |
104 |
|
105 |
public int getOrder() { |
106 |
return 0; |
107 |
} |
108 |
|
109 |
public String getText() { |
110 |
return PluginServices.getText(this, "eliminar_capa"); |
111 |
} |
112 |
|
113 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
114 |
return true; |
115 |
} |
116 |
|
117 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
118 |
if (isTocItemBranch(item)) {
|
119 |
return true; |
120 |
} |
121 |
return false; |
122 |
|
123 |
} |
124 |
|
125 |
|
126 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
127 |
// 050209, jmorell: Para poder borrar todas las capas seleccionadas desde el FPopUpMenu.
|
128 |
// Es necesario pulsar May?sculas a la vez que el bot?n derecho.
|
129 |
|
130 |
FLayer[] actives = selectedItems;
|
131 |
|
132 |
int i;
|
133 |
for (i= 0; i < actives.length;i++){ |
134 |
if (actives[i].isEditing() && actives[i].isAvailable()){
|
135 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this,"no_se_puede_borrar_una_capa_en_edicion"), PluginServices.getText(this, "eliminar_capa"), JOptionPane.WARNING_MESSAGE); |
136 |
return;
|
137 |
} |
138 |
} |
139 |
|
140 |
int option=-1; |
141 |
if (actives.length>0) { |
142 |
option=JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"desea_borrar_la_capa")); |
143 |
} else {
|
144 |
return;
|
145 |
} |
146 |
if (option!=JOptionPane.OK_OPTION) |
147 |
return;
|
148 |
getMapContext().beginAtomicEvent(); |
149 |
for (i = actives.length-1; i>=0; i--){ |
150 |
try {
|
151 |
//actives[i].getParentLayer().removeLayer(actives[i]);
|
152 |
//FLayers lyrs=getMapContext().getLayers();
|
153 |
//lyrs.addLayer(actives[i]);
|
154 |
actives[i].getParentLayer().removeLayer(actives[i]); |
155 |
|
156 |
if (actives[i] instanceof FLyrVect){ |
157 |
Project project = ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
158 |
FeatureTableDocument pt = project.getTable((FLyrVect) actives[i]); |
159 |
|
160 |
ArrayList tables = project.getDocumentsByType(FeatureTableDocumentFactory.registerName);
|
161 |
for (int j = 0; j < tables.size(); j++) { |
162 |
if (tables.get(j) == pt){
|
163 |
project.delDocument((ProjectDocument)tables.get(j)); |
164 |
break;
|
165 |
} |
166 |
} |
167 |
|
168 |
PluginServices.getMDIManager().closeSingletonWindow(pt); |
169 |
} |
170 |
|
171 |
//Cierra todas las ventanas asociadas a la capa
|
172 |
IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
|
173 |
for (int j = 0; j < wList.length; j++) { |
174 |
String name = wList[j].getWindowInfo().getAdditionalInfo();
|
175 |
for (int k = 0; k < actives.length; k++) { |
176 |
if( name != null && actives != null && actives[k] != null && |
177 |
actives[k].getName() != null &&
|
178 |
name.compareTo(actives[k].getName()) == 0)
|
179 |
PluginServices.getMDIManager().closeWindow(wList[j]); |
180 |
} |
181 |
} |
182 |
|
183 |
} catch (CancelationException e1) {
|
184 |
e1.printStackTrace(); |
185 |
} |
186 |
} |
187 |
getMapContext().endAtomicEvent(); |
188 |
Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
189 |
project.setModified(true);
|
190 |
PluginServices.getMainFrame().enableControls(); |
191 |
// 050209, jmorell: As? solo borra una capa (sobre la que pulsas).
|
192 |
/*FLayer lyr = getNodeLayer();
|
193 |
try {
|
194 |
getMapContext().getLayers().removeLayer(lyr);
|
195 |
if (getMapContext().getLayers().getLayersCount()==0)PluginServices.getMainFrame().enableControls();
|
196 |
} catch (CancelationException e1) {
|
197 |
e1.printStackTrace();
|
198 |
}*/
|
199 |
} |
200 |
} |