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

History | View | Annotate | Download (6.43 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.app.ApplicationLocator;
32
import org.gvsig.app.ApplicationManager;
33
import org.gvsig.app.project.ProjectManager;
34
import org.gvsig.app.project.documents.view.ViewDocument;
35
import org.gvsig.app.project.documents.view.ViewManager;
36
import org.gvsig.exportto.swing.ExporttoSwingLocator;
37
import org.gvsig.exportto.swing.ExporttoSwingManager;
38
import org.gvsig.exportto.swing.JExporttoServicePanel;
39
import org.gvsig.fmap.mapcontext.MapContext;
40
import org.gvsig.fmap.mapcontext.layers.FLayer;
41
import org.gvsig.fmap.mapcontext.layers.FLayers;
42
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
43
import org.gvsig.tools.ToolsLocator;
44
import org.gvsig.tools.dataTypes.DataTypes;
45
import org.gvsig.tools.i18n.I18nManager;
46
import org.gvsig.tools.swing.api.ToolsSwingLocator;
47
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
48
import org.gvsig.tools.util.ArrayUtils;
49

    
50

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

    
58
    private ExporttoSwingManager swingManager;
59

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

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

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

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

    
77
    }
78

    
79
    @Override
80
    public void execute(String actionCommand) {
81
        this.execute(actionCommand, null);
82
    }
83

    
84
    @Override
85
    public void execute(String command, Object[] args) {
86
        if( !"exportto".equalsIgnoreCase(command) ) {
87
            return;
88
        }
89
        Object layer = ArrayUtils.get(args, 0);
90
        if( layer instanceof FLyrVect ) {
91
            WindowManager.MODE mode = WindowManager.MODE.fromInteger(
92
                    (Integer)ArrayUtils.get(args, 1,DataTypes.INT, 0)
93
            );
94
            FLyrVect layervect = (FLyrVect) layer;
95
            MapContext mapContext = layervect.getMapContext();
96
            this.showExportto(layervect, mapContext.getProjection(), mapContext, mode);
97
            return;
98
        }
99
        
100
        ApplicationManager application = ApplicationLocator.getManager();
101
        ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
102
        if ( view != null ) {
103
            MapContext mapContext = view.getMapContext();
104
            FLayers layers = mapContext.getLayers();
105
            FLayer[] actives = layers.getActives();
106
            try {
107
                if ( actives.length == 1 ) {
108
                    if ( actives[0] instanceof FLyrVect ) {
109
                        FLyrVect fLyrVect = (FLyrVect) actives[0];
110
                        showExportto(fLyrVect, mapContext.getProjection(),
111
                                mapContext, WindowManager.MODE.WINDOW);
112
                    }
113
                } else {
114
                    for (FLayer active : actives) {
115
                        if (active instanceof FLyrVect) {
116
                            FLyrVect fLyrVect = (FLyrVect) active;
117
                            showExportto(fLyrVect, mapContext.getProjection(),
118
                                    mapContext, WindowManager.MODE.DIALOG);
119
                        }
120
                    }
121
                }
122
            } catch (Exception e) {
123
                NotificationManager.showMessageError(e.getMessage(), e);
124
            }
125
        }
126
    }
127

    
128
    public int showExportto(FLyrVect fLyrVect, IProjection projection,
129
            MapContext mapContext) {
130
        return this.showExportto(fLyrVect, projection, mapContext, WindowManager.MODE.DIALOG);
131
    }
132
    
133
    public int showExportto(FLyrVect fLyrVect, IProjection projection,
134
            MapContext mapContext, WindowManager.MODE mode) {
135

    
136
        I18nManager i18nManager = ToolsLocator.getI18nManager();
137
        
138
        JExporttoServicePanel panel
139
                = swingManager
140
                .createExportto(
141
                        fLyrVect,
142
                        new LoadLayerAction(mapContext),
143
                        new int[]{ExporttoSwingManager.VECTORIAL_TABLE_WITH_GEOMETRY});
144

    
145
        WindowManager winmgr = ToolsSwingLocator.getWindowManager();
146
        winmgr.showWindow(panel, i18nManager.getTranslation("_Export_to"), mode);
147
        return panel.getStatus();
148

    
149
    }
150

    
151
    @Override
152
    public boolean isEnabled() {
153
        ApplicationManager application = ApplicationLocator.getManager();
154
        ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
155
        if ( view != null ) {
156
            FLayer[] actives = view.getMapContext().getLayers().getActives();
157
            for (FLayer active : actives) {
158
                if (active instanceof FLyrVect) {
159
                    return true;
160
                }
161
            }
162
        }
163
        return false;
164
    }
165

    
166
    @Override
167
    public boolean isVisible() {
168
        ApplicationManager application = ApplicationLocator.getManager();
169
        ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
170
        return view != null;
171
    }
172

    
173
}