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 PullBundleDialog 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 PullBundleDialog dialog = new PullBundleDialog(frame, true, admin, defaultBundleName); 32 dialog.setLocationRelativeTo(frameComp); 33 dialog.setVisible(true); 34 return dialog.isOK(); 35 } 36 37 38 public PullBundleDialog(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 contractIDLabel = new javax.swing.JLabel (); 68 contractIDTextField = new javax.swing.JTextField (); 69 synchroCheckBox = new javax.swing.JCheckBox (); 70 jPanel3 = new javax.swing.JPanel (); 71 pullButton = new javax.swing.JButton (); 72 cancelButton = new javax.swing.JButton (); 73 74 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 75 setTitle("Pull Bundle"); 76 jPanel4.setLayout(new java.awt.BorderLayout ()); 77 78 jPanel4.setMinimumSize(new java.awt.Dimension (400, 93)); 79 jPanel4.setPreferredSize(new java.awt.Dimension (400, 210)); 80 jPanel1.setLayout(new java.awt.BorderLayout ()); 81 82 jPanel1.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (1, 10, 1, 10))); 83 jPanel1.setMinimumSize(new java.awt.Dimension (26, 23)); 84 jPanel1.setPreferredSize(new java.awt.Dimension (26, 23)); 85 jPanel5.setLayout(new java.awt.GridLayout (7, 0)); 86 87 bundleNameLabel.setText("Bundle Name:"); 88 jPanel5.add(bundleNameLabel); 89 90 bundleNameTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 91 bundleNameTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 92 jPanel5.add(bundleNameTextField); 93 94 nodeNameLabel.setText("Node name:"); 95 jPanel5.add(nodeNameLabel); 96 97 nodeNameTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 98 nodeNameTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 99 jPanel5.add(nodeNameTextField); 100 101 contractIDLabel.setText("Contract ID (leave empty for no contract):"); 102 jPanel5.add(contractIDLabel); 103 104 contractIDTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 105 contractIDTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 106 jPanel5.add(contractIDTextField); 107 108 synchroCheckBox.setSelected(true); 109 synchroCheckBox.setText("Synchronous"); 110 jPanel5.add(synchroCheckBox); 111 112 jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH); 113 114 jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER); 115 116 pullButton.setText("Pull Bundle"); 117 pullButton.addActionListener(new java.awt.event.ActionListener () 118 { 119 public void actionPerformed(java.awt.event.ActionEvent evt) 120 { 121 pullButtonActionPerformed(evt); 122 } 123 }); 124 125 jPanel3.add(pullButton); 126 127 cancelButton.setText("Cancel"); 128 cancelButton.addActionListener(new java.awt.event.ActionListener () 129 { 130 public void actionPerformed(java.awt.event.ActionEvent evt) 131 { 132 cancelButtonActionPerformed(evt); 133 } 134 }); 135 136 jPanel3.add(cancelButton); 137 138 jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH); 139 140 getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER); 141 142 pack(); 143 } 145 private void pullButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = bundleNameTextField.getText(); 148 String nodeName = nodeNameTextField.getText(); 149 String contractID = contractIDTextField.getText(); 150 boolean synchro = synchroCheckBox.isSelected(); 151 152 BundleInfo bundleInfo = new BundleInfo(); 153 try 154 { 155 bundleInfo.fromBundleName(bundleName); 156 } 157 catch (BundleInfo.InvalidBundleNameException e) 158 { 159 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 160 return; 161 } 162 163 NodeInfo nodeInfo = new NodeInfo(); 164 try 165 { 166 nodeInfo.setNodeName(nodeName); 167 } 168 catch (NodeInfo.InvalidNodeNameException e) 169 { 170 JOptionPane.showMessageDialog(this, "Invalid name of SOFA node:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 171 return; 172 } 173 174 try 175 { 176 admin.pullBundle(bundleName, nodeName, contractID, synchro); 177 } 178 catch (RemoteException e) 179 { 180 JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE); 181 dispose(); 182 return; 183 } 184 catch (RMIAdminException e) 185 { 186 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 187 dispose(); 188 return; 189 } 190 191 if (synchro) JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' has been pulled from node '" + nodeName + "'"); 192 else JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' has been scheduled to pull from node '" + nodeName + "'!"); 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.JLabel contractIDLabel; 209 private javax.swing.JTextField contractIDTextField; 210 private javax.swing.JPanel jPanel1; 211 private javax.swing.JPanel jPanel3; 212 private javax.swing.JPanel jPanel4; 213 private javax.swing.JPanel jPanel5; 214 private javax.swing.JLabel nodeNameLabel; 215 private javax.swing.JTextField nodeNameTextField; 216 private javax.swing.JButton pullButton; 217 private javax.swing.JCheckBox synchroCheckBox; 218 220 } 221 | Popular Tags |