KickJava   Java API By Example, From Geeks To Geeks.

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


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 CreateBinaryBundleDialog 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     CreateBinaryBundleDialog dialog = new CreateBinaryBundleDialog(frame, true, admin, defaultBundleName);
30     dialog.setLocationRelativeTo(frameComp);
31     dialog.setVisible(true);
32     return dialog.isOK();
33   }
34   
35   /** Creates new form CreateBinaryBundleDialog */
36   public CreateBinaryBundleDialog(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     overwriteCheckBox = new javax.swing.JCheckBox JavaDoc();
64     jPanel2 = new javax.swing.JPanel JavaDoc();
65     chooseInstalledBundleButton = new javax.swing.JButton JavaDoc();
66     jPanel3 = new javax.swing.JPanel JavaDoc();
67     CreateBinaryBundleButton = new javax.swing.JButton JavaDoc();
68     cancelButton = new javax.swing.JButton JavaDoc();
69
70     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
71     setTitle("Create Binary Bundle");
72     jPanel4.setLayout(new java.awt.BorderLayout JavaDoc());
73
74     jPanel4.setMinimumSize(new java.awt.Dimension JavaDoc(400, 93));
75     jPanel4.setPreferredSize(new java.awt.Dimension JavaDoc(400, 150));
76     jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
77
78     jPanel1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(1, 10, 1, 10)));
79     jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(26, 23));
80     jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(26, 23));
81     jPanel5.setLayout(new java.awt.GridLayout JavaDoc(3, 0));
82
83     bundleNameLabel.setText("Bundle Name:");
84     jPanel5.add(bundleNameLabel);
85
86     bundleNameTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
87     bundleNameTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
88     jPanel5.add(bundleNameTextField);
89
90     overwriteCheckBox.setText("Overwrite");
91     jPanel5.add(overwriteCheckBox);
92
93     jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH);
94
95     jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER);
96
97     chooseInstalledBundleButton.setText("Choose Installed Bundle");
98     chooseInstalledBundleButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
99     {
100       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
101       {
102         chooseInstalledBundleButtonActionPerformed(evt);
103       }
104     });
105
106     jPanel2.add(chooseInstalledBundleButton);
107
108     jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH);
109
110     CreateBinaryBundleButton.setText("Create Binary Bundle");
111     CreateBinaryBundleButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
112     {
113       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
114       {
115         CreateBinaryBundleButtonActionPerformed(evt);
116       }
117     });
118
119     jPanel3.add(CreateBinaryBundleButton);
120
121     cancelButton.setText("Cancel");
122     cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
123     {
124       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
125       {
126         cancelButtonActionPerformed(evt);
127       }
128     });
129
130     jPanel3.add(cancelButton);
131
132     jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH);
133
134     getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);
135
136     pack();
137   }//GEN-END:initComponents
138

139   private void chooseInstalledBundleButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_chooseInstalledBundleButtonActionPerformed
140
{//GEN-HEADEREND:event_chooseInstalledBundleButtonActionPerformed
141
LocalInfoDesc[] localInfoDescs = null;
142     try
143     {
144       localInfoDescs = admin.localInfoDescsList();
145     }
146     catch (RemoteException JavaDoc e)
147     {
148       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
149       return;
150     }
151
152     int size = 0;
153     int i;
154     for (i = 0; i < localInfoDescs.length; i++)
155     {
156       if (localInfoDescs[i].isInstalled()) size++;
157     }
158     
159     LocalInfoDesc[] shareClients = new LocalInfoDesc[size];
160     int j = 0;
161     for (i = 0; i < localInfoDescs.length; i++)
162     {
163       if (localInfoDescs[i].isInstalled())
164       {
165         shareClients[j++] = localInfoDescs[i];
166       }
167     }
168
169     Arrays.sort(shareClients);
170     
171     LocalInfoDesc result = (LocalInfoDesc)ListDialog.showDialog(this, this, "Installed Bundles:", "Choose Installed Bundle to Uninstall", shareClients, null, null, false, true);
172     if (result != null) bundleNameTextField.setText(result.bundleName);
173   }//GEN-LAST:event_chooseInstalledBundleButtonActionPerformed
174

175   private void CreateBinaryBundleButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_CreateBinaryBundleButtonActionPerformed
176
{//GEN-HEADEREND:event_CreateBinaryBundleButtonActionPerformed
177
String JavaDoc bundleName = bundleNameTextField.getText();
178     boolean overwrite = overwriteCheckBox.isSelected();
179
180     BundleInfo bundleInfo = new BundleInfo();
181     try
182     {
183       bundleInfo.fromBundleName(bundleName);
184     }
185     catch (BundleInfo.InvalidBundleNameException e)
186     {
187       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
188       return;
189     }
190     
191     try
192     {
193       admin.createBinaryBundle(bundleName, overwrite);
194     }
195     catch (RemoteException JavaDoc e)
196     {
197       JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE);
198       dispose();
199       return;
200     }
201     catch (RMIAdminException e)
202     {
203       JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
204       dispose();
205       return;
206     }
207     
208     JOptionPane.showMessageDialog(this, "Binary Bundle '" + bundleName + "' successfully created");
209     
210     isOK = true;
211     dispose();
212   }//GEN-LAST:event_CreateBinaryBundleButtonActionPerformed
213

214   private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
215
{//GEN-HEADEREND:event_cancelButtonActionPerformed
216
dispose();
217   }//GEN-LAST:event_cancelButtonActionPerformed
218

219   
220   // Variables declaration - do not modify//GEN-BEGIN:variables
221
private javax.swing.JButton JavaDoc CreateBinaryBundleButton;
222   private javax.swing.JLabel JavaDoc bundleNameLabel;
223   private javax.swing.JTextField JavaDoc bundleNameTextField;
224   private javax.swing.JButton JavaDoc cancelButton;
225   private javax.swing.JButton JavaDoc chooseInstalledBundleButton;
226   private javax.swing.JPanel JavaDoc jPanel1;
227   private javax.swing.JPanel JavaDoc jPanel2;
228   private javax.swing.JPanel JavaDoc jPanel3;
229   private javax.swing.JPanel JavaDoc jPanel4;
230   private javax.swing.JPanel JavaDoc jPanel5;
231   private javax.swing.JCheckBox JavaDoc overwriteCheckBox;
232   // End of variables declaration//GEN-END:variables
233

234 }
235
Popular Tags