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 PushBundleDialog 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 PushBundleDialog dialog = new PushBundleDialog(frame, true, admin, defaultBundleName); 32 dialog.setLocationRelativeTo(frameComp); 33 dialog.setVisible(true); 34 return dialog.isOK(); 35 } 36 37 38 public PushBundleDialog(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 numberOfLicencesLabel = new javax.swing.JLabel (); 68 numberOfLicencesTextField = new javax.swing.JTextField (); 69 warnLabel = new javax.swing.JLabel (); 70 jPanel2 = new javax.swing.JPanel (); 71 chooseBinaryBundleButton = new javax.swing.JButton (); 72 showLicenceButton = new javax.swing.JButton (); 73 jPanel3 = new javax.swing.JPanel (); 74 pushButton = new javax.swing.JButton (); 75 cancelButton = new javax.swing.JButton (); 76 77 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 78 setTitle("Push Bundle"); 79 jPanel4.setLayout(new java.awt.BorderLayout ()); 80 81 jPanel4.setMinimumSize(new java.awt.Dimension (400, 93)); 82 jPanel4.setPreferredSize(new java.awt.Dimension (400, 230)); 83 jPanel1.setLayout(new java.awt.BorderLayout ()); 84 85 jPanel1.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (1, 10, 1, 10))); 86 jPanel1.setMinimumSize(new java.awt.Dimension (26, 23)); 87 jPanel1.setPreferredSize(new java.awt.Dimension (26, 23)); 88 jPanel5.setLayout(new java.awt.GridLayout (7, 0)); 89 90 bundleNameLabel.setText("Bundle Name:"); 91 jPanel5.add(bundleNameLabel); 92 93 bundleNameTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 94 bundleNameTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 95 jPanel5.add(bundleNameTextField); 96 97 nodeNameLabel.setText("Node name:"); 98 jPanel5.add(nodeNameLabel); 99 100 nodeNameTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 101 nodeNameTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 102 jPanel5.add(nodeNameTextField); 103 104 numberOfLicencesLabel.setText("Number of Licences (leave empty for 'all'/'no licences'):"); 105 jPanel5.add(numberOfLicencesLabel); 106 107 numberOfLicencesTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 108 numberOfLicencesTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 109 jPanel5.add(numberOfLicencesTextField); 110 111 warnLabel.setText("'Number of Licences' has no effect if Contract is present."); 112 jPanel5.add(warnLabel); 113 114 jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH); 115 116 jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER); 117 118 chooseBinaryBundleButton.setText("Choose Binary Bundle"); 119 chooseBinaryBundleButton.addActionListener(new java.awt.event.ActionListener () 120 { 121 public void actionPerformed(java.awt.event.ActionEvent evt) 122 { 123 chooseBinaryBundleButtonActionPerformed(evt); 124 } 125 }); 126 127 jPanel2.add(chooseBinaryBundleButton); 128 129 showLicenceButton.setText("Show Licence of Selected Bundle"); 130 showLicenceButton.addActionListener(new java.awt.event.ActionListener () 131 { 132 public void actionPerformed(java.awt.event.ActionEvent evt) 133 { 134 showLicenceButtonActionPerformed(evt); 135 } 136 }); 137 138 jPanel2.add(showLicenceButton); 139 140 jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH); 141 142 pushButton.setText("Push Bundle"); 143 pushButton.addActionListener(new java.awt.event.ActionListener () 144 { 145 public void actionPerformed(java.awt.event.ActionEvent evt) 146 { 147 pushButtonActionPerformed(evt); 148 } 149 }); 150 151 jPanel3.add(pushButton); 152 153 cancelButton.setText("Cancel"); 154 cancelButton.addActionListener(new java.awt.event.ActionListener () 155 { 156 public void actionPerformed(java.awt.event.ActionEvent evt) 157 { 158 cancelButtonActionPerformed(evt); 159 } 160 }); 161 162 jPanel3.add(cancelButton); 163 164 jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH); 165 166 getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER); 167 168 pack(); 169 } 171 private void showLicenceButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = bundleNameTextField.getText(); 174 175 BundleInfo bundleInfo = new BundleInfo(); 176 try 177 { 178 bundleInfo.fromBundleName(bundleName); 179 } 180 catch (BundleInfo.InvalidBundleNameException e) 181 { 182 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 183 return; 184 } 185 186 Licence licence = null; 187 try 188 { 189 licence = admin.getLicence(bundleName); 190 } 191 catch (RemoteException e) 192 { 193 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 194 return; 195 } 196 197 if (licence != null) 198 { 199 LicenceEditDialog.showDialog(this, licence, false, "Licence File of '" + bundleName + "'"); 200 } 201 else 202 { 203 JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' is not limited by licence", "No Licence File Present", JOptionPane.INFORMATION_MESSAGE); 204 } 205 } 207 private void chooseBinaryBundleButtonActionPerformed(java.awt.event.ActionEvent evt) { String [] bundles = null; 210 try 211 { 212 bundles = admin.binBundlesList(); 213 } 214 catch (RemoteException e) 215 { 216 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 217 return; 218 } 219 220 Arrays.sort(bundles); 221 222 String result = ListDialog.showDialog(this, this, "Binary Bundles:", "Choose Binary Bundle to Push", bundles, null, null, false, true); 223 if (result.length() != 0) bundleNameTextField.setText(result); 224 225 } 227 private void pushButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = bundleNameTextField.getText(); 230 String nodeName = nodeNameTextField.getText(); 231 String numberOfLicencesText = numberOfLicencesTextField.getText().trim(); 232 233 BundleInfo bundleInfo = new BundleInfo(); 234 try 235 { 236 bundleInfo.fromBundleName(bundleName); 237 } 238 catch (BundleInfo.InvalidBundleNameException e) 239 { 240 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 241 return; 242 } 243 244 NodeInfo nodeInfo = new NodeInfo(); 245 try 246 { 247 nodeInfo.setNodeName(nodeName); 248 } 249 catch (NodeInfo.InvalidNodeNameException e) 250 { 251 JOptionPane.showMessageDialog(this, "Invalid name of SOFA node:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 252 return; 253 } 254 255 int numberOfLicences = Licence.ALL_LICENCES; 256 if (numberOfLicencesText.length() != 0) 257 { 258 try 259 { 260 numberOfLicences = Integer.parseInt(numberOfLicencesText); 261 if (numberOfLicences < 0) throw new NumberFormatException ("Negative 'Number of Licences' is not allowed"); 262 } 263 catch (NumberFormatException e) 264 { 265 JOptionPane.showMessageDialog(this, "Error occured while parsing 'Number of Copies':\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 266 return; 267 } 268 } 269 270 try 271 { 272 admin.pushBundle(bundleName, nodeName, numberOfLicences); 273 } 274 catch (RemoteException e) 275 { 276 JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE); 277 dispose(); 278 return; 279 } 280 catch (RMIAdminException e) 281 { 282 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 283 dispose(); 284 return; 285 } 286 287 JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' has been scheduled to push to node '" + nodeName + "'"); 288 289 isOK = true; 290 dispose(); 291 } 293 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 296 } 298 299 private javax.swing.JLabel bundleNameLabel; 301 private javax.swing.JTextField bundleNameTextField; 302 private javax.swing.JButton cancelButton; 303 private javax.swing.JButton chooseBinaryBundleButton; 304 private javax.swing.JPanel jPanel1; 305 private javax.swing.JPanel jPanel2; 306 private javax.swing.JPanel jPanel3; 307 private javax.swing.JPanel jPanel4; 308 private javax.swing.JPanel jPanel5; 309 private javax.swing.JLabel nodeNameLabel; 310 private javax.swing.JTextField nodeNameTextField; 311 private javax.swing.JLabel numberOfLicencesLabel; 312 private javax.swing.JTextField numberOfLicencesTextField; 313 private javax.swing.JButton pushButton; 314 private javax.swing.JButton showLicenceButton; 315 private javax.swing.JLabel warnLabel; 316 318 } 319 | Popular Tags |