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 @ 43197
History | View | Annotate | Download (5.1 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 modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.app.project.documents.view.toc.actions; |
24 |
|
25 |
import java.awt.Component; |
26 |
|
27 |
import javax.swing.JOptionPane; |
28 |
|
29 |
import org.gvsig.andami.PluginServices; |
30 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
31 |
import org.gvsig.app.extension.ProjectExtension; |
32 |
import org.gvsig.app.project.Project; |
33 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
34 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
35 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
36 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 |
|
38 |
public class EliminarCapaTocMenuEntry extends AbstractTocContextMenuAction { |
39 |
|
40 |
public String getGroup() { |
41 |
return "group3"; //FIXME |
42 |
} |
43 |
|
44 |
public int getGroupOrder() { |
45 |
return 30; |
46 |
} |
47 |
|
48 |
public int getOrder() { |
49 |
return 0; |
50 |
} |
51 |
|
52 |
public String getText() { |
53 |
return PluginServices.getText(this, "eliminar_capa"); |
54 |
} |
55 |
|
56 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
57 |
return true; |
58 |
} |
59 |
|
60 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
61 |
if (isTocItemBranch(item)) {
|
62 |
return true; |
63 |
} |
64 |
return false; |
65 |
|
66 |
} |
67 |
|
68 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
69 |
|
70 |
FLayer[] actives = selectedItems;
|
71 |
|
72 |
int i;
|
73 |
for (i = 0; i < actives.length; i++) { |
74 |
if (actives[i].isEditing() && actives[i].isAvailable()) {
|
75 |
JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), PluginServices.getText(this, "no_se_puede_borrar_una_capa_en_edicion"), PluginServices.getText(this, "eliminar_capa"), JOptionPane.WARNING_MESSAGE); |
76 |
return;
|
77 |
} |
78 |
} |
79 |
|
80 |
int option = -1; |
81 |
if (actives.length > 0) { |
82 |
option = JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(), PluginServices.getText(this, "desea_borrar_la_capa")); |
83 |
} else {
|
84 |
return;
|
85 |
} |
86 |
if (option != JOptionPane.OK_OPTION) { |
87 |
return;
|
88 |
} |
89 |
getMapContext().beginAtomicEvent(); |
90 |
for (i = actives.length - 1; i >= 0; i--) { |
91 |
try {
|
92 |
//actives[i].getParentLayer().removeLayer(actives[i]);
|
93 |
//FLayers lyrs=getMapContext().getLayers();
|
94 |
//lyrs.addLayer(actives[i]);
|
95 |
actives[i].getParentLayer().removeLayer(actives[i]); |
96 |
|
97 |
//Cierra todas las ventanas asociadas a la capa
|
98 |
IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
|
99 |
for (int j = 0; j < wList.length; j++) { |
100 |
String name = wList[j].getWindowInfo().getAdditionalInfo();
|
101 |
for (int k = 0; k < actives.length; k++) { |
102 |
if (name != null && actives != null && actives[k] != null |
103 |
&& actives[k].getName() != null
|
104 |
&& name.compareTo(actives[k].getName()) == 0) {
|
105 |
PluginServices.getMDIManager().closeWindow(wList[j]); |
106 |
} |
107 |
} |
108 |
} |
109 |
|
110 |
} catch (CancelationException e1) {
|
111 |
e1.printStackTrace(); |
112 |
} |
113 |
} |
114 |
// ===============================================
|
115 |
/*
|
116 |
* If the removed layer is in a group, the TOC does not received a
|
117 |
* notification to refresh, so we force a refreshment unless the TOC is empty
|
118 |
*/
|
119 |
if (getMapContext().getLayers().getLayersCount() > 0) { |
120 |
getMapContext().getLayers().moveTo(0, 0); |
121 |
} |
122 |
// ===============================================
|
123 |
getMapContext().endAtomicEvent(); |
124 |
Project project = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject(); |
125 |
project.setModified(true);
|
126 |
PluginServices.getMainFrame().enableControls(); |
127 |
// 050209, jmorell: As? solo borra una capa (sobre la que pulsas).
|
128 |
/*FLayer lyr = getNodeLayer();
|
129 |
try {
|
130 |
getMapContext().getLayers().removeLayer(lyr);
|
131 |
if (getMapContext().getLayers().getLayersCount()==0)PluginServices.getMainFrame().enableControls();
|
132 |
} catch (CancelationException e1) {
|
133 |
e1.printStackTrace();
|
134 |
}*/
|
135 |
} |
136 |
} |