Statistics
| Revision:

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 @ 40558

History | View | Annotate | Download (6.54 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

    
41
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
42
 *
43
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
44
 *
45
 * This program is free software; you can redistribute it and/or
46
 * modify it under the terms of the GNU General Public License
47
 * as published by the Free Software Foundation; either version 2
48
 * of the License, or (at your option) any later version.
49
 *
50
 * This program is distributed in the hope that it will be useful,
51
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
52
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
53
 * GNU General Public License for more details.
54
 *
55
 * You should have received a copy of the GNU General Public License
56
 * along with this program; if not, write to the Free Software
57
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
58
 *
59
 * For more information, contact:
60
 *
61
 *  Generalitat Valenciana
62
 *   Conselleria d'Infraestructures i Transport
63
 *   Av. Blasco Ib??ez, 50
64
 *   46010 VALENCIA
65
 *   SPAIN
66
 *
67
 *      +34 963862235
68
 *   gvsig@gva.es
69
 *      www.gvsig.gva.es
70
 *
71
 *    or
72
 *
73
 *   IVER T.I. S.A
74
 *   Salamanca 50
75
 *   46005 Valencia
76
 *   Spain
77
 *
78
 *   +34 963163400
79
 *   dac@iver.es
80
 */
81
/* CVS MESSAGES:
82
 *
83
 * $Id: EliminarCapaTocMenuEntry.java 36443 2011-09-19 08:36:54Z cordinyana $
84
 * $Log$
85
 * Revision 1.8  2007-08-29 10:52:01  nacho
86
 * Bug en eliminar capa
87
 *
88
 * Revision 1.7  2007/08/29 10:44:00  nacho
89
 * Comprobaci?n de null para que no salte la consola en caso de que la capa no est? seleccionada
90
 *
91
 * Revision 1.6  2007/08/21 11:47:26  nacho
92
 * Cerrar cuadros asociados a la capa al eliminar esta
93
 *
94
 * Revision 1.5  2007/06/06 15:53:09  jmvivo
95
 * Added check for edition layers: It cannot be removed
96
 *
97
 * Revision 1.4  2007/03/06 16:37:08  caballero
98
 * Exceptions
99
 *
100
 * Revision 1.3  2007/01/04 07:24:31  caballero
101
 * isModified
102
 *
103
 * Revision 1.2  2006/12/19 09:09:07  jmvivo
104
 * Faltaba un beginAtomicEvent para que no refrescase cada vez
105
 *
106
 * Revision 1.1  2006/09/15 10:41:30  caballero
107
 * extensibilidad de documentos
108
 *
109
 * Revision 1.1  2006/09/12 15:58:14  jorpiell
110
 * "Sacadas" las opcines del men? de FPopupMenu
111
 *
112
 *
113
 */
114
public class EliminarCapaTocMenuEntry extends AbstractTocContextMenuAction {
115
        public String getGroup() {
116
                return "group3"; //FIXME
117
        }
118

    
119
        public int getGroupOrder() {
120
                return 30;
121
        }
122

    
123
        public int getOrder() {
124
                return 0;
125
        }
126

    
127
        public String getText() {
128
                return PluginServices.getText(this, "eliminar_capa");
129
        }
130

    
131
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
132
                return true;
133
        }
134

    
135
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
136
                if (isTocItemBranch(item)) {
137
                        return true;
138
                }
139
                return false;
140

    
141
        }
142

    
143

    
144
        public void execute(ITocItem item, FLayer[] selectedItems) {
145
            // 050209, jmorell: Para poder borrar todas las capas seleccionadas desde el FPopUpMenu.
146
                //                                        Es necesario pulsar May?sculas a la vez que el bot?n derecho.
147

    
148
            FLayer[] actives = selectedItems;
149

    
150
            int i;
151
            for (i= 0; i < actives.length;i++){
152
                    if (actives[i].isEditing() && actives[i].isAvailable()){
153
                            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this,"no_se_puede_borrar_una_capa_en_edicion"), PluginServices.getText(this, "eliminar_capa"), JOptionPane.WARNING_MESSAGE);
154
                            return;
155
                    }
156
            }
157

    
158
            int option=-1;
159
            if (actives.length>0) {
160
                    option=JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"desea_borrar_la_capa"));
161
            } else {
162
                    return;
163
            }
164
            if (option!=JOptionPane.OK_OPTION)
165
                    return;
166
            getMapContext().beginAtomicEvent();
167
            for (i = actives.length-1; i>=0; i--){
168
                try {
169
                                //actives[i].getParentLayer().removeLayer(actives[i]);
170
                                //FLayers lyrs=getMapContext().getLayers();
171
                                //lyrs.addLayer(actives[i]);
172
                                actives[i].getParentLayer().removeLayer(actives[i]);
173

    
174
                //Cierra todas las ventanas asociadas a la capa
175
                        IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
176
                        for (int j = 0; j < wList.length; j++) {
177
                                String name = wList[j].getWindowInfo().getAdditionalInfo();
178
                                for (int k = 0; k < actives.length; k++) {
179
                                        if( name != null && actives != null && actives[k] != null &&
180
                                        actives[k].getName() != null &&
181
                                        name.compareTo(actives[k].getName()) == 0)
182
                                        PluginServices.getMDIManager().closeWindow(wList[j]);
183
                                        }
184
                        }
185

    
186
                    } catch (CancelationException e1) {
187
                            e1.printStackTrace();
188
                    }
189
            }
190
            getMapContext().endAtomicEvent();
191
            Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
192
                project.setModified(true);
193
            PluginServices.getMainFrame().enableControls();
194
                // 050209, jmorell: As? solo borra una capa (sobre la que pulsas).
195
            /*FLayer lyr = getNodeLayer();
196
        try {
197
                getMapContext().getLayers().removeLayer(lyr);
198
                if (getMapContext().getLayers().getLayersCount()==0)PluginServices.getMainFrame().enableControls();
199
                } catch (CancelationException e1) {
200
                        e1.printStackTrace();
201
                }*/
202
    }
203
}