Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toc / actions / EliminarCapaTocMenuEntry.java @ 13375

History | View | Annotate | Download (6.41 KB)

1
package com.iver.cit.gvsig.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 com.iver.andami.PluginServices;
9
import com.iver.andami.ui.mdiManager.IWindow;
10
import com.iver.cit.gvsig.ProjectExtension;
11
import com.iver.cit.gvsig.fmap.layers.CancelationException;
12
import com.iver.cit.gvsig.fmap.layers.FLayer;
13
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
14
import com.iver.cit.gvsig.project.Project;
15
import com.iver.cit.gvsig.project.documents.ProjectDocument;
16
import com.iver.cit.gvsig.project.documents.table.ProjectTable;
17
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory;
18
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction;
19
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
20

    
21

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

    
97
        public int getGroupOrder() {
98
                return 30;
99
        }
100

    
101
        public int getOrder() {
102
                return 0;
103
        }
104

    
105
        public String getText() {
106
                return PluginServices.getText(this, "eliminar_capa");
107
        }
108

    
109
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
110
                return true;
111
        }
112

    
113
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
114
                if (isTocItemBranch(item)) {
115
                        return true;
116
                }
117
                return false;
118

    
119
        }
120

    
121

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

    
126
            FLayer[] actives = selectedItems;
127

    
128
            int i;
129
            for (i= 0; i < actives.length;i++){
130
                    if (actives[i].isEditing()){
131
                            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this,"no_se_puede_borrar_una_capa_en_edicion"), PluginServices.getText(this, "eliminar_capa"), JOptionPane.WARNING_MESSAGE);
132
                            return;
133
                    }
134
            }
135
            
136
            int option=-1;
137
            if (actives.length>0) {
138
                    option=JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"desea_borrar_la_capa"));
139
            } else {
140
                    return;
141
            }
142
            if (option!=JOptionPane.OK_OPTION)
143
                    return;
144
            getMapContext().beginAtomicEvent();
145
            for (i = actives.length-1; i>=0; i--){
146
                try {
147
                                //actives[i].getParentLayer().removeLayer(actives[i]);
148
                                //FLayers lyrs=getMapContext().getLayers();
149
                                //lyrs.addLayer(actives[i]);
150
                                actives[i].getParentLayer().removeLayer(actives[i]);
151

    
152
                if (actives[i] instanceof AlphanumericData){
153
                    Project project = ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
154
                    ProjectTable pt = project.getTable((AlphanumericData) actives[i]);
155

    
156
                    ArrayList tables = project.getDocumentsByType(ProjectTableFactory.registerName);
157
                    for (int j = 0; j < tables.size(); j++) {
158
                        if (tables.get(j) == pt){
159
                                project.delDocument((ProjectDocument)tables.get(j));
160
                            break;
161
                        }
162
                    }
163
                   
164
                    PluginServices.getMDIManager().closeSingletonWindow(pt);
165
                }
166

    
167
                //Cierra todas las ventanas asociadas a la capa
168
                        IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
169
                        for (int j = 0; j < wList.length; j++) {
170
                                String name = wList[j].getWindowInfo().getAdditionalInfo();
171
                                if( name != null && actives != null && actives[j] != null &&
172
                                        actives[j].getName() != null &&
173
                                        name.compareTo(actives[j].getName()) == 0)
174
                                        PluginServices.getMDIManager().closeWindow(wList[i]);
175
                        }
176

    
177
                    } catch (CancelationException e1) {
178
                            e1.printStackTrace();
179
                    }
180
            }
181
            getMapContext().endAtomicEvent();
182
            Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
183
                project.setModified(true);
184
            PluginServices.getMainFrame().enableControls();
185
                // 050209, jmorell: As? solo borra una capa (sobre la que pulsas).
186
            /*FLayer lyr = getNodeLayer();
187
        try {
188
                getMapContext().getLayers().removeLayer(lyr);
189
                if (getMapContext().getLayers().getLayersCount()==0)PluginServices.getMainFrame().enableControls();
190
                } catch (CancelationException e1) {
191
                        e1.printStackTrace();
192
                }*/
193
    }
194
}