Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / fmap / dal / serverexplorer / filesystem / swing / FilesystemExplorerTableWizardPanel.java @ 39279

History | View | Annotate | Download (5.12 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

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 IVER T.I. S.A.   {{Task}}
26
 */
27

    
28
package org.gvsig.fmap.dal.serverexplorer.filesystem.swing;
29

    
30
import java.awt.Window;
31
import java.util.ArrayList;
32
import java.util.List;
33

    
34
import javax.swing.JOptionPane;
35

    
36
import org.cresques.cts.IProjection;
37
import org.slf4j.Logger;
38
import org.slf4j.LoggerFactory;
39

    
40
import org.gvsig.andami.PluginServices;
41
import org.gvsig.andami.messages.NotificationManager;
42
import org.gvsig.app.ApplicationLocator;
43
import org.gvsig.app.ApplicationManager;
44
import org.gvsig.app.prepareAction.PrepareContext;
45
import org.gvsig.app.project.Project;
46
import org.gvsig.app.project.ProjectManager;
47
import org.gvsig.app.project.documents.table.TableDocument;
48
import org.gvsig.app.project.documents.table.TableManager;
49
import org.gvsig.fmap.dal.DALLocator;
50
import org.gvsig.fmap.dal.DataManager;
51
import org.gvsig.fmap.dal.DataStoreParameters;
52
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
53
import org.gvsig.fmap.dal.feature.FeatureStore;
54
import org.gvsig.i18n.Messages;
55

    
56
public class FilesystemExplorerTableWizardPanel extends
57
    FilesystemExplorerWizardPanel {
58

    
59
    private static final long serialVersionUID = 8469934188826417698L;
60
    private static final Logger LOG = LoggerFactory.getLogger(
61
        FilesystemExplorerTableWizardPanel.class);
62

    
63
    private PrepareContext prepareDSContext = null;
64

    
65
    @Override
66
    public void execute() {
67
        executeWizard();
68
    }
69

    
70
    public Object executeWizard() {
71
        FeatureStore store;
72
        TableDocument table;
73

    
74
        ApplicationManager manager = ApplicationLocator.getManager();
75
        Project project = manager.getCurrentProject();
76

    
77
        PrepareContext context = this.getPrepareDataStoreContext();
78
        DataStoreParameters[] parameters = this.getParameters();
79
        List<TableDocument> tabledocs =
80
            new ArrayList<TableDocument>(parameters.length);
81
        
82
        String not_valid = "";
83
        for (DataStoreParameters params : parameters) {
84
            store = null;
85
            
86
            /*
87
             * Try to validate.
88
             */
89
            try {
90
                params.validate();
91
            } catch (ValidateDataParametersException ecx) {
92
                LOG.info("Unable to validate params: " + params.getDataStoreName());
93
                if (not_valid.length() == 0) {
94
                    not_valid = params.getDataStoreName();
95
                } else {
96
                    not_valid = not_valid + ", " + params.getDataStoreName();
97
                }
98
                
99
                continue;
100
            }
101
            
102
            try {
103

    
104
                DataManager dataManager = DALLocator.getDataManager();
105
                store =
106
                    (FeatureStore) dataManager.openStore(
107
                        params.getDataStoreName(), params);
108
                manager.pepareOpenDataSource(store, context);
109

    
110
                table =
111
                    (TableDocument) ProjectManager.getInstance()
112
                        .createDocument(TableManager.TYPENAME);
113
                table.setName(store.getName());
114
                table.setStore(store);
115

    
116
                // project.add(table);
117
                tabledocs.add(table);
118
            } catch (Exception e) {
119
                if (store != null) {
120
                    store.dispose();
121
                }
122
                NotificationManager.addError(e);
123
            }
124

    
125
        }
126
        
127
        if (not_valid.length() > 0) {
128
            JOptionPane.showMessageDialog(
129
                this,
130
                Messages.getText("_These_sources_were_not_loaded")
131
                + ": " + not_valid,
132
                Messages.getText("_Load_error"),
133
                JOptionPane.WARNING_MESSAGE);
134
        }
135
        return tabledocs;
136
    }
137

    
138
    @Override
139
    protected PrepareContext getPrepareDataStoreContext() {
140
        if (this.prepareDSContext == null) {
141
            this.prepareDSContext = new PrepareContext() {
142

    
143
                public Window getOwnerWindow() {
144
                    return null;
145
                }
146
                
147
                public IProjection getViewProjection() {
148
                        return null;
149
                }
150

    
151
            };
152
        }
153
        return this.prepareDSContext;
154
    }
155

    
156
    public String getTabName() {
157
        return PluginServices.getText(this, "File");
158
    }
159

    
160
}