1 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 ; 13 import java.util.Arrays ; 14 15 19 public class BundleOffersPanel extends javax.swing.JPanel 20 { 21 private RMIAdminInterface admin; 22 private DefaultListModel content; 23 24 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 [] bundleOffers = null; 37 try 38 { 39 bundleOffers = admin.bundleOffersList(); 40 } 41 catch (RemoteException 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 getSelectedBundleOfferName() 54 { 55 String bundleName = ""; 56 57 int index = contentList.getSelectedIndex(); 58 if (index != -1) bundleName = (String )content.getElementAt(index); 59 return bundleName; 60 } 61 62 67 private void initComponents() { 69 jPanel2 = new javax.swing.JPanel (); 70 jPanel4 = new javax.swing.JPanel (); 71 showButton = new javax.swing.JButton (); 72 deleteButton = new javax.swing.JButton (); 73 testPushBundleOfferButton = new javax.swing.JButton (); 74 pushBundleOfferButton = new javax.swing.JButton (); 75 jPanel1 = new javax.swing.JPanel (); 76 jPanel3 = new javax.swing.JPanel (); 77 refreshButton = new javax.swing.JButton (); 78 createBundleOfferlButton = new javax.swing.JButton (); 79 jScrollPane1 = new javax.swing.JScrollPane (); 80 contentList = new javax.swing.JList (); 81 82 setLayout(new java.awt.BorderLayout ()); 83 84 addComponentListener(new java.awt.event.ComponentAdapter () 85 { 86 public void componentShown(java.awt.event.ComponentEvent evt) 87 { 88 formComponentShown(evt); 89 } 90 }); 91 92 jPanel2.setLayout(new java.awt.BorderLayout ()); 93 94 jPanel2.setPreferredSize(new java.awt.Dimension (200, 204)); 95 jPanel4.setLayout(new java.awt.GridLayout (4, 0)); 96 97 jPanel4.setBorder(new javax.swing.border.TitledBorder ("Bundle Offer Specific")); 98 showButton.setText("Show Bundle Offer"); 99 showButton.addActionListener(new java.awt.event.ActionListener () 100 { 101 public void actionPerformed(java.awt.event.ActionEvent 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 () 111 { 112 public void actionPerformed(java.awt.event.ActionEvent 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 () 122 { 123 public void actionPerformed(java.awt.event.ActionEvent 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 () 133 { 134 public void actionPerformed(java.awt.event.ActionEvent 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 ()); 145 146 jPanel1.setBorder(new javax.swing.border.TitledBorder ("General")); 147 jPanel3.setLayout(new java.awt.GridLayout (2, 0)); 148 149 refreshButton.setText("Refresh"); 150 refreshButton.addActionListener(new java.awt.event.ActionListener () 151 { 152 public void actionPerformed(java.awt.event.ActionEvent 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 () 162 { 163 public void actionPerformed(java.awt.event.ActionEvent 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 () 181 { 182 public void mouseClicked(java.awt.event.MouseEvent evt) 183 { 184 contentListMouseClicked(evt); 185 } 186 }); 187 188 jScrollPane1.setViewportView(contentList); 189 190 add(jScrollPane1, java.awt.BorderLayout.CENTER); 191 192 } 194 private void contentListMouseClicked(java.awt.event.MouseEvent evt) { if (evt.getClickCount() == 2) 197 { 198 showButton.doClick(); } 200 } 202 private void formComponentShown(java.awt.event.ComponentEvent evt) { reload(); 205 } 207 private void pushBundleOfferButtonActionPerformed(java.awt.event.ActionEvent evt) { PushBundleOfferDialog.showDialog(this, admin, getSelectedBundleOfferName()); 210 } 212 private void testPushBundleOfferButtonActionPerformed(java.awt.event.ActionEvent evt) { TestPushBundleOfferDialog.showDialog(this, admin, getSelectedBundleOfferName()); 215 } 217 private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) { String 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 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 } 244 private void showButtonActionPerformed(java.awt.event.ActionEvent evt) { String 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 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 } 274 private void createBundleOfferlButtonActionPerformed(java.awt.event.ActionEvent evt) { if (CreateBundleOfferDialog.showDialog(this, admin, "")) reload(); 277 } 279 private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) { reload(); 282 } 284 285 private javax.swing.JList contentList; 287 private javax.swing.JButton createBundleOfferlButton; 288 private javax.swing.JButton deleteButton; 289 private javax.swing.JPanel jPanel1; 290 private javax.swing.JPanel jPanel2; 291 private javax.swing.JPanel jPanel3; 292 private javax.swing.JPanel jPanel4; 293 private javax.swing.JScrollPane jScrollPane1; 294 private javax.swing.JButton pushBundleOfferButton; 295 private javax.swing.JButton refreshButton; 296 private javax.swing.JButton showButton; 297 private javax.swing.JButton testPushBundleOfferButton; 298 300 } 301 | Popular Tags |