Statistics
| Revision:

svn-gvsig-desktop / tags / v1_11_0_Build_1306 / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / gui / dialogs / ArcImsPropsDialog.java @ 35731

History | View | Annotate | Download (16 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 es.prodevelop.cit.gvsig.arcims.gui.dialogs;
44

    
45
import java.awt.Dimension;
46
import java.awt.Toolkit;
47
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionListener;
49
import java.awt.event.KeyEvent;
50
import java.awt.event.KeyListener;
51
import java.net.URL;
52
import java.util.HashMap;
53

    
54
import javax.swing.DefaultListModel;
55
import javax.swing.JButton;
56
import javax.swing.JDialog;
57
import javax.swing.JOptionPane;
58
import javax.swing.JPanel;
59
import javax.swing.JTextField;
60
import javax.swing.JTree;
61
import javax.swing.event.ListDataEvent;
62
import javax.swing.event.ListDataListener;
63
import javax.swing.tree.DefaultMutableTreeNode;
64

    
65
import org.apache.log4j.Logger;
66

    
67
import com.iver.andami.PluginServices;
68
import com.iver.andami.ui.mdiManager.IWindow;
69
import com.iver.andami.ui.mdiManager.WindowInfo;
70
import com.iver.cit.gvsig.fmap.layers.FLayer;
71

    
72
import es.prodevelop.cit.gvsig.arcims.fmap.layers.FFeatureLyrArcIMS;
73
import es.prodevelop.cit.gvsig.arcims.fmap.layers.FRasterLyrArcIMS;
74
import es.prodevelop.cit.gvsig.arcims.gui.panels.FeatureServicePanel;
75
import es.prodevelop.cit.gvsig.arcims.gui.panels.ImageServicePanel;
76
import es.prodevelop.cit.gvsig.arcims.gui.panels.utils.LayersListElement;
77
import es.prodevelop.cit.gvsig.arcims.gui.wizards.ArcImsWizard;
78

    
79

    
80
/**
81
 * The TOC ArcIMS properties container panel. It allows users to change
82
 * a previous request (not the server or service name).
83
 *
84
 * @author jldominguez
85
 *
86
 */
87
public class ArcImsPropsDialog extends JPanel implements IWindow,
88
    ActionListener, KeyListener, ListDataListener {
89
    private static Logger logger = Logger.getLogger(ArcImsPropsDialog.class.getName());
90
    private static final long serialVersionUID = 0;
91
    private JPanel buttonsPanel = null;
92
    private FLayer fLayer = null;
93
    private String layerName;
94
    private URL hostURL;
95
    private String svcName;
96
    private String svcType;
97
    private String imageFormat;
98
    private JButton btnApply = null;
99
    private JButton btnOk = null;
100
    private JButton btnCancel = null;
101
    private ArcImsWizard arcImsWizard;
102
    private WindowInfo theViewInfo;
103
    private JTextField pointerToLayerNameTextField;
104
    private DefaultListModel pointerToSelectedLayersListModel;
105

    
106
    public ArcImsPropsDialog(FLayer layer) {
107
        super();
108
        initialize(layer);
109
    }
110

    
111
    private void initialize(FLayer layer) {
112
        setFLayer(layer);
113

    
114
        JPanel theServicePanel = null;
115

    
116
        if (layer instanceof FRasterLyrArcIMS) {
117
            arcImsWizard = getArcImsWizard(((FRasterLyrArcIMS) layer).getProperties(),
118
                    true);
119
            theServicePanel = arcImsWizard.getImgServicePanel();
120
        }
121
        else {
122
            if (layer instanceof FFeatureLyrArcIMS) {
123
                arcImsWizard = getArcImsWizard(((FFeatureLyrArcIMS) layer).getProperties(),
124
                        false);
125
                theServicePanel = arcImsWizard.getFeaServicePanel();
126
            }
127
            else {
128
                logger.error(
129
                    "Unknow type of layer. ArcImsPropsDialog was not initialized. ");
130

    
131
                return;
132
            }
133
        }
134

    
135
        arcImsWizard.setBounds(0, 0, 510, 510);
136
        buttonsPanel = getButtonsPanel();
137
        buttonsPanel.setBounds(0, 510, 510, 45);
138

    
139
        this.setLayout(null);
140
        this.add(arcImsWizard); //, BorderLayout.CENTER);
141
        this.add(buttonsPanel); //, BorderLayout.SOUTH);
142
        this.setSize(new java.awt.Dimension(512, 475));
143
        this.setPreferredSize(new java.awt.Dimension(512, 475));
144

    
145
        loadControlPointers(theServicePanel);
146
        loadAndDisableControls(theServicePanel, layer);
147
    }
148

    
149
    private void loadControlPointers(JPanel svcPanel) {
150
        if (svcPanel instanceof ImageServicePanel) {
151
            pointerToLayerNameTextField = ((ImageServicePanel) svcPanel).getNewLayerNameTextField();
152
            pointerToSelectedLayersListModel = ((ImageServicePanel) svcPanel).getOrderedLayersListModel();
153
        }
154

    
155
        if ((svcPanel instanceof FeatureServicePanel) &&
156
                (!(svcPanel instanceof ImageServicePanel))) {
157
            pointerToLayerNameTextField = ((FeatureServicePanel) svcPanel).getNewLayerNameTextField();
158
            pointerToSelectedLayersListModel = ((FeatureServicePanel) svcPanel).getOrderedLayersListModel();
159
        }
160

    
161
        pointerToLayerNameTextField.addKeyListener(this);
162
        pointerToSelectedLayersListModel.addListDataListener(this);
163
    }
164

    
165
    private void getNewLayerConfig() {
166
        if (fLayer instanceof FRasterLyrArcIMS) {
167
            ((FRasterLyrArcIMS) fLayer).setLayerQuery(arcImsWizard.getLayerQuery());
168
            ((FRasterLyrArcIMS) fLayer).setName(arcImsWizard.getNewLayerName());
169
            ((FRasterLyrArcIMS) fLayer).setFormat(arcImsWizard.getImageFormat());
170

    
171
            ((FRasterLyrArcIMS) fLayer).setNameQueryChange(true);
172
        }
173

    
174
        if (fLayer instanceof FFeatureLyrArcIMS) {
175
            ((FFeatureLyrArcIMS) fLayer).setLayerQuery(arcImsWizard.getLayerQuery());
176
            ((FFeatureLyrArcIMS) fLayer).setName(arcImsWizard.getNewLayerName());
177
        }
178
    }
179

    
180
    private void loadAndDisableControls(JPanel svcPanel, FLayer lyr) {
181
        arcImsWizard.getSvsNamesPanel().setServerComboText(hostURL.toString());
182

    
183
        JButton connB = arcImsWizard.getSvsNamesPanel().getConnectButton();
184
        ActionEvent ae = new ActionEvent(connB, ActionEvent.ACTION_PERFORMED, "");
185
        arcImsWizard.getSvsNamesPanel().actionPerformed(ae);
186

    
187
        // JRadioButton userRadio = arcImsWizard.getSvsNamesPanel().getServiceNameSelectionModeRadioButton();
188
        // userRadio.setSelected(true);
189
        // ae = new ActionEvent(userRadio, ActionEvent.ACTION_PERFORMED, "");
190
        arcImsWizard.getSvsNamesPanel().setUserDecisionTrue();
191

    
192
        arcImsWizard.getSvsNamesPanel().setServiceType(svcType);
193
        arcImsWizard.getSvsNamesPanel().setUserServiceName(svcName);
194

    
195
        JButton nextB = arcImsWizard.getSvsNamesPanel().getNextButton();
196
        ae = new ActionEvent(nextB, ActionEvent.ACTION_PERFORMED, "");
197

    
198
        // arcImsWizard.getSvsNamesPanel().actionPerformed(ae);
199
        arcImsWizard.getSvsNamesPanel().pseudoNextFired(lyr);
200

    
201
        if (svcPanel instanceof ImageServicePanel) { // ((ImageServicePanel) svcPanel)
202

    
203
            JTree avTree = ((ImageServicePanel) svcPanel).getAvailableLayersTree();
204
            Object root = avTree.getModel().getRoot();
205
            int nofchildren = avTree.getModel().getChildCount(root);
206

    
207
            String[] lyrIds = new String[1];
208
            lyrIds = ((FRasterLyrArcIMS) fLayer).getLayerQuery().split(",");
209

    
210
            int i;
211
            int j;
212
            LayersListElement lle;
213
            DefaultMutableTreeNode dmtn;
214

    
215
            for (i = 0; i < lyrIds.length; i++) {
216
                String id = lyrIds[i];
217

    
218
                for (j = (nofchildren - 1); j >= 0; j--) {
219
                    dmtn = (DefaultMutableTreeNode) avTree.getModel()
220
                                                          .getChild(root, j);
221
                    lle = (LayersListElement) dmtn.getUserObject();
222

    
223
                    if (lle.getID().compareTo(id) == 0) {
224
                        // arcImsWizard.getImgServicePanel().addLayerToSelectedList(lle);
225
                        ((ImageServicePanel) svcPanel).addLayerToSelectedListNoConfirm(lle);
226
                    }
227
                }
228
            }
229

    
230
            ((ImageServicePanel) svcPanel).refreshSelectedLayersList();
231
            ((ImageServicePanel) svcPanel).getNewLayerNameTextField()
232
             .setText(layerName);
233
            ((ImageServicePanel) svcPanel).getChangeServerButton()
234
             .setEnabled(false);
235
            ((ImageServicePanel) svcPanel).setInImageFormatCombo(imageFormat);
236
        }
237

    
238
        if ((svcPanel instanceof FeatureServicePanel) &&
239
                (!(svcPanel instanceof ImageServicePanel))) {
240
            // ((FeatureServicePanel) svcPanel).getImgServiceTab_2().setVisible(false);
241
            // ((FeatureServicePanel) svcPanel).getServiceInfoNextButton().setEnabled(false);
242
            ((FeatureServicePanel) svcPanel).getChangeServerPanel()
243
             .setVisible(false);
244

    
245
            // ((FeatureServicePanel) svcPanel)
246
            //                        JTree avTree = ((FeatureServicePanel) svcPanel).getAvailableLayersTree();
247
            //                        Object root = avTree.getModel().getRoot();
248
            //                        int nofchildren = avTree.getModel().getChildCount(root);
249
            //
250
            //                        String[] lyrIds = new String[1];
251
            //                        lyrIds = ((FFeatureLyrArcIMS) fLayer).getLayerQuery().split(",");
252
            //
253
            //                        int i, j;
254
            //                        LayersListElement lle;
255
            //                        DefaultMutableTreeNode dmtn;
256
            //                        for (i = 0; i < lyrIds.length; i++) {
257
            //                                String id = lyrIds[i];
258
            //                                for (j = (nofchildren - 1); j >= 0; j--) {
259
            //                                        dmtn = (DefaultMutableTreeNode) avTree.getModel().getChild(root, j);
260
            //                                        lle = (LayersListElement) dmtn.getUserObject();
261
            //                                        if (lle.getID().compareTo(id) == 0) {
262
            //                                                // arcImsWizard.getImgServicePanel().addLayerToSelectedList(lle);
263
            //                                                ((FeatureServicePanel) svcPanel).addLayerToSelectedListNoConfirm(lle);
264
            //                                        }
265
            //                                }
266
            //                        }
267
            //                        ((FeatureServicePanel) svcPanel).refreshSelectedLayersList();
268
            ((FeatureServicePanel) svcPanel).getNewLayerNameTextField()
269
             .setText(layerName);
270

    
271
            // ((FeatureServicePanel) svcPanel).getChangeServerButton().setEnabled(false);
272
            btnApply.setEnabled(false);
273
        }
274
    }
275

    
276
    public void setFLayer(FLayer f) {
277
        fLayer = f;
278
    }
279

    
280
    /**
281
     * Gets a new ArcImsWizard to allow the user to update the ArcIMS
282
     * layer's seetings. Needs the original layer info.
283
     *
284
     * @param info the layer info
285
     * @return a new ArcImsWizard to allow the user to update the ArcIMS settings
286
     */
287
    public ArcImsWizard getArcImsWizard(HashMap info, boolean editionallowed) {
288
        if (info != null) {
289
            try {
290
                layerName = (String) info.get("layerName");
291
                hostURL = (URL) info.get("serverUrl");
292
                svcName = (String) info.get("serviceName");
293
                svcType = (String) info.get("serviceType");
294
                imageFormat = (String) info.get("format");
295

    
296
                // this.imasvcType = (String) info.get("serviceType");
297
                ArcImsWizard wiz = new ArcImsWizard(editionallowed, true);
298
                wiz.initWizard();
299

    
300
                // wiz.getDataSource().setHostService(hostURL, svcName,
301
                // svcType);
302
                return wiz;
303
            }
304
            catch (Exception e) {
305
                logger.error("While starting wizard ", e);
306
                JOptionPane.showMessageDialog(null, e.getMessage(), "Error",
307
                    JOptionPane.ERROR_MESSAGE);
308
                e.printStackTrace();
309
            }
310
        }
311

    
312
        return null;
313
    }
314

    
315
    public JPanel getButtonsPanel() {
316
        if (buttonsPanel == null) {
317
            buttonsPanel = new JPanel();
318
            buttonsPanel.setLayout(null);
319
            buttonsPanel.setName("buttonPanel");
320

    
321
            buttonsPanel.add(getBtnOk(), null);
322
            buttonsPanel.add(getBtnApply(), null);
323
            buttonsPanel.add(getBtnCancel(), null);
324
        }
325

    
326
        return buttonsPanel;
327
    }
328

    
329
    public JButton getBtnOk() {
330
        if (btnOk == null) {
331
            btnOk = new JButton("ok");
332
            btnOk.setText(PluginServices.getText(this, "ok"));
333
            btnOk.setActionCommand("OK");
334
            btnOk.addActionListener(this);
335
            btnOk.setBounds(338, 10, 90, 25);
336
        }
337

    
338
        return btnOk;
339
    }
340

    
341
    public JButton getBtnApply() {
342
        if (btnApply == null) {
343
            btnApply = new JButton("apply");
344
            btnApply.setText(PluginServices.getText(this, "apply"));
345
            btnApply.setEnabled(true);
346
            btnApply.setActionCommand("APPLY");
347
            btnApply.addActionListener(this);
348
            btnApply.setBounds(238, 10, 90, 25);
349
        }
350

    
351
        return btnApply;
352
    }
353

    
354
    public JButton getBtnCancel() {
355
        if (btnCancel == null) {
356
            btnCancel = new JButton("cancel");
357
            btnCancel.setText(PluginServices.getText(this, "cancel"));
358
            btnCancel.setActionCommand("CANCEL");
359
            btnCancel.addActionListener(this);
360
            btnCancel.setBounds(80, 10, 90, 25);
361
        }
362

    
363
        return btnCancel;
364
    }
365

    
366
    public void close() {
367
        PluginServices.getMDIManager().closeWindow(this);
368
    }
369

    
370
    public WindowInfo getWindowInfo() {
371
        if (theViewInfo == null) {
372
            theViewInfo = new WindowInfo(WindowInfo.MODALDIALOG);
373
            theViewInfo.setTitle(PluginServices.getText(this, "fit_ArcIms_layer"));
374
            theViewInfo.setWidth(this.getWidth() + 10);
375
            theViewInfo.setHeight(this.getHeight() + 40);
376
        }
377

    
378
        return theViewInfo;
379
    }
380

    
381
    public void actionPerformed(ActionEvent e) {
382
        if (e.getSource() == this.btnApply) {
383
            getNewLayerConfig();
384
            fLayer.getMapContext().invalidate();
385
        }
386

    
387
        if (e.getSource() == this.btnOk) {
388
            if (fLayer instanceof FFeatureLyrArcIMS) {
389
            }
390
            else {
391
                getNewLayerConfig();
392
                fLayer.getMapContext().invalidate();
393
            }
394

    
395
            close();
396
        }
397

    
398
        if (e.getSource() == this.btnCancel) {
399
            close();
400
        }
401
    }
402

    
403
    /**
404
     * Utility method to center the given JDialog on the screen.
405
     *
406
     * @param jd
407
     */
408
    public void centerThis(JDialog jd) {
409
        int dw = jd.getBounds().width;
410
        int dh = jd.getBounds().height;
411
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
412
        jd.setBounds((screen.width - dw) / 2, (screen.height - dh) / 2, dw, dh);
413
    }
414

    
415
    public void keyPressed(KeyEvent e) {
416
    }
417

    
418
    public void keyTyped(KeyEvent e) {
419
    }
420

    
421
    public void keyReleased(KeyEvent e) {
422
        if (e.getSource() == pointerToLayerNameTextField) {
423
            boolean correct = isCorrectlyConfigured();
424
            btnOk.setEnabled(correct);
425
            btnApply.setEnabled(correct);
426
        }
427
    }
428

    
429
    public void contentsChanged(ListDataEvent e) {
430
    }
431

    
432
    private void contentChanged() {
433
        boolean correct = isCorrectlyConfigured();
434
        btnOk.setEnabled(correct);
435
        btnApply.setEnabled(correct);
436
    }
437

    
438
    public void intervalAdded(ListDataEvent e) {
439
        contentChanged();
440
    }
441

    
442
    public void intervalRemoved(ListDataEvent e) {
443
        contentChanged();
444
    }
445

    
446
    private boolean isCorrectlyConfigured() {
447
        if (pointerToSelectedLayersListModel.size() == 0) {
448
            return false;
449
        }
450

    
451
        if (pointerToLayerNameTextField.getText().length() == 0) {
452
            return false;
453
        }
454

    
455
        return true;
456
    }
457

    
458
        public Object getWindowProfile() {
459
                return WindowInfo.DIALOG_PROFILE;
460
        }
461

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