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 @ 44644
History | View | Annotate | Download (4.26 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.slf4j.Logger; |
33 |
import org.slf4j.LoggerFactory; |
34 |
|
35 |
import org.gvsig.andami.PluginServices; |
36 |
import org.gvsig.app.ApplicationLocator; |
37 |
import org.gvsig.app.project.Project; |
38 |
import org.gvsig.app.project.ProjectManager; |
39 |
import org.gvsig.app.project.documents.AbstractDocumentAction; |
40 |
import org.gvsig.app.project.documents.Document; |
41 |
import org.gvsig.i18n.Messages; |
42 |
|
43 |
|
44 |
public class CutDocumentAction extends AbstractDocumentAction { |
45 |
|
46 |
private static Logger logger = LoggerFactory.getLogger( |
47 |
CutDocumentAction.class); |
48 |
|
49 |
public CutDocumentAction() {
|
50 |
super("cut"); |
51 |
this.order = 0; |
52 |
this.title =PluginServices.getText(this, "cortar"); |
53 |
this.group = ProjectManager.getInstance().addDocumentActionGroup("ClipboardActions", "Clipboard actions", null, 0); |
54 |
} |
55 |
|
56 |
|
57 |
public int getOrder() { |
58 |
return 1; |
59 |
} |
60 |
|
61 |
public boolean isVisible(Document item, List<Document> selectedItems) { |
62 |
return true; |
63 |
} |
64 |
|
65 |
public boolean isAvailable(Document item, List<Document> selectedItems) { |
66 |
return selectedItems.size() > 0; |
67 |
} |
68 |
|
69 |
public void execute(Document document, List<Document> documents) { |
70 |
|
71 |
List<Document> docs = new ArrayList<Document>(documents); |
72 |
if(document != null && !docs.contains(document)) { |
73 |
docs.add(document); |
74 |
} |
75 |
// Now "docs" has all docs involved
|
76 |
try {
|
77 |
CopyPasteDocsUtils.saveToClipboard(docs); |
78 |
} catch (Exception e) { |
79 |
|
80 |
logger.info("While copying docs to clipboard in cut operation.", e);
|
81 |
JOptionPane.showMessageDialog(
|
82 |
ApplicationLocator.getManager().getRootComponent(), |
83 |
Messages.getText("_Clipboard_error") + ":\n" |
84 |
+ CopyPasteDocsUtils.getLastMessage(e), |
85 |
title, |
86 |
JOptionPane.ERROR_MESSAGE);
|
87 |
/*
|
88 |
* Clear clipboard after error
|
89 |
*/
|
90 |
try {
|
91 |
CopyPasteDocsUtils.clearClipboard(null);
|
92 |
} catch (Exception exc) { |
93 |
logger.error("While clearing clipboard.", exc);
|
94 |
} |
95 |
} |
96 |
|
97 |
// ==================================================
|
98 |
|
99 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
100 |
for (Document doc : docs) { |
101 |
if (doc.isLocked()) {
|
102 |
JOptionPane.showMessageDialog(
|
103 |
(Component)PluginServices.getMainFrame(),
|
104 |
PluginServices.getText(this, "locked_element_it_cannot_be_deleted") + ": " +doc.getName() |
105 |
); |
106 |
return;
|
107 |
} |
108 |
} |
109 |
|
110 |
int option=JOptionPane.showConfirmDialog( |
111 |
(Component)PluginServices.getMainFrame(),
|
112 |
PluginServices.getText(this,"desea_borrar_el_documento") |
113 |
); |
114 |
if (option!=JOptionPane.OK_OPTION) { |
115 |
return;
|
116 |
} |
117 |
|
118 |
this.removeDocuments(docs,project);
|
119 |
|
120 |
} |
121 |
|
122 |
private boolean removeDocuments(List<Document> selectedItems,Project project) { |
123 |
for (Document document : selectedItems) { |
124 |
if (document.isLocked()) {
|
125 |
JOptionPane.showMessageDialog(
|
126 |
(Component)PluginServices.getMainFrame(),
|
127 |
PluginServices.getText(this, "locked_element_it_cannot_be_deleted") + ": " +document.getName() |
128 |
); |
129 |
} else {
|
130 |
PluginServices.getMDIManager().closeSingletonWindow(document); |
131 |
project.remove(document); |
132 |
} |
133 |
} |
134 |
return true; |
135 |
} |
136 |
|
137 |
|
138 |
} |