Statistics
| Revision:

root / trunk / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / gui / dialogs / ArcImsPropsDialog.java @ 24994

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 com.iver.andami.PluginServices;
46
import com.iver.andami.ui.mdiManager.IWindow;
47
import com.iver.andami.ui.mdiManager.WindowInfo;
48

    
49
import com.iver.cit.gvsig.fmap.layers.FLayer;
50

    
51
import es.prodevelop.cit.gvsig.arcims.fmap.layers.FFeatureLyrArcIMS;
52
import es.prodevelop.cit.gvsig.arcims.fmap.layers.FRasterLyrArcIMS;
53
import es.prodevelop.cit.gvsig.arcims.gui.panels.FeatureServicePanel;
54
import es.prodevelop.cit.gvsig.arcims.gui.panels.ImageServicePanel;
55
import es.prodevelop.cit.gvsig.arcims.gui.panels.utils.LayersListElement;
56
import es.prodevelop.cit.gvsig.arcims.gui.wizards.ArcImsWizard;
57

    
58
import org.apache.log4j.Logger;
59

    
60
import java.awt.Dimension;
61
import java.awt.Toolkit;
62
import java.awt.event.ActionEvent;
63
import java.awt.event.ActionListener;
64
import java.awt.event.KeyEvent;
65
import java.awt.event.KeyListener;
66

    
67
import java.net.URL;
68

    
69
import java.util.HashMap;
70

    
71
import javax.swing.DefaultListModel;
72
import javax.swing.JButton;
73
import javax.swing.JDialog;
74
import javax.swing.JOptionPane;
75
import javax.swing.JPanel;
76
import javax.swing.JRadioButton;
77
import javax.swing.JTextField;
78
import javax.swing.JTree;
79
import javax.swing.event.ListDataEvent;
80
import javax.swing.event.ListDataListener;
81
import javax.swing.tree.DefaultMutableTreeNode;
82

    
83

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

    
110
    public ArcImsPropsDialog(FLayer layer) {
111
        super();
112
        initialize(layer);
113
    }
114

    
115
    private void initialize(FLayer layer) {
116
        setFLayer(layer);
117

    
118
        JPanel theServicePanel = null;
119

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

    
135
                return;
136
            }
137
        }
138

    
139
        arcImsWizard.setBounds(0, 0, 510, 510);
140
        buttonsPanel = getButtonsPanel();
141
        buttonsPanel.setBounds(0, 510, 510, 45);
142

    
143
        this.setLayout(null);
144
        this.add(arcImsWizard); //, BorderLayout.CENTER);
145
        this.add(buttonsPanel); //, BorderLayout.SOUTH);
146
        this.setSize(new java.awt.Dimension(512, 475));
147
        this.setPreferredSize(new java.awt.Dimension(512, 475));
148

    
149
        loadControlPointers(theServicePanel);
150
        loadAndDisableControls(theServicePanel, layer);
151
    }
152

    
153
    private void loadControlPointers(JPanel svcPanel) {
154
        if (svcPanel instanceof ImageServicePanel) {
155
            pointerToLayerNameTextField = ((ImageServicePanel) svcPanel).getNewLayerNameTextField();
156
            pointerToSelectedLayersListModel = ((ImageServicePanel) svcPanel).getOrderedLayersListModel();
157
        }
158

    
159
        if ((svcPanel instanceof FeatureServicePanel) &&
160
                (!(svcPanel instanceof ImageServicePanel))) {
161
            pointerToLayerNameTextField = ((FeatureServicePanel) svcPanel).getNewLayerNameTextField();
162
            pointerToSelectedLayersListModel = ((FeatureServicePanel) svcPanel).getOrderedLayersListModel();
163
        }
164

    
165
        pointerToLayerNameTextField.addKeyListener(this);
166
        pointerToSelectedLayersListModel.addListDataListener(this);
167
    }
168

    
169
    private void getNewLayerConfig() {
170
        if (fLayer instanceof FRasterLyrArcIMS) {
171
            ((FRasterLyrArcIMS) fLayer).setLayerQuery(arcImsWizard.getLayerQuery());
172
            ((FRasterLyrArcIMS) fLayer).setName(arcImsWizard.getNewLayerName());
173
            ((FRasterLyrArcIMS) fLayer).setFormat(arcImsWizard.getImageFormat());
174

    
175
            ((FRasterLyrArcIMS) fLayer).setNameQueryChange(true);
176
        }
177

    
178
        if (fLayer instanceof FFeatureLyrArcIMS) {
179
            ((FFeatureLyrArcIMS) fLayer).setLayerQuery(arcImsWizard.getLayerQuery());
180
            ((FFeatureLyrArcIMS) fLayer).setName(arcImsWizard.getNewLayerName());
181
        }
182
    }
183

    
184
    private void loadAndDisableControls(JPanel svcPanel, FLayer lyr) {
185
        arcImsWizard.getSvsNamesPanel().setServerComboText(hostURL.toString());
186

    
187
        JButton connB = arcImsWizard.getSvsNamesPanel().getConnectButton();
188
        ActionEvent ae = new ActionEvent(connB, ActionEvent.ACTION_PERFORMED, "");
189
        arcImsWizard.getSvsNamesPanel().actionPerformed(ae);
190

    
191
        // JRadioButton userRadio = arcImsWizard.getSvsNamesPanel().getServiceNameSelectionModeRadioButton();
192
        // userRadio.setSelected(true);
193
        // ae = new ActionEvent(userRadio, ActionEvent.ACTION_PERFORMED, "");
194
        arcImsWizard.getSvsNamesPanel().setUserDecisionTrue();
195

    
196
        arcImsWizard.getSvsNamesPanel().setServiceType(svcType);
197
        arcImsWizard.getSvsNamesPanel().setUserServiceName(svcName);
198

    
199
        JButton nextB = arcImsWizard.getSvsNamesPanel().getNextButton();
200
        ae = new ActionEvent(nextB, ActionEvent.ACTION_PERFORMED, "");
201

    
202
        // arcImsWizard.getSvsNamesPanel().actionPerformed(ae);
203
        arcImsWizard.getSvsNamesPanel().pseudoNextFired(lyr);
204

    
205
        if (svcPanel instanceof ImageServicePanel) { // ((ImageServicePanel) svcPanel)
206

    
207
            JTree avTree = ((ImageServicePanel) svcPanel).getAvailableLayersTree();
208
            Object root = avTree.getModel().getRoot();
209
            int nofchildren = avTree.getModel().getChildCount(root);
210

    
211
            String[] lyrIds = new String[1];
212
            lyrIds = ((FRasterLyrArcIMS) fLayer).getLayerQuery().split(",");
213

    
214
            int i;
215
            int j;
216
            LayersListElement lle;
217
            DefaultMutableTreeNode dmtn;
218

    
219
            for (i = 0; i < lyrIds.length; i++) {
220
                String id = lyrIds[i];
221

    
222
                for (j = (nofchildren - 1); j >= 0; j--) {
223
                    dmtn = (DefaultMutableTreeNode) avTree.getModel()
224
                                                          .getChild(root, j);
225
                    lle = (LayersListElement) dmtn.getUserObject();
226

    
227
                    if (lle.getID().compareTo(id) == 0) {
228
                        // arcImsWizard.getImgServicePanel().addLayerToSelectedList(lle);
229
                        ((ImageServicePanel) svcPanel).addLayerToSelectedListNoConfirm(lle);
230
                    }
231
                }
232
            }
233

    
234
            ((ImageServicePanel) svcPanel).refreshSelectedLayersList();
235
            ((ImageServicePanel) svcPanel).getNewLayerNameTextField()
236
             .setText(layerName);
237
            ((ImageServicePanel) svcPanel).getChangeServerButton()
238
             .setEnabled(false);
239
            ((ImageServicePanel) svcPanel).setInImageFormatCombo(imageFormat);
240
        }
241

    
242
        if ((svcPanel instanceof FeatureServicePanel) &&
243
                (!(svcPanel instanceof ImageServicePanel))) {
244
            // ((FeatureServicePanel) svcPanel).getImgServiceTab_2().setVisible(false);
245
            // ((FeatureServicePanel) svcPanel).getServiceInfoNextButton().setEnabled(false);
246
            ((FeatureServicePanel) svcPanel).getChangeServerPanel()
247
             .setVisible(false);
248

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

    
275
            // ((FeatureServicePanel) svcPanel).getChangeServerButton().setEnabled(false);
276
            btnApply.setEnabled(false);
277
        }
278
    }
279

    
280
    public void setFLayer(FLayer f) {
281
        fLayer = f;
282
    }
283

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

    
300
                // this.imasvcType = (String) info.get("serviceType");
301
                ArcImsWizard wiz = new ArcImsWizard(editionallowed, true);
302
                wiz.initWizard();
303

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

    
316
        return null;
317
    }
318

    
319
    public JPanel getButtonsPanel() {
320
        if (buttonsPanel == null) {
321
            buttonsPanel = new JPanel();
322
            buttonsPanel.setLayout(null);
323
            buttonsPanel.setName("buttonPanel");
324

    
325
            buttonsPanel.add(getBtnOk(), null);
326
            buttonsPanel.add(getBtnApply(), null);
327
            buttonsPanel.add(getBtnCancel(), null);
328
        }
329

    
330
        return buttonsPanel;
331
    }
332

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

    
342
        return btnOk;
343
    }
344

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

    
355
        return btnApply;
356
    }
357

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

    
367
        return btnCancel;
368
    }
369

    
370
    public void close() {
371
        PluginServices.getMDIManager().closeWindow(this);
372
    }
373

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

    
382
        return theViewInfo;
383
    }
384

    
385
    public void actionPerformed(ActionEvent e) {
386
        if (e.getSource() == this.btnApply) {
387
            getNewLayerConfig();
388
            fLayer.getMapContext().invalidate();
389
        }
390

    
391
        if (e.getSource() == this.btnOk) {
392
            if (fLayer instanceof FFeatureLyrArcIMS) {
393
            }
394
            else {
395
                getNewLayerConfig();
396
                fLayer.getMapContext().invalidate();
397
            }
398

    
399
            close();
400
        }
401

    
402
        if (e.getSource() == this.btnCancel) {
403
            close();
404
        }
405
    }
406

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

    
419
    public void keyPressed(KeyEvent e) {
420
    }
421

    
422
    public void keyTyped(KeyEvent e) {
423
    }
424

    
425
    public void keyReleased(KeyEvent e) {
426
        if (e.getSource() == pointerToLayerNameTextField) {
427
            boolean correct = isCorrectlyConfigured();
428
            btnOk.setEnabled(correct);
429
            btnApply.setEnabled(correct);
430
        }
431
    }
432

    
433
    public void contentsChanged(ListDataEvent e) {
434
    }
435

    
436
    private void contentChanged() {
437
        boolean correct = isCorrectlyConfigured();
438
        btnOk.setEnabled(correct);
439
        btnApply.setEnabled(correct);
440
    }
441

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

    
446
    public void intervalRemoved(ListDataEvent e) {
447
        contentChanged();
448
    }
449

    
450
    private boolean isCorrectlyConfigured() {
451
        if (pointerToSelectedLayersListModel.size() == 0) {
452
            return false;
453
        }
454

    
455
        if (pointerToLayerNameTextField.getText().length() == 0) {
456
            return false;
457
        }
458

    
459
        return true;
460
    }
461

    
462
        public Object getWindowProfile() {
463
                return WindowInfo.DIALOG_PROFILE;
464
        }
465

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