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 TestPullBundleDialog 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 TestPullBundleDialog dialog = new TestPullBundleDialog(frame, true, admin, defaultBundleName); 32 dialog.setLocationRelativeTo(frameComp); 33 dialog.setVisible(true); 34 return dialog.isOK(); 35 } 36 37 38 public TestPullBundleDialog(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 jPanel3 = new javax.swing.JPanel (); 70 testPullButton = new javax.swing.JButton (); 71 cancelButton = new javax.swing.JButton (); 72 73 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 74 setTitle("Test Pull 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 (6, 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 contractIDLabel.setText("Contract ID (leave empty for no contract):"); 101 jPanel5.add(contractIDLabel); 102 103 contractIDTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 104 contractIDTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 105 jPanel5.add(contractIDTextField); 106 107 jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH); 108 109 jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER); 110 111 testPullButton.setText("Test Pull Bundle"); 112 testPullButton.addActionListener(new java.awt.event.ActionListener () 113 { 114 public void actionPerformed(java.awt.event.ActionEvent evt) 115 { 116 testPullButtonActionPerformed(evt); 117 } 118 }); 119 120 jPanel3.add(testPullButton); 121 122 cancelButton.setText("Cancel"); 123 cancelButton.addActionListener(new java.awt.event.ActionListener () 124 { 125 public void actionPerformed(java.awt.event.ActionEvent evt) 126 { 127 cancelButtonActionPerformed(evt); 128 } 129 }); 130 131 jPanel3.add(cancelButton); 132 133 jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH); 134 135 getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER); 136 137 pack(); 138 } 140 private void testPullButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = bundleNameTextField.getText(); 143 String nodeName = nodeNameTextField.getText(); 144 String contractID = contractIDTextField.getText(); 145 146 BundleInfo bundleInfo = new BundleInfo(); 147 try 148 { 149 bundleInfo.fromBundleName(bundleName); 150 } 151 catch (BundleInfo.InvalidBundleNameException e) 152 { 153 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 154 return; 155 } 156 157 NodeInfo nodeInfo = new NodeInfo(); 158 try 159 { 160 nodeInfo.setNodeName(nodeName); 161 } 162 catch (NodeInfo.InvalidNodeNameException e) 163 { 164 JOptionPane.showMessageDialog(this, "Invalid name of SOFA node:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 165 return; 166 } 167 168 boolean result = false; 169 try 170 { 171 result = admin.testPull(bundleName, nodeName, contractID); 172 } 173 catch (RemoteException e) 174 { 175 JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE); 176 dispose(); 177 return; 178 } 179 catch (RMIAdminException e) 180 { 181 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 182 dispose(); 183 return; 184 } 185 186 if (result) JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' can be pulled from node '" + nodeName + "'"); 187 else JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' CAN NOT be pulled from node '" + nodeName + "'!"); 188 189 isOK = true; 190 dispose(); 191 } 193 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 196 } 198 199 private javax.swing.JLabel bundleNameLabel; 201 private javax.swing.JTextField bundleNameTextField; 202 private javax.swing.JButton cancelButton; 203 private javax.swing.JLabel contractIDLabel; 204 private javax.swing.JTextField contractIDTextField; 205 private javax.swing.JPanel jPanel1; 206 private javax.swing.JPanel jPanel3; 207 private javax.swing.JPanel jPanel4; 208 private javax.swing.JPanel jPanel5; 209 private javax.swing.JLabel nodeNameLabel; 210 private javax.swing.JTextField nodeNameTextField; 211 private javax.swing.JButton testPullButton; 212 214 } 215 | Popular Tags |