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 AcquireSharedBundleDialog 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, String defaultNodeName) 29 { 30 Frame frame = JOptionPane.getFrameForComponent(frameComp); 31 AcquireSharedBundleDialog dialog = new AcquireSharedBundleDialog(frame, true, admin, defaultBundleName, defaultNodeName); 32 dialog.setLocationRelativeTo(frameComp); 33 dialog.setVisible(true); 34 return dialog.isOK(); 35 } 36 37 38 public AcquireSharedBundleDialog(java.awt.Frame parent, boolean modal, RMIAdminInterface admin, String defaultBundleName, String defaultNodeName) 39 { 40 super(parent, modal); 41 this.admin = admin; 42 isOK = false; 43 initComponents(); 44 45 bundleNameTextField.setText(defaultBundleName); 46 nodeNameTextField.setText(defaultNodeName); 47 } 48 49 public boolean isOK() 50 { 51 return isOK; 52 } 53 54 59 private void initComponents() { 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 nodeNameLabel = new javax.swing.JLabel (); 67 nodeNameTextField = new javax.swing.JTextField (); 68 tryNoShareClientCheckBox = new javax.swing.JCheckBox (); 69 jPanel3 = new javax.swing.JPanel (); 70 acquireShareBundleButton = new javax.swing.JButton (); 71 cancelButton = new javax.swing.JButton (); 72 73 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 74 setTitle("Acquire Shared 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, 180)); 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 (7, 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 tryNoShareClientCheckBox.setSelected(true); 101 tryNoShareClientCheckBox.setText("Try to store to Binary Bundles without starting Share Client"); 102 jPanel5.add(tryNoShareClientCheckBox); 103 104 jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH); 105 106 jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER); 107 108 acquireShareBundleButton.setText("Acquire Shared Bundle"); 109 acquireShareBundleButton.addActionListener(new java.awt.event.ActionListener () 110 { 111 public void actionPerformed(java.awt.event.ActionEvent evt) 112 { 113 acquireShareBundleButtonActionPerformed(evt); 114 } 115 }); 116 117 jPanel3.add(acquireShareBundleButton); 118 119 cancelButton.setText("Cancel"); 120 cancelButton.addActionListener(new java.awt.event.ActionListener () 121 { 122 public void actionPerformed(java.awt.event.ActionEvent evt) 123 { 124 cancelButtonActionPerformed(evt); 125 } 126 }); 127 128 jPanel3.add(cancelButton); 129 130 jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH); 131 132 getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER); 133 134 pack(); 135 } 137 private void acquireShareBundleButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = bundleNameTextField.getText(); 140 String nodeName = nodeNameTextField.getText(); 141 boolean tryNoShareClient = tryNoShareClientCheckBox.isSelected(); 142 143 BundleInfo bundleInfo = new BundleInfo(); 144 try 145 { 146 bundleInfo.fromBundleName(bundleName); 147 } 148 catch (BundleInfo.InvalidBundleNameException e) 149 { 150 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 151 return; 152 } 153 154 NodeInfo nodeInfo = new NodeInfo(); 155 try 156 { 157 nodeInfo.setNodeName(nodeName); 158 } 159 catch (NodeInfo.InvalidNodeNameException e) 160 { 161 JOptionPane.showMessageDialog(this, "Invalid name of SOFA node:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 162 return; 163 } 164 165 try 166 { 167 admin.acquireSharedBundle(bundleName, nodeName, tryNoShareClient); 168 } 169 catch (RemoteException e) 170 { 171 JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE); 172 dispose(); 173 return; 174 } 175 catch (RMIAdminException e) 176 { 177 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 178 dispose(); 179 return; 180 } 181 182 JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' successfully acquired from '" + nodeName + "'"); 183 184 isOK = true; 185 dispose(); 186 } 188 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 191 } 193 194 private javax.swing.JButton acquireShareBundleButton; 196 private javax.swing.JLabel bundleNameLabel; 197 private javax.swing.JTextField bundleNameTextField; 198 private javax.swing.JButton cancelButton; 199 private javax.swing.JPanel jPanel1; 200 private javax.swing.JPanel jPanel3; 201 private javax.swing.JPanel jPanel4; 202 private javax.swing.JPanel jPanel5; 203 private javax.swing.JLabel nodeNameLabel; 204 private javax.swing.JTextField nodeNameTextField; 205 private javax.swing.JCheckBox tryNoShareClientCheckBox; 206 208 } 209 | Popular Tags |