1 23 package org.objectweb.joram.client.tools.admin; 24 25 import java.awt.*; 26 import java.awt.event.*; 27 import javax.swing.*; 28 import java.util.Iterator ; 29 import javax.jms.*; 30 31 import org.objectweb.joram.client.jms.admin.*; 32 33 import org.objectweb.joram.client.jms.Destination; 34 import org.objectweb.joram.client.jms.Queue; 35 import org.objectweb.joram.client.jms.Topic; 36 37 43 public class DestinationPanel extends JPanel { 44 private final AdminController c; 45 46 private Destination dest = null; 47 private JLabel idLabel = new JLabel(""); 48 private JLabel nameLabel = new JLabel(""); 49 private JLabel typeLabel = new JLabel(""); 50 private JLabel pendingMsgsLabel = new JLabel(""); 51 private JLabel pendingReqsLabel = new JLabel(""); 52 private JTextField thresholdField = new JTextField(10); 53 private JComboBox dmqCombo = new JComboBox(); 54 private JCheckBox freeRead = new JCheckBox(); 55 private JCheckBox freeWrite = new JCheckBox(); 56 private ACLPanel readingACL = new ACLPanel("Reading Access Control List"); 57 private ACLPanel writingACL = new ACLPanel("Writing Access Control List"); 58 private boolean nonZeroThreshold = false; 59 private boolean dmqSelected = false; 60 61 public DestinationPanel(AdminController c) { 62 super(new BorderLayout()); 63 this.c = c; 64 65 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 66 67 JLabel title = new JLabel("Destination Information"); 68 title.setFont(new Font("Arial", Font.BOLD, 18)); 69 title.setHorizontalAlignment(JLabel.LEFT); 70 add(title, BorderLayout.NORTH); 71 72 Box form = Box.createVerticalBox(); 73 form.add(Box.createVerticalStrut(15)); 74 JPanel idPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 75 idPanel.add(new JLabel("Destination identifier: ")); 76 idPanel.add(idLabel); 77 form.add(idPanel); 78 JPanel namePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 79 namePanel.add(new JLabel("JNDI name: ")); 80 namePanel.add(nameLabel); 81 form.add(namePanel); 82 JPanel typePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 83 typePanel.add(new JLabel("Destination type: ")); 84 typePanel.add(typeLabel); 85 form.add(typePanel); 86 87 JPanel pendingMsgsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 88 pendingMsgsPanel.add(new JLabel("Pending messages: ")); 89 pendingMsgsPanel.add(pendingMsgsLabel); 90 form.add(pendingMsgsPanel); 91 JPanel pendingReqsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 92 pendingReqsPanel.add(new JLabel("Pending requests: ")); 93 pendingReqsPanel.add(pendingReqsLabel); 94 form.add(pendingReqsPanel); 95 96 JPanel dtPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 97 dtPanel.add(new JLabel("Threshold: ")); 98 dtPanel.add(thresholdField); 99 form.add(dtPanel); 100 JPanel dmqPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 101 dmqPanel.add(new JLabel("Dead Message Queue: ")); 102 dmqPanel.add(dmqCombo); 103 form.add(dmqPanel); 104 JPanel frPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 105 frPanel.add(freeRead); 106 frPanel.add(new JLabel(" Allow free reading")); 107 form.add(frPanel); 108 JPanel fwPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 109 fwPanel.add(freeWrite); 110 fwPanel.add(new JLabel(" Allow free writing")); 111 form.add(fwPanel); 112 113 form.add(Box.createVerticalStrut(15)); 114 form.add(readingACL); 115 116 form.add(Box.createVerticalStrut(15)); 117 form.add(writingACL); 118 119 form.add(Box.createVerticalStrut(25)); 120 121 JButton applyButton = new JButton("Apply Changes"); 122 applyButton.addActionListener(new ApplyActionListener()); 123 form.add(applyButton, BorderLayout.SOUTH); 124 form.add(Box.createVerticalStrut(20)); 125 add(form, BorderLayout.CENTER); 126 } 127 128 private class ApplyActionListener implements ActionListener { 129 public void actionPerformed(ActionEvent e) { 130 String t = thresholdField.getText(); 131 if (thresholdField.isEnabled()) { 132 if (t != null && t.length() > 0) { 133 try { 134 Queue q = (Queue) dest; 135 c.setQueueThreshold(q, Integer.parseInt(t)); 136 } 137 catch (Exception exc) { 138 thresholdField.setText(""); 139 JOptionPane.showMessageDialog(null, exc.getMessage()); 140 } 141 } 142 else if (nonZeroThreshold) { 143 try { 144 Queue q = (Queue) dest; 145 c.unsetQueueThreshold(q); 146 } 147 catch (Exception exc) { 148 JOptionPane.showMessageDialog(null, exc.getMessage()); 149 } 150 } 151 } 152 153 int i = dmqCombo.getSelectedIndex(); 154 if (i > 0) { 155 try { 156 c.setDestinationDMQ(dest, (DeadMQueue) dmqCombo.getSelectedItem()); 157 } 158 catch (Exception exc) { 159 JOptionPane.showMessageDialog(null, exc.getMessage()); 160 } 161 } 162 else if (dmqSelected) { 163 try { 164 c.unsetDestinationDMQ(dest); 165 } 166 catch (Exception exc) { 167 JOptionPane.showMessageDialog(null, exc.getMessage()); 168 } 169 } 170 171 boolean fr = freeRead.isSelected(); 172 if (fr) { 173 try { 174 c.setFreeReading(dest); 175 } 176 catch (Exception exc) { 177 JOptionPane.showMessageDialog(null, exc.getMessage()); 178 } 179 } 180 else { 181 try { 182 c.unsetFreeReading(dest); 183 } 184 catch (Exception exc) { 185 JOptionPane.showMessageDialog(null, exc.getMessage()); 186 } 187 } 188 189 boolean fw = freeWrite.isSelected(); 190 if (fw) { 191 try { 192 c.setFreeWriting(dest); 193 } 194 catch (Exception exc) { 195 JOptionPane.showMessageDialog(null, exc.getMessage()); 196 } 197 } 198 else { 199 try { 200 c.unsetFreeWriting(dest); 201 } 202 catch (Exception exc) { 203 JOptionPane.showMessageDialog(null, exc.getMessage()); 204 } 205 } 206 207 try { 208 for (Iterator it = readingACL.getNewlyAuthorizedUsers().iterator(); 209 it.hasNext();) 210 c.setReader((User) it.next(), dest); 211 212 for (Iterator it = readingACL.getNewlyUnauthorizedUsers().iterator(); 213 it.hasNext();) 214 c.unsetReader((User) it.next(), dest); 215 216 for (Iterator it = writingACL.getNewlyAuthorizedUsers().iterator(); 217 it.hasNext();) 218 c.setWriter((User) it.next(), dest); 219 220 for (Iterator it = writingACL.getNewlyUnauthorizedUsers().iterator(); 221 it.hasNext();) 222 c.unsetWriter((User) it.next(), dest); 223 } 224 catch (Exception exc) { 225 JOptionPane.showMessageDialog(null, exc.getMessage()); 226 } 227 } 228 } 229 230 public void setDestination(Destination dest) { 231 this.dest = dest; 232 idLabel.setText(dest.getName()); 233 typeLabel.setText(dest.getType()); 234 String name = c.findDestinationJndiName(dest); 235 nameLabel.setText((name == null ? "Unknown" : name)); 236 } 237 238 public void setPendingMessages(int count) { 239 if (count >= 0) 240 pendingMsgsLabel.setText(Integer.toString(count)); 241 else 242 pendingMsgsLabel.setText("N/A"); 243 } 244 245 public void setPendingRequests(int count) { 246 if (count >= 0) 247 pendingReqsLabel.setText(Integer.toString(count)); 248 else 249 pendingReqsLabel.setText("N/A"); 250 } 251 252 public void setThreshold(String threshold) { 253 thresholdField.setText(threshold); 254 nonZeroThreshold = (!"".equals(threshold)); 255 } 256 257 public void setThresholdActive(boolean val) { 258 thresholdField.setEnabled(val); 259 } 260 261 public void setFreeReading(boolean val) { 262 freeRead.setSelected(val); 263 } 264 265 public void setFreeWriting(boolean val) { 266 freeWrite.setSelected(val); 267 } 268 269 public void setDMQList(java.util.List dmqs, DeadMQueue ddmq) { 270 dmqCombo.removeAllItems(); 271 dmqCombo.addItem("No Dead Message Queue"); 272 273 for (Iterator i = dmqs.iterator(); i.hasNext();) { 274 DeadMQueue dmq = (DeadMQueue) i.next(); 275 dmqCombo.addItem(dmq); 276 277 dmqSelected = false; 279 if (ddmq != null && ddmq.toString().equals(dmq.toString())) { 280 dmqCombo.setSelectedItem(dmq); 281 dmqSelected = true; 282 } 283 } 284 } 285 286 public void setReadingACL(java.util.List users, java.util.List auth) { 287 readingACL.setupLists(users, auth); 288 } 289 290 public void setWritingACL(java.util.List users, java.util.List auth) { 291 writingACL.setupLists(users, auth); 292 } 293 } 294 | Popular Tags |