KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnet > Browser > BundleOffersPanel


1 /*
2  * BundleOffersPanel.java
3  *
4  * Created on 10. květen 2004, 17:18
5  */

6
7 package SOFA.SOFAnet.Browser;
8
9 import javax.swing.*;
10 import SOFA.SOFAnet.Admin.RMI.*;
11 import SOFA.SOFAnet.Repository.BundleOffer;
12 import java.rmi.RemoteException JavaDoc;
13 import java.util.Arrays JavaDoc;
14
15 /**
16  *
17  * @author Ladislav Sobr
18  */

19 public class BundleOffersPanel extends javax.swing.JPanel JavaDoc
20 {
21   private RMIAdminInterface admin;
22   private DefaultListModel content;
23   
24   /** Creates new form BundleOffersPanel */
25   public BundleOffersPanel(RMIAdminInterface admin)
26   {
27     this.admin = admin;
28     content = new DefaultListModel();
29     initComponents();
30   }
31
32   private void reload()
33   {
34     content.clear();
35     
36     String JavaDoc[] bundleOffers = null;
37     try
38     {
39       bundleOffers = admin.bundleOffersList();
40     }
41     catch (RemoteException JavaDoc e)
42     {
43       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
44       return;
45     }
46     
47     Arrays.sort(bundleOffers);
48     
49     content.ensureCapacity(bundleOffers.length);
50     for (int i = 0; i < bundleOffers.length; i++) content.addElement(bundleOffers[i]);
51   }
52   
53   private String JavaDoc getSelectedBundleOfferName()
54   {
55     String JavaDoc bundleName = "";
56
57     int index = contentList.getSelectedIndex();
58     if (index != -1) bundleName = (String JavaDoc)content.getElementAt(index);
59     return bundleName;
60   }
61   
62   /** This method is called from within the constructor to
63    * initialize the form.
64    * WARNING: Do NOT modify this code. The content of this method is
65    * always regenerated by the Form Editor.
66    */

67   private void initComponents()//GEN-BEGIN:initComponents
68
{
69     jPanel2 = new javax.swing.JPanel JavaDoc();
70     jPanel4 = new javax.swing.JPanel JavaDoc();
71     showButton = new javax.swing.JButton JavaDoc();
72     deleteButton = new javax.swing.JButton JavaDoc();
73     testPushBundleOfferButton = new javax.swing.JButton JavaDoc();
74     pushBundleOfferButton = new javax.swing.JButton JavaDoc();
75     jPanel1 = new javax.swing.JPanel JavaDoc();
76     jPanel3 = new javax.swing.JPanel JavaDoc();
77     refreshButton = new javax.swing.JButton JavaDoc();
78     createBundleOfferlButton = new javax.swing.JButton JavaDoc();
79     jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
80     contentList = new javax.swing.JList JavaDoc();
81
82     setLayout(new java.awt.BorderLayout JavaDoc());
83
84     addComponentListener(new java.awt.event.ComponentAdapter JavaDoc()
85     {
86       public void componentShown(java.awt.event.ComponentEvent JavaDoc evt)
87       {
88         formComponentShown(evt);
89       }
90     });
91
92     jPanel2.setLayout(new java.awt.BorderLayout JavaDoc());
93
94     jPanel2.setPreferredSize(new java.awt.Dimension JavaDoc(200, 204));
95     jPanel4.setLayout(new java.awt.GridLayout JavaDoc(4, 0));
96
97     jPanel4.setBorder(new javax.swing.border.TitledBorder JavaDoc("Bundle Offer Specific"));
98     showButton.setText("Show Bundle Offer");
99     showButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
100     {
101       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
102       {
103         showButtonActionPerformed(evt);
104       }
105     });
106
107     jPanel4.add(showButton);
108
109     deleteButton.setText("Delete Bundle Offer");
110     deleteButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
111     {
112       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
113       {
114         deleteButtonActionPerformed(evt);
115       }
116     });
117
118     jPanel4.add(deleteButton);
119
120     testPushBundleOfferButton.setText("Test Push Bundle Offer");
121     testPushBundleOfferButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
122     {
123       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
124       {
125         testPushBundleOfferButtonActionPerformed(evt);
126       }
127     });
128
129     jPanel4.add(testPushBundleOfferButton);
130
131     pushBundleOfferButton.setText("Push Bundle Offer");
132     pushBundleOfferButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
133     {
134       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
135       {
136         pushBundleOfferButtonActionPerformed(evt);
137       }
138     });
139
140     jPanel4.add(pushBundleOfferButton);
141
142     jPanel2.add(jPanel4, java.awt.BorderLayout.NORTH);
143
144     jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
145
146     jPanel1.setBorder(new javax.swing.border.TitledBorder JavaDoc("General"));
147     jPanel3.setLayout(new java.awt.GridLayout JavaDoc(2, 0));
148
149     refreshButton.setText("Refresh");
150     refreshButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
151     {
152       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
153       {
154         refreshButtonActionPerformed(evt);
155       }
156     });
157
158     jPanel3.add(refreshButton);
159
160     createBundleOfferlButton.setText("Create Bundle Offer");
161     createBundleOfferlButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
162     {
163       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
164       {
165         createBundleOfferlButtonActionPerformed(evt);
166       }
167     });
168
169     jPanel3.add(createBundleOfferlButton);
170
171     jPanel1.add(jPanel3, java.awt.BorderLayout.NORTH);
172
173     jPanel2.add(jPanel1, java.awt.BorderLayout.CENTER);
174
175     add(jPanel2, java.awt.BorderLayout.EAST);
176
177     contentList.setModel(content);
178     contentList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
179     contentList.setVisibleRowCount(-1);
180     contentList.addMouseListener(new java.awt.event.MouseAdapter JavaDoc()
181     {
182       public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt)
183       {
184         contentListMouseClicked(evt);
185       }
186     });
187
188     jScrollPane1.setViewportView(contentList);
189
190     add(jScrollPane1, java.awt.BorderLayout.CENTER);
191
192   }//GEN-END:initComponents
193

194   private void contentListMouseClicked(java.awt.event.MouseEvent JavaDoc evt)//GEN-FIRST:event_contentListMouseClicked
195
{//GEN-HEADEREND:event_contentListMouseClicked
196
if (evt.getClickCount() == 2)
197     {
198       showButton.doClick(); //emulate button click
199
}
200   }//GEN-LAST:event_contentListMouseClicked
201

202   private void formComponentShown(java.awt.event.ComponentEvent JavaDoc evt)//GEN-FIRST:event_formComponentShown
203
{//GEN-HEADEREND:event_formComponentShown
204
reload();
205   }//GEN-LAST:event_formComponentShown
206

207   private void pushBundleOfferButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_pushBundleOfferButtonActionPerformed
208
{//GEN-HEADEREND:event_pushBundleOfferButtonActionPerformed
209
PushBundleOfferDialog.showDialog(this, admin, getSelectedBundleOfferName());
210   }//GEN-LAST:event_pushBundleOfferButtonActionPerformed
211

212   private void testPushBundleOfferButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_testPushBundleOfferButtonActionPerformed
213
{//GEN-HEADEREND:event_testPushBundleOfferButtonActionPerformed
214
TestPushBundleOfferDialog.showDialog(this, admin, getSelectedBundleOfferName());
215   }//GEN-LAST:event_testPushBundleOfferButtonActionPerformed
216

217   private void deleteButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_deleteButtonActionPerformed
218
{//GEN-HEADEREND:event_deleteButtonActionPerformed
219
String JavaDoc bundleOfferName = getSelectedBundleOfferName();
220     
221     if (bundleOfferName.length() == 0)
222     {
223       JOptionPane.showMessageDialog(this, "No Bundle Offer selected", "Warning", JOptionPane.WARNING_MESSAGE);
224       return;
225     }
226     else
227     {
228       if (JOptionPane.showConfirmDialog(this, "Do you really want to delete Bundle Offer '" + bundleOfferName + "'?") != JOptionPane.YES_OPTION) return;
229     }
230     
231     try
232     {
233       admin.deleteBundleOffer(bundleOfferName);
234     }
235     catch (RemoteException JavaDoc e)
236     {
237       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
238       return;
239     }
240     
241     reload();
242   }//GEN-LAST:event_deleteButtonActionPerformed
243

244   private void showButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_showButtonActionPerformed
245
{//GEN-HEADEREND:event_showButtonActionPerformed
246
String JavaDoc bundleOfferName = getSelectedBundleOfferName();
247     
248     if (bundleOfferName.length() == 0)
249     {
250       JOptionPane.showMessageDialog(this, "No Bundle Offer selected", "Warning", JOptionPane.WARNING_MESSAGE);
251       return;
252     }
253     
254     BundleOffer bundleOffer = null;
255     try
256     {
257       bundleOffer = admin.getBundleOffer(bundleOfferName);
258     }
259     catch (RemoteException JavaDoc e)
260     {
261       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
262       return;
263     }
264
265     if (bundleOffer == null)
266     {
267       JOptionPane.showMessageDialog(this, "Selected Bundle Offer doesn't exist on the node anymore", "Error", JOptionPane.ERROR_MESSAGE);
268       return;
269     }
270     
271     BundleOfferDialog.showDialog(this, bundleOffer);
272   }//GEN-LAST:event_showButtonActionPerformed
273

274   private void createBundleOfferlButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_createBundleOfferlButtonActionPerformed
275
{//GEN-HEADEREND:event_createBundleOfferlButtonActionPerformed
276
if (CreateBundleOfferDialog.showDialog(this, admin, "")) reload();
277   }//GEN-LAST:event_createBundleOfferlButtonActionPerformed
278

279   private void refreshButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_refreshButtonActionPerformed
280
{//GEN-HEADEREND:event_refreshButtonActionPerformed
281
reload();
282   }//GEN-LAST:event_refreshButtonActionPerformed
283

284   
285   // Variables declaration - do not modify//GEN-BEGIN:variables
286
private javax.swing.JList JavaDoc contentList;
287   private javax.swing.JButton JavaDoc createBundleOfferlButton;
288   private javax.swing.JButton JavaDoc deleteButton;
289   private javax.swing.JPanel JavaDoc jPanel1;
290   private javax.swing.JPanel JavaDoc jPanel2;
291   private javax.swing.JPanel JavaDoc jPanel3;
292   private javax.swing.JPanel JavaDoc jPanel4;
293   private javax.swing.JScrollPane JavaDoc jScrollPane1;
294   private javax.swing.JButton JavaDoc pushBundleOfferButton;
295   private javax.swing.JButton JavaDoc refreshButton;
296   private javax.swing.JButton JavaDoc showButton;
297   private javax.swing.JButton JavaDoc testPushBundleOfferButton;
298   // End of variables declaration//GEN-END:variables
299

300 }
301
Popular Tags