Statistics
| Revision:

root / trunk / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / gui / panels / ServiceNamesPanel.java @ 8110

History | View | Annotate | Download (29 KB)

1
package es.prodevelop.cit.gvsig.arcims.gui.panels;
2

    
3
import java.net.MalformedURLException;
4
import java.net.URL;
5
import java.util.Vector;
6
import javax.swing.event.ListSelectionEvent;
7
import javax.swing.table.TableColumn;
8
import javax.swing.table.TableColumnModel;
9

    
10
import java.awt.Color;
11
import java.awt.event.ItemEvent;
12
import java.awt.event.ItemListener;
13
import java.awt.event.KeyEvent;
14
import java.awt.event.KeyListener;
15
import java.awt.event.MouseEvent;
16
import java.awt.event.MouseListener;
17
import java.awt.event.ActionEvent;
18
import java.awt.event.ActionListener;
19

    
20
import javax.swing.ButtonGroup;
21
import javax.swing.JCheckBox;
22
import javax.swing.JComponent;
23
import javax.swing.JPanel;
24
import javax.swing.JLabel;
25
import javax.swing.JComboBox;
26
import javax.swing.JButton;
27
import javax.swing.JOptionPane;
28
import javax.swing.JTable;
29
import javax.swing.JTextField;
30
import javax.swing.ListSelectionModel;
31

    
32
import es.prodevelop.cit.gvsig.arcims.fmap.drivers.FMapRasterArcImsDriver;
33
import es.prodevelop.cit.gvsig.arcims.fmap.drivers.FMapFeatureArcImsDriver;
34
import es.prodevelop.cit.gvsig.arcims.gui.panels.utils.ServicesTableModel;
35
import es.prodevelop.cit.gvsig.arcims.gui.panels.utils.ServicesTableSelectionListener;
36
import es.prodevelop.cit.gvsig.arcims.gui.panels.utils.ServicesTableDataSource;
37
import es.prodevelop.cit.gvsig.arcims.gui.wizards.ArcImsWizard;
38
import com.iver.andami.PluginServices;
39

    
40
import javax.swing.JScrollPane;
41

    
42
import com.iver.cit.gvsig.fmap.DriverException;
43
import com.iver.cit.gvsig.fmap.layers.FLayer;
44
import com.iver.utiles.NotExistInXMLEntity;
45
import com.iver.utiles.XMLEntity;
46

    
47
import org.apache.log4j.Logger;
48
import org.gvsig.remoteClient.arcims.ArcImsClientP;
49
import org.gvsig.remoteClient.arcims.ArcImsProtocolHandler;
50
import org.gvsig.remoteClient.arcims.exceptions.ArcImsException;
51
import org.gvsig.remoteClient.arcims.utils.ServiceInfoTags;
52
import org.gvsig.remoteClient.arcims.utils.ServiceInformation;
53

    
54
import javax.swing.JRadioButton;
55

    
56
/**
57
 * This class implements the first panels of the ArcIMS wizard. It
58
 * asks for the server's URL and the service name (which can be either an
59
 * ImageService or a FeatureService). Depending on the type of service, one
60
 * panel (Image Service Panel) or the other (Feature Service Panel) will be enabled.
61
 * All three panels are owned by the ArcIMS wizard.
62
 * 
63
 * @see es.prodevelop.cit.gvsig.arcims.gui.panels.FeatureServicePanel
64
 * 
65
 * 
66
 * @author jldominguez
67
 */
68
public class ServiceNamesPanel extends JPanel implements ActionListener,
69
                MouseListener, KeyListener, ItemListener {
70
        
71
        private static Logger logger = Logger.getLogger(ServiceNamesPanel.class.getName());
72

    
73
        private ArcImsWizard parentWizard = null;
74
        private JPanel northPanel = null;
75
        private JLabel serverLabel = null;
76
        private JComboBox serverComboBox = null;
77
        private JButton connectButton = null;
78
        private JScrollPane servicesTableScrollPane = null;
79
        private JButton nextButton = null;
80
        private JButton previousButton = null;
81
        private JTable servicesTable = new JTable();
82
        private String selectedServiceType = "";
83
        private String selectedServiceName = "";
84
        private Vector favoriteServers = new Vector();
85
        private ServicesTableSelectionListener tableSelectionListener;
86
        private JPanel userDefinedServiceNamePanel = null;
87
        // private JRadioButton serviceNameSelectionModeUserRadioButton = null;
88
        // private JRadioButton serviceNameSelectionModeListRadioButton = null;
89
        // private ButtonGroup serviceSelectionModeButtonGroup = null;
90
        private JLabel serviceNameLabel = null;
91
        private JTextField userDefinedServiceNameTextField = null;
92
        private String serviceType = "";
93
        private URL completeURL = null;
94
        private JLabel versionTitleLabel = null;
95
        private JLabel versionLabel = null;
96
        private JCheckBox cacheOverride = null;
97
        
98
        private static final long serialVersionUID = 0;
99
        
100

    
101
        /**
102
         * The owning wizard is used as a parameter to allow easy <i>upwards</i>
103
         * references.
104
         * 
105
         * @param parent
106
         *            the wizard that owns this panel
107
         */
108
        public ServiceNamesPanel(ArcImsWizard parent) {
109
                super();
110
                parentWizard = parent;
111
                initialize();
112
        }
113

    
114
        private void initialize() {
115
                this.setSize(501, 470);
116
                this.setLayout(null);
117
                this.add(getNorthPanel(), null);
118
                tableSelectionListener = new ServicesTableSelectionListener(this);
119
                this.add(getServicesTableScrollPane(), null);
120
                this.add(getNextButton(), null);
121
                this.add(getPreviousButton(), null);
122
                this.add(getUserDefinedServiceNamePanel(), null);
123
                this.nextButton.setEnabled(false);
124
                
125
                versionTitleLabel = new JLabel(PluginServices.getText(this, "server_version") + ":");
126
                versionTitleLabel.setBounds(new java.awt.Rectangle(39, 443, 125, 21));
127
                this.add(versionTitleLabel, null);
128
                versionLabel = new JLabel("-");
129
                versionLabel.setBounds(new java.awt.Rectangle(170 - 15, 443, 160, 21));
130
                this.add(versionLabel, null);
131
                
132
                servicesTable.addMouseListener(this);
133
                servicesTable.setBounds(new java.awt.Rectangle(15, 45, 400, 181));
134
                servicesTable.setDragEnabled(false);
135
                servicesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
136
                servicesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
137
                
138
                fireServerUrlUnknown();
139
        }
140

    
141
        /**
142
         * Gets the service type of the selected service (ImageService or
143
         * FeatureService)
144
         * 
145
         * @return service type of the service selected by the user
146
         */
147
        public String getSelectedServiceType() {
148
                return selectedServiceType;
149
        }
150

    
151
        /**
152
         * This method initializes northPanel
153
         * 
154
         * @return javax.swing.JPanel
155
         */
156
        private JPanel getNorthPanel() {
157
                if (northPanel == null) {
158
                        serverLabel = new JLabel();
159
                        serverLabel.setText("URL:");
160
                        serverLabel.setBounds(new java.awt.Rectangle(10, 20, 71, 20));
161
                        
162
                        versionTitleLabel = new JLabel(PluginServices.getText(this, "version") + ":");
163
                        versionTitleLabel.setBounds(new java.awt.Rectangle(10, 40, 71, 20));
164
                        versionLabel = new JLabel("-");
165
                        versionLabel.setBounds(new java.awt.Rectangle(60, 40, 200, 20));
166
                        
167
                        cacheOverride = new JCheckBox(PluginServices.getText(this, "update_catalog"), false);
168
                        cacheOverride.setBounds(new java.awt.Rectangle(7, 60 - 9, 200, 20));
169
                        
170
                        northPanel = new JPanel();
171
                        northPanel.setLayout(null);
172
                        northPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
173
                                        null, PluginServices.getText(this, "server"),
174
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
175
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
176
                                        null));
177
                        northPanel.setBounds(new java.awt.Rectangle(17, 10, 477, 85)); // hasta y = 96
178
                        // northPanel.add(serverLabel, null);
179
                        northPanel.add(getServerComboBox(), null);
180
                        northPanel.add(getConnectButton(), null);
181
                        
182
                        // northPanel.add(versionTitleLabel);
183
                        // northPanel.add(versionLabel);
184
                        northPanel.add(cacheOverride);
185
                }
186
                return northPanel;
187
        }
188

    
189
        /**
190
         * Initializes the JComboBox that contains the URLs of the favorite servers,
191
         * read from a XML file located on the user's local directory.
192
         * 
193
         * @return javax.swing.JComboBox
194
         */
195
        public JComboBox getServerComboBox() {
196
                if (serverComboBox == null) {
197
                        serverComboBox = new JComboBox();
198
                        serverComboBox.setEditable(true);
199
                        
200
                        serverComboBox.getEditor().getEditorComponent().addKeyListener(this);
201
                        serverComboBox.addItemListener(this);
202

    
203
                        loadFavoriteServers();
204
                        addServersFromVector();
205

    
206
                        serverComboBox.setBounds(new java.awt.Rectangle(11, 26, 380 + 74, 20));
207
                }
208
                return serverComboBox;
209
        }
210

    
211
        /**
212
         * Inicializes the connectButton
213
         * 
214
         * @return javax.swing.JButton
215
         */
216
        public JButton getConnectButton() {
217
                if (connectButton == null) {
218
                        connectButton = new JButton();
219
                        connectButton.setText(PluginServices.getText(this, "conectar"));
220
                        connectButton.setBounds(new java.awt.Rectangle(383 - 17, 33 + 17, 100, 20));
221

    
222
                        connectButton.addActionListener(this);
223
                }
224
                return connectButton;
225
        }
226

    
227
        /**
228
         * Inicializes the servicesTableScrollPane
229
         * 
230
         * @return javax.swing.JScrollPane
231
         */
232
        private JScrollPane getServicesTableScrollPane() {
233
                if (servicesTableScrollPane == null) {
234
                        servicesTableScrollPane = new JScrollPane();
235
                        servicesTableScrollPane
236
                                        .setBorder(javax.swing.BorderFactory
237
                                                        .createTitledBorder(
238
                                                                        null,
239
                                                                        PluginServices.getText(this,
240
                                                                                        "available_services"),
241
                                                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
242
                                                                        javax.swing.border.TitledBorder.DEFAULT_POSITION,
243
                                                                        null, null));
244

    
245
                        servicesTableScrollPane.setBounds(new java.awt.Rectangle(17, 152, 477, 261 + 12)); // hasta y = 413
246
                }
247
                return servicesTableScrollPane;
248
        }
249

    
250
        /**
251
         * Inicializes the nextButton, which will enable and open a new panel
252
         * depending on the user's selection
253
         * 
254
         * @return javax.swing.JButton
255
         */
256
        public JButton getNextButton() {
257
                if (nextButton == null) {
258
                        nextButton = new JButton(); // 
259
                        nextButton.setText(PluginServices.getText(this, "siguiente"));
260
                        nextButton.setBounds(new java.awt.Rectangle(395, 444, 100, 20));
261
                        nextButton.addActionListener(this);
262
                }
263
                return nextButton;
264
        }
265
        
266
        public JButton getPreviousButton() {
267
                if (previousButton == null) {
268
                        previousButton = new JButton(); // 
269
                        previousButton.setText(PluginServices.getText(this, "anterior"));
270
                        previousButton.setBounds(new java.awt.Rectangle(395 - 103, 444, 100, 20));
271
                        previousButton.setEnabled(false);
272
                        previousButton.addActionListener(this);
273
                }
274
                return previousButton;
275
        }
276
        
277
        
278
        
279

    
280
        public void setServerComboText(String s) {
281
                this.serverComboBox.addItem(s);
282
                this.serverComboBox.setSelectedItem(s);
283
        }
284

    
285
        /**
286
         * Writes the list of ArcIMS servers contained in the serverComboBox on a
287
         * XML local file. It should remove server URLs from unsuccessful
288
         * connections.
289
         * 
290
         * @param v
291
         *            a vector of Strings (servers' URLs)
292
         */
293
        private void writeServerVectorToXML(Vector v) {
294
                String s = "";
295
                for (int i = 0; i < v.size(); i++)
296
                        s = s + "," + ((String) v.get(i));
297
                s = s.substring(1);
298

    
299
                XMLEntity xml = PluginServices.getPluginServices(this)
300
                                .getPersistentXML();
301
                if (xml == null) {
302
                        xml = new XMLEntity();
303
                        xml.putProperty("arcims-servers", s);
304
                } else {
305
                        xml.putProperty("arcims-servers", s);
306
                }
307
        }
308

    
309
        /**
310
         * Loads a local variable (favoriteServers) with a list of servers and the
311
         * ones found in the local persistent data XML file.
312
         * 
313
         */
314
        private void loadFavoriteServers() {
315
                
316
                favoriteServers.add("http://www.geographynetwork.com");
317
                favoriteServers.add("http://cartoweb.paeria.es"); // Ayunt. de Lerida
318
                favoriteServers.add("http://geodaten.stadt-bottrop.de"); // Ayunt. de Bottrop (Alemania)
319

    
320
                XMLEntity xml = PluginServices.getPluginServices(this)
321
                                .getPersistentXML();
322
                if (xml == null)
323
                        return;
324
                try {
325
                        String[] s = xml.getStringArrayProperty("arcims-servers");
326
                        String[] servers = s[0].split(",");
327

    
328
                        for (int i = 0; i < servers.length; i++)
329
                                addIfNotRepeated(favoriteServers, servers[i]);
330
                } catch (NotExistInXMLEntity e) {
331
                        logger.warn("Property 'arcims-servers' not found in XML file. ");
332
                }
333
        }
334

    
335
        private void addIfNotRepeated(Vector v, String s) {
336
                if (v.contains(s))
337
                        return;
338
                v.add(0, s);
339
        }
340

    
341
        private void removeServerFromVector(Vector v, String s) {
342
                if (!(v.contains(s)))
343
                        return;
344
                v.remove(s);
345
        }
346

    
347
        /**
348
         * Utility method to load the server names from a 'favoriteServers' vector
349
         * into the server names combobox.
350
         */
351
        private void addServersFromVector() {
352
                for (int i = 0; i < favoriteServers.size(); i++)
353
                        this.serverComboBox.addItem((String) favoriteServers.get(i));
354
        }
355

    
356
        /**
357
         * Listens to mouse events on the available services list. A double click
358
         * will have the same effect as a click on the nextButton.
359
         */
360
        public void mouseClicked(MouseEvent e) {
361
                if (e.getSource() == this.servicesTable) {
362
                        if (! this.servicesTable.isEnabled()) {
363
                                return;
364
                        }
365
                        
366
                        int selrow = servicesTable.getSelectedRow();
367
                        if (selrow == -1) {
368
                                return;
369
                        }
370
                        String servname = ServicesTableModel.getColumnValueOfRow(servicesTable, PluginServices
371
                                        .getText(this, "name"), selrow);
372
                        userDefinedServiceNameTextField.setText(servname);
373
                        
374
                        // double click event:
375
                        if (e.getClickCount() == 2) {
376
                                ActionEvent artificialEvent = new ActionEvent(nextButton,
377
                                                ActionEvent.ACTION_PERFORMED, "");
378
                                this.actionPerformed(artificialEvent);
379
                        }
380
                }
381
        }
382

    
383
        public void mouseEntered(MouseEvent e) {
384
        }
385

    
386
        public void mouseExited(MouseEvent e) {
387
        }
388

    
389
        public void mousePressed(MouseEvent e) {
390
        }
391

    
392
        public void mouseReleased(MouseEvent e) {
393
        }
394

    
395
        /**
396
         * Listens to button events: connectButton will retrieve the server's
397
         * available services list (catalog). NextButton will be enabled if a valid
398
         * service (imageservice or featureservice) has been selected by the user.
399
         */
400
        public void actionPerformed(ActionEvent e) {
401

    
402
                if (e.getSource() == connectButton) {
403

    
404
                        // ---------------------- CONNECT BUTTON - START
405
                        this.nextButton.setEnabled(false);
406
                        boolean badURL = false;
407
                        URL url = null;
408
                        ServicesTableDataSource stds = null;
409
                        url = null;
410

    
411
                        // find out complete url (using libArcIMS):
412
                        try {
413
                                url = new URL(serverComboBox.getSelectedItem().toString());
414
                                completeURL = ArcImsProtocolHandler.getUrlWithServlet(url);
415
                                // this truly loads the service names, types and status:
416
                                stds = new ServicesTableDataSource(completeURL, cacheOverride.isSelected());
417
                        } catch (MalformedURLException e1) {
418
                                badURL = true;
419
                        } catch (ArcImsException e1) {
420
                                badURL = true;
421
                        }
422

    
423
                        if (badURL) {
424
                                logger.info("Wrong url");
425
                                JOptionPane.showMessageDialog(this, PluginServices.getText(
426
                                                this, "wrong_url")
427
                                                + ": " + serverComboBox.getSelectedItem().toString(),
428
                                                PluginServices.getText(this, "wrong_url"),
429
                                                JOptionPane.ERROR_MESSAGE);
430
                                return;
431
                        } else {
432
                                // check that the list is non-empty:
433
                                if (stds.getDataVector().size() == 0) {
434
                                        JOptionPane.showMessageDialog(this, PluginServices.getText(
435
                                                        this, "server_has_no_services")
436
                                                        + ": " + url, PluginServices.getText(this,
437
                                                        "server_has_no_services"),
438
                                                        JOptionPane.ERROR_MESSAGE);
439
                                        // remove useless url:
440
                                        removeServerFromVector(favoriteServers, url.toString());
441
                                        writeServerVectorToXML(favoriteServers);
442
                                        return;
443
                                }
444
                        }
445

    
446
                        // enables certain controls if the url is ok and there are services:
447
                        fireServerUrlOk();
448
                        
449
                        // save working url:
450
                        favoriteServers.add(0, url.toString());
451
                        writeServerVectorToXML(favoriteServers);
452

    
453
                        parentWizard.setHostName(completeURL.toString());
454
                        ServicesTableModel dtm = new ServicesTableModel(stds.getDataVector(), stds.getColNamesVector());
455
                        setModelAndWidths(servicesTable, dtm);
456

    
457
                        // Ask to be notified of selection changes.
458
                        ListSelectionModel rowSM = servicesTable.getSelectionModel();
459
                        rowSM.addListSelectionListener(this.tableSelectionListener);
460

    
461
                        servicesTableScrollPane.setViewportView(servicesTable);
462
                        servicesTable.repaint();
463
                        servicesTableScrollPane.repaint();
464
                        
465
                        // setEnableComponent(servicesTable, serviceNameSelectionModeListRadioButton.isSelected());
466
                        // ---------------------- CONNECT BUTTON - END
467
                }
468

    
469
                // ---------------------- NEXT BUTTON - START
470

    
471
                if (e.getSource() == nextButton) {
472
                        
473
                        // if the 'user defined' option is set, local variables get values from
474
                        // the combobox
475
                        // if (serviceNameSelectionModeUserRadioButton.isSelected()) {
476
                                String userServiceName = userDefinedServiceNameTextField.getText();
477
                                int ind = -1;
478
                                
479
                                try {
480
                                        ind = ServicesTableModel.getFirstRowWithValueInColumnName(servicesTable,
481
                                                        PluginServices.getText(this, ServiceInfoTags.aNAME), userServiceName);
482
                                } catch (ArcImsException e1) {
483
                                        logger.error("While searching value in table ", e1);
484
                                        ind = -1;
485
                                }
486
                                if (ind == -1) {
487
                                        JOptionPane.showMessageDialog(this, PluginServices
488
                                                        .getText(this, "service_does_not_exist")
489
                                                        + ": " + userServiceName, "Error", JOptionPane.ERROR_MESSAGE);
490
                                        return;
491
                                }
492

    
493
                                selectedServiceType = ServicesTableModel.getColumnValueOfRowWithIndex(servicesTable,
494
                                                1, ind); 
495
                                selectedServiceName = userServiceName;
496
                        // }
497
                        
498
                        // check that service type is supported:
499
                        if (! isSupportedServiceType(selectedServiceName)) {
500
                                return;
501
                        }
502

    
503
                        try {
504
                                // +++++++++++++  This line truly starts the connection:          ++++++++++++
505
                                // +++++++++++++  creates driver, client and gets capabilities    ++++++++++++
506
                                parentWizard.getDataSource().setHostService(completeURL, selectedServiceName,
507
                                                selectedServiceType);
508
                        } catch (DriverException de) {
509
                                logger.error("While setting host service ", de);
510
                                showErrorMessage(de.getMessage());
511
                                return;
512
                        }
513
                        
514
                        // get service information:
515
                        ArcImsClientP cli = null;
516
                        if (selectedServiceType.compareToIgnoreCase(ServiceInfoTags.vIMAGESERVICE) == 0) {
517
                                FMapRasterArcImsDriver idrv = (FMapRasterArcImsDriver) parentWizard.getDataSource().getDriver();
518
                                cli = (ArcImsClientP) idrv.getClient();
519
                        }
520
                        if (selectedServiceType.compareToIgnoreCase(ServiceInfoTags.vFEATURESERVICE) == 0) {
521
                                FMapFeatureArcImsDriver fdrv = (FMapFeatureArcImsDriver) parentWizard.getDataSource().getDriver();
522
                                cli = (ArcImsClientP) fdrv.getClient();
523
                        }
524
                        
525
                        ServiceInformation si = cli.getServiceInformation();
526
                        
527
                        // 
528
                        if ((si.getLayers() == null) || (si.getLayers().size() == 0)) {
529
                                logger.warn("No layers found ");
530
                                JOptionPane.showMessageDialog(this,
531
                                                PluginServices.getText(this, "no_layers_found")
532
                                                + ". " + PluginServices.getText(this, "service") + ": "
533
                                                + selectedServiceName,
534
                                                PluginServices.getText(this, "no_layers_found"),
535
                                                JOptionPane.ERROR_MESSAGE);
536
                                return;
537
                        }
538

    
539
                        parentWizard.setServiceName(selectedServiceName);
540
                        parentWizard.setServiceType(selectedServiceType);
541
                        parentWizard.fillAndMoveTabbedPaneToEnabled();
542
                        // ---------------------- NEXT BUTTON - END
543
                }
544
        }
545
        
546
        public void pseudoNextFired(FLayer lyr) {
547
                // if the 'user defined' option is set, local variables get values from
548
                // the combobox
549
                // if (serviceNameSelectionModeUserRadioButton.isSelected()) {
550
                        String userServiceName = userDefinedServiceNameTextField.getText();
551
                        int ind = -1;
552
                        
553
                        try {
554
                                ind = ServicesTableModel.getFirstRowWithValueInColumnName(servicesTable,
555
                                                PluginServices.getText(this, ServiceInfoTags.aNAME), userServiceName);
556
                        } catch (ArcImsException e1) {
557
                                logger.error("While searching value in table ", e1);
558
                                ind = -1;
559
                        }
560
                        if (ind == -1) {
561
                                JOptionPane.showMessageDialog(this, PluginServices
562
                                                .getText(this, "service_does_not_exist")
563
                                                + ": " + userServiceName, "Error", JOptionPane.ERROR_MESSAGE);
564
                                return;
565
                        }
566

    
567
                        selectedServiceType = ServicesTableModel.getColumnValueOfRowWithIndex(servicesTable,
568
                                        1, ind); 
569
                        selectedServiceName = userServiceName;
570
                // }
571
                
572
                // check that service type is supported:
573
                if (! isSupportedServiceType(selectedServiceName)) {
574
                        return;
575
                }
576

    
577
                try {
578
                        // +++++++++++++  This line truly starts the connection:          ++++++++++++
579
                        // +++++++++++++  creates driver, client and gets capabilities    ++++++++++++
580
                        parentWizard.getDataSource().setHostService(completeURL, selectedServiceName,
581
                                        selectedServiceType, lyr);
582
                } catch (DriverException de) {
583
                        logger.error("While setting host service ", de);
584
                        showErrorMessage(de.getMessage());
585
                        return;
586
                }
587
                
588
                // get service information:
589
                ArcImsClientP cli = null;
590
                if (selectedServiceType.compareToIgnoreCase(ServiceInfoTags.vIMAGESERVICE) == 0) {
591
                        FMapRasterArcImsDriver idrv = (FMapRasterArcImsDriver) parentWizard.getDataSource().getDriver();
592
                        cli = (ArcImsClientP) idrv.getClient();
593
                }
594
                if (selectedServiceType.compareToIgnoreCase(ServiceInfoTags.vFEATURESERVICE) == 0) {
595
                        FMapFeatureArcImsDriver fdrv = (FMapFeatureArcImsDriver) parentWizard.getDataSource().getDriver();
596
                        cli = (ArcImsClientP) fdrv.getClient();
597
                }
598
                
599
                ServiceInformation si = cli.getServiceInformation();
600
                
601
                // 
602
                if ((si.getLayers() == null) || (si.getLayers().size() == 0)) {
603
                        logger.warn("No layers found ");
604
                        JOptionPane.showMessageDialog(this,
605
                                        PluginServices.getText(this, "no_layers_found")
606
                                        + ". " + PluginServices.getText(this, "service") + ": "
607
                                        + selectedServiceName,
608
                                        PluginServices.getText(this, "no_layers_found"),
609
                                        JOptionPane.ERROR_MESSAGE);
610
                        return;
611
                }
612

    
613
                parentWizard.setServiceName(selectedServiceName);
614
                parentWizard.setServiceType(selectedServiceType);
615
                parentWizard.fillAndMoveTabbedPaneToEnabled();
616
        }
617
        
618

    
619
        private void setModelAndWidths(JTable table, ServicesTableModel m) {
620
                table.setModel(m);
621
                TableColumnModel cm = table.getColumnModel();
622
                TableColumn col;
623
                int count = cm.getColumnCount();
624
                if (count == 3) {
625
                        col = cm.getColumn(0);
626
                        col.setPreferredWidth(230);
627
                        col = cm.getColumn(1);
628
                        col.setPreferredWidth(110);
629
                        col = cm.getColumn(2);
630
                        col.setPreferredWidth(110);
631
                        table.repaint();
632
                }
633
        }
634

    
635
        private void showErrorMessage(String message) {
636
                JOptionPane.showMessageDialog(this,
637
                                PluginServices.getText(this, message),
638
                                PluginServices.getText(this, "error"),
639
                                JOptionPane.ERROR_MESSAGE);
640
        }
641

    
642
        private boolean servicesTableHasSelection() {
643
                return (servicesTable.getSelectedRow() != -1);
644
        }
645

    
646
        /**
647
         * Utility method to manage the services names table.
648
         * 
649
         * @param sName service name
650
         * @return row that contains it
651
         */
652
        public int getRowNumberOfServiceName(String sName) {
653
                int l = servicesTable.getRowCount();
654
                String s;
655
                for (int i = 0; i < l; i++) {
656
                        s = ServicesTableModel.getColumnValueOfRow(servicesTable, PluginServices
657
                                        .getText(this, "name"), i);
658
                        if (s.compareToIgnoreCase(sName) == 0)
659
                                return i;
660
                }
661
                logger.error("Service name not found: " + sName);
662
                return -1;
663
        }
664

    
665
        public JTable getServicesTable() {
666
                return servicesTable;
667
        }
668

    
669
        public void setServicesTable(JTable servicesTable) {
670
                this.servicesTable = servicesTable;
671
        }
672

    
673
        public void setSelectedServiceType(String selectedServiceType) {
674
                this.selectedServiceType = selectedServiceType;
675
        }
676

    
677
        public String getSelectedServiceName() {
678
                return selectedServiceName;
679
        }
680

    
681
        public void setSelectedServiceName(String selectedServiceName) {
682
                this.selectedServiceName = selectedServiceName;
683
        }
684

    
685
        public ArcImsWizard getParentWizard() {
686
                return parentWizard;
687
        }
688

    
689
        public void setParentWizard(ArcImsWizard parentWizard) {
690
                this.parentWizard = parentWizard;
691
        }
692

    
693
        public ServicesTableSelectionListener getTableSelectionListener() {
694
                return tableSelectionListener;
695
        }
696

    
697
        public void setTableSelectionListener(
698
                        ServicesTableSelectionListener tableSelectionListener) {
699
                this.tableSelectionListener = tableSelectionListener;
700
        }
701

    
702
        /**
703
         * This method initializes userDefinedServiceNamePanel
704
         * 
705
         * @return javax.swing.JPanel
706
         */
707
        private JPanel getUserDefinedServiceNamePanel() {
708
                if (userDefinedServiceNamePanel == null) {
709
                        userDefinedServiceNamePanel = new JPanel();
710
                        userDefinedServiceNamePanel.setBounds(new java.awt.Rectangle(17, 97, 477, 56)); // hasta y = 151
711
                        userDefinedServiceNamePanel.setLayout(null);
712
                        userDefinedServiceNamePanel
713
                                        .setBorder(javax.swing.BorderFactory
714
                                                        .createTitledBorder(
715
                                                                        null,
716
                                                                        PluginServices.getText(this,
717
                                                                                        "service_name"),
718
                                                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
719
                                                                        javax.swing.border.TitledBorder.DEFAULT_POSITION,
720
                                                                        null, null));
721
                        userDefinedServiceNameTextField = new JTextField();
722
                        userDefinedServiceNameTextField.setBounds(11, 21, 380 + 74, 20);
723
                        userDefinedServiceNameTextField.addKeyListener(this);
724
                        
725
                        serviceNameLabel = new JLabel(PluginServices.getText(this, "service_name"));
726
                        serviceNameLabel.setBounds(70, 21, 120, 20);
727
                        
728

    
729
                        // serviceSelectionModeButtonGroup = new ButtonGroup();
730
                        // serviceSelectionModeButtonGroup.add(getServiceNameSelectionModeRadioButton());
731
                        // serviceSelectionModeButtonGroup.add(getServiceNameSelectionModeListRadioButton());
732
                        
733
                        // userDefinedServiceNamePanel.add(getServiceNameSelectionModeRadioButton());
734
                        // userDefinedServiceNamePanel.add(getServiceNameSelectionModeListRadioButton());
735
                        userDefinedServiceNamePanel.add(userDefinedServiceNameTextField);
736
                        // userDefinedServiceNamePanel.add(serviceNameLabel);
737
                        
738

    
739
                }
740
                return userDefinedServiceNamePanel;
741
        }
742

    
743
        /**
744
         * This method initializes serviceNameSelectionModeRadioButton
745
         * 
746
         * @return javax.swing.JRadioButton
747
         */
748
        /*
749
        public JRadioButton getServiceNameSelectionModeRadioButton() {
750
                if (serviceNameSelectionModeUserRadioButton == null) {
751
                        serviceNameSelectionModeUserRadioButton = new JRadioButton();
752
                        serviceNameSelectionModeUserRadioButton.addActionListener(this);
753
                        serviceNameSelectionModeUserRadioButton
754
                                        .setBounds(new java.awt.Rectangle(170, 20, 160, 20));
755
                        serviceNameSelectionModeUserRadioButton.setText(PluginServices
756
                                        .getText(this, "defined_by_user") + ":");
757
                }
758
                return serviceNameSelectionModeUserRadioButton;
759
        }
760
        */
761

    
762
        /**
763
         * This method initializes serviceNameSelectionModeListRadioButton
764
         * 
765
         * @return javax.swing.JRadioButton
766
         */
767
        /*
768
        private JRadioButton getServiceNameSelectionModeListRadioButton() {
769
                if (serviceNameSelectionModeListRadioButton == null) {
770
                        serviceNameSelectionModeListRadioButton = new JRadioButton();
771
                        serviceNameSelectionModeListRadioButton.addActionListener(this);
772
                        serviceNameSelectionModeListRadioButton
773
                                        .setBounds(new java.awt.Rectangle(10, 20, 160, 20));
774
                        serviceNameSelectionModeListRadioButton.setText(PluginServices
775
                                        .getText(this, "selected_from_list"));
776

777
                }
778
                return serviceNameSelectionModeListRadioButton;
779
        }
780
        */
781

    
782
        private void setEnableComponent(JComponent c, boolean v) {
783
                if (c == null) return;
784
                c.setEnabled(v);
785

    
786
                if (c instanceof JTable) {
787
                        if (v) {
788
                                c.setForeground(Color.BLACK);
789
                        } else {
790
                                c.setForeground(Color.LIGHT_GRAY);
791
                        }
792
                }
793
        }
794

    
795
        public void keyPressed(KeyEvent e) {
796
        }
797
        
798
        public void keyTyped(KeyEvent e) {
799
        }
800

    
801
        public void keyReleased(KeyEvent e) {
802
                if (e.getSource() == userDefinedServiceNameTextField) {
803
                        boolean user = true;
804
                        int length = userDefinedServiceNameTextField.getText().length();
805
                        setServiceType("");
806
                        nextButton.setEnabled(user && (length > 0));
807
                }
808
                if (e.getSource() == serverComboBox.getEditor().getEditorComponent()) {
809
                        fireServerUrlUnknown();
810
                }
811
                
812
        }
813

    
814
        private void fireServerUrlUnknown() {
815
                // setEnableComponent(serviceNameSelectionModeListRadioButton, false);
816
                // setEnableComponent(serviceNameSelectionModeUserRadioButton, false);
817
                setEnableComponent(servicesTable, false);
818
                setEnableComponent(nextButton, false);
819
                setEnableComponent(userDefinedServiceNameTextField, false);
820
                if (versionLabel != null) {
821
                        versionLabel.setText("-");
822
                }
823
        }
824
        
825
        private void fireServerUrlOk() {
826
                // setEnableComponent(serviceNameSelectionModeListRadioButton, true);
827
                // setEnableComponent(serviceNameSelectionModeUserRadioButton, true);
828
                setEnableComponent(servicesTable, true);
829
                setEnableComponent(nextButton, true);
830
                
831
                String str = "-";
832
                
833
                if (versionLabel != null) {
834
                        str = getServerVersion(completeURL);
835
                        versionLabel.setText(str);
836
                        parentWizard.setServerVersionInPanels(str);
837
                }
838
                
839
                
840
                
841
                // serviceNameSelectionModeListRadioButton.setSelected(true);
842
                // ActionEvent ae = new ActionEvent(serviceNameSelectionModeListRadioButton, ActionEvent.ACTION_PERFORMED, "");
843
                // actionPerformed(ae);
844
                
845
                setUserDecisionTrue();
846
        }
847

    
848
        /**
849
         * This method calls the liArcIMS library to quickly find out
850
         * the server full url (with '/servlet/...')
851
         * 
852
         * @param url server short url
853
         * @return full url
854
         */
855
        private String getServerVersion(URL url) {
856
                String vers[];
857
                try {
858
                        vers = ArcImsProtocolHandler.getVersion(url);
859
                } catch (ArcImsException e) {
860
                        logger.error("Server version not found ", e);
861
                        JOptionPane.showMessageDialog(this,
862
                                        PluginServices.getText(this, "unable_to_findout_server_version"),
863
                                        PluginServices.getText(this, "unable_to_findout_server_version"),
864
                                        JOptionPane.ERROR_MESSAGE);
865
                        return "-";
866
                }
867
                return vers[0] + " (" + vers[1] + ")";
868
        }
869

    
870
        public String getServiceType() {
871
                return serviceType;
872
        }
873

    
874
        public void setServiceType(String serviceType) {
875
                this.serviceType = serviceType;
876
        }
877

    
878
        public void setUserServiceName(String str) {
879
                userDefinedServiceNameTextField.setText(str);
880
        }
881

    
882
        public void itemStateChanged(ItemEvent e) {
883
                this.fireServerUrlUnknown();
884
        }
885
        
886
        /**
887
         * 
888
         * Utility method to decide if a service type is supported
889
         * or not (ServiceInfoTags.IMAGESERVICE, etc)
890
         */
891
        private boolean isSupportedServiceType(String svcName) {
892
                
893
                int ind = -1;
894
                try {
895
                        ind = ServicesTableModel.getFirstRowWithValueInColumnIndex(servicesTable,
896
                                        0, svcName);
897
                } catch (ArcImsException e1) {
898
                        logger.error("While searching value in table ", e1);
899
                        ind = -1;
900
                }
901
                if (ind == -1) {
902
                        // should never happen
903
                        JOptionPane.showMessageDialog(this, PluginServices
904
                                        .getText(this, "service_does_not_exist")
905
                                        + ": " + svcName, "Error", JOptionPane.ERROR_MESSAGE);
906
                        return false;
907
                }
908
                
909
                String svcType = ServicesTableModel.getColumnValueOfRowWithIndex(servicesTable,
910
                                1, ind);
911
                
912
                if (
913
                (svcType.compareToIgnoreCase(ServiceInfoTags.vIMAGESERVICE) != 0)
914
                &&
915
                (svcType.compareToIgnoreCase(ServiceInfoTags.vFEATURESERVICE) != 0)
916
                ) {
917
                        showNotImplementedMessage();
918
                        return false;
919
                }
920
                return true;
921
        }
922

    
923
        
924
        private void showNotImplementedMessage() {
925
                JOptionPane.showMessageDialog(this,
926
                                PluginServices.getText(this, "service_type_not_supported"),
927
                                PluginServices.getText(this, "error"),
928
                                JOptionPane.ERROR_MESSAGE);
929
        }
930
        
931
        public void setUserDecisionTrue() {
932
                setEnableComponent(userDefinedServiceNameTextField, true);
933
                setEnableComponent(servicesTable, true);
934
                int length = userDefinedServiceNameTextField.getText().length();
935
                setEnableComponent(nextButton, (length > 0));
936
        }
937

    
938

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