Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / toc / actions / EliminarCapaTocMenuEntry.java @ 31496

History | View | Annotate | Download (6.57 KB)

1
package org.gvsig.app.project.documents.view.toc.actions;
2

    
3
import java.awt.Component;
4
import java.util.List;
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.Project;
13
import org.gvsig.app.project.documents.Document;
14
import org.gvsig.app.project.documents.AbstractDocument;
15
import org.gvsig.app.project.documents.table.TableDocument;
16
import org.gvsig.app.project.documents.table.TableManager;
17
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
18
import org.gvsig.app.project.documents.view.toc.ITocItem;
19
import org.gvsig.fmap.mapcontext.layers.CancelationException;
20
import org.gvsig.fmap.mapcontext.layers.FLayer;
21
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
22

    
23

    
24

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

    
103
        public int getGroupOrder() {
104
                return 30;
105
        }
106

    
107
        public int getOrder() {
108
                return 0;
109
        }
110

    
111
        public String getText() {
112
                return PluginServices.getText(this, "eliminar_capa");
113
        }
114

    
115
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
116
                return true;
117
        }
118

    
119
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
120
                if (isTocItemBranch(item)) {
121
                        return true;
122
                }
123
                return false;
124

    
125
        }
126

    
127

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

    
132
            FLayer[] actives = selectedItems;
133

    
134
            int i;
135
            for (i= 0; i < actives.length;i++){
136
                    if (actives[i].isEditing() && actives[i].isAvailable()){
137
                            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this,"no_se_puede_borrar_una_capa_en_edicion"), PluginServices.getText(this, "eliminar_capa"), JOptionPane.WARNING_MESSAGE);
138
                            return;
139
                    }
140
            }
141

    
142
            int option=-1;
143
            if (actives.length>0) {
144
                    option=JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"desea_borrar_la_capa"));
145
            } else {
146
                    return;
147
            }
148
            if (option!=JOptionPane.OK_OPTION)
149
                    return;
150
            getMapContext().beginAtomicEvent();
151
            for (i = actives.length-1; i>=0; i--){
152
                try {
153
                                //actives[i].getParentLayer().removeLayer(actives[i]);
154
                                //FLayers lyrs=getMapContext().getLayers();
155
                                //lyrs.addLayer(actives[i]);
156
                                actives[i].getParentLayer().removeLayer(actives[i]);
157

    
158
                if (actives[i] instanceof FLyrVect){
159
                    Project project = ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
160
                    TableDocument pt = project.getTable((FLyrVect) actives[i]);
161

    
162
                    List<Document> tables = project.getDocuments(TableManager.TYPENAME);
163
                    for (int j = 0; j < tables.size(); j++) {
164
                        if (tables.get(j) == pt){
165
                                project.remove((AbstractDocument)tables.get(j));
166
                            break;
167
                        }
168
                    }
169

    
170
                    PluginServices.getMDIManager().closeSingletonWindow(pt);
171
                }
172

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

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