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 @ 280

History | View | Annotate | Download (3.5 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
                        plugin.addLayers(fframes[0].getMapContext());
63
                        fframes[0].refresh();
64
                        layout.getDocument().setModified(true);
65
                }
66
        }
67
    }
68
    
69

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

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

    
95
        if (f == null) {
96
            return false;
97
        }
98

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