KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * MakeBundleInSharingPresentDialog.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 MakeBundleInSharingPresentDialog 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, boolean isShareManager)
27   {
28     Frame JavaDoc frame = JOptionPane.getFrameForComponent(frameComp);
29     MakeBundleInSharingPresentDialog dialog = new MakeBundleInSharingPresentDialog(frame, true, admin, defaultBundleName, isShareManager);
30     dialog.setLocationRelativeTo(frameComp);
31     dialog.setVisible(true);
32     return dialog.isOK();
33   }
34   
35   /** Creates new form MakeBundleInSharingPresentDialog */
36   public MakeBundleInSharingPresentDialog(java.awt.Frame JavaDoc parent, boolean modal, RMIAdminInterface admin, String JavaDoc defaultBundleName, boolean isShareManager)
37   {
38     super(parent, modal);
39     this.admin = admin;
40     isOK = false;
41     initComponents();
42     
43     bundleNameTextField.setText(defaultBundleName);
44     if (isShareManager) shareManagerRadioButton.setSelected(true);
45     else shareClientRadioButton.setSelected(true);
46   }
47   
48   public boolean isOK()
49   {
50     return isOK;
51   }
52   
53   /** This method is called from within the constructor to
54    * initialize the form.
55    * WARNING: Do NOT modify this code. The content of this method is
56    * always regenerated by the Form Editor.
57    */

58   private void initComponents()//GEN-BEGIN:initComponents
59
{
60     buttonGroup = new javax.swing.ButtonGroup JavaDoc();
61     jPanel4 = new javax.swing.JPanel JavaDoc();
62     jPanel1 = new javax.swing.JPanel JavaDoc();
63     jPanel5 = new javax.swing.JPanel JavaDoc();
64     bundleNameLabel = new javax.swing.JLabel JavaDoc();
65     bundleNameTextField = new javax.swing.JTextField JavaDoc();
66     shareManagerRadioButton = new javax.swing.JRadioButton JavaDoc();
67     shareClientRadioButton = new javax.swing.JRadioButton JavaDoc();
68     jPanel2 = new javax.swing.JPanel JavaDoc();
69     chooseShareManagerButton = new javax.swing.JButton JavaDoc();
70     chooseShareClientButton = new javax.swing.JButton JavaDoc();
71     jPanel3 = new javax.swing.JPanel JavaDoc();
72     makeBundlePresentButton = new javax.swing.JButton JavaDoc();
73     cancelButton = new javax.swing.JButton JavaDoc();
74
75     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
76     setTitle("Make Bundle In Sharing Present");
77     jPanel4.setLayout(new java.awt.BorderLayout JavaDoc());
78
79     jPanel4.setMinimumSize(new java.awt.Dimension JavaDoc(400, 93));
80     jPanel4.setPreferredSize(new java.awt.Dimension JavaDoc(400, 180));
81     jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
82
83     jPanel1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(1, 10, 1, 10)));
84     jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(26, 23));
85     jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(26, 23));
86     jPanel5.setLayout(new java.awt.GridLayout JavaDoc(4, 0));
87
88     bundleNameLabel.setText("Bundle Name:");
89     jPanel5.add(bundleNameLabel);
90
91     bundleNameTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
92     bundleNameTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
93     jPanel5.add(bundleNameTextField);
94
95     shareManagerRadioButton.setSelected(true);
96     shareManagerRadioButton.setText("Share Manager");
97     buttonGroup.add(shareManagerRadioButton);
98     jPanel5.add(shareManagerRadioButton);
99
100     shareClientRadioButton.setText("Share Client");
101     buttonGroup.add(shareClientRadioButton);
102     jPanel5.add(shareClientRadioButton);
103
104     jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH);
105
106     jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER);
107
108     chooseShareManagerButton.setText("Choose Share Manager");
109     chooseShareManagerButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
110     {
111       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
112       {
113         chooseShareManagerButtonActionPerformed(evt);
114       }
115     });
116
117     jPanel2.add(chooseShareManagerButton);
118
119     chooseShareClientButton.setText("Choose Share Client");
120     chooseShareClientButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
121     {
122       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
123       {
124         chooseShareClientButtonActionPerformed(evt);
125       }
126     });
127
128     jPanel2.add(chooseShareClientButton);
129
130     jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH);
131
132     makeBundlePresentButton.setText("Make Bundle Present");
133     makeBundlePresentButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
134     {
135       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
136       {
137         makeBundlePresentButtonActionPerformed(evt);
138       }
139     });
140
141     jPanel3.add(makeBundlePresentButton);
142
143     cancelButton.setText("Cancel");
144     cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
145     {
146       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
147       {
148         cancelButtonActionPerformed(evt);
149       }
150     });
151
152     jPanel3.add(cancelButton);
153
154     jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH);
155
156     getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);
157
158     pack();
159   }//GEN-END:initComponents
160

161   private void chooseShareClientButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_chooseShareClientButtonActionPerformed
162
{//GEN-HEADEREND:event_chooseShareClientButtonActionPerformed
163
LocalInfoDesc[] localInfoDescs = null;
164     try
165     {
166       localInfoDescs = admin.localInfoDescsList();
167     }
168     catch (RemoteException JavaDoc e)
169     {
170       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
171       return;
172     }
173
174     int size = 0;
175     int i;
176     for (i = 0; i < localInfoDescs.length; i++)
177     {
178       if (localInfoDescs[i].isShareClient()) size++;
179     }
180     
181     LocalInfoDesc[] shareClients = new LocalInfoDesc[size];
182     int j = 0;
183     for (i = 0; i < localInfoDescs.length; i++)
184     {
185       if (localInfoDescs[i].isShareClient())
186       {
187         shareClients[j++] = localInfoDescs[i];
188       }
189     }
190
191     Arrays.sort(shareClients);
192     
193     LocalInfoDesc result = (LocalInfoDesc)ListDialog.showDialog(this, this, "Bundles in Share Client Mode:", "Choose Share Client", shareClients, null, null, false, true);
194     if (result != null)
195     {
196       bundleNameTextField.setText(result.bundleName);
197       shareClientRadioButton.setSelected(true);
198     }
199   }//GEN-LAST:event_chooseShareClientButtonActionPerformed
200

201   private void chooseShareManagerButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_chooseShareManagerButtonActionPerformed
202
{//GEN-HEADEREND:event_chooseShareManagerButtonActionPerformed
203
LocalInfoDesc[] localInfoDescs = null;
204     try
205     {
206       localInfoDescs = admin.localInfoDescsList();
207     }
208     catch (RemoteException JavaDoc e)
209     {
210       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
211       return;
212     }
213
214     int size = 0;
215     int i;
216     for (i = 0; i < localInfoDescs.length; i++)
217     {
218       if (localInfoDescs[i].isShareManager()) size++;
219     }
220     
221     LocalInfoDesc[] shareManagers = new LocalInfoDesc[size];
222     int j = 0;
223     for (i = 0; i < localInfoDescs.length; i++)
224     {
225       if (localInfoDescs[i].isShareManager())
226       {
227         shareManagers[j++] = localInfoDescs[i];
228       }
229     }
230
231     Arrays.sort(shareManagers);
232     
233     LocalInfoDesc result = (LocalInfoDesc)ListDialog.showDialog(this, this, "Bundles in Share Manager Mode:", "Choose Share Manager", shareManagers, null, null, false, true);
234     if (result != null)
235     {
236       bundleNameTextField.setText(result.bundleName);
237       shareManagerRadioButton.setSelected(true);
238     }
239   }//GEN-LAST:event_chooseShareManagerButtonActionPerformed
240

241   private void makeBundlePresentButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_makeBundlePresentButtonActionPerformed
242
{//GEN-HEADEREND:event_makeBundlePresentButtonActionPerformed
243
String JavaDoc bundleName = bundleNameTextField.getText();
244     boolean isShareManager = shareManagerRadioButton.isSelected();
245
246     BundleInfo bundleInfo = new BundleInfo();
247     try
248     {
249       bundleInfo.fromBundleName(bundleName);
250     }
251     catch (BundleInfo.InvalidBundleNameException e)
252     {
253       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
254       return;
255     }
256     
257     try
258     {
259       if (isShareManager) admin.makeShareClientsReturnBundle(bundleName);
260       else admin.acquireSharedBundle(bundleName, null, false);
261     }
262     catch (RemoteException JavaDoc e)
263     {
264       JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE);
265       dispose();
266       return;
267     }
268     catch (RMIAdminException e)
269     {
270       JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
271       dispose();
272       return;
273     }
274     
275     JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' successfully made present");
276     
277     isOK = true;
278     dispose();
279   }//GEN-LAST:event_makeBundlePresentButtonActionPerformed
280

281   private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
282
{//GEN-HEADEREND:event_cancelButtonActionPerformed
283
dispose();
284   }//GEN-LAST:event_cancelButtonActionPerformed
285

286   
287   // Variables declaration - do not modify//GEN-BEGIN:variables
288
private javax.swing.JLabel JavaDoc bundleNameLabel;
289   private javax.swing.JTextField JavaDoc bundleNameTextField;
290   private javax.swing.ButtonGroup JavaDoc buttonGroup;
291   private javax.swing.JButton JavaDoc cancelButton;
292   private javax.swing.JButton JavaDoc chooseShareClientButton;
293   private javax.swing.JButton JavaDoc chooseShareManagerButton;
294   private javax.swing.JPanel JavaDoc jPanel1;
295   private javax.swing.JPanel JavaDoc jPanel2;
296   private javax.swing.JPanel JavaDoc jPanel3;
297   private javax.swing.JPanel JavaDoc jPanel4;
298   private javax.swing.JPanel JavaDoc jPanel5;
299   private javax.swing.JButton JavaDoc makeBundlePresentButton;
300   private javax.swing.JRadioButton JavaDoc shareClientRadioButton;
301   private javax.swing.JRadioButton JavaDoc shareManagerRadioButton;
302   // End of variables declaration//GEN-END:variables
303

304 }
305
Popular Tags