Revision 43197

View differences:

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
3 3
 *
4 4
 * Copyright (C) 2007-2013 gvSIG Association.
5 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.
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 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.
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 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.
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.
20 19
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
23 22
 */
24 23
package org.gvsig.app.project.documents.view.toc.actions;
25 24

  
......
36 35
import org.gvsig.fmap.mapcontext.layers.CancelationException;
37 36
import org.gvsig.fmap.mapcontext.layers.FLayer;
38 37

  
39

  
40 38
public class EliminarCapaTocMenuEntry extends AbstractTocContextMenuAction {
41
	public String getGroup() {
42
		return "group3"; //FIXME
43
	}
44 39

  
45
	public int getGroupOrder() {
46
		return 30;
47
	}
40
    public String getGroup() {
41
        return "group3"; //FIXME
42
    }
48 43

  
49
	public int getOrder() {
50
		return 0;
51
	}
44
    public int getGroupOrder() {
45
        return 30;
46
    }
52 47

  
53
	public String getText() {
54
		return PluginServices.getText(this, "eliminar_capa");
55
	}
48
    public int getOrder() {
49
        return 0;
50
    }
56 51

  
57
	public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
58
		return true;
59
	}
52
    public String getText() {
53
        return PluginServices.getText(this, "eliminar_capa");
54
    }
60 55

  
61
	public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
62
		if (isTocItemBranch(item)) {
63
			return true;
64
		}
65
		return false;
56
    public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
57
        return true;
58
    }
66 59

  
67
	}
60
    public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
61
        if (isTocItemBranch(item)) {
62
            return true;
63
        }
64
        return false;
68 65

  
66
    }
69 67

  
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.
68
    public void execute(ITocItem item, FLayer[] selectedItems) {
73 69

  
74
    	FLayer[] actives = selectedItems;
70
        FLayer[] actives = selectedItems;
75 71

  
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
    	}
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
        }
83 79

  
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 {
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 {
95 92
				//actives[i].getParentLayer().removeLayer(actives[i]);
96
				//FLayers lyrs=getMapContext().getLayers();
97
				//lyrs.addLayer(actives[i]);
98
				actives[i].getParentLayer().removeLayer(actives[i]);
93
                //FLayers lyrs=getMapContext().getLayers();
94
                //lyrs.addLayer(actives[i]);
95
                actives[i].getParentLayer().removeLayer(actives[i]);
99 96

  
100 97
                //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
        		}
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
                }
111 109

  
112
    		} catch (CancelationException e1) {
113
    			e1.printStackTrace();
114
    		}
115
    	}
110
            } catch (CancelationException e1) {
111
                e1.printStackTrace();
112
            }
113
        }
116 114
        // ===============================================
117 115
    	/*
118
    	 * If the removed layer is in a group, the TOC does not received a
119
    	 * notification to refresh, so we force a refreshment unless the TOC is empty
120
    	 */
121
    	if (getMapContext().getLayers().getLayersCount() > 0) {
122
    	    getMapContext().getLayers().moveTo(0, 0);
123
    	}
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
        }
124 122
        // ===============================================
125
    	getMapContext().endAtomicEvent();
126
    	Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
127
		project.setModified(true);
128
    	PluginServices.getMainFrame().enableControls();
123
        getMapContext().endAtomicEvent();
124
        Project project = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject();
125
        project.setModified(true);
126
        PluginServices.getMainFrame().enableControls();
129 127
		// 050209, jmorell: As? solo borra una capa (sobre la que pulsas).
130 128
    	/*FLayer lyr = getNodeLayer();
131
        try {
132
        	getMapContext().getLayers().removeLayer(lyr);
133
        	if (getMapContext().getLayers().getLayersCount()==0)PluginServices.getMainFrame().enableControls();
134
		} catch (CancelationException e1) {
135
			e1.printStackTrace();
136
		}*/
129
         try {
130
         getMapContext().getLayers().removeLayer(lyr);
131
         if (getMapContext().getLayers().getLayersCount()==0)PluginServices.getMainFrame().enableControls();
132
         } catch (CancelationException e1) {
133
         e1.printStackTrace();
134
         }*/
137 135
    }
138 136
}

Also available in: Unified diff