Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2059 / 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 @ 39322

History | View | Annotate | Download (5.08 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.HashSet;
33
import java.util.List;
34
import java.util.Set;
35

    
36
import javax.swing.JOptionPane;
37

    
38
import org.cresques.cts.IProjection;
39
import org.slf4j.Logger;
40
import org.slf4j.LoggerFactory;
41

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

    
58
public class FilesystemExplorerTableWizardPanel extends
59
    FilesystemExplorerWizardPanel {
60

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

    
65
    private PrepareContext prepareDSContext = null;
66

    
67
    @Override
68
    public void execute() {
69
        executeWizard();
70
    }
71

    
72
    public Object executeWizard() {
73
        FeatureStore store;
74
        TableDocument table;
75

    
76
        ApplicationManager manager = ApplicationLocator.getManager();
77
        Project project = manager.getCurrentProject();
78

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

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

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

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

    
123
        }
124
        
125
        if (not_valid.size() > 0) {
126
            String not_str = not_valid.toString();
127
            JOptionPane.showMessageDialog(
128
                this,
129
                Messages.getText("_These_sources_were_not_loaded")
130
                + ": " + not_str, // not_valid,
131
                Messages.getText("_Load_error"),
132
                JOptionPane.WARNING_MESSAGE);
133
        }
134
        return tabledocs;
135
    }
136

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

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

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

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

    
159
}