Statistics
| Revision:

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

History | View | Annotate | Download (12.4 KB)

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

    
3
import java.awt.Dimension;
4
import java.awt.Toolkit;
5
import java.awt.event.ActionEvent;
6
import java.awt.event.ActionListener;
7
import java.awt.event.KeyEvent;
8
import java.awt.event.KeyListener;
9
import java.net.URL;
10
import java.util.HashMap;
11

    
12
import javax.swing.JButton;
13
import javax.swing.JDialog;
14
import javax.swing.JOptionPane;
15
import javax.swing.JPanel;
16
import javax.swing.DefaultListModel;
17
import javax.swing.JRadioButton;
18
import javax.swing.JTextField;
19
import javax.swing.JTree;
20
import javax.swing.event.ListDataEvent;
21
import javax.swing.event.ListDataListener;
22
import javax.swing.tree.DefaultMutableTreeNode;
23

    
24
import org.apache.log4j.Logger;
25

    
26
import com.iver.andami.PluginServices;
27
import com.iver.andami.ui.mdiManager.WindowInfo;
28
import com.iver.andami.ui.mdiManager.IWindow;
29
import com.iver.cit.gvsig.fmap.layers.FLayer;
30

    
31
import es.prodevelop.cit.gvsig.arcims.fmap.layers.FFeatureLyrArcIMS;
32
import es.prodevelop.cit.gvsig.arcims.fmap.layers.FRasterLyrArcIMS;
33
import es.prodevelop.cit.gvsig.arcims.gui.panels.FeatureServicePanel;
34
import es.prodevelop.cit.gvsig.arcims.gui.panels.ImageServicePanel;
35
import es.prodevelop.cit.gvsig.arcims.gui.panels.utils.LayersListElement;
36
import es.prodevelop.cit.gvsig.arcims.gui.wizards.ArcImsWizard;
37

    
38
/**
39
 * The TOC ArcIMS properties container panel. It allows users to change 
40
 * a previous request (not the server or service name). 
41
 * 
42
 * @author jldominguez
43
 * 
44
 */
45
public class ArcImsPropsDialog extends JPanel implements IWindow, ActionListener,
46
                KeyListener, ListDataListener {
47
        
48
        private static Logger logger = Logger.getLogger(ArcImsPropsDialog.class.getName());
49
        
50
        private JPanel buttonsPanel = null;
51
        private FLayer fLayer = null;
52
        private String layerName;
53
        private URL hostURL;
54
        private String svcName;
55
        private String svcType;
56
        private String imageFormat;
57
        private JButton btnApply = null;
58
        private JButton btnOk = null;
59
        private JButton btnCancel = null;
60
        private ArcImsWizard arcImsWizard;
61
        private WindowInfo theViewInfo;
62
        
63
        private JTextField pointerToLayerNameTextField;
64
        private DefaultListModel pointerToSelectedLayersListModel;
65
        private static final long serialVersionUID = 0;
66

    
67

    
68
        public ArcImsPropsDialog(FLayer layer) {
69
                super();
70
                initialize(layer);
71
        }
72

    
73
        private void initialize(FLayer layer) {
74
                setFLayer(layer);
75
                
76
                JPanel theServicePanel = null;
77
                
78
                if (layer instanceof FRasterLyrArcIMS) {
79
                        arcImsWizard = getArcImsWizard(((FRasterLyrArcIMS) layer).getProperties(), true);
80
                        theServicePanel = arcImsWizard.getImgServicePanel();
81
                } else {
82
                        if (layer instanceof FFeatureLyrArcIMS) {
83
                                arcImsWizard = getArcImsWizard(((FFeatureLyrArcIMS) layer).getProperties(), false);
84
                                theServicePanel = arcImsWizard.getFeaServicePanel();
85
                        } else {
86
                                logger.error("Unknow type of layer. ArcImsPropsDialog was not initialized. ");
87
                                return;
88
                        }
89
                }
90
                
91
                
92
                arcImsWizard.setBounds(0, 0, 510, 510);
93
                buttonsPanel = getButtonsPanel();
94
                buttonsPanel.setBounds(0, 510, 510, 45);
95

    
96
                this.setLayout(null);
97
                this.add(arcImsWizard); //, BorderLayout.CENTER);
98
                this.add(buttonsPanel); //, BorderLayout.SOUTH);
99
                this.setSize(new java.awt.Dimension(512, 475));
100
                this.setPreferredSize(new java.awt.Dimension(512, 475));
101

    
102
                loadControlPointers(theServicePanel);
103
                loadAndDisableControls(theServicePanel,layer);
104
        }
105

    
106
        private void loadControlPointers(JPanel svcPanel) {
107
                
108
                if (svcPanel instanceof ImageServicePanel) {
109
                        pointerToLayerNameTextField = ((ImageServicePanel) svcPanel).getNewLayerNameTextField();
110
                        pointerToSelectedLayersListModel = ((ImageServicePanel) svcPanel).getOrderedLayersListModel();
111
                }
112
                if ((svcPanel instanceof FeatureServicePanel) && (!(svcPanel instanceof ImageServicePanel))) {
113
                        pointerToLayerNameTextField = ((FeatureServicePanel) svcPanel).getNewLayerNameTextField();
114
                        pointerToSelectedLayersListModel = ((FeatureServicePanel) svcPanel).getOrderedLayersListModel();
115
                }
116
                pointerToLayerNameTextField.addKeyListener(this);
117
                pointerToSelectedLayersListModel.addListDataListener(this);
118
        }
119

    
120
        private void getNewLayerConfig() {
121
                if (fLayer instanceof FRasterLyrArcIMS) {
122
                        ((FRasterLyrArcIMS) fLayer).setLayerQuery(arcImsWizard.getLayerQuery());
123
                        ((FRasterLyrArcIMS) fLayer).setName(arcImsWizard.getNewLayerName());
124
                        ((FRasterLyrArcIMS) fLayer).setFormat(arcImsWizard.getImageFormat());
125
                        
126
                        ((FRasterLyrArcIMS) fLayer).setNameQueryChange(true);
127
                }
128
                if (fLayer instanceof FFeatureLyrArcIMS) {
129
                        ((FFeatureLyrArcIMS) fLayer).setLayerQuery(arcImsWizard.getLayerQuery());
130
                        ((FFeatureLyrArcIMS) fLayer).setName(arcImsWizard.getNewLayerName());
131
                }
132
        }
133

    
134
        private void loadAndDisableControls(JPanel svcPanel, FLayer lyr) {
135
                
136
                arcImsWizard.getSvsNamesPanel().setServerComboText(hostURL.toString());
137
                
138
                JButton connB = arcImsWizard.getSvsNamesPanel().getConnectButton();
139
                ActionEvent ae = new ActionEvent(connB, ActionEvent.ACTION_PERFORMED, "");
140
                arcImsWizard.getSvsNamesPanel().actionPerformed(ae);
141
                
142
                // JRadioButton userRadio = arcImsWizard.getSvsNamesPanel().getServiceNameSelectionModeRadioButton();
143
                // userRadio.setSelected(true);
144
                // ae = new ActionEvent(userRadio, ActionEvent.ACTION_PERFORMED, "");
145
                arcImsWizard.getSvsNamesPanel().setUserDecisionTrue();
146

    
147
                arcImsWizard.getSvsNamesPanel().setServiceType(svcType);
148
                arcImsWizard.getSvsNamesPanel().setUserServiceName(svcName);
149
                
150
                JButton nextB = arcImsWizard.getSvsNamesPanel().getNextButton();
151
                ae = new ActionEvent(nextB, ActionEvent.ACTION_PERFORMED, "");
152
                
153
                // arcImsWizard.getSvsNamesPanel().actionPerformed(ae);
154
                arcImsWizard.getSvsNamesPanel().pseudoNextFired(lyr);
155
                
156
                if (svcPanel instanceof ImageServicePanel) { // ((ImageServicePanel) svcPanel)
157
                        JTree avTree = ((ImageServicePanel) svcPanel).getAvailableLayersTree();
158
                        Object root = avTree.getModel().getRoot();
159
                        int nofchildren = avTree.getModel().getChildCount(root);
160
                        
161
                        String[] lyrIds = new String[1];
162
                        lyrIds = ((FRasterLyrArcIMS) fLayer).getLayerQuery().split(",");
163
                        
164
                        int i, j;
165
                        LayersListElement lle;
166
                        DefaultMutableTreeNode dmtn;
167
                        for (i = 0; i < lyrIds.length; i++) {
168
                                String id = lyrIds[i];
169
                                for (j = (nofchildren - 1); j >= 0; j--) {
170
                                        dmtn = (DefaultMutableTreeNode) avTree.getModel().getChild(root, j);
171
                                        lle = (LayersListElement) dmtn.getUserObject();
172
                                        if (lle.getID().compareTo(id) == 0) {
173
                                                // arcImsWizard.getImgServicePanel().addLayerToSelectedList(lle);
174
                                                ((ImageServicePanel) svcPanel).addLayerToSelectedListNoConfirm(lle);
175
                                        }
176
                                }
177
                        }
178
                        ((ImageServicePanel) svcPanel).refreshSelectedLayersList();
179
                        ((ImageServicePanel) svcPanel).getNewLayerNameTextField().setText(layerName);
180
                        ((ImageServicePanel) svcPanel).getChangeServerButton().setEnabled(false);
181
                        ((ImageServicePanel) svcPanel).setInImageFormatCombo(imageFormat);
182
                }
183
                
184
                if ((svcPanel instanceof FeatureServicePanel) && (!(svcPanel instanceof ImageServicePanel))) {
185
                        
186
                        // ((FeatureServicePanel) svcPanel).getImgServiceTab_2().setVisible(false);
187
                        // ((FeatureServicePanel) svcPanel).getServiceInfoNextButton().setEnabled(false);
188
                        
189
                        ((FeatureServicePanel) svcPanel).getChangeServerPanel().setVisible(false);
190
                        
191
                        
192
                        // ((FeatureServicePanel) svcPanel)
193
//                        JTree avTree = ((FeatureServicePanel) svcPanel).getAvailableLayersTree();
194
//                        Object root = avTree.getModel().getRoot();
195
//                        int nofchildren = avTree.getModel().getChildCount(root);
196
//                        
197
//                        String[] lyrIds = new String[1];
198
//                        lyrIds = ((FFeatureLyrArcIMS) fLayer).getLayerQuery().split(",");
199
//
200
//                        int i, j;
201
//                        LayersListElement lle;
202
//                        DefaultMutableTreeNode dmtn;
203
//                        for (i = 0; i < lyrIds.length; i++) {
204
//                                String id = lyrIds[i];
205
//                                for (j = (nofchildren - 1); j >= 0; j--) {
206
//                                        dmtn = (DefaultMutableTreeNode) avTree.getModel().getChild(root, j);
207
//                                        lle = (LayersListElement) dmtn.getUserObject();
208
//                                        if (lle.getID().compareTo(id) == 0) {
209
//                                                // arcImsWizard.getImgServicePanel().addLayerToSelectedList(lle);
210
//                                                ((FeatureServicePanel) svcPanel).addLayerToSelectedListNoConfirm(lle);
211
//                                        }
212
//                                }
213
//                        }
214
//                        ((FeatureServicePanel) svcPanel).refreshSelectedLayersList();
215
                        ((FeatureServicePanel) svcPanel).getNewLayerNameTextField().setText(layerName);
216
                        // ((FeatureServicePanel) svcPanel).getChangeServerButton().setEnabled(false);
217
                        btnApply.setEnabled(false);
218
                }
219
                
220
        }
221

    
222
        public void setFLayer(FLayer f) {
223
                fLayer = f;
224
        }
225

    
226
        /**
227
         * Gets a new ArcImsWizard to allow the user to update the ArcIMS
228
         * layer's seetings. Needs the original layer info.
229
         * 
230
         * @param info the layer info
231
         * @return a new ArcImsWizard to allow the user to update the ArcIMS settings
232
         */
233
        public ArcImsWizard getArcImsWizard(HashMap info, boolean editionallowed) {
234
                if (info != null) {
235
                        try {
236
                                layerName = (String) info.get("layerName");
237
                                hostURL = (URL) info.get("serverUrl");
238
                                svcName = (String) info.get("serviceName");
239
                                svcType = (String) info.get("serviceType");
240
                                imageFormat = (String) info.get("format");
241
                                // this.imasvcType = (String) info.get("serviceType");
242

    
243
                                ArcImsWizard wiz = new ArcImsWizard(editionallowed, true);
244
                                wiz.initWizard();
245
                                // wiz.getDataSource().setHostService(hostURL, svcName,
246
                                // svcType);
247
                                return wiz;
248
                        } catch (Exception e) {
249
                                logger.error("While starting wizard ", e);
250
                                JOptionPane.showMessageDialog(null, e.getMessage(), "Error",
251
                                                JOptionPane.ERROR_MESSAGE);
252
                                e.printStackTrace();
253
                        }
254
                }
255
                return null;
256
        }
257

    
258
        public JPanel getButtonsPanel() {
259
                if (buttonsPanel == null) {
260
                        buttonsPanel = new JPanel();
261
                        buttonsPanel.setLayout(null);
262
                        buttonsPanel.setName("buttonPanel");
263

    
264
                        buttonsPanel.add(getBtnOk(), null);
265
                        buttonsPanel.add(getBtnApply(), null);
266
                        buttonsPanel.add(getBtnCancel(), null);
267
                }
268
                return buttonsPanel;
269
        }
270

    
271
        public JButton getBtnOk() {
272
                if (btnOk == null) {
273
                        btnOk = new JButton("ok");
274
                        btnOk.setText(PluginServices.getText(this, "ok"));
275
                        btnOk.setActionCommand("OK");
276
                        btnOk.addActionListener(this);
277
                        btnOk.setBounds(338, 10, 90, 25);
278
                }
279
                return btnOk;
280
        }
281

    
282
        public JButton getBtnApply() {
283
                if (btnApply == null) {
284
                        btnApply = new JButton("apply");
285
                        btnApply.setText(PluginServices.getText(this, "apply"));
286
                        btnApply.setEnabled(true);
287
                        btnApply.setActionCommand("APPLY");
288
                        btnApply.addActionListener(this);
289
                        btnApply.setBounds(238, 10, 90, 25);
290
                }
291
                return btnApply;
292
        }
293

    
294
        public JButton getBtnCancel() {
295
                if (btnCancel == null) {
296
                        btnCancel = new JButton("cancel");
297
                        btnCancel.setText(PluginServices.getText(this, "cancel"));
298
                        btnCancel.setActionCommand("CANCEL");
299
                        btnCancel.addActionListener(this);
300
                        btnCancel.setBounds(80, 10, 90, 25);
301
                }
302
                return btnCancel;
303
        }
304

    
305
        public void close() {
306
                PluginServices.getMDIManager().closeWindow(this);
307
        }
308

    
309
        public WindowInfo getWindowInfo() {
310
                if (theViewInfo == null) {
311
                        theViewInfo = new WindowInfo(WindowInfo.MODALDIALOG);
312
                        theViewInfo.setTitle(PluginServices.getText(this,
313
                                        "fit_ArcIms_layer"));
314
                        theViewInfo.setWidth(this.getWidth() + 10);
315
                        theViewInfo.setHeight(this.getHeight() + 40);
316
                }
317
                return theViewInfo;
318
        }
319

    
320
        public void actionPerformed(ActionEvent e) {
321

    
322
                if (e.getSource() == this.btnApply) {
323
                        getNewLayerConfig();
324
                        fLayer.getMapContext().invalidate();
325
                }
326

    
327
                if (e.getSource() == this.btnOk) {
328
                        
329
                        if (fLayer instanceof FFeatureLyrArcIMS) {
330
                                
331
                        } else {
332
                                getNewLayerConfig();
333
                                fLayer.getMapContext().invalidate();
334
                        }
335
                        close();
336
                }
337

    
338
                if (e.getSource() == this.btnCancel) {
339
                        close();
340
                }
341

    
342
        }
343

    
344
        /**
345
         * Utility method to center the given JDialog on the screen.
346
         * 
347
         * @param jd
348
         */
349
        public void centerThis(JDialog jd) {
350
                int dw = jd.getBounds().width;
351
                int dh = jd.getBounds().height;
352
                Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
353
                jd.setBounds((screen.width - dw) / 2, (screen.height - dh) / 2, dw, dh);
354
        }
355

    
356

    
357
        public void keyPressed(KeyEvent e) { }
358
        public void keyTyped(KeyEvent e) { }
359
        public void keyReleased(KeyEvent e) {
360
                if (e.getSource() == pointerToLayerNameTextField) {
361
                        boolean correct = isCorrectlyConfigured();
362
                        btnOk.setEnabled(correct);
363
                        btnApply.setEnabled(correct);
364
                }
365
        }
366

    
367
        public void contentsChanged(ListDataEvent e) { }
368
        private void contentChanged() {
369
                boolean correct = isCorrectlyConfigured();
370
                btnOk.setEnabled(correct);
371
                btnApply.setEnabled(correct);
372
        }
373
        public void intervalAdded(ListDataEvent e) { contentChanged(); }
374
        public void intervalRemoved(ListDataEvent e) { contentChanged(); }
375
        
376
        private boolean isCorrectlyConfigured() {
377
                if (pointerToSelectedLayersListModel.size() == 0) return false;
378
                if (pointerToLayerNameTextField.getText().length() == 0) return false;
379
                return true;
380
        }
381
} // @jve:decl-index=0:visual-constraint="10,10"
382