Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.exportto.app / org.gvsig.exportto.app.extension / src / main / java / org / gvsig / exportto / app / extension / ExporttoLayerExtension.java @ 37781

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

    
24
import java.util.Locale;
25

    
26
import org.cresques.cts.IProjection;
27

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

    
46
/**
47
 * @author gvSIG Team
48
 * @version $Id$
49
 * 
50
 */
51
public class ExporttoLayerExtension extends Extension {
52

    
53
    private ExporttoSwingManager swingManager;
54
    private static final ApplicationManager APPLICATION_MANAGER =
55
        ApplicationLocator.getManager();
56

    
57
    public void initialize() {
58
        if (!Messages.hasLocales()) {
59
            Messages.addLocale(Locale.getDefault());
60
        }
61
        Messages.addResourceFamily(
62
            "org.gvsig.exportto.app.extension.i18n.text",
63
            ExporttoLayerExtension.class.getClassLoader(),
64
            ExporttoLayerExtension.class.getClass().getName());
65
    }
66

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

    
73
        swingManager.registerWindowManager(new GvSIGExporttoWindowManager());
74
    }
75

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

    
98
    public int showExportto(FLyrVect fLyrVect, IProjection projection,
99
        MapContext mapContext) {
100

    
101
        JExporttoServicePanel panel =
102
            swingManager
103
                .createExportto(
104
                    fLyrVect.getFeatureStore(),
105
                    projection,
106
                    new LoadLayerAction(mapContext),
107
                    new int[] { ExporttoSwingManager.VECTORIAL_TABLE_WITH_GEOMETRY });
108

    
109
        swingManager.getWindowManager().showWindow(panel, "Exportto",
110
            ExporttoWindowManager.MODE_WINDOW);
111

    
112
        return panel.getStatus();
113

    
114
    }
115

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

    
131
    public boolean isVisible() {
132
        IWindow window = APPLICATION_MANAGER.getUIManager().getActiveWindow();
133

    
134
        if (window == null) {
135
            return false;
136
        }
137

    
138
        if (window instanceof DefaultViewPanel) {
139
            return true;
140
        }
141
        return false;
142
    }
143
}