Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.exportto.app / org.gvsig.exportto.app.mainplugin / src / main / java / org / gvsig / exportto / app / extension / ExporttoLayerExtension.java @ 41494

History | View | Annotate | Download (5.63 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.exportto.app.extension;
25

    
26
import org.cresques.cts.IProjection;
27

    
28
import org.gvsig.andami.IconThemeHelper;
29
import org.gvsig.andami.messages.NotificationManager;
30
import org.gvsig.andami.plugins.Extension;
31
import org.gvsig.andami.ui.mdiManager.IWindow;
32
import org.gvsig.app.ApplicationLocator;
33
import org.gvsig.app.ApplicationManager;
34
import org.gvsig.app.project.ProjectManager;
35
import org.gvsig.app.project.documents.view.ViewDocument;
36
import org.gvsig.app.project.documents.view.ViewManager;
37
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
38
import org.gvsig.exportto.swing.ExporttoSwingLocator;
39
import org.gvsig.exportto.swing.ExporttoSwingManager;
40
import org.gvsig.exportto.swing.ExporttoWindowManager;
41
import org.gvsig.exportto.swing.JExporttoServicePanel;
42
import org.gvsig.fmap.mapcontext.MapContext;
43
import org.gvsig.fmap.mapcontext.layers.FLayer;
44
import org.gvsig.fmap.mapcontext.layers.FLayers;
45
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
46
import org.gvsig.tools.swing.api.ToolsSwingLocator;
47
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
48

    
49
/**
50
 * @author gvSIG Team
51
 * @version $Id$
52
 *
53
 */
54
public class ExporttoLayerExtension extends Extension {
55

    
56
    private ExporttoSwingManager swingManager;
57
    private static final ApplicationManager APPLICATION_MANAGER
58
            = ApplicationLocator.getManager();
59

    
60
    public void initialize() {
61
        IconThemeHelper.registerIcon("action", "layer-export", this);
62
    }
63

    
64
    @Override
65
    public void postInitialize() {
66
        super.postInitialize();
67
        // Asignamos el locator e iniciamos la instancia
68
        swingManager = ExporttoSwingLocator.getSwingManager();
69

    
70
        swingManager.registerWindowManager(new GvSIGExporttoWindowManager());
71

    
72
        ProjectManager projectManager = ApplicationLocator.getProjectManager();
73
        ViewManager viewManager = (ViewManager) projectManager.getDocumentManager(ViewManager.TYPENAME);
74
        viewManager.addTOCContextAction("layer-exportto");
75

    
76
    }
77

    
78
    public void execute(String actionCommand) {
79
        ApplicationManager application = ApplicationLocator.getManager();
80
        ViewDocument view
81
                = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
82
        if ( view != null ) {
83
            MapContext mapContext = view.getMapContext();
84
            FLayers layers = mapContext.getLayers();
85
            FLayer[] actives = layers.getActives();
86
            try {
87
                if ( actives.length == 1 ) {
88
                    if ( actives[0] instanceof FLyrVect ) {
89
                        FLyrVect fLyrVect = (FLyrVect) actives[0];
90
                        showExportto(fLyrVect, mapContext.getProjection(),
91
                                mapContext, WindowManager.MODE.WINDOW);
92
                    }
93
                } else {
94
                    for ( int i = 0; i < actives.length; i++ ) {
95
                        if ( actives[i] instanceof FLyrVect ) {
96
                            FLyrVect fLyrVect = (FLyrVect) actives[i];
97
                            showExportto(fLyrVect, mapContext.getProjection(),
98
                                    mapContext, WindowManager.MODE.DIALOG);
99
                        }
100
                    }
101
                }
102
            } catch (Exception e) {
103
                NotificationManager.showMessageError(e.getMessage(), e);
104
            }
105
        }
106
    }
107

    
108
    public int showExportto(FLyrVect fLyrVect, IProjection projection,
109
            MapContext mapContext, WindowManager.MODE mode) {
110

    
111
        JExporttoServicePanel panel
112
                = swingManager
113
                .createExportto(
114
                        fLyrVect,
115
                        new LoadLayerAction(mapContext),
116
                        new int[]{ExporttoSwingManager.VECTORIAL_TABLE_WITH_GEOMETRY});
117

    
118
        WindowManager winmgr = ToolsSwingLocator.getWindowManager();
119
        winmgr.showWindow(panel, "Exportto", mode);
120
        return panel.getStatus();
121

    
122
    }
123

    
124
    public boolean isEnabled() {
125
        ApplicationManager application = ApplicationLocator.getManager();
126
        ViewDocument view
127
                = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
128
        if ( view != null ) {
129
            FLayer[] actives = view.getMapContext().getLayers().getActives();
130
            for ( int i = 0; i < actives.length; i++ ) {
131
                if ( actives[i] instanceof FLyrVect ) {
132
                    return true;
133
                }
134
            }
135
        }
136
        return false;
137
    }
138

    
139
    public boolean isVisible() {
140
        IWindow window = APPLICATION_MANAGER.getUIManager().getActiveWindow();
141

    
142
        if ( window == null ) {
143
            return false;
144
        }
145

    
146
        if ( window instanceof DefaultViewPanel ) {
147
            return true;
148
        }
149
        return false;
150
    }
151

    
152
}