Statistics
| Revision:

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

History | View | Annotate | Download (2.56 KB)

1
package com.iver.cit.gvsig.project.documents.view.toc.actions;
2

    
3
import java.awt.Component;
4

    
5
import javax.swing.JOptionPane;
6

    
7
import com.iver.andami.PluginServices;
8
import com.iver.cit.gvsig.ProjectExtension;
9
import com.iver.cit.gvsig.fmap.layers.FLayer;
10
import com.iver.cit.gvsig.project.Project;
11
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction;
12
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
13
import com.iver.utiles.XMLEntity;
14

    
15
public class CutLayersTocMenuEntry extends AbstractTocContextMenuAction {
16
        private CopyPasteLayersUtiles utiles = CopyPasteLayersUtiles.getInstance();
17

    
18
        public String getGroup() {
19
                return "copyPasteLayer";
20
        }
21

    
22
        public int getGroupOrder() {
23
                return 60;
24
        }
25
        public int getOrder() {
26
                return 1;
27
        }
28

    
29
        public String getText() {
30
                return PluginServices.getText(this, "cortar");
31
        }
32

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

    
45

    
46
        public void execute(ITocItem item, FLayer[] selectedItems) {
47
                XMLEntity xml = this.utiles.generateXMLCopyLayers(selectedItems);
48
                if (xml == null) {
49
                        JOptionPane.showMessageDialog(
50
                                        (Component)PluginServices.getMainFrame(),
51
                                        "<html>"+PluginServices.getText(this,"No_ha_sido_posible_realizar_la_operacion")+"</html>",//Mensaje
52
                                        PluginServices.getText(this,"cortar"),//titulo
53
                                        JOptionPane.ERROR_MESSAGE
54
                                        );
55
                        return;
56
                }
57

    
58
                String data = xml.toString();
59
                if (data == null) {
60
                        JOptionPane.showMessageDialog(
61
                                        (Component)PluginServices.getMainFrame(),
62
                                        "<html>"+PluginServices.getText(this,"No_ha_sido_posible_realizar_la_operacion")+"</html>",//Mensaje
63
                                        PluginServices.getText(this,"cortar"),//titulo
64
                                        JOptionPane.ERROR_MESSAGE
65
                                        );
66
                        return;
67
                }
68

    
69

    
70
                PluginServices.putInClipboard(data);
71

    
72

    
73
            int option=JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"desea_borrar_la_capa"));
74
            if (option!=JOptionPane.OK_OPTION) {
75
                    return;
76
            }
77
                getMapContext().beginAtomicEvent();
78

    
79

    
80
                boolean isOK =this.utiles.removeLayers(selectedItems);
81

    
82
                getMapContext().endAtomicEvent();
83

    
84
                if (isOK) {
85
                        getMapContext().invalidate();
86
                        Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
87
                        project.setModified(true);
88
                        if (getMapContext().getLayers().getLayersCount()==0) {
89
                                PluginServices.getMainFrame().enableControls();
90
                        }
91
                }
92

    
93
        }
94

    
95
}