Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

AuthenticationTab.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk.
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.console.wizard.tab;
00026 
00027 import java.awt.GridBagConstraints;
00028 import java.awt.GridBagLayout;
00029 import java.awt.event.ActionEvent;
00030 import java.awt.event.ActionListener;
00031 import java.awt.event.FocusEvent;
00032 import java.awt.event.FocusListener;
00033 import java.awt.event.ItemEvent;
00034 import java.awt.event.ItemListener;
00035 import java.util.ArrayList;
00036 
00037 import javax.swing.BorderFactory;
00038 import javax.swing.JButton;
00039 import javax.swing.JComboBox;
00040 import javax.swing.JLabel;
00041 import javax.swing.JPanel;
00042 import javax.swing.JTextField;
00043 
00044 import org.objectweb.cjdbc.common.i18n.WizardTranslate;
00045 import org.objectweb.cjdbc.console.wizard.WizardConstants;
00046 import org.objectweb.cjdbc.console.wizard.WizardTab;
00047 import org.objectweb.cjdbc.console.wizard.WizardTabs;
00048 import org.objectweb.cjdbc.console.wizard.objects.User;
00049 
00050 /**
00051  * This tab has al the fields for the authentication section of the virtual database.
00052  * 
00053  * @see <code>WizardTab</code>
00054  * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
00055  * @version 1.0
00056  */
00057 public class AuthenticationTab extends WizardTab
00058 {
00059 
00060   public UserPanel users;
00061   public UserPanel admin;
00062 
00063   /**
00064    * Creates a new <code>AuthenticationTab</code> object
00065    * 
00066    * @param tabs
00067    */
00068   public AuthenticationTab(WizardTabs tabs)
00069   {
00070     super(tabs, WizardConstants.TAB_AUTHENTICATION);
00071 
00072     admin = new UserPanel("label.admin");
00073     this.add(admin, constraints);
00074 
00075     constraints.gridy = ++constraints.gridy;
00076 
00077     users = new UserPanel("label.users");
00078     this.add(users, constraints);
00079   }
00080 
00081   public ArrayList getUsers()
00082   {
00083     JComboBox usersBox = users.getUsersCombo();
00084     return WizardConstants.getItemsFromCombo(usersBox);
00085   }
00086 
00087  public class UserPanel extends JPanel
00088       implements
00089         ItemListener,
00090         ActionListener,
00091         FocusListener
00092   {
00093     private JComboBox  usersCombo;
00094     private JButton    buttonAdd;
00095     private JButton    buttonRemove;
00096     int                currentIndex = 0;
00097     private JTextField userName;
00098     private JTextField password;
00099 
00100     public UserPanel(String title)
00101     {
00102 
00103       this.setBorder(BorderFactory.createTitledBorder(WizardTranslate
00104           .get(title)));
00105       this.setLayout(new GridBagLayout());
00106       GridBagConstraints localconstraints = new GridBagConstraints();
00107       localconstraints.fill = GridBagConstraints.HORIZONTAL;
00108       localconstraints.gridy = 0;
00109       localconstraints.weightx = 1.0;
00110       localconstraints.weighty = 1.0;
00111 
00112       localconstraints.gridwidth = 2;
00113       usersCombo = new JComboBox(new Object[]{});
00114       usersCombo.addItemListener(this);
00115       this.add(usersCombo, localconstraints);
00116 
00117       localconstraints.gridwidth = 1;
00118 
00119       localconstraints.gridy = ++localconstraints.gridy;
00120       localconstraints.gridx = 0;
00121       buttonAdd = new JButton(WizardTranslate.get("label.adduser"));
00122       buttonAdd.setActionCommand(WizardConstants.COMMAND_ADD_USER);
00123       buttonAdd.addActionListener(this);
00124       this.add(buttonAdd, localconstraints);
00125       localconstraints.gridx = 1;
00126       buttonRemove = new JButton(WizardTranslate.get("label.removeuser"));
00127       buttonRemove.setActionCommand(WizardConstants.COMMAND_REMOVE_USER);
00128       buttonRemove.addActionListener(this);
00129       this.add(buttonRemove, localconstraints);
00130 
00131       localconstraints.gridy = ++localconstraints.gridy;
00132       localconstraints.gridx = 0;
00133       this.add(new JLabel(WizardTranslate.get("label.username")),
00134           localconstraints);
00135       localconstraints.gridx = 1;
00136       userName = new JTextField();
00137       userName.addFocusListener(this);
00138       this.add(userName, localconstraints);
00139 
00140       localconstraints.gridy = ++localconstraints.gridy;
00141       localconstraints.gridx = 0;
00142       this.add(new JLabel(WizardTranslate.get("label.password")),
00143           localconstraints);
00144       localconstraints.gridx = 1;
00145       password = new JTextField();
00146       password.addFocusListener(this);
00147       this.add(password, localconstraints);
00148     }
00149 
00150     /**
00151      * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
00152      */
00153     public void focusGained(FocusEvent e)
00154     {
00155 
00156     }
00157 
00158     /**
00159      * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
00160      */
00161     public void focusLost(FocusEvent e)
00162     {
00163       if (e.getSource() == userName || e.getSource() == password)
00164       {
00165         User user = ((User) usersCombo.getSelectedItem());
00166         user.setUsername(userName.getText());
00167         user.setPassword(password.getText());
00168         usersCombo.repaint();
00169       }
00170     }
00171 
00172     /**
00173      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
00174      */
00175     public void actionPerformed(ActionEvent e)
00176     {
00177       String command = e.getActionCommand();
00178       if (command.equals(WizardConstants.COMMAND_ADD_USER))
00179       {
00180         User user = new User();
00181         usersCombo.addItem(user);
00182         usersCombo.setSelectedItem(user);
00183         usersCombo.validate();
00184         tabs.usersChanged();
00185       }
00186       else if (command.equals(WizardConstants.COMMAND_REMOVE_USER))
00187       {
00188         User user = (User) usersCombo.getSelectedItem();
00189         usersCombo.removeItem(user);
00190         usersCombo.validate();
00191         usersCombo.repaint();
00192         tabs.usersChanged();
00193       }
00194 
00195     }
00196 
00197     /**
00198      * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
00199      */
00200     public void itemStateChanged(ItemEvent e)
00201     {
00202       User user = (User) usersCombo.getSelectedItem();
00203       if (user == null)
00204       {
00205         userName.setText("");
00206         password.setText("");
00207       }
00208       else
00209       {
00210         userName.setText(user.getUsername());
00211         password.setText(user.getPassword());
00212       }
00213     }
00214 
00215     /**
00216      * Returns the usersCombo value.
00217      * 
00218      * @return Returns the usersCombo.
00219      */
00220     public JComboBox getUsersCombo()
00221     {
00222       return usersCombo;
00223     }
00224   }
00225 }

Generated on Mon Apr 11 22:01:29 2005 for C-JDBC by  doxygen 1.3.9.1