Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2059 / extensions / org.gvsig.exportto.app / org.gvsig.exportto.app.extension / src / main / java / org / gvsig / exportto / app / extension / ExporttoLayerExtension.java @ 39325

History | View | Annotate | Download (5.11 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.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.documents.view.ViewDocument;
35
import org.gvsig.app.project.documents.view.ViewManager;
36
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
37
import org.gvsig.exportto.swing.ExporttoSwingLocator;
38
import org.gvsig.exportto.swing.ExporttoSwingManager;
39
import org.gvsig.exportto.swing.ExporttoWindowManager;
40
import org.gvsig.exportto.swing.JExporttoServicePanel;
41
import org.gvsig.fmap.mapcontext.MapContext;
42
import org.gvsig.fmap.mapcontext.layers.FLayer;
43
import org.gvsig.fmap.mapcontext.layers.FLayers;
44
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
45
import org.gvsig.i18n.Messages;
46

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

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

    
58
    public void initialize() {
59
        if (!Messages.hasLocales()) {
60
            Messages.addLocale(Locale.getDefault());
61
        }
62
        Messages.addResourceFamily(
63
            "org.gvsig.exportto.app.extension.i18n.text",
64
            ExporttoLayerExtension.class.getClassLoader(),
65
            ExporttoLayerExtension.class.getClass().getName());
66
        
67
        IconThemeHelper.registerIcon("action", "layer-export", this);
68
    }
69

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

    
76
        swingManager.registerWindowManager(new GvSIGExporttoWindowManager());
77
    }
78

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

    
101
    public int showExportto(FLyrVect fLyrVect, IProjection projection,
102
        MapContext mapContext) {
103

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

    
112
        swingManager.getWindowManager().showWindow(panel, "Exportto",
113
            ExporttoWindowManager.MODE_WINDOW);
114

    
115
        return panel.getStatus();
116

    
117
    }
118

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

    
134
    public boolean isVisible() {
135
        IWindow window = APPLICATION_MANAGER.getUIManager().getActiveWindow();
136

    
137
        if (window == null) {
138
            return false;
139
        }
140

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