svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / extension / NewTableExtension.java @ 46873
History | View | Annotate | Download (4.75 KB)
1 | 40557 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40557 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40557 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40557 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | 46873 | jjdelcerro | package org.gvsig.app.extension; |
25 | 40435 | jjdelcerro | |
26 | import org.gvsig.andami.plugins.Extension; |
||
27 | import org.gvsig.app.ApplicationLocator; |
||
28 | import org.gvsig.app.ApplicationManager; |
||
29 | 46873 | jjdelcerro | import org.gvsig.app.project.Project; |
30 | import org.gvsig.app.project.ProjectManager; |
||
31 | import org.gvsig.app.project.documents.table.TableDocument; |
||
32 | import org.gvsig.app.project.documents.table.TableManager; |
||
33 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.ViewDocument; |
34 | import org.gvsig.app.project.documents.view.ViewManager; |
||
35 | 46873 | jjdelcerro | import org.gvsig.fmap.dal.DALLocator; |
36 | import org.gvsig.fmap.dal.DataManager; |
||
37 | import org.gvsig.fmap.dal.DataStoreParameters; |
||
38 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
39 | 40435 | jjdelcerro | import org.gvsig.i18n.Messages; |
40 | import org.gvsig.newlayer.NewLayerLocator; |
||
41 | import org.gvsig.newlayer.NewLayerManager; |
||
42 | import org.gvsig.newlayer.NewLayerService; |
||
43 | 46873 | jjdelcerro | import org.gvsig.newlayer.NewLayerService.NewLayerServiceAdapter; |
44 | 40435 | jjdelcerro | import org.gvsig.newlayer.NewLayerWizard; |
45 | 46873 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
46 | import org.gvsig.tools.i18n.I18nManager; |
||
47 | 40435 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
48 | 46873 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingUtils; |
49 | 40435 | jjdelcerro | import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
50 | |||
51 | /**
|
||
52 | * @author gvSIG Team
|
||
53 | * @version $Id$
|
||
54 | 46873 | jjdelcerro | *
|
55 | 40435 | jjdelcerro | */
|
56 | 46873 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
57 | public class NewTableExtension extends Extension { |
||
58 | 40435 | jjdelcerro | |
59 | 46873 | jjdelcerro | @Override
|
60 | public void initialize() { |
||
61 | } |
||
62 | 40435 | jjdelcerro | |
63 | 46873 | jjdelcerro | @Override
|
64 | public void postInitialize() { |
||
65 | super.postInitialize();
|
||
66 | } |
||
67 | 40435 | jjdelcerro | |
68 | 46873 | jjdelcerro | @Override
|
69 | public void execute(String actionCommand) { |
||
70 | final I18nManager i18n = ToolsLocator.getI18nManager();
|
||
71 | final ApplicationManager application = ApplicationLocator.getManager();
|
||
72 | final ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
|
||
73 | 40435 | jjdelcerro | |
74 | 46873 | jjdelcerro | if (view != null) { |
75 | NewLayerManager manager = NewLayerLocator.getManager(); |
||
76 | NewLayerService service = manager.createNewLayerService(); |
||
77 | service.addNewLayerServiceListener(new NewLayerServiceAdapter() {
|
||
78 | @Override
|
||
79 | public void postCreateTable(NewLayerService service) { |
||
80 | if( !service.isAddTableToProject() ) {
|
||
81 | return;
|
||
82 | } |
||
83 | try {
|
||
84 | DataStoreParameters storeParameters = service.getOpenStoreParameters(); |
||
85 | DataManager dataManager = DALLocator.getDataManager(); |
||
86 | FeatureStore store = (FeatureStore) dataManager.openStore(storeParameters.getProviderName(), storeParameters); |
||
87 | String name = FeatureStore.getLabel(store);
|
||
88 | |||
89 | ProjectManager projectManager = application.getProjectManager(); |
||
90 | TableDocument doc = (TableDocument) projectManager.createDocument(TableManager.TYPENAME, name); |
||
91 | doc.setStore(store); |
||
92 | |||
93 | Project project = application.getCurrentProject(); |
||
94 | project.addDocument(doc); |
||
95 | |||
96 | } catch (Exception e) { |
||
97 | 40435 | jjdelcerro | |
98 | 46873 | jjdelcerro | } |
99 | } |
||
100 | }); |
||
101 | NewLayerWizard wizard = manager.createNewLayerWizard(service); |
||
102 | wizard.setAddTableToProjectTitle(i18n.getTranslation("_Add_table"));
|
||
103 | wizard.setAddTableToProjectLabel(i18n.getTranslation("_Add_table_to_project"));
|
||
104 | ToolsSwingUtils.ensureRowsCols(wizard, 40, 140, 50, 170); |
||
105 | 40435 | jjdelcerro | |
106 | 46873 | jjdelcerro | WindowManager windowMgr = ToolsSwingLocator.getWindowManager(); |
107 | windowMgr.showWindow( |
||
108 | wizard, |
||
109 | i18n.getTranslation("_New_table_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 | return true; |
||
122 | } |
||
123 | |||
124 | 40435 | jjdelcerro | } |