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 TestPushBundleDialog 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 TestPushBundleDialog dialog = new TestPushBundleDialog(frame, true, admin, defaultBundleName); 32 dialog.setLocationRelativeTo(frameComp); 33 dialog.setVisible(true); 34 return dialog.isOK(); 35 } 36 37 38 public TestPushBundleDialog(java.awt.Frame parent, boolean modal, RMIAdminInterface admin, String defaultBundleName) 39 { 40 super(parent, modal); 41 this.admin = admin; 42 initComponents(); 43 44 bundleNameTextField.setText(defaultBundleName); 45 } 46 47 public boolean isOK() 48 { 49 return isOK; 50 } 51 52 57 private void initComponents() { 59 jPanel4 = new javax.swing.JPanel (); 60 jPanel1 = new javax.swing.JPanel (); 61 jPanel5 = new javax.swing.JPanel (); 62 bundleNameLabel = new javax.swing.JLabel (); 63 bundleNameTextField = new javax.swing.JTextField (); 64 nodeNameLabel = new javax.swing.JLabel (); 65 nodeNameTextField = new javax.swing.JTextField (); 66 jPanel2 = new javax.swing.JPanel (); 67 chooseBinaryBundleButton = new javax.swing.JButton (); 68 showLicenceButton = new javax.swing.JButton (); 69 jPanel3 = new javax.swing.JPanel (); 70 testPushButton = new javax.swing.JButton (); 71 cancelButton = new javax.swing.JButton (); 72 73 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 74 setTitle("Test Push Bundle"); 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 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 chooseBinaryBundleButton.setText("Choose Binary Bundle"); 105 chooseBinaryBundleButton.addActionListener(new java.awt.event.ActionListener () 106 { 107 public void actionPerformed(java.awt.event.ActionEvent evt) 108 { 109 chooseBinaryBundleButtonActionPerformed(evt); 110 } 111 }); 112 113 jPanel2.add(chooseBinaryBundleButton); 114 115 showLicenceButton.setText("Show Licence of Selected Bundle"); 116 showLicenceButton.addActionListener(new java.awt.event.ActionListener () 117 { 118 public void actionPerformed(java.awt.event.ActionEvent evt) 119 { 120 showLicenceButtonActionPerformed(evt); 121 } 122 }); 123 124 jPanel2.add(showLicenceButton); 125 126 jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH); 127 128 testPushButton.setText("Test Push Bundle"); 129 testPushButton.addActionListener(new java.awt.event.ActionListener () 130 { 131 public void actionPerformed(java.awt.event.ActionEvent evt) 132 { 133 testPushButtonActionPerformed(evt); 134 } 135 }); 136 137 jPanel3.add(testPushButton); 138 139 cancelButton.setText("Cancel"); 140 cancelButton.addActionListener(new java.awt.event.ActionListener () 141 { 142 public void actionPerformed(java.awt.event.ActionEvent evt) 143 { 144 cancelButtonActionPerformed(evt); 145 } 146 }); 147 148 jPanel3.add(cancelButton); 149 150 jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH); 151 152 getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER); 153 154 pack(); 155 } 157 private void showLicenceButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = bundleNameTextField.getText(); 160 161 BundleInfo bundleInfo = new BundleInfo(); 162 try 163 { 164 bundleInfo.fromBundleName(bundleName); 165 } 166 catch (BundleInfo.InvalidBundleNameException e) 167 { 168 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 169 return; 170 } 171 172 Licence licence = null; 173 try 174 { 175 licence = admin.getLicence(bundleName); 176 } 177 catch (RemoteException e) 178 { 179 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 180 return; 181 } 182 183 if (licence != null) 184 { 185 LicenceEditDialog.showDialog(this, licence, false, "Licence File of '" + bundleName + "'"); 186 } 187 else 188 { 189 JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' is not limited by licence", "No Licence File Present", JOptionPane.INFORMATION_MESSAGE); 190 } 191 } 193 private void chooseBinaryBundleButtonActionPerformed(java.awt.event.ActionEvent evt) { String [] bundles = null; 196 try 197 { 198 bundles = admin.binBundlesList(); 199 } 200 catch (RemoteException e) 201 { 202 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 203 return; 204 } 205 206 Arrays.sort(bundles); 207 208 String result = ListDialog.showDialog(this, this, "Binary Bundles:", "Choose Binary Bundle to Test Push", bundles, null, null, false, true); 209 if (result.length() != 0) bundleNameTextField.setText(result); 210 211 } 213 private void testPushButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = bundleNameTextField.getText(); 216 String nodeName = nodeNameTextField.getText(); 217 218 BundleInfo bundleInfo = new BundleInfo(); 219 try 220 { 221 bundleInfo.fromBundleName(bundleName); 222 } 223 catch (BundleInfo.InvalidBundleNameException e) 224 { 225 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 226 return; 227 } 228 229 NodeInfo nodeInfo = new NodeInfo(); 230 try 231 { 232 nodeInfo.setNodeName(nodeName); 233 } 234 catch (NodeInfo.InvalidNodeNameException e) 235 { 236 JOptionPane.showMessageDialog(this, "Invalid name of SOFA node:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 237 return; 238 } 239 240 boolean result = false; 241 try 242 { 243 result = admin.testPush(bundleName, nodeName, false); 244 } 245 catch (RemoteException e) 246 { 247 JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE); 248 dispose(); 249 return; 250 } 251 catch (RMIAdminException e) 252 { 253 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 254 dispose(); 255 return; 256 } 257 258 if (result) JOptionPane.showMessageDialog(this, "Node '" + nodeName + "' accepts push of bundle '" + bundleName + "'"); 259 else JOptionPane.showMessageDialog(this, "Node '" + nodeName + "' DOES NOT ACCEPT push of bundle '" + bundleName + "'!"); 260 261 isOK = true; 262 dispose(); 263 } 265 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 268 } 270 271 private javax.swing.JLabel bundleNameLabel; 273 private javax.swing.JTextField bundleNameTextField; 274 private javax.swing.JButton cancelButton; 275 private javax.swing.JButton chooseBinaryBundleButton; 276 private javax.swing.JPanel jPanel1; 277 private javax.swing.JPanel jPanel2; 278 private javax.swing.JPanel jPanel3; 279 private javax.swing.JPanel jPanel4; 280 private javax.swing.JPanel jPanel5; 281 private javax.swing.JLabel nodeNameLabel; 282 private javax.swing.JTextField nodeNameTextField; 283 private javax.swing.JButton showLicenceButton; 284 private javax.swing.JButton testPushButton; 285 287 } 288 | Popular Tags |