Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / contextMenu / actions / CutDocumentContextMenuAction.java @ 29596

History | View | Annotate | Download (2.62 KB)

1
package org.gvsig.app.project.documents.contextMenu.actions;
2

    
3
import java.awt.Component;
4

    
5
import javax.swing.JOptionPane;
6

    
7
import org.gvsig.andami.PluginServices;
8
import org.gvsig.app.extension.ProjectExtension;
9
import org.gvsig.app.project.Project;
10
import org.gvsig.app.project.documents.ProjectDocument;
11
import org.gvsig.app.project.documents.exceptions.SaveException;
12

    
13

    
14
public class CutDocumentContextMenuAction extends
15
                AbstractClipboardDocumentContextMenuAction {
16
        public int getOrder() {
17
                return 1;
18
        }
19

    
20
        public boolean isVisible(ProjectDocument item,
21
                        ProjectDocument[] selectedItems) {
22
                return true;
23
        }
24

    
25
        public boolean isEnabled(ProjectDocument item,
26
                        ProjectDocument[] selectedItems) {
27
                return selectedItems.length > 0;
28
        }
29

    
30
        public void execute(ProjectDocument item, ProjectDocument[] selectedItems) {
31
                ProjectExtension projectExtension = (ProjectExtension)PluginServices.getExtension(ProjectExtension.class);
32
                Project project = projectExtension.getProject();
33
                String data;
34

    
35

    
36

    
37

    
38

    
39
                try {
40
                        data = project.exportToXML(selectedItems);
41
                } catch (SaveException e) {
42
                        JOptionPane.showMessageDialog(
43
                                        (Component)PluginServices.getMainFrame(),
44
                                        "<html>"+PluginServices.getText(this,"No_ha_sido_posible_realizar_la_operacion")+"</html>",//Mensaje
45
                                        PluginServices.getText(this,"cortar"),//titulo
46
                                        JOptionPane.ERROR_MESSAGE
47
                                        );
48
                        return;
49
                }
50
                PluginServices.putInClipboard(data);
51

    
52
                for (int i =0;i<selectedItems.length;i++) {
53
                        if (selectedItems[i].isLocked()) {
54
                                JOptionPane.showMessageDialog(
55
                                                (Component)PluginServices.getMainFrame(),
56
                                                PluginServices.getText(this, "locked_element_it_cannot_be_deleted") + ": " +selectedItems[i].getName()
57
                                );
58
                                return;
59

    
60
                        }
61
                }
62

    
63

    
64
            int option=JOptionPane.showConfirmDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"desea_borrar_el_documento"));
65
            if (option!=JOptionPane.OK_OPTION) {
66
                    return;
67
            }
68

    
69
                this.removeDocuments(selectedItems,project);
70
                project.setModified(true);
71

    
72
        }
73

    
74
        public String getText() {
75
                return PluginServices.getText(this, "cortar");
76
        }
77

    
78
        private boolean removeDocuments(ProjectDocument[] selectedItems,Project project) {
79
                ProjectDocument element;
80
                int index;
81
                for (int i=selectedItems.length-1;i>=0;i--) {
82

    
83
                        element = selectedItems[i];
84

    
85

    
86
                        if (element.isLocked()) {
87
                                JOptionPane.showMessageDialog(
88
                                                (Component)PluginServices.getMainFrame(),
89
                                                PluginServices.getText(this, "locked_element_it_cannot_be_deleted") + ": " +element.getName()
90
                                );
91
                                //return false;
92
                        } else {
93
                                PluginServices.getMDIManager().closeSingletonWindow(element);
94
                                project.delDocument(element);
95
                        }
96
                }
97
                return true;
98
        }
99

    
100

    
101
}