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

History | View | Annotate | Download (5.16 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 java.util.Locale;
27

    
28
import org.cresques.cts.IProjection;
29

    
30
import org.gvsig.andami.IconThemeHelper;
31
import org.gvsig.andami.messages.NotificationManager;
32
import org.gvsig.andami.plugins.Extension;
33
import org.gvsig.andami.ui.mdiManager.IWindow;
34
import org.gvsig.app.ApplicationLocator;
35
import org.gvsig.app.ApplicationManager;
36
import org.gvsig.app.project.documents.view.ViewDocument;
37
import org.gvsig.app.project.documents.view.ViewManager;
38
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
39
import org.gvsig.exportto.swing.ExporttoSwingLocator;
40
import org.gvsig.exportto.swing.ExporttoSwingManager;
41
import org.gvsig.exportto.swing.ExporttoWindowManager;
42
import org.gvsig.exportto.swing.JExporttoServicePanel;
43
import org.gvsig.fmap.mapcontext.MapContext;
44
import org.gvsig.fmap.mapcontext.layers.FLayer;
45
import org.gvsig.fmap.mapcontext.layers.FLayers;
46
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
47
import org.gvsig.i18n.Messages;
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
        if (!Messages.hasLocales()) {
62
            Messages.addLocale(Locale.getDefault());
63
        }
64
        Messages.addResourceFamily(
65
            "org.gvsig.exportto.app.extension.i18n.text",
66
            ExporttoLayerExtension.class.getClassLoader(),
67
            ExporttoLayerExtension.class.getClass().getName());
68
        
69
        IconThemeHelper.registerIcon("action", "layer-export", this);
70
    }
71

    
72
    @Override
73
    public void postInitialize() {
74
        super.postInitialize();
75
        // Asignamos el locator e iniciamos la instancia
76
        swingManager = ExporttoSwingLocator.getSwingManager();
77

    
78
        swingManager.registerWindowManager(new GvSIGExporttoWindowManager());
79
    }
80

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

    
103
    public int showExportto(FLyrVect fLyrVect, IProjection projection,
104
        MapContext mapContext) {
105

    
106
        JExporttoServicePanel panel =
107
            swingManager
108
                .createExportto(
109
                    fLyrVect.getFeatureStore(),
110
                    projection,
111
                    new LoadLayerAction(mapContext),
112
                    new int[] { ExporttoSwingManager.VECTORIAL_TABLE_WITH_GEOMETRY });
113

    
114
        swingManager.getWindowManager().showWindow(panel, "Exportto",
115
            ExporttoWindowManager.MODE_WINDOW);
116

    
117
        return panel.getStatus();
118

    
119
    }
120

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

    
136
    public boolean isVisible() {
137
        IWindow window = APPLICATION_MANAGER.getUIManager().getActiveWindow();
138

    
139
        if (window == null) {
140
            return false;
141
        }
142

    
143
        if (window instanceof DefaultViewPanel) {
144
            return true;
145
        }
146
        return false;
147
    }
148
}