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 MakeBundleInSharingPresentDialog 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, boolean isShareManager) 27 { 28 Frame frame = JOptionPane.getFrameForComponent(frameComp); 29 MakeBundleInSharingPresentDialog dialog = new MakeBundleInSharingPresentDialog(frame, true, admin, defaultBundleName, isShareManager); 30 dialog.setLocationRelativeTo(frameComp); 31 dialog.setVisible(true); 32 return dialog.isOK(); 33 } 34 35 36 public MakeBundleInSharingPresentDialog(java.awt.Frame parent, boolean modal, RMIAdminInterface admin, String defaultBundleName, boolean isShareManager) 37 { 38 super(parent, modal); 39 this.admin = admin; 40 isOK = false; 41 initComponents(); 42 43 bundleNameTextField.setText(defaultBundleName); 44 if (isShareManager) shareManagerRadioButton.setSelected(true); 45 else shareClientRadioButton.setSelected(true); 46 } 47 48 public boolean isOK() 49 { 50 return isOK; 51 } 52 53 58 private void initComponents() { 60 buttonGroup = new javax.swing.ButtonGroup (); 61 jPanel4 = new javax.swing.JPanel (); 62 jPanel1 = new javax.swing.JPanel (); 63 jPanel5 = new javax.swing.JPanel (); 64 bundleNameLabel = new javax.swing.JLabel (); 65 bundleNameTextField = new javax.swing.JTextField (); 66 shareManagerRadioButton = new javax.swing.JRadioButton (); 67 shareClientRadioButton = new javax.swing.JRadioButton (); 68 jPanel2 = new javax.swing.JPanel (); 69 chooseShareManagerButton = new javax.swing.JButton (); 70 chooseShareClientButton = new javax.swing.JButton (); 71 jPanel3 = new javax.swing.JPanel (); 72 makeBundlePresentButton = new javax.swing.JButton (); 73 cancelButton = new javax.swing.JButton (); 74 75 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 76 setTitle("Make Bundle In Sharing Present"); 77 jPanel4.setLayout(new java.awt.BorderLayout ()); 78 79 jPanel4.setMinimumSize(new java.awt.Dimension (400, 93)); 80 jPanel4.setPreferredSize(new java.awt.Dimension (400, 180)); 81 jPanel1.setLayout(new java.awt.BorderLayout ()); 82 83 jPanel1.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (1, 10, 1, 10))); 84 jPanel1.setMinimumSize(new java.awt.Dimension (26, 23)); 85 jPanel1.setPreferredSize(new java.awt.Dimension (26, 23)); 86 jPanel5.setLayout(new java.awt.GridLayout (4, 0)); 87 88 bundleNameLabel.setText("Bundle Name:"); 89 jPanel5.add(bundleNameLabel); 90 91 bundleNameTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 92 bundleNameTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 93 jPanel5.add(bundleNameTextField); 94 95 shareManagerRadioButton.setSelected(true); 96 shareManagerRadioButton.setText("Share Manager"); 97 buttonGroup.add(shareManagerRadioButton); 98 jPanel5.add(shareManagerRadioButton); 99 100 shareClientRadioButton.setText("Share Client"); 101 buttonGroup.add(shareClientRadioButton); 102 jPanel5.add(shareClientRadioButton); 103 104 jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH); 105 106 jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER); 107 108 chooseShareManagerButton.setText("Choose Share Manager"); 109 chooseShareManagerButton.addActionListener(new java.awt.event.ActionListener () 110 { 111 public void actionPerformed(java.awt.event.ActionEvent evt) 112 { 113 chooseShareManagerButtonActionPerformed(evt); 114 } 115 }); 116 117 jPanel2.add(chooseShareManagerButton); 118 119 chooseShareClientButton.setText("Choose Share Client"); 120 chooseShareClientButton.addActionListener(new java.awt.event.ActionListener () 121 { 122 public void actionPerformed(java.awt.event.ActionEvent evt) 123 { 124 chooseShareClientButtonActionPerformed(evt); 125 } 126 }); 127 128 jPanel2.add(chooseShareClientButton); 129 130 jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH); 131 132 makeBundlePresentButton.setText("Make Bundle Present"); 133 makeBundlePresentButton.addActionListener(new java.awt.event.ActionListener () 134 { 135 public void actionPerformed(java.awt.event.ActionEvent evt) 136 { 137 makeBundlePresentButtonActionPerformed(evt); 138 } 139 }); 140 141 jPanel3.add(makeBundlePresentButton); 142 143 cancelButton.setText("Cancel"); 144 cancelButton.addActionListener(new java.awt.event.ActionListener () 145 { 146 public void actionPerformed(java.awt.event.ActionEvent evt) 147 { 148 cancelButtonActionPerformed(evt); 149 } 150 }); 151 152 jPanel3.add(cancelButton); 153 154 jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH); 155 156 getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER); 157 158 pack(); 159 } 161 private void chooseShareClientButtonActionPerformed(java.awt.event.ActionEvent evt) { LocalInfoDesc[] localInfoDescs = null; 164 try 165 { 166 localInfoDescs = admin.localInfoDescsList(); 167 } 168 catch (RemoteException e) 169 { 170 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 171 return; 172 } 173 174 int size = 0; 175 int i; 176 for (i = 0; i < localInfoDescs.length; i++) 177 { 178 if (localInfoDescs[i].isShareClient()) size++; 179 } 180 181 LocalInfoDesc[] shareClients = new LocalInfoDesc[size]; 182 int j = 0; 183 for (i = 0; i < localInfoDescs.length; i++) 184 { 185 if (localInfoDescs[i].isShareClient()) 186 { 187 shareClients[j++] = localInfoDescs[i]; 188 } 189 } 190 191 Arrays.sort(shareClients); 192 193 LocalInfoDesc result = (LocalInfoDesc)ListDialog.showDialog(this, this, "Bundles in Share Client Mode:", "Choose Share Client", shareClients, null, null, false, true); 194 if (result != null) 195 { 196 bundleNameTextField.setText(result.bundleName); 197 shareClientRadioButton.setSelected(true); 198 } 199 } 201 private void chooseShareManagerButtonActionPerformed(java.awt.event.ActionEvent evt) { LocalInfoDesc[] localInfoDescs = null; 204 try 205 { 206 localInfoDescs = admin.localInfoDescsList(); 207 } 208 catch (RemoteException e) 209 { 210 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 211 return; 212 } 213 214 int size = 0; 215 int i; 216 for (i = 0; i < localInfoDescs.length; i++) 217 { 218 if (localInfoDescs[i].isShareManager()) size++; 219 } 220 221 LocalInfoDesc[] shareManagers = new LocalInfoDesc[size]; 222 int j = 0; 223 for (i = 0; i < localInfoDescs.length; i++) 224 { 225 if (localInfoDescs[i].isShareManager()) 226 { 227 shareManagers[j++] = localInfoDescs[i]; 228 } 229 } 230 231 Arrays.sort(shareManagers); 232 233 LocalInfoDesc result = (LocalInfoDesc)ListDialog.showDialog(this, this, "Bundles in Share Manager Mode:", "Choose Share Manager", shareManagers, null, null, false, true); 234 if (result != null) 235 { 236 bundleNameTextField.setText(result.bundleName); 237 shareManagerRadioButton.setSelected(true); 238 } 239 } 241 private void makeBundlePresentButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = bundleNameTextField.getText(); 244 boolean isShareManager = shareManagerRadioButton.isSelected(); 245 246 BundleInfo bundleInfo = new BundleInfo(); 247 try 248 { 249 bundleInfo.fromBundleName(bundleName); 250 } 251 catch (BundleInfo.InvalidBundleNameException e) 252 { 253 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 254 return; 255 } 256 257 try 258 { 259 if (isShareManager) admin.makeShareClientsReturnBundle(bundleName); 260 else admin.acquireSharedBundle(bundleName, null, false); 261 } 262 catch (RemoteException e) 263 { 264 JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE); 265 dispose(); 266 return; 267 } 268 catch (RMIAdminException e) 269 { 270 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 271 dispose(); 272 return; 273 } 274 275 JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' successfully made present"); 276 277 isOK = true; 278 dispose(); 279 } 281 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 284 } 286 287 private javax.swing.JLabel bundleNameLabel; 289 private javax.swing.JTextField bundleNameTextField; 290 private javax.swing.ButtonGroup buttonGroup; 291 private javax.swing.JButton cancelButton; 292 private javax.swing.JButton chooseShareClientButton; 293 private javax.swing.JButton chooseShareManagerButton; 294 private javax.swing.JPanel jPanel1; 295 private javax.swing.JPanel jPanel2; 296 private javax.swing.JPanel jPanel3; 297 private javax.swing.JPanel jPanel4; 298 private javax.swing.JPanel jPanel5; 299 private javax.swing.JButton makeBundlePresentButton; 300 private javax.swing.JRadioButton shareClientRadioButton; 301 private javax.swing.JRadioButton shareManagerRadioButton; 302 304 } 305 | Popular Tags |