Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.arcims.feature.extension / src / main / java / org / gvsig / arcims / feature / gui / dialogs / ArcImsPropsDialog.java @ 32593

History | View | Annotate | Download (12 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 org.gvsig.arcims.feature.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.event.ListDataEvent;
61
import javax.swing.event.ListDataListener;
62

    
63
import org.gvsig.andami.PluginServices;
64
import org.gvsig.andami.ui.mdiManager.IWindow;
65
import org.gvsig.andami.ui.mdiManager.WindowInfo;
66
import org.gvsig.arcims.feature.gui.panels.FeatureServicePanel;
67
import org.gvsig.arcims.feature.gui.wizards.ArcImsFeatureWizard;
68
import org.gvsig.fmap.mapcontext.layers.FLayer;
69
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
70
import org.slf4j.Logger;
71
import org.slf4j.LoggerFactory;
72

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

    
100
        public ArcImsPropsDialog(FLayer layer) {
101
                super();
102
                initialize(layer);
103
        }
104

    
105
        private void initialize(FLayer layer) {
106
                setFLayer(layer);
107

    
108
                JPanel theServicePanel = null;
109

    
110
                // if (layer instanceof FFeatureLyrArcIMS) {
111
                // arcImsWizard = getArcImsWizard(((FFeatureLyrArcIMS) layer)
112
                // .getProperties(), false);
113
                // theServicePanel = arcImsWizard.getFeaServicePanel();
114
                // } else {
115
                // logger
116
                // .error("Unknow type of layer. ArcImsPropsDialog was not initialized. ");
117
                //
118
                // return;
119
                // }
120

    
121
                if (layer instanceof FLyrVect) {
122
                        // FIXME
123
                        // arcImsWizard = getArcImsWizard(((FFeatureLyrArcIMS) layer)
124
                        // .getProperties(), false);
125
                        theServicePanel = arcImsWizard.getFeaServicePanel();
126
                } else {
127
                        logger
128
                                        .error("Unknow type of layer. ArcImsPropsDialog was not initialized. ");
129

    
130
                        return;
131
                }
132

    
133
                arcImsWizard.setBounds(0, 0, 510, 510);
134
                buttonsPanel = getButtonsPanel();
135
                buttonsPanel.setBounds(0, 510, 510, 45);
136

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

    
143
                loadControlPointers(theServicePanel);
144
                loadAndDisableControls(theServicePanel, layer);
145
        }
146

    
147
        private void loadControlPointers(JPanel svcPanel) {
148

    
149
                if (svcPanel instanceof FeatureServicePanel) {
150
                        pointerToLayerNameTextField = ((FeatureServicePanel) svcPanel)
151
                                        .getNewLayerNameTextField();
152
                        pointerToSelectedLayersListModel = ((FeatureServicePanel) svcPanel)
153
                                        .getOrderedLayersListModel();
154
                }
155

    
156
                pointerToLayerNameTextField.addKeyListener(this);
157
                pointerToSelectedLayersListModel.addListDataListener(this);
158
        }
159

    
160
        private void getNewLayerConfig() {
161
                // FIXME
162
                // if (fLayer instanceof FFeatureLyrArcIMS) {
163
                // ((FFeatureLyrArcIMS) fLayer).setLayerQuery(arcImsWizard
164
                // .getServerExplorer().getStatus().getLayerQueryString());
165
                // ((FLayer) fLayer).setName(arcImsWizard.getServerExplorer()
166
                // .getStatus().getNewLayerName());
167
                // }
168
        }
169

    
170
        private void loadAndDisableControls(JPanel svcPanel, FLayer lyr) {
171
                arcImsWizard.getSvsNamesPanel().setServerComboText(hostURL.toString());
172

    
173
                JButton connB = arcImsWizard.getSvsNamesPanel().getConnectButton();
174
                ActionEvent ae = new ActionEvent(connB, ActionEvent.ACTION_PERFORMED,
175
                                "");
176
                arcImsWizard.getSvsNamesPanel().actionPerformed(ae);
177

    
178
                // JRadioButton userRadio =
179
                // arcImsWizard.getSvsNamesPanel().getServiceNameSelectionModeRadioButton();
180
                // userRadio.setSelected(true);
181
                // ae = new ActionEvent(userRadio, ActionEvent.ACTION_PERFORMED, "");
182
                arcImsWizard.getSvsNamesPanel().setUserDecisionTrue();
183

    
184
                arcImsWizard.getSvsNamesPanel().setServiceType(svcType);
185
                arcImsWizard.getSvsNamesPanel().setUserServiceName(svcName);
186

    
187
                JButton nextB = arcImsWizard.getSvsNamesPanel().getNextButton();
188
                ae = new ActionEvent(nextB, ActionEvent.ACTION_PERFORMED, "");
189

    
190
                // arcImsWizard.getSvsNamesPanel().actionPerformed(ae);
191
                arcImsWizard.getSvsNamesPanel().pseudoNextFired(lyr);
192

    
193
                if (svcPanel instanceof FeatureServicePanel) {
194
                        // ((FeatureServicePanel)
195
                        // svcPanel).getImgServiceTab_2().setVisible(false);
196
                        // ((FeatureServicePanel)
197
                        // svcPanel).getServiceInfoNextButton().setEnabled(false);
198
                        ((FeatureServicePanel) svcPanel).getChangeServerPanel().setVisible(
199
                                        false);
200

    
201
                        // ((FeatureServicePanel) svcPanel)
202
                        // JTree avTree = ((FeatureServicePanel)
203
                        // svcPanel).getAvailableLayersTree();
204
                        // Object root = avTree.getModel().getRoot();
205
                        // int nofchildren = avTree.getModel().getChildCount(root);
206
                        //
207
                        // String[] lyrIds = new String[1];
208
                        // lyrIds = ((FFeatureLyrArcIMS) fLayer).getLayerQuery().split(",");
209
                        //
210
                        // int i, j;
211
                        // LayersListElement lle;
212
                        // DefaultMutableTreeNode dmtn;
213
                        // for (i = 0; i < lyrIds.length; i++) {
214
                        // String id = lyrIds[i];
215
                        // for (j = (nofchildren - 1); j >= 0; j--) {
216
                        // dmtn = (DefaultMutableTreeNode) avTree.getModel().getChild(root,
217
                        // j);
218
                        // lle = (LayersListElement) dmtn.getUserObject();
219
                        // if (lle.getID().compareTo(id) == 0) {
220
                        // // arcImsWizard.getImgServicePanel().addLayerToSelectedList(lle);
221
                        // ((FeatureServicePanel)
222
                        // svcPanel).addLayerToSelectedListNoConfirm(lle);
223
                        // }
224
                        // }
225
                        // }
226
                        // ((FeatureServicePanel) svcPanel).refreshSelectedLayersList();
227
                        ((FeatureServicePanel) svcPanel).getNewLayerNameTextField()
228
                                        .setText(layerName);
229

    
230
                        // ((FeatureServicePanel)
231
                        // svcPanel).getChangeServerButton().setEnabled(false);
232
                        btnApply.setEnabled(false);
233
                }
234
        }
235

    
236
        public void setFLayer(FLayer f) {
237
                fLayer = f;
238
        }
239

    
240
        /**
241
         * Gets a new ArcImsWizard to allow the user to update the ArcIMS layer's
242
         * seetings. Needs the original layer info.
243
         * 
244
         * @param info
245
         *            the layer info
246
         * @return a new ArcImsWizard to allow the user to update the ArcIMS
247
         *         settings
248
         */
249
        public ArcImsFeatureWizard getArcImsWizard(HashMap info,
250
                        boolean editionallowed) {
251
                if (info != null) {
252
                        try {
253
                                layerName = (String) info.get("layerName");
254
                                hostURL = (URL) info.get("serverUrl");
255
                                svcName = (String) info.get("serviceName");
256
                                svcType = (String) info.get("serviceType");
257
                                imageFormat = (String) info.get("format");
258

    
259
                                // this.imasvcType = (String) info.get("serviceType");
260
                                ArcImsFeatureWizard wiz = new ArcImsFeatureWizard(
261
                                                editionallowed, true);
262
                                wiz.initWizard();
263

    
264
                                // wiz.getDataSource().setHostService(hostURL, svcName,
265
                                // svcType);
266
                                return wiz;
267
                        } catch (Exception e) {
268
                                logger.error("While starting wizard ", e);
269
                                JOptionPane.showMessageDialog(null, e.getMessage(), "Error",
270
                                                JOptionPane.ERROR_MESSAGE);
271
                                e.printStackTrace();
272
                        }
273
                }
274

    
275
                return null;
276
        }
277

    
278
        public JPanel getButtonsPanel() {
279
                if (buttonsPanel == null) {
280
                        buttonsPanel = new JPanel();
281
                        buttonsPanel.setLayout(null);
282
                        buttonsPanel.setName("buttonPanel");
283

    
284
                        buttonsPanel.add(getBtnOk(), null);
285
                        buttonsPanel.add(getBtnApply(), null);
286
                        buttonsPanel.add(getBtnCancel(), null);
287
                }
288

    
289
                return buttonsPanel;
290
        }
291

    
292
        public JButton getBtnOk() {
293
                if (btnOk == null) {
294
                        btnOk = new JButton("ok");
295
                        btnOk.setText(PluginServices.getText(this, "ok"));
296
                        btnOk.setActionCommand("OK");
297
                        btnOk.addActionListener(this);
298
                        btnOk.setBounds(338, 10, 90, 25);
299
                }
300

    
301
                return btnOk;
302
        }
303

    
304
        public JButton getBtnApply() {
305
                if (btnApply == null) {
306
                        btnApply = new JButton("apply");
307
                        btnApply.setText(PluginServices.getText(this, "apply"));
308
                        btnApply.setEnabled(true);
309
                        btnApply.setActionCommand("APPLY");
310
                        btnApply.addActionListener(this);
311
                        btnApply.setBounds(238, 10, 90, 25);
312
                }
313

    
314
                return btnApply;
315
        }
316

    
317
        public JButton getBtnCancel() {
318
                if (btnCancel == null) {
319
                        btnCancel = new JButton("cancel");
320
                        btnCancel.setText(PluginServices.getText(this, "cancel"));
321
                        btnCancel.setActionCommand("CANCEL");
322
                        btnCancel.addActionListener(this);
323
                        btnCancel.setBounds(80, 10, 90, 25);
324
                }
325

    
326
                return btnCancel;
327
        }
328

    
329
        public void close() {
330
                PluginServices.getMDIManager().closeWindow(this);
331
        }
332

    
333
        public WindowInfo getWindowInfo() {
334
                if (theViewInfo == null) {
335
                        theViewInfo = new WindowInfo(WindowInfo.MODALDIALOG);
336
                        theViewInfo.setTitle(PluginServices.getText(this,
337
                                        "fit_ArcIms_layer"));
338
                        theViewInfo.setWidth(this.getWidth() + 10);
339
                        theViewInfo.setHeight(this.getHeight() + 40);
340
                }
341

    
342
                return theViewInfo;
343
        }
344

    
345
        public void actionPerformed(ActionEvent e) {
346
                if (e.getSource() == this.btnApply) {
347
                        getNewLayerConfig();
348
                        fLayer.getMapContext().invalidate();
349
                }
350

    
351
                if (e.getSource() == this.btnOk) {
352
                        // FIXME
353
                        // if (fLayer instanceof FFeatureLyrArcIMS) {
354
                        // } else {
355
                        // getNewLayerConfig();
356
                        // fLayer.getMapContext().invalidate();
357
                        // }
358

    
359
                        close();
360
                }
361

    
362
                if (e.getSource() == this.btnCancel) {
363
                        close();
364
                }
365
        }
366

    
367
        /**
368
         * Utility method to center the given JDialog on the screen.
369
         * 
370
         * @param jd
371
         */
372
        public void centerThis(JDialog jd) {
373
                int dw = jd.getBounds().width;
374
                int dh = jd.getBounds().height;
375
                Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
376
                jd.setBounds((screen.width - dw) / 2, (screen.height - dh) / 2, dw, dh);
377
        }
378

    
379
        public void keyPressed(KeyEvent e) {
380
        }
381

    
382
        public void keyTyped(KeyEvent e) {
383
        }
384

    
385
        public void keyReleased(KeyEvent e) {
386
                if (e.getSource() == pointerToLayerNameTextField) {
387
                        boolean correct = isCorrectlyConfigured();
388
                        btnOk.setEnabled(correct);
389
                        btnApply.setEnabled(correct);
390
                }
391
        }
392

    
393
        public void contentsChanged(ListDataEvent e) {
394
        }
395

    
396
        private void contentChanged() {
397
                boolean correct = isCorrectlyConfigured();
398
                btnOk.setEnabled(correct);
399
                btnApply.setEnabled(correct);
400
        }
401

    
402
        public void intervalAdded(ListDataEvent e) {
403
                contentChanged();
404
        }
405

    
406
        public void intervalRemoved(ListDataEvent e) {
407
                contentChanged();
408
        }
409

    
410
        private boolean isCorrectlyConfigured() {
411
                if (pointerToSelectedLayersListModel.size() == 0) {
412
                        return false;
413
                }
414

    
415
                if (pointerToLayerNameTextField.getText().length() == 0) {
416
                        return false;
417
                }
418

    
419
                return true;
420
        }
421

    
422
        public Object getWindowProfile() {
423
                return WindowInfo.DIALOG_PROFILE;
424
        }
425

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