KickJava   Java API By Example, From Geeks To Geeks.

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


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

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 JavaDoc;
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 /**
38  * @author afedoro
39  *
40  * To change the template for this generated type comment go to
41  * Window>Preferences>Java>Code Generation>Code and Comments
42  */

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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc exc) {
159           JOptionPane.showMessageDialog(null, exc.getMessage());
160         }
161       }
162       else if (dmqSelected) {
163         try {
164           c.unsetDestinationDMQ(dest);
165         }
166         catch (Exception JavaDoc 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 JavaDoc exc) {
177           JOptionPane.showMessageDialog(null, exc.getMessage());
178         }
179       }
180       else {
181         try {
182           c.unsetFreeReading(dest);
183         }
184         catch (Exception JavaDoc 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 JavaDoc exc) {
195           JOptionPane.showMessageDialog(null, exc.getMessage());
196         }
197       }
198       else {
199         try {
200           c.unsetFreeWriting(dest);
201         }
202         catch (Exception JavaDoc exc) {
203           JOptionPane.showMessageDialog(null, exc.getMessage());
204         }
205       }
206
207       try {
208         for (Iterator JavaDoc it = readingACL.getNewlyAuthorizedUsers().iterator();
209              it.hasNext();)
210           c.setReader((User) it.next(), dest);
211     
212         for (Iterator JavaDoc it = readingACL.getNewlyUnauthorizedUsers().iterator();
213              it.hasNext();)
214           c.unsetReader((User) it.next(), dest);
215     
216         for (Iterator JavaDoc it = writingACL.getNewlyAuthorizedUsers().iterator();
217              it.hasNext();)
218           c.setWriter((User) it.next(), dest);
219     
220         for (Iterator JavaDoc it = writingACL.getNewlyUnauthorizedUsers().iterator();
221              it.hasNext();)
222           c.unsetWriter((User) it.next(), dest);
223       }
224       catch (Exception JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc dmqs, DeadMQueue ddmq) {
270     dmqCombo.removeAllItems();
271     dmqCombo.addItem("No Dead Message Queue");
272
273     for (Iterator JavaDoc i = dmqs.iterator(); i.hasNext();) {
274       DeadMQueue dmq = (DeadMQueue) i.next();
275       dmqCombo.addItem(dmq);
276
277       // TODO: This comparison is not very clean and should be improved
278
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 JavaDoc users, java.util.List JavaDoc auth) {
287     readingACL.setupLists(users, auth);
288   }
289
290   public void setWritingACL(java.util.List JavaDoc users, java.util.List JavaDoc auth) {
291     writingACL.setupLists(users, auth);
292   }
293 }
294
Popular Tags