Revision 40971 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/actions/CopyDocumentAction.java
CopyDocumentAction.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.app.project.documents.actions; |
25 | 25 |
|
26 |
import java.io.IOException; |
|
26 | 27 |
import java.util.ArrayList; |
27 | 28 |
import java.util.List; |
28 | 29 |
|
30 |
import javax.swing.JOptionPane; |
|
31 |
|
|
32 |
import org.slf4j.Logger; |
|
33 |
import org.slf4j.LoggerFactory; |
|
34 |
|
|
29 | 35 |
import org.gvsig.andami.PluginServices; |
36 |
import org.gvsig.app.ApplicationLocator; |
|
30 | 37 |
import org.gvsig.app.project.Project; |
31 | 38 |
import org.gvsig.app.project.ProjectManager; |
32 | 39 |
import org.gvsig.app.project.documents.AbstractDocumentAction; |
33 | 40 |
import org.gvsig.app.project.documents.Document; |
41 |
import org.gvsig.i18n.Messages; |
|
42 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
34 | 43 |
|
35 | 44 |
|
36 | 45 |
public class CopyDocumentAction extends AbstractDocumentAction { |
37 | 46 |
|
47 |
private static Logger logger = LoggerFactory.getLogger( |
|
48 |
CopyDocumentAction.class); |
|
49 |
|
|
38 | 50 |
public CopyDocumentAction() { |
39 | 51 |
super("copy"); |
40 | 52 |
this.order = 0; |
41 |
this.title =PluginServices.getText(this, "copiar");
|
|
53 |
this.title = Messages.getText("copiar");
|
|
42 | 54 |
this.group = ProjectManager.getInstance().addDocumentActionGroup("ClipboardActions", "Clipboard actions", null, 0); |
43 | 55 |
} |
44 | 56 |
|
45 | 57 |
public void execute(Document document, List<Document> documents) { |
46 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
|
47 |
|
|
58 |
|
|
48 | 59 |
List<Document> docs = new ArrayList<Document>(documents); |
49 |
if( !docs.contains(documents)) {
|
|
60 |
if(document != null && !docs.contains(document)) {
|
|
50 | 61 |
docs.add(document); |
51 | 62 |
} |
52 |
String data = project.exportDocumentsAsText(docs); |
|
53 |
PluginServices.putInClipboard(data); |
|
63 |
// Now "docs" has all docs involved |
|
64 |
try { |
|
65 |
CopyPasteDocsUtils.saveToClipboard(docs); |
|
66 |
} catch (Exception e) { |
|
67 |
|
|
68 |
logger.info("While copying docs to clipboard.", e); |
|
69 |
JOptionPane.showMessageDialog( |
|
70 |
ApplicationLocator.getManager().getRootComponent(), |
|
71 |
Messages.getText("_Clipboard_error") + ":\n" |
|
72 |
+ CopyPasteDocsUtils.getLastMessage(e), |
|
73 |
title, |
|
74 |
JOptionPane.ERROR_MESSAGE); |
|
75 |
/* |
|
76 |
* Clear clipboard after error |
|
77 |
*/ |
|
78 |
try { |
|
79 |
CopyPasteDocsUtils.clearClipboard(null); |
|
80 |
} catch (Exception exc) { |
|
81 |
logger.error("While clearing clipboard.", exc); |
|
82 |
} |
|
83 |
|
|
84 |
} |
|
54 | 85 |
} |
55 | 86 |
|
56 |
public boolean isAvailable(Document document, List<Document> documents) {
|
|
57 |
return true;
|
|
87 |
public boolean isAvailable(Document document, List<Document> selectedItems) {
|
|
88 |
return selectedItems.size() > 0;
|
|
58 | 89 |
} |
59 | 90 |
|
60 | 91 |
public boolean isVisible(Document document, List<Document> documents) { |
Also available in: Unified diff