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 / EliminarCapaTocMenuEntry.java @ 40596
History | View | Annotate | Download (4.42 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 java.awt.Component; |
27 |
|
28 |
import javax.swing.JOptionPane; |
29 |
|
30 |
import org.gvsig.andami.PluginServices; |
31 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
32 |
import org.gvsig.app.extension.ProjectExtension; |
33 |
import org.gvsig.app.project.Project; |
34 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
35 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
36 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
37 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
38 |
|
39 |
|
40 |
public class EliminarCapaTocMenuEntry extends AbstractTocContextMenuAction { |
41 |
public String getGroup() { |
42 |
return "group3"; //FIXME |
43 |
} |
44 |
|
45 |
public int getGroupOrder() { |
46 |
return 30; |
47 |
} |
48 |
|
49 |
public int getOrder() { |
50 |
return 0; |
51 |
} |
52 |
|
53 |
public String getText() { |
54 |
return PluginServices.getText(this, "eliminar_capa"); |
55 |
} |
56 |
|
57 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
58 |
return true; |
59 |
} |
60 |
|
61 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
62 |
if (isTocItemBranch(item)) {
|
63 |
return true; |
64 |
} |
65 |
return false; |
66 |
|
67 |
} |
68 |
|
69 |
|
70 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
71 |
// 050209, jmorell: Para poder borrar todas las capas seleccionadas desde el FPopUpMenu.
|
72 |
// Es necesario pulsar May?sculas a la vez que el bot?n derecho.
|
73 |
|
74 |
FLayer[] actives = selectedItems;
|
75 |
|
76 |
int i;
|
77 |
for (i= 0; i < actives.length;i++){ |
78 |
if (actives[i].isEditing() && actives[i].isAvailable()){
|
79 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this,"no_se_puede_borrar_una_capa_en_edicion"), PluginServices.getText(this, "eliminar_capa"), JOptionPane.WARNING_MESSAGE); |
80 |
return;
|
81 |
} |
82 |
} |
83 |
|
84 |
int option=-1; |
85 |
if (actives.length>0) { |
86 |
option=JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"desea_borrar_la_capa")); |
87 |
} else {
|
88 |
return;
|
89 |
} |
90 |
if (option!=JOptionPane.OK_OPTION) |
91 |
return;
|
92 |
getMapContext().beginAtomicEvent(); |
93 |
for (i = actives.length-1; i>=0; i--){ |
94 |
try {
|
95 |
//actives[i].getParentLayer().removeLayer(actives[i]);
|
96 |
//FLayers lyrs=getMapContext().getLayers();
|
97 |
//lyrs.addLayer(actives[i]);
|
98 |
actives[i].getParentLayer().removeLayer(actives[i]); |
99 |
|
100 |
//Cierra todas las ventanas asociadas a la capa
|
101 |
IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
|
102 |
for (int j = 0; j < wList.length; j++) { |
103 |
String name = wList[j].getWindowInfo().getAdditionalInfo();
|
104 |
for (int k = 0; k < actives.length; k++) { |
105 |
if( name != null && actives != null && actives[k] != null && |
106 |
actives[k].getName() != null &&
|
107 |
name.compareTo(actives[k].getName()) == 0)
|
108 |
PluginServices.getMDIManager().closeWindow(wList[j]); |
109 |
} |
110 |
} |
111 |
|
112 |
} catch (CancelationException e1) {
|
113 |
e1.printStackTrace(); |
114 |
} |
115 |
} |
116 |
getMapContext().endAtomicEvent(); |
117 |
Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
118 |
project.setModified(true);
|
119 |
PluginServices.getMainFrame().enableControls(); |
120 |
// 050209, jmorell: As? solo borra una capa (sobre la que pulsas).
|
121 |
/*FLayer lyr = getNodeLayer();
|
122 |
try {
|
123 |
getMapContext().getLayers().removeLayer(lyr);
|
124 |
if (getMapContext().getLayers().getLayersCount()==0)PluginServices.getMainFrame().enableControls();
|
125 |
} catch (CancelationException e1) {
|
126 |
e1.printStackTrace();
|
127 |
}*/
|
128 |
} |
129 |
} |