Statistics
| Revision:

root / branches / v10 / extensions / extSDE / src / com / iver / cit / gvsig / sde / gui / sdewizard2 / WizardSDE.java @ 11012

History | View | Annotate | Download (24.8 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Prodevelop Integraci?n de Tecnolog?as SL
34
 *   Conde Salvatierra de ?lava , 34-10
35
 *   46004 Valencia
36
 *   Spain
37
 *
38
 *   +34 963 510 612
39
 *   +34 963 510 968
40
 *   gis@prodevelop.es
41
 *   http://www.prodevelop.es
42
 */
43
package com.iver.cit.gvsig.sde.gui.sdewizard2;
44

    
45
import java.awt.BorderLayout;
46
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionListener;
48
import java.awt.geom.Rectangle2D;
49
import java.sql.SQLException;
50
import java.util.ArrayList;
51
import java.util.TreeMap;
52
import java.util.Vector;
53

    
54
import javax.swing.DefaultListModel;
55
import javax.swing.ImageIcon;
56
import javax.swing.JComboBox;
57
import javax.swing.JOptionPane;
58
import javax.swing.JPanel;
59
import javax.swing.JScrollPane;
60
import javax.swing.ListSelectionModel;
61
import javax.swing.event.ListSelectionEvent;
62
import javax.swing.event.ListSelectionListener;
63

    
64
import org.apache.log4j.Logger;
65
import org.cresques.cts.IProjection;
66
import org.gvsig.gui.beans.swing.JButton;
67

    
68
import com.esri.sde.sdk.client.SeConnection;
69
import com.esri.sde.sdk.client.SeException;
70
import com.esri.sde.sdk.client.SeLayer;
71
import com.hardcode.driverManager.DriverLoadException;
72
import com.iver.andami.PluginServices;
73
import com.iver.andami.messages.NotificationManager;
74
import com.iver.andami.ui.mdiManager.IWindow;
75
import com.iver.cit.gvsig.fmap.MapContext;
76
import com.iver.cit.gvsig.fmap.core.ICanReproject;
77
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
78
import com.iver.cit.gvsig.fmap.drivers.sde.ArcSdeDriver;
79
import com.iver.cit.gvsig.fmap.drivers.sde.VectorialSDEDriver;
80
import com.iver.cit.gvsig.fmap.drivers.sde.utils.SDELayerDefinition;
81
import com.iver.cit.gvsig.fmap.layers.FLayer;
82
import com.iver.cit.gvsig.fmap.layers.FLayers;
83
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
84
import com.iver.cit.gvsig.gui.WizardPanel;
85
import com.iver.cit.gvsig.project.documents.view.gui.View;
86
import com.iver.utiles.swing.JPasswordDlg;
87

    
88

    
89
/**
90
 * Driver-independent GeoBD wizard. Queries the drivers to fill GUI controls.
91
 * Multi-table selection available.
92
 *
93
 * @author jldominguez
94
 *
95
 */
96
public class WizardSDE extends WizardPanel implements ActionListener,
97
    ListSelectionListener {
98
    private static Logger logger = Logger.getLogger(WizardSDE.class.getName());
99

    
100
    private SeConnection conex = null;
101
    private ConnectionWithParamsSDE selectedDataSource = null;
102
    private JPanel namePanel = null;
103
    private JPanel tablesPanel = null;
104
    private JScrollPane tablesScrollPane = null;
105
    private AvailableTablesCheckBoxList tablesList = null;
106
    private JComboBox datasourceComboBox = null;
107
    private UserTableSettingsPanel settingsPanel = null;
108
    private UserSelectedFieldsPanel fieldsPanel = null;
109
    private UserTableSettingsPanel emptySettingsPanel = null;
110
    private UserSelectedFieldsPanel emptyFieldsPanel = null;
111
    private JButton jdbcButton = null;
112
    private View view = null;
113

    
114
    public WizardSDE() {
115
        super();
116
        initialize();
117
    }
118

    
119
    /**
120
     * This method initializes this
121
     *
122
     * @return void
123
     */
124
    private void initialize() {
125
        setTabName("SDE");
126
        setLayout(null);
127
        setSize(512, 478);
128

    
129
        IWindow iw = PluginServices.getMDIManager().getActiveWindow();
130

    
131
        if (iw == null) {
132
            return;
133
        }
134

    
135
        if (!(iw instanceof View)) {
136
            return;
137
        }
138

    
139
        view = (View) iw;
140
        setMapCtrl(view.getMapControl());
141

    
142
        emptySettingsPanel = new UserTableSettingsPanel(null, null, "",
143
                getMapCtrl(), true, this);
144
        emptyFieldsPanel = new UserSelectedFieldsPanel(null, null, true, this);
145

    
146
        add(getNamePanel(), null);
147
        loadJdbcDatasourcesCombo();
148

    
149
        add(getTablesPanel(), null);
150
    }
151

    
152
    private void loadJdbcDatasourcesCombo() {
153
        getDatasourceComboBox().removeAllItems();
154

    
155
        getDatasourceComboBox().addItem(new ConnectionWithParamsSDE());
156

    
157
        ConnectionWithParamsSDE[] conn = SingleSDEConnectionManager.instance()
158
                                                                 .getAllConnections();
159

    
160
        if (conn == null) {
161
            return;
162
        }
163

    
164
        for (int i = 0; i < conn.length; i++) {
165
            getDatasourceComboBox().addItem(conn[i]);
166
        }
167
    }
168

    
169
    private String[] getDriverNames() {
170
        Class[] classes = new Class[] { VectorialSDEDriver.class };
171

    
172
        ArrayList ret = new ArrayList();
173
        String[] driverNames = LayerFactory.getDM().getDriverNames();
174

    
175
        for (int i = 0; i < driverNames.length; i++) {
176
            boolean is = false;
177

    
178
            for (int j = 0; j < classes.length; j++) {
179
                if (LayerFactory.getDM().isA(driverNames[i], classes[j])) {
180
                    ret.add(driverNames[i]);
181
                }
182
            }
183
        }
184

    
185
        return (String[]) ret.toArray(new String[0]);
186
    }
187

    
188
    /**
189
     * Utility method to instantiate a VectorialJDBCDriver from its name.
190
     *
191
     * @param drvname driver's name
192
     * @return a VectorialJDBCDriver
193
     *
194
     * @throws DriverLoadException
195
     */
196
    public VectorialSDEDriver getDriverFromName(String drvname)
197
        throws DriverLoadException {
198
        VectorialSDEDriver resp = (VectorialSDEDriver) LayerFactory.getDM()
199
                                                                     .getDriver(drvname);
200

    
201
        return resp;
202
    }
203

    
204
    public void initWizard() {
205
    }
206

    
207
    public void execute() {
208
    }
209
    /**
210
     * Return FLayers if user performs multi selection.
211
     */
212
    public FLayer getLayer() {
213
        try {
214
            IProjection proj = null;
215
            TablesListItem[] selected = getSelectedTables();
216
            int count = selected.length;
217
            String groupName = selectedDataSource.getDb() + " (" +
218
                conex.getSdeDbaName() + ")";
219

    
220
            FLayer[] all_layers = new FLayer[count];
221
            String strEPSG = getMapCtrl().getViewPort().getProjection()
222
                                 .getAbrev().substring(5);
223

    
224
            for (int i = 0; i < count; i++) {
225
                TablesListItem item = selected[i];
226

    
227
                VectorialSDEDriver driver = null;
228
                driver = (VectorialSDEDriver) getDriverFromName(selectedDataSource.getDrvName());
229

    
230
                Rectangle2D _wa = item.getUserTableSettingsPanel()
231
                                      .getWorkingArea();
232

    
233
                if (_wa != null) {
234
                    driver.setWorkingArea(_wa);
235
                }
236

    
237
                String layerName = item.getUserTableSettingsPanel()
238
                                       .getUserLayerName();
239
                String tableName = item.getTableName();
240
                String fidField = item.getUserTableSettingsPanel()
241
                                      .getIdFieldName();
242
                String geomField = item.getUserTableSettingsPanel()
243
                                       .getGeoFieldName();
244
                String[] fields = item.getUserSelectedFieldsPanel()
245
                                      .getUserSelectedFields(fidField, geomField);
246

    
247
                //                        fields = driver.manageGeometryField(fields, geomField);
248

    
249
                // driver.manageGeometryField(geomField);
250
                SDELayerDefinition lyrDef = new SDELayerDefinition();
251
                lyrDef.setHost(selectedDataSource.getHost());
252
                lyrDef.setPort(selectedDataSource.getPort());
253
                lyrDef.setSchema(selectedDataSource.getDb());
254
                lyrDef.setUser(selectedDataSource.getUser());
255
                lyrDef.setPassword(selectedDataSource.getPw());
256
                lyrDef.setName(layerName);
257
                lyrDef.setTableName(tableName);
258
//                lyrDef.setWhereClause(whereClause);
259
//                lyrDef.setFieldGeometry(arcsde_wizard.getGeomField());
260
//                lyrDef.setFieldID(arcsde_wizard.getFID());
261
//                lyrDef.setFieldNames(arcsde_wizard.getFields());
262
//                lyrDef.setSRID_EPSG(strEPSG);
263
                lyrDef.setConnectionName(selectedDataSource.getName());
264

    
265
                if (item.getUserTableSettingsPanel().isSqlActive()) {
266
                    String whereClause = item.getUserTableSettingsPanel()
267
                                             .getWhereClause();
268
                    lyrDef.setWhereClause(whereClause);
269
                }
270
                else {
271
                    lyrDef.setWhereClause("");
272
                }
273

    
274
                lyrDef.setFieldGeometry(geomField);
275
                String[] fieldsAux=null;
276
                if ((fields != null) && (fields.length != 0)) {
277
                    if (!fields[0].equals(lyrDef.getFieldGeometry())) {
278
                        fieldsAux = new String[fields.length + 1];
279
                        fieldsAux[0] = lyrDef.getFieldGeometry();
280

    
281
                        for (int k = 1; k < fields.length+1; k++) {
282
                            fieldsAux[k] = fields[k - 1];
283
                        }
284
                    }
285
                }
286
                fields=fieldsAux;
287
//                else {
288
//                    SeSqlConstruct sqlConstruct = new SeSqlConstruct(tableName);
289
//                    sqlTotal = sqlConstruct.getWhere();
290
//
291
//                    SeTable table1 = new SeTable(conn, tableName);
292
//
293
//                    /*
294
//                     *   Get the table's column definition.
295
//                     */
296
//                    SeColumnDefinition[] tableDef = table1.describe();
297
//                    this.fields = new String[tableDef.length];
298
//
299
//                    /*
300
//                     *   Store the names of all the table's columns in the
301
//                     *   String array cols. This array specifies the columns
302
//                     *   to be retrieved from the database.
303
//                     */
304
//                    int idField = 1;
305
//
306
//                    for (int i = 0; i < tableDef.length; i++) {
307
//                        if (tableDef[i].getType() == SeColumnDefinition.TYPE_SHAPE) {
308
//                            this.fields[0] = tableDef[i].getName();
309
//                        } else {
310
//                            this.fields[idField] = tableDef[i].getName();
311
//                            idField++;
312
//                        }
313
//                    }
314
//
315
//                }
316

    
317
                lyrDef.setFieldNames(fields);
318

    
319
                lyrDef.setFieldID(fidField);
320

    
321
                if (_wa != null) {
322
                    lyrDef.setWorkingArea(_wa);
323
                }
324

    
325
                lyrDef.setSRID_EPSG(strEPSG);
326

    
327
                if (driver instanceof ICanReproject) {
328
                    ((ICanReproject) driver).setDestProjection(strEPSG);
329
                }
330

    
331
                driver.setData(null, lyrDef);
332

    
333
                if (driver instanceof ICanReproject) {
334
                    proj = CRSFactory.getCRS("EPSG:" +
335
                            ((ICanReproject) driver).getSourceProjection());
336
                }
337

    
338
                all_layers[i] = LayerFactory.createDBLayer(driver, layerName,
339
                        proj);
340
            }
341

    
342
            return layerArrayToGroup(all_layers, groupName);
343
        }
344
        catch (Exception e) {
345
            logger.error("While creating jdbc layer: " + e.getMessage(), e);
346
            NotificationManager.addError("Error al cargar la capa: " +
347
                e.getMessage(), e);
348
        }
349

    
350
        return null;
351
    }
352

    
353
    private FLayer layerArrayToGroup(FLayer[] all_layers, String name) {
354
        if (all_layers.length == 1) {
355
            return all_layers[0];
356
        }
357

    
358
        MapContext mc = view.getMapControl().getMapContext();
359
        FLayers root = view.getMapControl().getMapContext().getLayers();
360

    
361
        FLayers group = new FLayers(mc, root);
362
        group.setName(name);
363

    
364
        for (int i = 0; i < all_layers.length; i++) {
365
            group.addLayer(all_layers[i]);
366
        }
367

    
368
        return group;
369
    }
370

    
371
    private TablesListItem[] getSelectedTables() {
372
        int count = tablesList.getModel().getSize();
373
        ArrayList resp = new ArrayList();
374

    
375
        for (int i = 0; i < count; i++) {
376
            TablesListItem item = (TablesListItem) tablesList.getModel()
377
                                                             .getElementAt(i);
378

    
379
            if (item.isSelected()) {
380
                resp.add(item);
381
            }
382
        }
383

    
384
        return (TablesListItem[]) resp.toArray(new TablesListItem[0]);
385
    }
386

    
387
    /**
388
     * This method initializes namePanel
389
     *
390
     * @return javax.swing.JPanel
391
     */
392
    private JPanel getNamePanel() {
393
        if (namePanel == null) {
394
            namePanel = new JPanel();
395
            namePanel.setLayout(null);
396
            namePanel.setBounds(new java.awt.Rectangle(5, 5, 501, 51));
397
            namePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
398
                    null, PluginServices.getText(this, "choose_connection"),
399
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
400
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
401
            namePanel.add(getDatasourceComboBox(), null);
402
            namePanel.add(getJdbcButton(), null);
403
        }
404

    
405
        return namePanel;
406
    }
407

    
408
    /**
409
     * This method initializes tablesPanel
410
     *
411
     * @return javax.swing.JPanel
412
     */
413
    private JPanel getTablesPanel() {
414
        if (tablesPanel == null) {
415
            tablesPanel = new JPanel();
416
            tablesPanel.setLayout(new BorderLayout());
417
            tablesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
418
                    null, PluginServices.getText(this, "choose_table"),
419
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
420
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
421
            tablesPanel.setBounds(new java.awt.Rectangle(5, 55, 246, 191));
422
            tablesPanel.add(getTablesScrollPane(), java.awt.BorderLayout.CENTER);
423
        }
424

    
425
        return tablesPanel;
426
    }
427

    
428
    /**
429
     * This method initializes settingsPanel
430
     *
431
     * @return javax.swing.JPanel
432
     */
433

    
434
    /**
435
     * This method initializes tablesScrollPane
436
     *
437
     * @return javax.swing.JScrollPane
438
     */
439
    private JScrollPane getTablesScrollPane() {
440
        if (tablesScrollPane == null) {
441
            tablesScrollPane = new JScrollPane();
442
            tablesScrollPane.setViewportView(getTablesList());
443
        }
444

    
445
        return tablesScrollPane;
446
    }
447

    
448
    /**
449
     * This method initializes tablesList
450
     *
451
     * @return javax.swing.JList
452
     */
453
    private AvailableTablesCheckBoxList getTablesList() {
454
        if (tablesList == null) {
455
            tablesList = new AvailableTablesCheckBoxList(this);
456
            tablesList.addListSelectionListener(this);
457
            tablesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
458
        }
459

    
460
        return tablesList;
461
    }
462

    
463
    /**
464
     * This method initializes layerNameTextField
465
     *
466
     * @return javax.swing.JTextField
467
     */
468

    
469
    /**
470
     * This method initializes jComboBox
471
     *
472
     * @return javax.swing.JComboBox
473
     */
474
    private JComboBox getDatasourceComboBox() {
475
        if (datasourceComboBox == null) {
476
            datasourceComboBox = new JComboBox();
477
            datasourceComboBox.setBounds(new java.awt.Rectangle(10, 20, 446, 21));
478
            datasourceComboBox.addActionListener(this);
479
        }
480

    
481
        return datasourceComboBox;
482
    }
483

    
484
    public void actionPerformed(ActionEvent arg0) {
485
        Object src = arg0.getSource();
486

    
487
        if (src == datasourceComboBox) {
488
            Object sel_obj = datasourceComboBox.getSelectedItem();
489

    
490
            if (sel_obj == null) {
491
                return;
492
            }
493

    
494
            if (!(sel_obj instanceof ConnectionWithParamsSDE)) {
495
                return;
496
            }
497

    
498
            selectedDataSource = (ConnectionWithParamsSDE) sel_obj;
499

    
500
            if (selectedDataSource.isNull()) {
501
                updateTableList(selectedDataSource);
502
                setEmptyPanels();
503

    
504
                return;
505
            }
506

    
507
            if (!selectedDataSource.isConnected()) {
508
                if (!tryToConnect(selectedDataSource)) {
509
                    datasourceComboBox.setSelectedIndex(0);
510

    
511
                    return;
512
                }
513
            }
514

    
515
            getDatasourceComboBox().repaint();
516
            updateTableList(selectedDataSource);
517

    
518
            // setEmptyPanels();
519
            return;
520
        }
521

    
522
        if (src == jdbcButton) {
523
            ConnectionWithParamsSDE sel = addNewConnection();
524

    
525
            if (sel != null) {
526
                loadJdbcDatasourcesCombo();
527
                getDatasourceComboBox().setSelectedItem(sel);
528
            }
529
        }
530
    }
531

    
532
    private boolean tryToConnect(ConnectionWithParamsSDE _cwp) {
533
        JPasswordDlg dlg = new JPasswordDlg();
534
        String strMessage = PluginServices.getText(this, "conectar_jdbc");
535
        String strPassword = PluginServices.getText(this, "password");
536
        dlg.setMessage(strMessage + " [" + _cwp.getDrvName() + ", " +
537
            _cwp.getHost() + ", " + _cwp.getPort() + ", " + _cwp.getDb() +
538
            ", " + _cwp.getUser() + "]. " + strPassword + "?");
539

    
540
        dlg.show();
541

    
542
        String clave = dlg.getPassword();
543

    
544
        if (clave == null) {
545
            return false;
546
        }
547

    
548
        try {
549
            _cwp.connect(clave);
550
        }
551
        catch (SQLException e) {
552
            showConnectionErrorMessage(e.getMessage());
553

    
554
            return false;
555
        }
556

    
557
        return true;
558
    }
559

    
560
    private void updateTableList(ConnectionWithParamsSDE src) {
561
        if (src.isNull()) {
562
            getTablesList().setModel(new DefaultListModel());
563
            getTablesScrollPane().setViewportView(tablesList);
564
            tablesScrollPane.updateUI();
565

    
566
            return;
567
        }
568

    
569
        conex = src.getConnection();
570

    
571
        String drvName = src.getDrvName();
572
        String dbName = "";
573

    
574
        VectorialSDEDriver drv = null;
575

    
576
        try {
577
            dbName = src.getDb();//getConnection().getDatabaseName();
578
            drv = (VectorialSDEDriver) LayerFactory.getDM().getDriver(drvName);
579
        } catch (Exception e) {
580
            logger.error("While getting driver instance: " + e.getMessage(), e);
581
        }
582

    
583
        if (!(drv instanceof VectorialSDEDriver)) {
584
            logger.error(
585
                "Unexpected driver type (not a ArcSdeDriver driver)");
586

    
587
            return;
588
        }
589

    
590
        String[] tablnames = null;
591

    
592
        try {
593
            tablnames = getTableNames(conex, dbName);
594
        } catch (SQLException e) {
595
                logger.error("While getting table names: " + e.getMessage(), e);
596

    
597
            return;
598
                }
599

    
600
        DefaultListModel lmodel = new DefaultListModel();
601

    
602
        for (int i = 0; i < tablnames.length; i++) {
603
            lmodel.addElement(new TablesListItem(tablnames[i], drv, conex,
604
                    getMapCtrl(), this));
605
        }
606

    
607
        getTablesList().setModel(lmodel);
608
        getTablesScrollPane().setViewportView(tablesList);
609
        tablesScrollPane.updateUI();
610
    }
611

    
612
    public void valueChanged(ListSelectionEvent arg0) {
613
        Object src = arg0.getSource();
614

    
615
        if (src == tablesList) {
616
            TablesListItem selected = (TablesListItem) tablesList.getSelectedValue();
617

    
618
            try {
619
                setSettingsPanels(selected);
620
            }
621
            catch (SQLException e) {
622
                showConnectionErrorMessage(e.getMessage());
623
                tablesList.clearSelection();
624
                setEmptyPanels();
625
            }
626

    
627
            checkFinishable();
628
        }
629
    }
630

    
631
    private boolean validFormSettings() {
632
        int count = tablesList.getModel().getSize();
633

    
634
        boolean at_least_one = false;
635
        boolean resp = true;
636

    
637
        for (int i = 0; i < count; i++) {
638
            TablesListItem item = (TablesListItem) tablesList.getModel()
639
                                                             .getElementAt(i);
640

    
641
            if (item.isSelected()) {
642
                at_least_one = true;
643
            }
644

    
645
            if (item.disturbsWizardValidity()) {
646
                resp = false;
647
            }
648
        }
649

    
650
        return (at_least_one && resp);
651
    }
652

    
653
    public void checkFinishable() {
654
        boolean finishable = validFormSettings();
655
        callStateChanged(finishable);
656
    }
657

    
658
    /**
659
     * This method initializes jdbcButton
660
     *
661
     * @return javax.swing.JButton
662
     */
663
    private JButton getJdbcButton() {
664
        if (jdbcButton == null) {
665
            jdbcButton = new JButton();
666
            jdbcButton.addActionListener(this);
667
            jdbcButton.setToolTipText(PluginServices.getText(this,
668
                    "add_connection"));
669
            jdbcButton.setBounds(new java.awt.Rectangle(465, 20, 26, 21));
670

    
671
            String _file = createResourceUrl("images/jdbc.png").getFile();
672
            jdbcButton.setIcon(new ImageIcon(_file));
673
        }
674

    
675
        return jdbcButton;
676
    }
677

    
678
    private ConnectionWithParamsSDE addNewConnection() {
679
        ConnectionWithParamsSDE resp = null;
680

    
681
        SDEConnectionParamsDialog newco = new SDEConnectionParamsDialog();
682
        newco.showDialog();
683

    
684
        if (newco.isOkPressed()) {
685
            String _drvname = newco.getConnectionDriverName();
686
            String _host = newco.getConnectionServerUrl();
687
            String _port = newco.getConnectionPort();
688
            String _dbname = newco.getConnectionDBName();
689
            String _user = newco.getConnectionUser();
690
            String _pw = newco.getConnectionPassword();
691
            String _conn_usr_name = newco.getConnectionName();
692

    
693
            boolean hasToBeCon = newco.hasToBeConnected();
694

    
695
            try {
696
                resp = SingleSDEConnectionManager.instance()
697
                                                  .getConnection(_drvname,
698
                        _user, _pw, _conn_usr_name, _host, _port, _dbname,
699
                        hasToBeCon);
700
            }
701
            catch (SQLException e) {
702
                showConnectionErrorMessage(e.getMessage());
703

    
704
                return null;
705
            }
706

    
707
            return resp;
708
        }
709
        else {
710
            return null;
711
        }
712
    }
713

    
714
    private void showConnectionErrorMessage(String _msg) {
715
        String msg = (_msg.length() > 300) ? "" : (": " + _msg);
716
        String title = PluginServices.getText(this, "connection_error");
717
        JOptionPane.showMessageDialog(this, title + msg, title,
718
            JOptionPane.ERROR_MESSAGE);
719
    }
720

    
721
    private java.net.URL createResourceUrl(String path) {
722
        return getClass().getClassLoader().getResource(path);
723
    }
724

    
725
    public void setSettingsPanels(TablesListItem actTable)
726
        throws SQLException {
727
        if (actTable == null) {
728
            setEmptyPanels();
729

    
730
            return;
731
        }
732

    
733
        settingsPanel = actTable.getUserTableSettingsPanel();
734
        fieldsPanel = actTable.getUserSelectedFieldsPanel();
735

    
736
        removeFieldPanels();
737
        add(fieldsPanel);
738
        fieldsPanel.repaint();
739

    
740
        removeSettingsPanels();
741
        add(settingsPanel);
742
        settingsPanel.repaint();
743

    
744
        repaint();
745
    }
746

    
747
    private void setEmptyPanels() {
748
        removeFieldPanels();
749
        add(emptyFieldsPanel);
750
        removeSettingsPanels();
751
        add(emptySettingsPanel);
752

    
753
        settingsPanel = emptySettingsPanel;
754
        fieldsPanel = emptyFieldsPanel;
755

    
756
        repaint();
757
    }
758

    
759
    private void removeFieldPanels() {
760
        for (int i = 0; i < getComponentCount(); i++) {
761
            if (getComponent(i) instanceof UserSelectedFieldsPanel) {
762
                remove(i);
763
            }
764
        }
765
    }
766

    
767
    private void removeSettingsPanels() {
768
        for (int i = 0; i < getComponentCount(); i++) {
769
            if (getComponent(i) instanceof UserTableSettingsPanel) {
770
                remove(i);
771
            }
772
        }
773
    }
774

    
775

    
776
    public String[] getTableNames(Object conex, String dbName) throws SQLException {
777
                Vector theLayers=null;
778
                try {
779
                        theLayers = ((SeConnection)conex).getLayers();
780
                } catch (SeException e) {
781
                        throw new SQLException(e.getMessage());
782
                }
783
                TreeMap ret = new TreeMap();
784
                for (int i = 0; i < theLayers.size(); i++) {
785
                        SeLayer layer = (SeLayer) theLayers.elementAt(i);
786
                        ret.put(layer.getTableName(), layer.getTableName());
787
                }
788
                return (String[]) ret.keySet().toArray(new String[0]);
789
        }
790

    
791

    
792

    
793
} //  @jve:decl-index=0:visual-constraint="10,10"