KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > wizard > tab > RequestManagerTab


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.console.wizard.tab;
26
27 import java.awt.GridBagConstraints JavaDoc;
28 import java.awt.GridBagLayout JavaDoc;
29 import java.awt.event.ItemEvent JavaDoc;
30 import java.awt.event.ItemListener JavaDoc;
31
32 import javax.swing.BorderFactory JavaDoc;
33 import javax.swing.JCheckBox JavaDoc;
34 import javax.swing.JComboBox JavaDoc;
35 import javax.swing.JComponent JavaDoc;
36 import javax.swing.JLabel JavaDoc;
37 import javax.swing.JPanel JavaDoc;
38 import javax.swing.JSlider JavaDoc;
39
40 import org.objectweb.cjdbc.common.i18n.WizardTranslate;
41 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
42 import org.objectweb.cjdbc.console.wizard.WizardConstants;
43 import org.objectweb.cjdbc.console.wizard.WizardTab;
44 import org.objectweb.cjdbc.console.wizard.WizardTabs;
45
46 /**
47  * RequestManager is the main panel for the information regarding the request
48  * manager. This tab will open tabs like <code>CachingTab</code> and
49  * <code>RecoveryTab</code>
50  *
51  * @see <code>WizardTab</code>
52  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
53  * @version 1.0
54  */

55 public class RequestManagerTab extends WizardTab implements ItemListener JavaDoc
56 {
57   /** Request manager case sensitive parsing */
58   public JCheckBox JavaDoc caseSensitiveParsing;
59   /** Request manager begin timeout */
60   public JSlider JavaDoc beginTimeout;
61   /** Request manager commit timeout */
62   public JSlider JavaDoc commitTimeout;
63   /** Request manager rollback timeout */
64   public JSlider JavaDoc rollbackTimeout;
65   /** Request manager scheduler */
66   public JComboBox JavaDoc scheduler;
67   /** Request manager scheduler panel */
68   public JPanel JavaDoc shedulerPanel;
69   /** Request manager scheduler panel constraints */
70   public GridBagConstraints JavaDoc shedulerPanelconstraints;
71   /** Request manager scheduler level */
72   public JComboBox JavaDoc schedulerLevel;
73   /** Request manager load balancer */
74   public JComboBox JavaDoc loadbalancer;
75   /** Request manager load balancer panel constraints */
76   public GridBagConstraints JavaDoc loadbalancerPanelconstraints;
77   /** Request manager load balancer panel */
78   public JPanel JavaDoc loadbalancerPanel;
79   /** Request manager caching usage */
80   public JCheckBox JavaDoc usecaching;
81   /** Request manager recovery log usage */
82   public JCheckBox JavaDoc userecoverylog;
83   /** Request manager load balancer Wait For Completion policy */
84   public JComboBox JavaDoc wait4completion;
85
86   /**
87    * Creates a new <code>RequestManagerTab</code> object
88    *
89    * @param tabs the wizard tabs
90    */

91   public RequestManagerTab(WizardTabs tabs)
92   {
93     super(tabs, WizardConstants.TAB_REQUEST_MANAGER);
94
95     ///////////////////////////////////////////////////////////////////////////
96
// general panel
97
///////////////////////////////////////////////////////////////////////////
98

99     JPanel JavaDoc general = new JPanel JavaDoc();
100     general.setBorder(BorderFactory.createTitledBorder(WizardTranslate
101         .get("label.scheduler")));
102     general.setLayout(new GridBagLayout JavaDoc());
103     GridBagConstraints JavaDoc generalconstraints = new GridBagConstraints JavaDoc();
104     generalconstraints.fill = GridBagConstraints.HORIZONTAL;
105     generalconstraints.weightx = 1.0;
106
107     // caseSensitiveParsing
108
generalconstraints.gridy = ++generalconstraints.gridy;
109     generalconstraints.gridx = 0;
110     general.add(new JLabel JavaDoc(WizardTranslate.get("label.caseSensitiveParsing")),
111         generalconstraints);
112     generalconstraints.gridx = 1;
113     caseSensitiveParsing = new JCheckBox JavaDoc();
114     caseSensitiveParsing.setName("label.caseSensitiveParsing");
115     general.add(caseSensitiveParsing, generalconstraints);
116
117     // beginTimeout
118
generalconstraints.gridy = ++generalconstraints.gridy;
119     beginTimeout = new JSlider JavaDoc(JSlider.HORIZONTAL, 0, 2000, 60);
120     beginTimeout.setPaintTicks(true);
121     beginTimeout.setPaintLabels(true);
122     beginTimeout.setMajorTickSpacing(500);
123     generalconstraints.gridx = 0;
124     general.add(new JLabel JavaDoc(WizardTranslate.get("label.beginTimeout")),
125         generalconstraints);
126     generalconstraints.gridx = 1;
127     general.add(beginTimeout, generalconstraints);
128
129     // commitTimeout
130
generalconstraints.gridy = ++generalconstraints.gridy;
131     commitTimeout = new JSlider JavaDoc(JSlider.HORIZONTAL, 0, 2000, 60);
132     commitTimeout.setPaintTicks(true);
133     commitTimeout.setPaintLabels(true);
134     commitTimeout.setMajorTickSpacing(500);
135     generalconstraints.gridx = 0;
136     general.add(new JLabel JavaDoc(WizardTranslate.get("label.commitTimeout")),
137         generalconstraints);
138     generalconstraints.gridx = 1;
139     general.add(commitTimeout, generalconstraints);
140
141     // beginTimeout
142
generalconstraints.gridy = ++generalconstraints.gridy;
143     rollbackTimeout = new JSlider JavaDoc(JSlider.HORIZONTAL, 0, 2000, 60);
144     rollbackTimeout.setPaintTicks(true);
145     rollbackTimeout.setPaintLabels(true);
146     rollbackTimeout.setMajorTickSpacing(500);
147     generalconstraints.gridx = 0;
148     general.add(new JLabel JavaDoc(WizardTranslate.get("label.rollbackTimeout")),
149         generalconstraints);
150     generalconstraints.gridx = 1;
151     general.add(rollbackTimeout, generalconstraints);
152
153     // use caching
154
generalconstraints.gridy = ++generalconstraints.gridy;
155     generalconstraints.gridx = 0;
156     general.add(new JLabel JavaDoc(WizardTranslate.get("label.usecaching")),
157         generalconstraints);
158     generalconstraints.gridx = 1;
159     usecaching = new JCheckBox JavaDoc();
160     usecaching.setName("label.usecaching");
161     usecaching.addItemListener(this);
162     general.add(usecaching, generalconstraints);
163
164     // use recovery log
165
generalconstraints.gridy = ++generalconstraints.gridy;
166     generalconstraints.gridx = 0;
167     general.add(new JLabel JavaDoc(WizardTranslate.get("label.userecoverylog")),
168         generalconstraints);
169     generalconstraints.gridx = 1;
170     userecoverylog = new JCheckBox JavaDoc();
171     userecoverylog.addItemListener(this);
172     userecoverylog.setName("label.userecoverylog");
173     general.add(userecoverylog, generalconstraints);
174
175     this.add(general, constraints);
176     constraints.gridy = ++constraints.gridy;
177
178     ///////////////////////////////////////////////////////////////////////////
179
// scheduler panel
180
///////////////////////////////////////////////////////////////////////////
181

182     shedulerPanel = new JPanel JavaDoc();
183     shedulerPanel.setBorder(BorderFactory.createTitledBorder(WizardTranslate
184         .get("label.scheduler")));
185     shedulerPanel.setLayout(new GridBagLayout JavaDoc());
186     shedulerPanelconstraints = new GridBagConstraints JavaDoc();
187     shedulerPanelconstraints.fill = GridBagConstraints.HORIZONTAL;
188     shedulerPanelconstraints.weightx = 1.0;
189
190     // scheduler list
191
scheduler = new JComboBox JavaDoc(WizardConstants.SCHEDULERS_STANDARD);
192     scheduler.setSelectedIndex(0);
193     scheduler.addItemListener(this);
194     shedulerPanelconstraints.gridx = 0;
195     shedulerPanel.add(new JLabel JavaDoc(WizardTranslate.get("label.scheduler.type")),
196         shedulerPanelconstraints);
197     shedulerPanelconstraints.gridx = 1;
198     shedulerPanel.add(scheduler, shedulerPanelconstraints);
199
200     shedulerPanelconstraints.gridy = 1;
201     schedulerLevel = new JComboBox JavaDoc(WizardConstants.SCHEDULER_SINGLEDB_LEVELS);
202     schedulerLevel.setSelectedIndex(0);
203     schedulerLevel.addItemListener(this);
204     shedulerPanelconstraints.gridx = 0;
205     shedulerPanel.add(new JLabel JavaDoc(WizardTranslate.get("label.scheduler.level")),
206         shedulerPanelconstraints);
207     shedulerPanelconstraints.gridx = 1;
208     shedulerPanel.add(schedulerLevel, shedulerPanelconstraints);
209
210     this.add(shedulerPanel, constraints);
211     constraints.gridy = ++constraints.gridy;
212
213     ///////////////////////////////////////////////////////////////////////////
214
// loadbalancer panel
215
///////////////////////////////////////////////////////////////////////////
216

217     loadbalancerPanel = new JPanel JavaDoc();
218     loadbalancerPanel.setBorder(BorderFactory
219         .createTitledBorder(WizardTranslate.get("label.loadbalancer")));
220     loadbalancerPanel.setLayout(new GridBagLayout JavaDoc());
221     loadbalancerPanelconstraints = new GridBagConstraints JavaDoc();
222     loadbalancerPanelconstraints.fill = GridBagConstraints.HORIZONTAL;
223     loadbalancerPanelconstraints.weightx = 1.0;
224
225     loadbalancer = new JComboBox JavaDoc(WizardConstants.LOAD_BALANCER_SINGLEDB);
226     loadbalancer.setSelectedIndex(0);
227     loadbalancer.addItemListener(this);
228     loadbalancerPanelconstraints.gridx = 0;
229     loadbalancerPanel.add(new JLabel JavaDoc(WizardTranslate
230         .get("label.loadbalancer.type")), loadbalancerPanelconstraints);
231     loadbalancerPanelconstraints.gridx = 1;
232     loadbalancerPanel.add(loadbalancer, loadbalancerPanelconstraints);
233
234     loadbalancerPanelconstraints.gridy = 1;
235     wait4completion = new JComboBox JavaDoc(WizardConstants.WAIT_POLICIES);
236     wait4completion.setEnabled(false);
237     loadbalancerPanelconstraints.gridx = 0;
238     loadbalancerPanel.add(new JLabel JavaDoc(WizardTranslate
239         .get("label.loadbalancer.wait")), loadbalancerPanelconstraints);
240     loadbalancerPanelconstraints.gridx = 1;
241     loadbalancerPanel.add(wait4completion, loadbalancerPanelconstraints);
242
243     this.add(loadbalancerPanel, constraints);
244   }
245
246   /**
247    * @see org.objectweb.cjdbc.console.wizard.listeners.WizardListener#distributionChanged()
248    */

249   public void distributionChanged()
250   {
251     shedulerPanel.remove(scheduler);
252     if (tabs.isDistributedDatabase())
253     {
254       scheduler = new JComboBox JavaDoc(WizardConstants.SCHEDULERS_DISTRIBUTED);
255     }
256     else
257     {
258       scheduler = new JComboBox JavaDoc(WizardConstants.SCHEDULERS_STANDARD);
259     }
260     scheduler.setSelectedIndex(0);
261     scheduler.addItemListener(this);
262     shedulerPanelconstraints.gridx = 1;
263     shedulerPanelconstraints.gridy = 0;
264     shedulerPanel.add(scheduler, shedulerPanelconstraints);
265     shedulerPanel.validate();
266     shedulerPanel.repaint();
267   }
268
269   /**
270    * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
271    */

272   public void itemStateChanged(ItemEvent JavaDoc e)
273   {
274     JComponent JavaDoc source = (JComponent JavaDoc) e.getSource();
275     if (source.equals(scheduler))
276     {
277       // change scheduler level
278
shedulerPanel.remove(schedulerLevel);
279       if (scheduler.getSelectedIndex() == 0)
280         schedulerLevel = new JComboBox JavaDoc(
281             WizardConstants.SCHEDULER_SINGLEDB_LEVELS);
282       else if (scheduler.getSelectedIndex() == 1)
283         schedulerLevel = new JComboBox JavaDoc(WizardConstants.SCHEDULER_RAIDB0_LEVELS);
284       else if (scheduler.getSelectedIndex() == 2)
285         schedulerLevel = new JComboBox JavaDoc(WizardConstants.SCHEDULER_RAIDB1_LEVELS);
286       else if (scheduler.getSelectedIndex() == 3)
287         schedulerLevel = new JComboBox JavaDoc(WizardConstants.SCHEDULER_RAIDB2_LEVELS);
288
289       shedulerPanelconstraints.gridx = 1;
290       shedulerPanelconstraints.gridy = 1;
291       schedulerLevel.setSelectedIndex(0);
292       schedulerLevel.addItemListener(this);
293       shedulerPanel.add(schedulerLevel, shedulerPanelconstraints);
294       shedulerPanel.validate();
295       shedulerPanel.repaint();
296
297       // change loadbalancer list
298
loadbalancerPanel.remove(loadbalancer);
299       if (scheduler.getSelectedIndex() == 0)
300         loadbalancer = new JComboBox JavaDoc(WizardConstants.LOAD_BALANCER_SINGLEDB);
301       else if (scheduler.getSelectedIndex() == 1)
302         loadbalancer = new JComboBox JavaDoc(WizardConstants.LOAD_BALANCER_RAIDB0);
303       else if (scheduler.getSelectedIndex() == 2)
304         loadbalancer = new JComboBox JavaDoc(WizardConstants.LOAD_BALANCER_RAIDB1);
305       else if (scheduler.getSelectedIndex() == 3)
306         loadbalancer = new JComboBox JavaDoc(WizardConstants.LOAD_BALANCER_RAIDB2);
307
308       loadbalancerPanelconstraints.gridx = 1;
309       loadbalancerPanelconstraints.gridy = 0;
310       loadbalancer.setSelectedIndex(0);
311       loadbalancer.addItemListener(this);
312       loadbalancerPanel.add(loadbalancer, loadbalancerPanelconstraints);
313       loadbalancerPanel.validate();
314       loadbalancerPanel.repaint();
315
316     }
317     else if (source.equals(usecaching))
318     {
319       if (usecaching.getSelectedObjects() != null)
320         tabs.setTabEnabled(WizardConstants.TAB_CACHING, true);
321       else
322         tabs.setTabEnabled(WizardConstants.TAB_CACHING, false);
323     }
324     else if (source.equals(userecoverylog))
325     {
326       if (userecoverylog.getSelectedObjects() != null)
327         tabs.setTabEnabled(WizardConstants.TAB_RECOVERY, true);
328       else
329         tabs.setTabEnabled(WizardConstants.TAB_RECOVERY, false);
330     }
331
332     // enable wait4completion combo ?
333
if (source.equals(loadbalancer) || source.equals(scheduler))
334     {
335       String JavaDoc selected = (String JavaDoc) loadbalancer.getSelectedItem();
336       if (selected.startsWith(DatabasesXmlTags.ELT_RAIDb_1)
337           || selected.startsWith(DatabasesXmlTags.ELT_RAIDb_2))
338         wait4completion.setEnabled(true);
339       else
340         wait4completion.setEnabled(false);
341     }
342   }
343 }
Popular Tags