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 / CutLayersTocMenuEntry.java @ 40558

History | View | Annotate | Download (3.47 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.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

    
33
import org.gvsig.andami.PluginServices;
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.FLayer;
37
import org.gvsig.i18n.Messages;
38
import org.gvsig.tools.persistence.PersistentState;
39

    
40

    
41
public class CutLayersTocMenuEntry extends AbstractTocContextMenuAction {
42

    
43
    private static Logger logger =
44
        LoggerFactory.getLogger(CutLayersTocMenuEntry.class);
45

    
46
        public String getGroup() {
47
                return "copyPasteLayer";
48
        }
49

    
50
        public int getGroupOrder() {
51
                return 60;
52
        }
53
        public int getOrder() {
54
                return 1;
55
        }
56

    
57
        public String getText() {
58
                return PluginServices.getText(this, "cortar");
59
        }
60

    
61
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
62
                if ( selectedItems.length >= 1 && isTocItemBranch(item)){
63
                        for (int i=0;i< selectedItems.length;i++) {
64
                                if (selectedItems[i].isEditing()){
65
                                        return false;
66
                                }
67
                        }
68
                        return true;
69
                }
70
                return false;
71
        }
72

    
73

    
74
        public void execute(ITocItem item, FLayer[] selectedItems) {
75
            
76
        PersistentState lyrs_state = null;
77
        
78
        try {
79
            lyrs_state = CopyPasteLayersUtils.getAsFLayersPersistentState(
80
                 selectedItems, this.getMapContext());
81
            /*
82
             * Saving layers data to clipboard.
83
             * Files and URLs are not relativized
84
             */
85
            CopyPasteLayersUtils.saveToClipboard(lyrs_state);
86

    
87
            int option=JOptionPane.showConfirmDialog(
88
                (Component)PluginServices.getMainFrame(),
89
                PluginServices.getText(this,"desea_borrar_la_capa"));
90
            
91
            if (option == JOptionPane.OK_OPTION) {
92
                /*
93
                 * If user says no, this is like copy (not cut)
94
                 */
95
                CopyPasteLayersUtils.removeLayers(
96
                    selectedItems,
97
                    this.getMapContext());
98
            }
99
            
100
        } catch (Exception e) {
101
            
102
            JOptionPane.showMessageDialog(
103
                (Component)PluginServices.getMainFrame(),
104
                Messages.getText("No_ha_sido_posible_realizar_la_operacion")
105
                + "\n\n" + e.getMessage(),
106
                Messages.getText("cortar"),
107
                JOptionPane.ERROR_MESSAGE
108
                );
109
            logger.info("While cutting layers.", e);
110
            return;
111
        }
112

    
113

    
114

    
115
        }
116

    
117
}