Statistics
| Revision:

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 / fmap / dal / serverexplorer / filesystem / swing / FilesystemExplorerTableWizardPanel.java @ 42775

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

    
25
package org.gvsig.fmap.dal.serverexplorer.filesystem.swing;
26

    
27
import java.awt.Window;
28
import java.util.ArrayList;
29
import java.util.HashSet;
30
import java.util.List;
31
import java.util.Set;
32

    
33
import javax.swing.JOptionPane;
34

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

    
39
import org.gvsig.andami.PluginServices;
40
import org.gvsig.andami.messages.NotificationManager;
41
import org.gvsig.app.ApplicationLocator;
42
import org.gvsig.app.ApplicationManager;
43
import org.gvsig.app.prepareAction.PrepareContext;
44
import org.gvsig.app.project.Project;
45
import org.gvsig.app.project.ProjectManager;
46
import org.gvsig.app.project.documents.table.TableDocument;
47
import org.gvsig.app.project.documents.table.TableManager;
48
import org.gvsig.fmap.dal.DALLocator;
49
import org.gvsig.fmap.dal.DataManager;
50
import org.gvsig.fmap.dal.DataStoreParameters;
51
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
52
import org.gvsig.fmap.dal.feature.FeatureStore;
53
import org.gvsig.i18n.Messages;
54
import org.gvsig.tools.dynobject.DynObject;
55
import org.gvsig.tools.dynobject.exception.DynFieldRequiredValueException;
56
import org.gvsig.tools.dynobject.exception.DynObjectValidateException;
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
    @Override
73
    public Object executeWizard() {
74
        FeatureStore store;
75
        TableDocument table;
76

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

    
80
        PrepareContext context = this.getPrepareDataStoreContext();
81
        DataStoreParameters[] parameters = this.getParameters();
82
        List<TableDocument> tabledocs =
83
            new ArrayList<>(parameters.length);
84
        
85
        Set<String> not_valid = new HashSet<>();
86
        
87
        for (DataStoreParameters params : parameters) {
88
            store = null;
89
            
90
            /*
91
             * Try to validate.
92
             */
93
            try {
94
                params.validate();
95
            } catch (ValidateDataParametersException ecx) {
96
                StringBuffer buffer = new StringBuffer();
97
                if( ecx.getCause() instanceof DynObjectValidateException ) {
98
                    DynObjectValidateException exceptions = (DynObjectValidateException) ecx.getCause();
99
                    for( int i=0; i<exceptions.size(); i++ ) {
100
                        if( exceptions.get(i) instanceof DynFieldRequiredValueException ) {
101
                            DynFieldRequiredValueException exx = (DynFieldRequiredValueException) exceptions.get(i);
102
                            if( buffer.length()>0 ) {
103
                                buffer.append(", ");
104
                            }
105
                            buffer.append(exx.getMessage());
106
                        }
107
                        
108
                    }
109
                }
110
                String msg = params.getDataStoreName();
111
                if( buffer.length()>0 ) {
112
                    msg = msg + ": "+buffer.toString();
113
                }
114
                LOG.info("Unable to validate params: " + msg);
115
                not_valid.add(msg);
116
                continue;
117
            }
118
            
119
            try {
120

    
121
                DataManager dataManager = DALLocator.getDataManager();
122
                store =
123
                    (FeatureStore) dataManager.openStore(
124
                        params.getDataStoreName(), params);
125
                manager.pepareOpenDataSource(store, context);
126

    
127
                table =
128
                    (TableDocument) ProjectManager.getInstance()
129
                        .createDocument(TableManager.TYPENAME);
130
                table.setName(store.getName());
131
                table.setStore(store);
132

    
133
                // project.add(table);
134
                tabledocs.add(table);
135
            } catch (Exception e) {
136
                if (store != null) {
137
                    store.dispose();
138
                }
139
                NotificationManager.addError(e);
140
            }
141

    
142
        }
143
        
144
        if (not_valid.size() > 0) {
145
            String not_str = not_valid.toString();
146
            JOptionPane.showMessageDialog(
147
                this,
148
                Messages.getText("_These_sources_were_not_loaded")
149
                + ": " + not_str, // not_valid,
150
                Messages.getText("_Load_error"),
151
                JOptionPane.WARNING_MESSAGE);
152
        }
153
        return tabledocs;
154
    }
155

    
156
    @Override
157
    protected PrepareContext getPrepareDataStoreContext() {
158
        if (this.prepareDSContext == null) {
159
            this.prepareDSContext = new PrepareContext() {
160

    
161
                @Override
162
                public Window getOwnerWindow() {
163
                    return null;
164
                }
165
                
166
                @Override
167
                public IProjection getViewProjection() {
168
                        return null;
169
                }
170

    
171
            };
172
        }
173
        return this.prepareDSContext;
174
    }
175

    
176
    @Override
177
    public String getTabName() {
178
        return PluginServices.getText(this, "File");
179
    }
180

    
181

    
182
    @Override
183
    protected void showPropertiesDialog(final DynObject parameters) {
184
        FilesystemExplorerPropertiesPanelManager manager = ApplicationLocator.getFilesystemExplorerPropertiesPanelManager();
185
        FilesystemExplorerPropertiesPanel panel = manager.createPanel(parameters);        
186
        panel.setExcludeGeometryOptions(true);
187
        manager.showPropertiesDialog(parameters, panel);
188
        
189
        refreshFileList();
190
    }
191
    
192
}