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 StopShareClientDialog 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 StopShareClientDialog dialog = new StopShareClientDialog(frame, true, admin, defaultBundleName); 30 dialog.setLocationRelativeTo(frameComp); 31 dialog.setVisible(true); 32 return dialog.isOK(); 33 } 34 35 36 public StopShareClientDialog(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 returnLicenceCheckBox = new javax.swing.JCheckBox (); 64 forcelCheckBox = new javax.swing.JCheckBox (); 65 jPanel2 = new javax.swing.JPanel (); 66 chooseShareClientButton = new javax.swing.JButton (); 67 jPanel3 = new javax.swing.JPanel (); 68 stopShareClientButton = new javax.swing.JButton (); 69 cancelButton = new javax.swing.JButton (); 70 71 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 72 setTitle("Stop Share Client"); 73 jPanel4.setLayout(new java.awt.BorderLayout ()); 74 75 jPanel4.setMinimumSize(new java.awt.Dimension (400, 93)); 76 jPanel4.setPreferredSize(new java.awt.Dimension (400, 170)); 77 jPanel1.setLayout(new java.awt.BorderLayout ()); 78 79 jPanel1.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (1, 10, 1, 10))); 80 jPanel1.setMinimumSize(new java.awt.Dimension (26, 23)); 81 jPanel1.setPreferredSize(new java.awt.Dimension (26, 23)); 82 jPanel5.setLayout(new java.awt.GridLayout (4, 0)); 83 84 bundleNameLabel.setText("Bundle Name:"); 85 jPanel5.add(bundleNameLabel); 86 87 bundleNameTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 88 bundleNameTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 89 jPanel5.add(bundleNameTextField); 90 91 returnLicenceCheckBox.setSelected(true); 92 returnLicenceCheckBox.setText("Return Licence to Share Manager (if needed)"); 93 jPanel5.add(returnLicenceCheckBox); 94 95 forcelCheckBox.setText("Force (stop Share Client even if licence cannot be returned to Share Manager)"); 96 jPanel5.add(forcelCheckBox); 97 98 jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH); 99 100 jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER); 101 102 chooseShareClientButton.setText("Choose Share Client"); 103 chooseShareClientButton.addActionListener(new java.awt.event.ActionListener () 104 { 105 public void actionPerformed(java.awt.event.ActionEvent evt) 106 { 107 chooseShareClientButtonActionPerformed(evt); 108 } 109 }); 110 111 jPanel2.add(chooseShareClientButton); 112 113 jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH); 114 115 stopShareClientButton.setText("Stop Share Client"); 116 stopShareClientButton.addActionListener(new java.awt.event.ActionListener () 117 { 118 public void actionPerformed(java.awt.event.ActionEvent evt) 119 { 120 stopShareClientButtonActionPerformed(evt); 121 } 122 }); 123 124 jPanel3.add(stopShareClientButton); 125 126 cancelButton.setText("Cancel"); 127 cancelButton.addActionListener(new java.awt.event.ActionListener () 128 { 129 public void actionPerformed(java.awt.event.ActionEvent evt) 130 { 131 cancelButtonActionPerformed(evt); 132 } 133 }); 134 135 jPanel3.add(cancelButton); 136 137 jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH); 138 139 getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER); 140 141 pack(); 142 } 144 private void chooseShareClientButtonActionPerformed(java.awt.event.ActionEvent evt) { LocalInfoDesc[] localInfoDescs = null; 147 try 148 { 149 localInfoDescs = admin.localInfoDescsList(); 150 } 151 catch (RemoteException e) 152 { 153 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 154 return; 155 } 156 157 int size = 0; 158 int i; 159 for (i = 0; i < localInfoDescs.length; i++) 160 { 161 if (localInfoDescs[i].isShareClient()) size++; 162 } 163 164 LocalInfoDesc[] shareClients = new LocalInfoDesc[size]; 165 int j = 0; 166 for (i = 0; i < localInfoDescs.length; i++) 167 { 168 if (localInfoDescs[i].isShareClient()) 169 { 170 shareClients[j++] = localInfoDescs[i]; 171 } 172 } 173 174 Arrays.sort(shareClients); 175 176 LocalInfoDesc result = (LocalInfoDesc)ListDialog.showDialog(this, this, "Bundles in Share Client Mode:", "Choose Share Client to Install", shareClients, null, null, false, true); 177 if (result != null) bundleNameTextField.setText(result.bundleName); 178 179 } 181 private void stopShareClientButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = bundleNameTextField.getText(); 184 boolean returnLicence = returnLicenceCheckBox.isSelected(); 185 boolean force = forcelCheckBox.isSelected(); 186 187 BundleInfo bundleInfo = new BundleInfo(); 188 try 189 { 190 bundleInfo.fromBundleName(bundleName); 191 } 192 catch (BundleInfo.InvalidBundleNameException e) 193 { 194 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 195 return; 196 } 197 198 try 199 { 200 admin.stopShareClientOfBundle(bundleName, returnLicence, force); 201 } 202 catch (RemoteException e) 203 { 204 JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE); 205 dispose(); 206 return; 207 } 208 catch (RMIAdminException e) 209 { 210 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 211 dispose(); 212 return; 213 } 214 215 JOptionPane.showMessageDialog(this, "Share client of bundle '" + bundleName + "' successfully stopped"); 216 217 isOK = true; 218 dispose(); 219 } 221 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 224 } 226 227 private javax.swing.JLabel bundleNameLabel; 229 private javax.swing.JTextField bundleNameTextField; 230 private javax.swing.JButton cancelButton; 231 private javax.swing.JButton chooseShareClientButton; 232 private javax.swing.JCheckBox forcelCheckBox; 233 private javax.swing.JPanel jPanel1; 234 private javax.swing.JPanel jPanel2; 235 private javax.swing.JPanel jPanel3; 236 private javax.swing.JPanel jPanel4; 237 private javax.swing.JPanel jPanel5; 238 private javax.swing.JCheckBox returnLicenceCheckBox; 239 private javax.swing.JButton stopShareClientButton; 240 242 } 243 | Popular Tags |