svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.newlayer.app / org.gvsig.newlayer.app.mainplugin / src / main / java / org / gvsig / newlayer / app / extension / NewLayerExtension.java @ 47433
History | View | Annotate | Download (4.87 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.newlayer.app.extension; |
25 |
|
26 |
import org.gvsig.andami.IconThemeHelper; |
27 |
import org.gvsig.andami.plugins.Extension; |
28 |
import org.gvsig.app.ApplicationLocator; |
29 |
import org.gvsig.app.ApplicationManager; |
30 |
import org.gvsig.app.project.documents.view.ViewDocument; |
31 |
import org.gvsig.app.project.documents.view.ViewManager; |
32 |
import org.gvsig.fmap.dal.DALLocator; |
33 |
import org.gvsig.fmap.dal.DataManager; |
34 |
import org.gvsig.fmap.dal.DataStore; |
35 |
import org.gvsig.fmap.dal.DataStoreParameters; |
36 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
37 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
38 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
39 |
import org.gvsig.i18n.Messages; |
40 |
import org.gvsig.newlayer.NewLayerLocator; |
41 |
import org.gvsig.newlayer.NewLayerManager; |
42 |
import org.gvsig.newlayer.NewLayerService; |
43 |
import org.gvsig.newlayer.NewLayerService.NewLayerServiceAdapter; |
44 |
import org.gvsig.newlayer.NewLayerWizard; |
45 |
import org.gvsig.tools.ToolsLocator; |
46 |
import org.gvsig.tools.i18n.I18nManager; |
47 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
48 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
49 |
|
50 |
/**
|
51 |
* @author gvSIG Team
|
52 |
* @version $Id$
|
53 |
*
|
54 |
*/
|
55 |
public class NewLayerExtension extends Extension { |
56 |
|
57 |
public void initialize() { |
58 |
} |
59 |
|
60 |
@Override
|
61 |
public void postInitialize() { |
62 |
super.postInitialize();
|
63 |
} |
64 |
|
65 |
@Override
|
66 |
public void execute(String actionCommand) { |
67 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
68 |
ApplicationManager application = ApplicationLocator.getManager(); |
69 |
final ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
|
70 |
|
71 |
if (view != null) { |
72 |
NewLayerManager manager = NewLayerLocator.getManager(); |
73 |
NewLayerService service = manager.createNewLayerService(); |
74 |
service.setDefaultProjection(view.getProjection()); |
75 |
service.addNewLayerServiceListener(new NewLayerServiceAdapter() {
|
76 |
@Override
|
77 |
public void postCreateTable(NewLayerService service) { |
78 |
if( !service.isAddTableToProject() ) {
|
79 |
return;
|
80 |
} |
81 |
try {
|
82 |
if (service.getFeatureType().getDefaultGeometryAttribute() == null) { |
83 |
return;
|
84 |
} |
85 |
DataStoreParameters storeParameters = service.getOpenStoreParameters(); |
86 |
DataManager dataManager = DALLocator.getDataManager(); |
87 |
DataStore store = dataManager.openStore(storeParameters.getProviderName(), storeParameters); |
88 |
String layerName = store.getName();
|
89 |
|
90 |
MapContextManager mapContextManager = MapContextLocator.getMapContextManager(); |
91 |
FLayer lyr = mapContextManager.createLayer(layerName, store); |
92 |
lyr.setActive(true);
|
93 |
lyr.setVisible(true);
|
94 |
view.getMapContext().getLayers().addLayer(lyr); |
95 |
|
96 |
lyr.dispose(); |
97 |
} catch (Exception e) { |
98 |
|
99 |
} |
100 |
} |
101 |
}); |
102 |
NewLayerWizard wizard = manager.createNewLayerWizard(service); |
103 |
wizard.setAddTableToProjectTitle(i18n.getTranslation("_Adding_layer"));
|
104 |
wizard.setAddTableToProjectLabel(i18n.getTranslation("_Add_layer_to_view"));
|
105 |
|
106 |
WindowManager windowMgr = ToolsSwingLocator.getWindowManager(); |
107 |
windowMgr.showWindow( |
108 |
wizard, |
109 |
Messages.getText("_New_layer_wizard"),
|
110 |
WindowManager.MODE.WINDOW); |
111 |
} |
112 |
} |
113 |
|
114 |
@Override
|
115 |
public boolean isEnabled() { |
116 |
return isVisible();
|
117 |
} |
118 |
|
119 |
@Override
|
120 |
public boolean isVisible() { |
121 |
ApplicationManager application = ApplicationLocator.getManager(); |
122 |
ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
123 |
return (view != null); |
124 |
} |
125 |
|
126 |
} |