KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnet > Browser > UnshareBundleDialog


1 /*
2  * InstallBundleDialog.java
3  *
4  * Created on 10. květen 2004, 22:42
5  */

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 JavaDoc;
13 import java.util.*;
14 import java.awt.Component JavaDoc;
15 import java.awt.Frame JavaDoc;
16
17 /**
18  *
19  * @author Ladislav Sobr
20  */

21 public class UnshareBundleDialog extends javax.swing.JDialog JavaDoc
22 {
23   private RMIAdminInterface admin;
24   private boolean isOK;
25   
26   public static boolean showDialog(Component JavaDoc frameComp, RMIAdminInterface admin, String JavaDoc defaultBundleName)
27   {
28     Frame JavaDoc frame = JOptionPane.getFrameForComponent(frameComp);
29     UnshareBundleDialog dialog = new UnshareBundleDialog(frame, true, admin, defaultBundleName);
30     dialog.setLocationRelativeTo(frameComp);
31     dialog.setVisible(true);
32     return dialog.isOK();
33   }
34   
35   /** Creates new form UnshareBundleDialog */
36   public UnshareBundleDialog(java.awt.Frame JavaDoc parent, boolean modal, RMIAdminInterface admin, String JavaDoc 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   /** This method is called from within the constructor to
52    * initialize the form.
53    * WARNING: Do NOT modify this code. The content of this method is
54    * always regenerated by the Form Editor.
55    */

56   private void initComponents()//GEN-BEGIN:initComponents
57
{
58     jPanel4 = new javax.swing.JPanel JavaDoc();
59     jPanel1 = new javax.swing.JPanel JavaDoc();
60     jPanel5 = new javax.swing.JPanel JavaDoc();
61     bundleNameLabel = new javax.swing.JLabel JavaDoc();
62     bundleNameTextField = new javax.swing.JTextField JavaDoc();
63     recoverCheckBox = new javax.swing.JCheckBox JavaDoc();
64     forcelCheckBox = new javax.swing.JCheckBox JavaDoc();
65     jPanel2 = new javax.swing.JPanel JavaDoc();
66     chooseSharedBundleButton = new javax.swing.JButton JavaDoc();
67     jPanel3 = new javax.swing.JPanel JavaDoc();
68     unsharelButton = new javax.swing.JButton JavaDoc();
69     cancelButton = new javax.swing.JButton JavaDoc();
70
71     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
72     setTitle("Unshare Bundle");
73     jPanel4.setLayout(new java.awt.BorderLayout JavaDoc());
74
75     jPanel4.setMinimumSize(new java.awt.Dimension JavaDoc(400, 93));
76     jPanel4.setPreferredSize(new java.awt.Dimension JavaDoc(400, 170));
77     jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
78
79     jPanel1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(1, 10, 1, 10)));
80     jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(26, 23));
81     jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(26, 23));
82     jPanel5.setLayout(new java.awt.GridLayout JavaDoc(4, 0));
83
84     bundleNameLabel.setText("Bundle Name:");
85     jPanel5.add(bundleNameLabel);
86
87     bundleNameTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
88     bundleNameTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
89     jPanel5.add(bundleNameTextField);
90
91     recoverCheckBox.setSelected(true);
92     recoverCheckBox.setText("Recover Licences from Share Clients");
93     jPanel5.add(recoverCheckBox);
94
95     forcelCheckBox.setText("Force (unshare even if not all licences recovered)");
96     jPanel5.add(forcelCheckBox);
97
98     jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH);
99
100     jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER);
101
102     chooseSharedBundleButton.setText("Choose Shared Bundle");
103     chooseSharedBundleButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
104     {
105       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
106       {
107         chooseSharedBundleButtonActionPerformed(evt);
108       }
109     });
110
111     jPanel2.add(chooseSharedBundleButton);
112
113     jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH);
114
115     unsharelButton.setText("Unshare Bundle");
116     unsharelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
117     {
118       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
119       {
120         unsharelButtonActionPerformed(evt);
121       }
122     });
123
124     jPanel3.add(unsharelButton);
125
126     cancelButton.setText("Cancel");
127     cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
128     {
129       public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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   }//GEN-END:initComponents
143

144   private void chooseSharedBundleButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_chooseSharedBundleButtonActionPerformed
145
{//GEN-HEADEREND:event_chooseSharedBundleButtonActionPerformed
146
LocalInfoDesc[] localInfoDescs = null;
147     try
148     {
149       localInfoDescs = admin.localInfoDescsList();
150     }
151     catch (RemoteException JavaDoc 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].isShareManager()) size++;
162     }
163     
164     LocalInfoDesc[] shareManagers = new LocalInfoDesc[size];
165     int j = 0;
166     for (i = 0; i < localInfoDescs.length; i++)
167     {
168       if (localInfoDescs[i].isShareManager())
169       {
170         shareManagers[j++] = localInfoDescs[i];
171       }
172     }
173
174     Arrays.sort(shareManagers);
175     
176     LocalInfoDesc result = (LocalInfoDesc)ListDialog.showDialog(this, this, "Shared Bundles (in Share Mananger Mode):", "Choose Shared Bundle to Unshare", shareManagers, null, null, false, true);
177     if (result != null) bundleNameTextField.setText(result.bundleName);
178   }//GEN-LAST:event_chooseSharedBundleButtonActionPerformed
179

180   private void unsharelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_unsharelButtonActionPerformed
181
{//GEN-HEADEREND:event_unsharelButtonActionPerformed
182
String JavaDoc bundleName = bundleNameTextField.getText();
183     boolean recoverLicences = recoverCheckBox.isSelected();
184     boolean force = forcelCheckBox.isSelected();
185
186     BundleInfo bundleInfo = new BundleInfo();
187     try
188     {
189       bundleInfo.fromBundleName(bundleName);
190     }
191     catch (BundleInfo.InvalidBundleNameException e)
192     {
193       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
194       return;
195     }
196     
197     try
198     {
199       admin.unshareBundle(bundleName, recoverLicences, force);
200     }
201     catch (RemoteException JavaDoc e)
202     {
203       JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE);
204       dispose();
205       return;
206     }
207     catch (RMIAdminException e)
208     {
209       JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
210       dispose();
211       return;
212     }
213     
214     JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' successfully unshared");
215     
216     isOK = true;
217     dispose();
218   }//GEN-LAST:event_unsharelButtonActionPerformed
219

220   private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
221
{//GEN-HEADEREND:event_cancelButtonActionPerformed
222
dispose();
223   }//GEN-LAST:event_cancelButtonActionPerformed
224

225   
226   // Variables declaration - do not modify//GEN-BEGIN:variables
227
private javax.swing.JLabel JavaDoc bundleNameLabel;
228   private javax.swing.JTextField JavaDoc bundleNameTextField;
229   private javax.swing.JButton JavaDoc cancelButton;
230   private javax.swing.JButton JavaDoc chooseSharedBundleButton;
231   private javax.swing.JCheckBox JavaDoc forcelCheckBox;
232   private javax.swing.JPanel JavaDoc jPanel1;
233   private javax.swing.JPanel JavaDoc jPanel2;
234   private javax.swing.JPanel JavaDoc jPanel3;
235   private javax.swing.JPanel JavaDoc jPanel4;
236   private javax.swing.JPanel JavaDoc jPanel5;
237   private javax.swing.JCheckBox JavaDoc recoverCheckBox;
238   private javax.swing.JButton JavaDoc unsharelButton;
239   // End of variables declaration//GEN-END:variables
240

241 }
242
Popular Tags