svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / toc / actions / PasteLayersTocMenuEntry.java @ 39574
History | View | Annotate | Download (3.14 KB)
1 |
package org.gvsig.app.project.documents.view.toc.actions; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
|
5 |
import javax.swing.JOptionPane; |
6 |
|
7 |
import org.slf4j.Logger; |
8 |
import org.slf4j.LoggerFactory; |
9 |
|
10 |
import org.gvsig.andami.PluginServices; |
11 |
import org.gvsig.app.ApplicationLocator; |
12 |
import org.gvsig.app.extension.ProjectExtension; |
13 |
import org.gvsig.app.project.Project; |
14 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
15 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
16 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
17 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
18 |
import org.gvsig.i18n.Messages; |
19 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
20 |
|
21 |
|
22 |
public class PasteLayersTocMenuEntry extends AbstractTocContextMenuAction { |
23 |
|
24 |
private static Logger logger = |
25 |
LoggerFactory.getLogger(PasteLayersTocMenuEntry.class); |
26 |
|
27 |
public String getGroup() { |
28 |
return "copyPasteLayer"; |
29 |
} |
30 |
|
31 |
public int getGroupOrder() { |
32 |
return 60; |
33 |
} |
34 |
|
35 |
public int getOrder() { |
36 |
return 2; |
37 |
} |
38 |
|
39 |
public String getText() { |
40 |
return PluginServices.getText(this, "pegar"); |
41 |
} |
42 |
|
43 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
44 |
if (isTocItemBranch(item)) {
|
45 |
FLayer lyr = getNodeLayer(item); |
46 |
if (lyr instanceof FLayers) { |
47 |
FLayers aux = this.getFLayersFromClipboard();
|
48 |
return aux != null; |
49 |
} |
50 |
|
51 |
} else if (!isTocItemLeaf(item)) { |
52 |
if (getNodeLayer(item) == null) { |
53 |
FLayers aux = this.getFLayersFromClipboard();
|
54 |
return aux != null; |
55 |
} |
56 |
} |
57 |
return false; |
58 |
} |
59 |
|
60 |
/**
|
61 |
* This method can return null (if content of clipboard not useful)
|
62 |
*
|
63 |
* @return
|
64 |
*/
|
65 |
private FLayers getFLayersFromClipboard() {
|
66 |
|
67 |
FLayers resp = null;
|
68 |
try {
|
69 |
resp = CopyPasteLayersUtils.getClipboardAsFLayers(); |
70 |
// resp can be null here if clipboard content not useful
|
71 |
} catch (PersistenceException e) {
|
72 |
ApplicationLocator.getManager().message( |
73 |
Messages.getText("_Clipboard_error"),
|
74 |
JOptionPane.ERROR_MESSAGE);
|
75 |
resp = null;
|
76 |
} |
77 |
return resp;
|
78 |
} |
79 |
|
80 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
81 |
FLayers target_root; |
82 |
|
83 |
FLayers clipboard_root = this.getFLayersFromClipboard();
|
84 |
if (clipboard_root == null) { |
85 |
JOptionPane.showMessageDialog(
|
86 |
(Component)PluginServices.getMainFrame(),
|
87 |
Messages.getText("No_ha_sido_posible_realizar_la_operacion"),
|
88 |
Messages.getText("pegar"),
|
89 |
JOptionPane.ERROR_MESSAGE
|
90 |
); |
91 |
logger.info("Unable to parse clipboard as flayers");
|
92 |
return;
|
93 |
} |
94 |
|
95 |
if (isTocItemBranch(item)) {
|
96 |
target_root = (FLayers)getNodeLayer(item); |
97 |
} else if (getNodeLayer(item) == null){ |
98 |
target_root = getMapContext().getLayers(); |
99 |
} else {
|
100 |
return;
|
101 |
} |
102 |
|
103 |
getMapContext().beginAtomicEvent(); |
104 |
|
105 |
boolean isOK = CopyPasteLayersUtils.addLayers(clipboard_root, target_root);
|
106 |
|
107 |
getMapContext().endAtomicEvent(); |
108 |
|
109 |
if (isOK) {
|
110 |
getMapContext().invalidate(); |
111 |
Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
112 |
project.setModified(true);
|
113 |
} |
114 |
} |
115 |
|
116 |
|
117 |
} |