Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.oracle / src / org / gvsig / oracle / gui / OracleConnectionChooserPanel.java @ 30231

History | View | Annotate | Download (6.55 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 Prodevelop S.L. main development
26
 */
27
package org.gvsig.oracle.gui;
28

    
29
import java.awt.GridBagConstraints;
30
import java.awt.GridBagLayout;
31
import java.awt.event.ActionEvent;
32
import java.awt.event.ActionListener;
33
import java.awt.event.ItemEvent;
34
import java.awt.event.ItemListener;
35
import java.awt.event.KeyEvent;
36
import java.awt.event.KeyListener;
37

    
38
import javax.swing.JButton;
39
import javax.swing.JPanel;
40

    
41
import org.gvsig.andami.PluginServices;
42
import org.gvsig.andami.ui.mdiManager.IWindow;
43
import org.gvsig.andami.ui.mdiManager.WindowInfo;
44
import org.gvsig.geodb.vectorialdb.wizard.MyExplorer;
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

    
48
/**
49
 * This dialog lets the user choose an available connection.
50
 * 
51
 * @author jldominguez, vsanjaime
52
 * 
53
 */
54
public class OracleConnectionChooserPanel extends JPanel implements IWindow,
55
                ActionListener, ItemListener, KeyListener {
56

    
57
        private static final long serialVersionUID = 1L;
58

    
59
        @SuppressWarnings("unused")
60
        private static Logger logger = LoggerFactory
61
                        .getLogger(OracleConnectionChooserPanel.class.getName());
62

    
63
        private ConnectionChooserPanel connectionPanel = null;
64
        private JButton okButton = null;
65
        private JButton cancelButton = null;
66

    
67
        private MyExplorer selectedExplorerParams = null;
68

    
69
        private boolean okPressed = false;
70
        WindowInfo winfo = null;
71

    
72
        /**
73
         * This method initializes
74
         * 
75
         */
76
        public OracleConnectionChooserPanel() {
77
                super();
78
                initialize();
79
        }
80

    
81
        /**
82
         * get window info
83
         */
84
        public WindowInfo getWindowInfo() {
85
                return winfo;
86
        }
87

    
88
        /**
89
         * get window profile
90
         */
91
        public Object getWindowProfile() {
92
                return WindowInfo.DIALOG_PROFILE;
93
        }
94

    
95
        /**
96
         * Create a explorer parameters with name of selected explorer
97
         * 
98
         * @return
99
         */
100
        public MyExplorer getSelectedServerExplorer() {
101

    
102
                return selectedExplorerParams;
103
        }
104

    
105
        /**
106
         * is ok button pressed
107
         * 
108
         * @return
109
         */
110
        public boolean isOkPressed() {
111
                return okPressed;
112
        }
113

    
114
        /**
115
         * Action Performed event
116
         */
117
        public void actionPerformed(ActionEvent arg0) {
118

    
119
                Object obj = arg0.getSource();
120

    
121
                // ok button
122
                if (obj == okButton) {
123
                        okPressed = true;
124
                        selectedExplorerParams = connectionPanel
125
                                        .getSelectedServerExplorer();
126
                        PluginServices.getMDIManager().closeWindow(this);
127
                }
128
                // cancel button
129
                if (obj == cancelButton) {
130
                        okPressed = false;
131
                        selectedExplorerParams = null;
132
                        PluginServices.getMDIManager().closeWindow(this);
133
                }
134
        }
135

    
136
        /**
137
         * changes selected item
138
         */
139
        public void itemStateChanged(ItemEvent e) {
140
                // combo explorers
141
                if (e.getSource() == connectionPanel.availableConnectionsComboBox) {
142

    
143
                        MyExplorer selExplorer = connectionPanel
144
                                        .getSelectedServerExplorer();
145

    
146
                        if (selExplorer == null) {
147
                                okButton.setEnabled(false);
148
                                selectedExplorerParams = null;
149
                                return;
150
                        } else {
151
                                selectedExplorerParams = selExplorer;
152
                                okButton.setEnabled(true);
153
                                okButton.requestFocus();
154
                        }
155
                }
156
        }
157

    
158
        /**
159
         * Key pressed event
160
         */
161
        public void keyPressed(KeyEvent e) {
162
                Object src = e.getSource();
163

    
164
                if ((src == okButton) || (src == cancelButton)) {
165
                        ActionEvent aux = new ActionEvent(src,
166
                                        ActionEvent.ACTION_PERFORMED, "");
167
                        actionPerformed(aux);
168
                }
169
        }
170

    
171
        /**
172
         * Key released event
173
         */
174
        public void keyReleased(KeyEvent e) {
175
                // nothing to do
176
        }
177

    
178
        /**
179
         * Key typed event
180
         */
181
        public void keyTyped(KeyEvent e) {
182
                // nothing to do
183
        }
184

    
185
        /**
186
         * This method initializes this
187
         * 
188
         */
189
        private void initialize() {
190
                winfo = new WindowInfo(WindowInfo.MODALDIALOG);
191
                winfo.setHeight(50);
192
                winfo.setWidth(400);
193
                winfo.setTitle(PluginServices.getText(this, "choose_connection"));
194

    
195
                connectionPanel = new ConnectionChooserPanel();
196

    
197
                this.setLayout(new GridBagLayout());
198
                this.setSize(new java.awt.Dimension(395, 89));
199

    
200
                GridBagConstraints gridBagConstraints = new GridBagConstraints();
201
                gridBagConstraints.gridx = 0;
202
                gridBagConstraints.gridy = 1;
203
                gridBagConstraints.anchor = GridBagConstraints.EAST;
204
                gridBagConstraints.insets = new java.awt.Insets(2, 10, 5, 5);
205
                this.add(getOkButton(), gridBagConstraints);
206

    
207
                gridBagConstraints = new GridBagConstraints();
208
                gridBagConstraints.gridx = 1;
209
                gridBagConstraints.gridy = 1;
210
                gridBagConstraints.insets = new java.awt.Insets(2, 10, 5, 5);
211
                this.add(getCancelButton(), gridBagConstraints);
212

    
213
                gridBagConstraints = new GridBagConstraints();
214
                gridBagConstraints.gridx = 0;
215
                gridBagConstraints.gridy = 0;
216
                gridBagConstraints.gridwidth = 2;
217
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
218
                gridBagConstraints.weightx = 1.0;
219
                gridBagConstraints.weighty = 1.0;
220
                gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 0);
221
                this.add(connectionPanel, gridBagConstraints);
222

    
223
                connectionPanel.availableConnectionsComboBox.addItemListener(this);
224

    
225
                selectedExplorerParams = connectionPanel.getSelectedServerExplorer();
226

    
227
                if (selectedExplorerParams == null) {
228
                        getOkButton().setEnabled(false);
229
                }
230
        }
231

    
232
        /**
233
         * This method initializes okButton
234
         * 
235
         * @return JButton
236
         */
237
        private JButton getOkButton() {
238
                if (okButton == null) {
239
                        okButton = new JButton(PluginServices.getText(this, "ok"));
240
                        okButton.addActionListener(this);
241
                        okButton.addKeyListener(this);
242
                }
243
                return okButton;
244
        }
245

    
246
        /**
247
         * This method initializes cancelButton
248
         * 
249
         * @return JButton
250
         */
251
        private JButton getCancelButton() {
252
                if (cancelButton == null) {
253
                        cancelButton = new JButton(PluginServices.getText(this, "cancel"));
254
                        cancelButton.addActionListener(this);
255
                        cancelButton.addKeyListener(this);
256
                }
257
                return cancelButton;
258
        }
259

    
260
}