1 6 7 package SOFA.SOFAnet.Browser; 8 9 import SOFA.SOFAnet.Admin.RMI.*; 10 import SOFA.SOFAnet.Repository.BundleInfo; 11 import SOFA.SOFAnet.Repository.NodeInfo; 12 import SOFA.SOFAnet.Repository.Licence; 13 import javax.swing.*; 14 import java.rmi.RemoteException ; 15 import java.util.*; 16 import java.awt.Component ; 17 import java.awt.Frame ; 18 19 23 public class PushBundleOfferDialog extends javax.swing.JDialog 24 { 25 private RMIAdminInterface admin; 26 private boolean isOK; 27 28 public static boolean showDialog(Component frameComp, RMIAdminInterface admin, String defaultBundleName) 29 { 30 Frame frame = JOptionPane.getFrameForComponent(frameComp); 31 PushBundleOfferDialog dialog = new PushBundleOfferDialog(frame, true, admin, defaultBundleName); 32 dialog.setLocationRelativeTo(frameComp); 33 dialog.setVisible(true); 34 return dialog.isOK(); 35 } 36 37 38 public PushBundleOfferDialog(java.awt.Frame parent, boolean modal, RMIAdminInterface admin, String defaultBundleName) 39 { 40 super(parent, modal); 41 this.admin = admin; 42 isOK = false; 43 initComponents(); 44 45 bundleNameTextField.setText(defaultBundleName); 46 } 47 48 public boolean isOK() 49 { 50 return isOK; 51 } 52 53 58 private void initComponents() { 60 jPanel4 = new javax.swing.JPanel (); 61 jPanel1 = new javax.swing.JPanel (); 62 jPanel5 = new javax.swing.JPanel (); 63 bundleNameLabel = new javax.swing.JLabel (); 64 bundleNameTextField = new javax.swing.JTextField (); 65 nodeNameLabel = new javax.swing.JLabel (); 66 nodeNameTextField = new javax.swing.JTextField (); 67 jPanel2 = new javax.swing.JPanel (); 68 chooseBundleOfferButton = new javax.swing.JButton (); 69 jPanel3 = new javax.swing.JPanel (); 70 pushBundleOfferButton = new javax.swing.JButton (); 71 cancelButton = new javax.swing.JButton (); 72 73 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 74 setTitle("Push Bundle Offer"); 75 jPanel4.setLayout(new java.awt.BorderLayout ()); 76 77 jPanel4.setMinimumSize(new java.awt.Dimension (400, 93)); 78 jPanel4.setPreferredSize(new java.awt.Dimension (400, 170)); 79 jPanel1.setLayout(new java.awt.BorderLayout ()); 80 81 jPanel1.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (1, 10, 1, 10))); 82 jPanel1.setMinimumSize(new java.awt.Dimension (26, 23)); 83 jPanel1.setPreferredSize(new java.awt.Dimension (26, 23)); 84 jPanel5.setLayout(new java.awt.GridLayout (4, 0)); 85 86 bundleNameLabel.setText("Bundle Offer Name:"); 87 jPanel5.add(bundleNameLabel); 88 89 bundleNameTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 90 bundleNameTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 91 jPanel5.add(bundleNameTextField); 92 93 nodeNameLabel.setText("Node name:"); 94 jPanel5.add(nodeNameLabel); 95 96 nodeNameTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 97 nodeNameTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 98 jPanel5.add(nodeNameTextField); 99 100 jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH); 101 102 jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER); 103 104 chooseBundleOfferButton.setText("Choose Bundle Offer"); 105 chooseBundleOfferButton.addActionListener(new java.awt.event.ActionListener () 106 { 107 public void actionPerformed(java.awt.event.ActionEvent evt) 108 { 109 chooseBundleOfferButtonActionPerformed(evt); 110 } 111 }); 112 113 jPanel2.add(chooseBundleOfferButton); 114 115 jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH); 116 117 pushBundleOfferButton.setText("Push Bundle Offer"); 118 pushBundleOfferButton.addActionListener(new java.awt.event.ActionListener () 119 { 120 public void actionPerformed(java.awt.event.ActionEvent evt) 121 { 122 pushBundleOfferButtonActionPerformed(evt); 123 } 124 }); 125 126 jPanel3.add(pushBundleOfferButton); 127 128 cancelButton.setText("Cancel"); 129 cancelButton.addActionListener(new java.awt.event.ActionListener () 130 { 131 public void actionPerformed(java.awt.event.ActionEvent evt) 132 { 133 cancelButtonActionPerformed(evt); 134 } 135 }); 136 137 jPanel3.add(cancelButton); 138 139 jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH); 140 141 getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER); 142 143 pack(); 144 } 146 private void chooseBundleOfferButtonActionPerformed(java.awt.event.ActionEvent evt) { String [] bundles = null; 149 try 150 { 151 bundles = admin.bundleOffersList(); 152 } 153 catch (RemoteException e) 154 { 155 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 156 return; 157 } 158 159 Arrays.sort(bundles); 160 161 String result = ListDialog.showDialog(this, this, "Bundle Offers:", "Choose Bundle Offer to Test Push", bundles, null, null, false, true); 162 if (result.length() != 0) bundleNameTextField.setText(result); 163 164 } 166 private void pushBundleOfferButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = bundleNameTextField.getText(); 169 String nodeName = nodeNameTextField.getText(); 170 171 BundleInfo bundleInfo = new BundleInfo(); 172 try 173 { 174 bundleInfo.fromBundleName(bundleName); 175 } 176 catch (BundleInfo.InvalidBundleNameException e) 177 { 178 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 179 return; 180 } 181 182 NodeInfo nodeInfo = new NodeInfo(); 183 try 184 { 185 nodeInfo.setNodeName(nodeName); 186 } 187 catch (NodeInfo.InvalidNodeNameException e) 188 { 189 JOptionPane.showMessageDialog(this, "Invalid name of SOFA node:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 190 return; 191 } 192 193 try 194 { 195 admin.pushBundleOffer(bundleName, nodeName); 196 } 197 catch (RemoteException e) 198 { 199 JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE); 200 dispose(); 201 return; 202 } 203 catch (RMIAdminException e) 204 { 205 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 206 dispose(); 207 return; 208 } 209 210 JOptionPane.showMessageDialog(this, "Bundle offer '" + bundleName + "' has been scheduled to push to node '" + nodeName + "'"); 211 212 isOK = true; 213 dispose(); 214 } 216 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 219 } 221 222 private javax.swing.JLabel bundleNameLabel; 224 private javax.swing.JTextField bundleNameTextField; 225 private javax.swing.JButton cancelButton; 226 private javax.swing.JButton chooseBundleOfferButton; 227 private javax.swing.JPanel jPanel1; 228 private javax.swing.JPanel jPanel2; 229 private javax.swing.JPanel jPanel3; 230 private javax.swing.JPanel jPanel4; 231 private javax.swing.JPanel jPanel5; 232 private javax.swing.JLabel nodeNameLabel; 233 private javax.swing.JTextField nodeNameTextField; 234 private javax.swing.JButton pushBundleOfferButton; 235 237 } 238 | Popular Tags |