1 7 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 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 t = thresholdField.getText(); 89 if (t != null && t.length() > 0) { 90 try { 91 c.setUserThreshold(user, Integer.parseInt(t)); 92 } 93 catch (Exception exc) { 94 thresholdField.setText(""); 95 JOptionPane.showMessageDialog(null, exc.getMessage()); 96 } 97 } 98 else { 99 try { 100 c.unsetUserThreshold(user); 101 } 102 catch (Exception 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 exc) { 113 JOptionPane.showMessageDialog(null, exc.getMessage()); 114 } 115 } 116 else { 117 try { 118 c.unsetUserDMQ(user); 119 } 120 catch (Exception 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 ) user.code().get("name")); 131 } catch (Exception exc) {} 132 } 133 134 public void setThreshold(String threshold) { thresholdField.setText(threshold); } 135 136 public void setDMQList(java.util.List 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 if (ddmq != null && ddmq.toString().equals(dmq.toString())) 146 dmqCombo.setSelectedItem(dmq); 147 } 148 } 149 } 150 | Popular Tags |