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 / view / toc / actions / PasteLayersTocMenuEntry.java @ 40558
History | View | Annotate | Download (4.08 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.view.toc.actions; |
25 |
|
26 |
import java.awt.Component; |
27 |
|
28 |
import javax.swing.JOptionPane; |
29 |
|
30 |
import org.slf4j.Logger; |
31 |
import org.slf4j.LoggerFactory; |
32 |
|
33 |
import org.gvsig.andami.PluginServices; |
34 |
import org.gvsig.app.ApplicationLocator; |
35 |
import org.gvsig.app.extension.ProjectExtension; |
36 |
import org.gvsig.app.project.Project; |
37 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
38 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
39 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
40 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
41 |
import org.gvsig.i18n.Messages; |
42 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
43 |
|
44 |
|
45 |
public class PasteLayersTocMenuEntry extends AbstractTocContextMenuAction { |
46 |
|
47 |
private static Logger logger = |
48 |
LoggerFactory.getLogger(PasteLayersTocMenuEntry.class); |
49 |
|
50 |
public String getGroup() { |
51 |
return "copyPasteLayer"; |
52 |
} |
53 |
|
54 |
public int getGroupOrder() { |
55 |
return 60; |
56 |
} |
57 |
|
58 |
public int getOrder() { |
59 |
return 2; |
60 |
} |
61 |
|
62 |
public String getText() { |
63 |
return PluginServices.getText(this, "pegar"); |
64 |
} |
65 |
|
66 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
67 |
if (isTocItemBranch(item)) {
|
68 |
FLayer lyr = getNodeLayer(item); |
69 |
if (lyr instanceof FLayers) { |
70 |
FLayers aux = this.getFLayersFromClipboard();
|
71 |
return aux != null; |
72 |
} |
73 |
|
74 |
} else if (!isTocItemLeaf(item)) { |
75 |
if (getNodeLayer(item) == null) { |
76 |
FLayers aux = this.getFLayersFromClipboard();
|
77 |
return aux != null; |
78 |
} |
79 |
} |
80 |
return false; |
81 |
} |
82 |
|
83 |
/**
|
84 |
* This method can return null (if content of clipboard not useful)
|
85 |
*
|
86 |
* @return
|
87 |
*/
|
88 |
private FLayers getFLayersFromClipboard() {
|
89 |
|
90 |
FLayers resp = null;
|
91 |
try {
|
92 |
resp = CopyPasteLayersUtils.getClipboardAsFLayers(); |
93 |
// resp can be null here if clipboard content not useful
|
94 |
} catch (PersistenceException e) {
|
95 |
ApplicationLocator.getManager().message( |
96 |
Messages.getText("_Clipboard_error"),
|
97 |
JOptionPane.ERROR_MESSAGE);
|
98 |
resp = null;
|
99 |
} |
100 |
return resp;
|
101 |
} |
102 |
|
103 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
104 |
FLayers target_root; |
105 |
|
106 |
FLayers clipboard_root = this.getFLayersFromClipboard();
|
107 |
if (clipboard_root == null) { |
108 |
JOptionPane.showMessageDialog(
|
109 |
(Component)PluginServices.getMainFrame(),
|
110 |
Messages.getText("No_ha_sido_posible_realizar_la_operacion"),
|
111 |
Messages.getText("pegar"),
|
112 |
JOptionPane.ERROR_MESSAGE
|
113 |
); |
114 |
logger.info("Unable to parse clipboard as flayers");
|
115 |
return;
|
116 |
} |
117 |
|
118 |
if (isTocItemBranch(item)) {
|
119 |
target_root = (FLayers)getNodeLayer(item); |
120 |
} else if (getNodeLayer(item) == null){ |
121 |
target_root = getMapContext().getLayers(); |
122 |
} else {
|
123 |
return;
|
124 |
} |
125 |
|
126 |
getMapContext().beginAtomicEvent(); |
127 |
|
128 |
boolean isOK = CopyPasteLayersUtils.addLayers(clipboard_root, target_root);
|
129 |
|
130 |
getMapContext().endAtomicEvent(); |
131 |
|
132 |
if (isOK) {
|
133 |
getMapContext().invalidate(); |
134 |
Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
135 |
project.setModified(true);
|
136 |
} |
137 |
} |
138 |
|
139 |
|
140 |
} |