Statistics
| Revision:

svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / extension / FFrameViewAddLayerExtension.java @ 341

History | View | Annotate | Download (3.62 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.app.extension;
23

    
24
import org.gvsig.andami.PluginServices;
25
import org.gvsig.andami.PluginsLocator;
26
import org.gvsig.andami.PluginsManager;
27
import org.gvsig.andami.plugins.Extension;
28
import org.gvsig.andami.ui.mdiManager.IWindow;
29
import org.gvsig.app.project.documents.layout.fframes.FFrameOverView;
30
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap;
31
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

    
35
/**
36
 * Extension to control the options that can be done on a view added to layout
37
 * 
38
 * @author Cesar Martinez Izquierdo
39
 */
40
public class FFrameViewAddLayerExtension extends Extension {
41

    
42
    private static Logger logger = LoggerFactory.getLogger(FFrameViewAddLayerExtension.class);
43
    //.info("Can't change scale of view.", ex);
44

    
45
    /**
46
     * @see org.gvsig.andami.plugins.IExtension#initialize()
47
     */
48
    public void initialize() {
49
            
50
    }
51
    
52
    /**
53
     * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
54
     */
55
    public void execute(String s) {
56
        LayoutPanel layout = (LayoutPanel) PluginServices.getMDIManager().getActiveWindow();
57
            if (s.compareTo("layout-view-add-layer") == 0) {
58
                PluginsManager manager = PluginsLocator.getManager();
59
                AddLayer plugin = (AddLayer) manager.getExtension(AddLayer.class);
60
                IFFrameUseFMap[] fframes = layout.getLayoutContext().getSelectedFFrames(IFFrameUseFMap.class);
61
                if (fframes.length>0) {
62
                        if (fframes[0].getMapContext()!=null) {
63
                                plugin.addLayers(fframes[0].getMapContext());
64
                                fframes[0].refresh();
65
                                layout.getDocument().setModified(true);
66
                        }
67
                }
68
        }
69
    }
70
    
71

    
72
    /**
73
     * @see org.gvsig.andami.plugins.IExtension#isEnabled()
74
     */
75
    public boolean isEnabled() {
76
            IWindow window = PluginServices.getMDIManager().getActiveWindow();
77
            if (window instanceof LayoutPanel) {
78
                    LayoutPanel l =
79
                                    (LayoutPanel) PluginServices.getMDIManager().getActiveWindow();
80
                    if (!l.getLayoutContext().isEditable()) {
81
                            return false;
82
                    }
83
                    IFFrameUseFMap[] fframes = l.getLayoutContext().getSelectedFFrames(IFFrameUseFMap.class);
84
                    if (fframes.length==1 && !(fframes[0] instanceof FFrameOverView) && ((IFFrameUseFMap)fframes[0]).getMapContext()!=null) {
85
                            return true;
86
                    }
87
            }
88
            return false;
89
    }
90

    
91
    /**
92
     * @see org.gvsig.andami.plugins.IExtension#isVisible()
93
     */
94
    public boolean isVisible() {
95
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
96

    
97
        if (f == null) {
98
            return false;
99
        }
100

    
101
        if (f instanceof LayoutPanel) {
102
            return true;
103
        } else {
104
            return false;
105
        }
106
    }
107
}