Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2059 / applications / appgvSIG / src / org / gvsig / app / project / documents / view / toc / actions / CutLayersTocMenuEntry.java @ 39289

History | View | Annotate | Download (2.53 KB)

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

    
3
import java.awt.Component;
4

    
5
import javax.swing.JOptionPane;
6

    
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9

    
10
import org.gvsig.andami.PluginServices;
11
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
12
import org.gvsig.app.project.documents.view.toc.ITocItem;
13
import org.gvsig.fmap.mapcontext.layers.FLayer;
14
import org.gvsig.i18n.Messages;
15
import org.gvsig.tools.persistence.PersistentState;
16

    
17

    
18
public class CutLayersTocMenuEntry extends AbstractTocContextMenuAction {
19

    
20
    private static Logger logger =
21
        LoggerFactory.getLogger(CutLayersTocMenuEntry.class);
22

    
23
        public String getGroup() {
24
                return "copyPasteLayer";
25
        }
26

    
27
        public int getGroupOrder() {
28
                return 60;
29
        }
30
        public int getOrder() {
31
                return 1;
32
        }
33

    
34
        public String getText() {
35
                return PluginServices.getText(this, "cortar");
36
        }
37

    
38
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
39
                if ( selectedItems.length >= 1 && isTocItemBranch(item)){
40
                        for (int i=0;i< selectedItems.length;i++) {
41
                                if (selectedItems[i].isEditing()){
42
                                        return false;
43
                                }
44
                        }
45
                        return true;
46
                }
47
                return false;
48
        }
49

    
50

    
51
        public void execute(ITocItem item, FLayer[] selectedItems) {
52
            
53
        PersistentState lyrs_state = null;
54
        
55
        try {
56
            lyrs_state = CopyPasteLayersUtils.getAsFLayersPersistentState(
57
                 selectedItems, this.getMapContext());
58
            /*
59
             * Saving layers data to clipboard.
60
             * Files and URLs are not relativized
61
             */
62
            CopyPasteLayersUtils.saveToClipboard(lyrs_state);
63

    
64
            int option=JOptionPane.showConfirmDialog(
65
                (Component)PluginServices.getMainFrame(),
66
                PluginServices.getText(this,"desea_borrar_la_capa"));
67
            
68
            if (option == JOptionPane.OK_OPTION) {
69
                /*
70
                 * If user says no, this is like copy (not cut)
71
                 */
72
                CopyPasteLayersUtils.removeLayers(
73
                    selectedItems,
74
                    this.getMapContext());
75
            }
76
            
77
        } catch (Exception e) {
78
            
79
            JOptionPane.showMessageDialog(
80
                (Component)PluginServices.getMainFrame(),
81
                Messages.getText("No_ha_sido_posible_realizar_la_operacion")
82
                + "\n\n" + e.getMessage(),
83
                Messages.getText("cortar"),
84
                JOptionPane.ERROR_MESSAGE
85
                );
86
            logger.info("While cutting layers.", e);
87
            return;
88
        }
89

    
90

    
91

    
92
        }
93

    
94
}