Statistics
| Revision:

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 / CopyLayersTocMenuEntry.java @ 40558

History | View | Annotate | Download (3.29 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.project.documents.view.toc.AbstractTocContextMenuAction;
35
import org.gvsig.app.project.documents.view.toc.ITocItem;
36
import org.gvsig.fmap.mapcontext.layers.FLayer;
37
import org.gvsig.i18n.Messages;
38
import org.gvsig.tools.persistence.PersistentState;
39

    
40

    
41
public class CopyLayersTocMenuEntry extends AbstractTocContextMenuAction {
42
    
43
    private static Logger logger =
44
        LoggerFactory.getLogger(CopyLayersTocMenuEntry.class);
45
    
46
        public String getGroup() {
47
                return "copyPasteLayer";
48
        }
49

    
50
        public int getGroupOrder() {
51
                return 60;
52
        }
53

    
54
        public int getOrder() {
55
                return 0;
56
        }
57

    
58
        public String getText() {
59
                return PluginServices.getText(this, "copiar");
60
        }
61

    
62
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
63
                if ( selectedItems.length >= 1 && isTocItemBranch(item)){
64
                        for (int i=0;i< selectedItems.length;i++) {
65
                                if (selectedItems[i].isEditing()){
66
                                        return false;
67
                                }
68
                        }
69
                        return true;
70
                }
71
                return false;
72

    
73
        }
74

    
75

    
76
        public void execute(ITocItem item, FLayer[] selectedItems) {
77

    
78
               PersistentState lyrs_state = null;
79
                
80
                try {
81
                    lyrs_state = CopyPasteLayersUtils.getAsFLayersPersistentState(
82
                        selectedItems, this.getMapContext());
83
                    /*
84
                     * Saving layers data to clipboard.
85
                     * Files and URLs are not relativized
86
                     */
87
                    CopyPasteLayersUtils.saveToClipboard(lyrs_state);
88
                    
89
                    /*
90
                     * This code does not look right: why modified?
91
                     * 
92
                    Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
93
                    project.setModified(true);
94
                    */
95

    
96
                } catch (Exception e) {
97
                    
98
                    JOptionPane.showMessageDialog(
99
                    (Component)PluginServices.getMainFrame(),
100
                    Messages.getText("No_ha_sido_posible_realizar_la_operacion")
101
                    + "\n\n" + e.getMessage(),
102
                    Messages.getText("copiar"),
103
                    JOptionPane.ERROR_MESSAGE
104
                    );
105
                    logger.info("While copying layers.", e);
106
                    return;
107
                }
108
        }
109

    
110

    
111
}