KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > tools > admin > UserPanel


1 /*
2  * Created on May 31, 2003
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 /*
8  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA.
24  *
25  * Initial developer(s): Alexander Fedorowicz
26  * Contributor(s):
27  */

28 package org.objectweb.joram.client.tools.admin;
29
30 import java.awt.*;
31 import java.awt.event.*;
32 import javax.swing.*;
33 import java.util.*;
34
35 import org.objectweb.joram.client.jms.admin.*;
36
37
38 /**
39  * @author afedoro
40  *
41  * To change the template for this generated type comment go to
42  * Window>Preferences>Java>Code Generation>Code and Comments
43  */

44 public class UserPanel extends JPanel {
45   private final AdminController c;
46
47   private User user = null;
48   private JLabel idLabel = new JLabel("");
49   private JTextField thresholdField = new JTextField(10);
50   private JComboBox dmqCombo = new JComboBox();
51
52   public UserPanel(AdminController c) {
53     super(new BorderLayout());
54     this.c = c;
55
56     setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
57
58     JLabel title = new JLabel("User Information");
59     title.setFont(new Font("Arial", Font.BOLD, 18));
60     title.setHorizontalAlignment(JLabel.LEFT);
61     add(title, BorderLayout.NORTH);
62
63     Box form = Box.createVerticalBox();
64     form.add(Box.createVerticalStrut(25));
65     JPanel idPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
66     idPanel.add(new JLabel("User Name: "));
67     idPanel.add(idLabel);
68     form.add(idPanel);
69     JPanel dtPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
70     dtPanel.add(new JLabel("Threshold: "));
71     dtPanel.add(thresholdField);
72     form.add(dtPanel);
73     JPanel dmqPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
74     dmqPanel.add(new JLabel("Dead Message Queue: "));
75     dmqPanel.add(dmqCombo);
76     form.add(dmqPanel);
77     form.add(Box.createVerticalStrut(30));
78
79     JButton applyButton = new JButton("Apply Changes");
80     applyButton.addActionListener(new ApplyActionListener());
81     form.add(applyButton, BorderLayout.SOUTH);
82     form.add(Box.createVerticalStrut(250));
83     add(form, BorderLayout.CENTER);
84   }
85
86   private class ApplyActionListener implements ActionListener {
87     public void actionPerformed(ActionEvent e) {
88       String JavaDoc t = thresholdField.getText();
89       if (t != null && t.length() > 0) {
90         try {
91           c.setUserThreshold(user, Integer.parseInt(t));
92         }
93         catch (Exception JavaDoc exc) {
94           thresholdField.setText("");
95           JOptionPane.showMessageDialog(null, exc.getMessage());
96         }
97       }
98       else {
99         try {
100           c.unsetUserThreshold(user);
101         }
102         catch (Exception JavaDoc exc) {
103           JOptionPane.showMessageDialog(null, exc.getMessage());
104         }
105       }
106
107       int i = dmqCombo.getSelectedIndex();
108       if (i > 0) {
109         try {
110           c.setUserDMQ(user, (DeadMQueue) dmqCombo.getSelectedItem());
111         }
112         catch (Exception JavaDoc exc) {
113           JOptionPane.showMessageDialog(null, exc.getMessage());
114         }
115       }
116       else {
117         try {
118           c.unsetUserDMQ(user);
119         }
120         catch (Exception JavaDoc exc) {
121           JOptionPane.showMessageDialog(null, exc.getMessage());
122         }
123       }
124     }
125   }
126
127   public void setUser(User user) {
128     this.user = user;
129     try {
130       idLabel.setText((String JavaDoc) user.code().get("name"));
131     } catch (Exception JavaDoc exc) {}
132   }
133
134   public void setThreshold(String JavaDoc threshold) { thresholdField.setText(threshold); }
135
136   public void setDMQList(java.util.List JavaDoc dmqs, DeadMQueue ddmq) {
137     dmqCombo.removeAllItems();
138     dmqCombo.addItem("No Dead Message Queue");
139
140     for (Iterator i = dmqs.iterator(); i.hasNext();) {
141       DeadMQueue dmq = (DeadMQueue) i.next();
142       dmqCombo.addItem(dmq);
143
144       // TODO: This comparison is not very clean and should be improved
145
if (ddmq != null && ddmq.toString().equals(dmq.toString()))
146         dmqCombo.setSelectedItem(dmq);
147     }
148   }
149 }
150
Popular Tags