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 / actions / CutDocumentAction.java @ 40558
History | View | Annotate | Download (3.23 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.actions; |
25 |
|
26 |
import java.awt.Component; |
27 |
import java.util.ArrayList; |
28 |
import java.util.List; |
29 |
|
30 |
import javax.swing.JOptionPane; |
31 |
|
32 |
import org.gvsig.andami.PluginServices; |
33 |
import org.gvsig.app.project.Project; |
34 |
import org.gvsig.app.project.ProjectManager; |
35 |
import org.gvsig.app.project.documents.AbstractDocumentAction; |
36 |
import org.gvsig.app.project.documents.Document; |
37 |
|
38 |
|
39 |
public class CutDocumentAction extends AbstractDocumentAction { |
40 |
|
41 |
public CutDocumentAction() {
|
42 |
super("cut"); |
43 |
this.order = 0; |
44 |
this.title =PluginServices.getText(this, "cortar"); |
45 |
this.group = ProjectManager.getInstance().addDocumentActionGroup("ClipboardActions", "Clipboard actions", null, 0); |
46 |
} |
47 |
|
48 |
|
49 |
public int getOrder() { |
50 |
return 1; |
51 |
} |
52 |
|
53 |
public boolean isVisible(Document item, List<Document> selectedItems) { |
54 |
return true; |
55 |
} |
56 |
|
57 |
public boolean isAvailable(Document item, List<Document> selectedItems) { |
58 |
return selectedItems.size() > 0; |
59 |
} |
60 |
|
61 |
public void execute(Document document, List<Document> documents) { |
62 |
|
63 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
64 |
|
65 |
List<Document> docs = new ArrayList<Document>(documents); |
66 |
if( !docs.contains(documents)) {
|
67 |
docs.add(document); |
68 |
} |
69 |
String data = project.exportDocumentsAsText(docs);
|
70 |
PluginServices.putInClipboard(data); |
71 |
|
72 |
|
73 |
for (Document doc : documents) { |
74 |
if (doc.isLocked()) {
|
75 |
JOptionPane.showMessageDialog(
|
76 |
(Component)PluginServices.getMainFrame(),
|
77 |
PluginServices.getText(this, "locked_element_it_cannot_be_deleted") + ": " +doc.getName() |
78 |
); |
79 |
return;
|
80 |
} |
81 |
} |
82 |
|
83 |
int option=JOptionPane.showConfirmDialog( |
84 |
(Component)PluginServices.getMainFrame(),
|
85 |
PluginServices.getText(this,"desea_borrar_el_documento") |
86 |
); |
87 |
if (option!=JOptionPane.OK_OPTION) { |
88 |
return;
|
89 |
} |
90 |
|
91 |
this.removeDocuments(documents,project);
|
92 |
|
93 |
} |
94 |
|
95 |
private boolean removeDocuments(List<Document> selectedItems,Project project) { |
96 |
for (Document document : selectedItems) { |
97 |
if (document.isLocked()) {
|
98 |
JOptionPane.showMessageDialog(
|
99 |
(Component)PluginServices.getMainFrame(),
|
100 |
PluginServices.getText(this, "locked_element_it_cannot_be_deleted") + ": " +document.getName() |
101 |
); |
102 |
} else {
|
103 |
PluginServices.getMDIManager().closeSingletonWindow(document); |
104 |
project.remove(document); |
105 |
} |
106 |
} |
107 |
return true; |
108 |
} |
109 |
|
110 |
|
111 |
} |