1 6 7 package SOFA.SOFAnet.Browser; 8 9 import SOFA.SOFAnet.Admin.RMI.*; 10 import SOFA.SOFAnet.Repository.BundleInfo; 11 import javax.swing.*; 12 import java.rmi.RemoteException ; 13 import java.util.*; 14 import java.awt.Component ; 15 import java.awt.Frame ; 16 17 21 public class CreateBundleOfferDialog extends javax.swing.JDialog 22 { 23 private RMIAdminInterface admin; 24 private boolean isOK; 25 26 public static boolean showDialog(Component frameComp, RMIAdminInterface admin, String defaultBundleName) 27 { 28 Frame frame = JOptionPane.getFrameForComponent(frameComp); 29 CreateBundleOfferDialog dialog = new CreateBundleOfferDialog(frame, true, admin, defaultBundleName); 30 dialog.setLocationRelativeTo(frameComp); 31 dialog.setVisible(true); 32 return dialog.isOK(); 33 } 34 35 36 public CreateBundleOfferDialog(java.awt.Frame parent, boolean modal, RMIAdminInterface admin, String defaultBundleName) 37 { 38 super(parent, modal); 39 this.admin = admin; 40 isOK = false; 41 initComponents(); 42 43 bundleNameTextField.setText(defaultBundleName); 44 } 45 46 public boolean isOK() 47 { 48 return isOK; 49 } 50 51 56 private void initComponents() { 58 jPanel4 = new javax.swing.JPanel (); 59 jPanel1 = new javax.swing.JPanel (); 60 jPanel5 = new javax.swing.JPanel (); 61 bundleNameLabel = new javax.swing.JLabel (); 62 bundleNameTextField = new javax.swing.JTextField (); 63 overwriteCheckBox = new javax.swing.JCheckBox (); 64 jPanel2 = new javax.swing.JPanel (); 65 chooseBinaryBundleButton = new javax.swing.JButton (); 66 jPanel3 = new javax.swing.JPanel (); 67 createBundleOfferButton = new javax.swing.JButton (); 68 cancelButton = new javax.swing.JButton (); 69 70 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 71 setTitle("Create Bundle Offer"); 72 jPanel4.setLayout(new java.awt.BorderLayout ()); 73 74 jPanel4.setMinimumSize(new java.awt.Dimension (400, 93)); 75 jPanel4.setPreferredSize(new java.awt.Dimension (400, 150)); 76 jPanel1.setLayout(new java.awt.BorderLayout ()); 77 78 jPanel1.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (1, 10, 1, 10))); 79 jPanel1.setMinimumSize(new java.awt.Dimension (26, 23)); 80 jPanel1.setPreferredSize(new java.awt.Dimension (26, 23)); 81 jPanel5.setLayout(new java.awt.GridLayout (3, 0)); 82 83 bundleNameLabel.setText("Bundle Name:"); 84 jPanel5.add(bundleNameLabel); 85 86 bundleNameTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 87 bundleNameTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 88 jPanel5.add(bundleNameTextField); 89 90 overwriteCheckBox.setText("Overwrite"); 91 jPanel5.add(overwriteCheckBox); 92 93 jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH); 94 95 jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER); 96 97 chooseBinaryBundleButton.setText("Choose Binary Bundle"); 98 chooseBinaryBundleButton.addActionListener(new java.awt.event.ActionListener () 99 { 100 public void actionPerformed(java.awt.event.ActionEvent evt) 101 { 102 chooseBinaryBundleButtonActionPerformed(evt); 103 } 104 }); 105 106 jPanel2.add(chooseBinaryBundleButton); 107 108 jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH); 109 110 createBundleOfferButton.setText("Create Bundle Offer"); 111 createBundleOfferButton.addActionListener(new java.awt.event.ActionListener () 112 { 113 public void actionPerformed(java.awt.event.ActionEvent evt) 114 { 115 createBundleOfferButtonActionPerformed(evt); 116 } 117 }); 118 119 jPanel3.add(createBundleOfferButton); 120 121 cancelButton.setText("Cancel"); 122 cancelButton.addActionListener(new java.awt.event.ActionListener () 123 { 124 public void actionPerformed(java.awt.event.ActionEvent evt) 125 { 126 cancelButtonActionPerformed(evt); 127 } 128 }); 129 130 jPanel3.add(cancelButton); 131 132 jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH); 133 134 getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER); 135 136 pack(); 137 } 139 private void chooseBinaryBundleButtonActionPerformed(java.awt.event.ActionEvent evt) { String [] bundles = null; 142 try 143 { 144 bundles = admin.binBundlesList(); 145 } 146 catch (RemoteException e) 147 { 148 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 149 return; 150 } 151 152 Arrays.sort(bundles); 153 154 String result = ListDialog.showDialog(this, this, "Binary Bundles:", "Choose Binary Bundle to Create Bundle Offer", bundles, null, null, false, true); 155 if (result.length() != 0) bundleNameTextField.setText(result); 156 157 } 159 private void createBundleOfferButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = bundleNameTextField.getText(); 162 boolean overwrite = overwriteCheckBox.isSelected(); 163 164 BundleInfo bundleInfo = new BundleInfo(); 165 try 166 { 167 bundleInfo.fromBundleName(bundleName); 168 } 169 catch (BundleInfo.InvalidBundleNameException e) 170 { 171 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 172 return; 173 } 174 175 try 176 { 177 admin.createBundleOfferFromBinBundle(bundleName, overwrite); 178 } 179 catch (RemoteException e) 180 { 181 JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE); 182 dispose(); 183 return; 184 } 185 catch (RMIAdminException e) 186 { 187 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 188 dispose(); 189 return; 190 } 191 192 JOptionPane.showMessageDialog(this, "Bundle Offer '" + bundleName + "' successfully created"); 193 194 isOK = true; 195 dispose(); 196 } 198 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 201 } 203 204 private javax.swing.JLabel bundleNameLabel; 206 private javax.swing.JTextField bundleNameTextField; 207 private javax.swing.JButton cancelButton; 208 private javax.swing.JButton chooseBinaryBundleButton; 209 private javax.swing.JButton createBundleOfferButton; 210 private javax.swing.JPanel jPanel1; 211 private javax.swing.JPanel jPanel2; 212 private javax.swing.JPanel jPanel3; 213 private javax.swing.JPanel jPanel4; 214 private javax.swing.JPanel jPanel5; 215 private javax.swing.JCheckBox overwriteCheckBox; 216 218 } 219 | Popular Tags |