KickJava   Java API By Example, From Geeks To Geeks.

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


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 SOFA.SOFAnet.Repository.NodeInfo;
12 import SOFA.SOFAnet.Repository.Licence;
13 import javax.swing.*;
14 import java.rmi.RemoteException JavaDoc;
15 import java.util.*;
16 import java.awt.Component JavaDoc;
17 import java.awt.Frame JavaDoc;
18
19 /**
20  *
21  * @author Ladislav Sobr
22  */

23 public class AcquireSharedBundleDialog extends javax.swing.JDialog JavaDoc
24 {
25   private RMIAdminInterface admin;
26   private boolean isOK;
27   
28   public static boolean showDialog(Component JavaDoc frameComp, RMIAdminInterface admin, String JavaDoc defaultBundleName, String JavaDoc defaultNodeName)
29   {
30     Frame JavaDoc frame = JOptionPane.getFrameForComponent(frameComp);
31     AcquireSharedBundleDialog dialog = new AcquireSharedBundleDialog(frame, true, admin, defaultBundleName, defaultNodeName);
32     dialog.setLocationRelativeTo(frameComp);
33     dialog.setVisible(true);
34     return dialog.isOK();
35   }
36   
37   /** Creates new form AcquireSharedBundleDialog */
38   public AcquireSharedBundleDialog(java.awt.Frame JavaDoc parent, boolean modal, RMIAdminInterface admin, String JavaDoc defaultBundleName, String JavaDoc defaultNodeName)
39   {
40     super(parent, modal);
41     this.admin = admin;
42     isOK = false;
43     initComponents();
44     
45     bundleNameTextField.setText(defaultBundleName);
46     nodeNameTextField.setText(defaultNodeName);
47   }
48   
49   public boolean isOK()
50   {
51     return isOK;
52   }
53   
54   /** This method is called from within the constructor to
55    * initialize the form.
56    * WARNING: Do NOT modify this code. The content of this method is
57    * always regenerated by the Form Editor.
58    */

59   private void initComponents()//GEN-BEGIN:initComponents
60
{
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     nodeNameLabel = new javax.swing.JLabel JavaDoc();
67     nodeNameTextField = new javax.swing.JTextField JavaDoc();
68     tryNoShareClientCheckBox = new javax.swing.JCheckBox JavaDoc();
69     jPanel3 = new javax.swing.JPanel JavaDoc();
70     acquireShareBundleButton = new javax.swing.JButton JavaDoc();
71     cancelButton = new javax.swing.JButton JavaDoc();
72
73     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
74     setTitle("Acquire Shared Bundle");
75     jPanel4.setLayout(new java.awt.BorderLayout JavaDoc());
76
77     jPanel4.setMinimumSize(new java.awt.Dimension JavaDoc(400, 93));
78     jPanel4.setPreferredSize(new java.awt.Dimension JavaDoc(400, 180));
79     jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
80
81     jPanel1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(1, 10, 1, 10)));
82     jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(26, 23));
83     jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(26, 23));
84     jPanel5.setLayout(new java.awt.GridLayout JavaDoc(7, 0));
85
86     bundleNameLabel.setText("Bundle Name:");
87     jPanel5.add(bundleNameLabel);
88
89     bundleNameTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
90     bundleNameTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
91     jPanel5.add(bundleNameTextField);
92
93     nodeNameLabel.setText("Node name:");
94     jPanel5.add(nodeNameLabel);
95
96     nodeNameTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
97     nodeNameTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
98     jPanel5.add(nodeNameTextField);
99
100     tryNoShareClientCheckBox.setSelected(true);
101     tryNoShareClientCheckBox.setText("Try to store to Binary Bundles without starting Share Client");
102     jPanel5.add(tryNoShareClientCheckBox);
103
104     jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH);
105
106     jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER);
107
108     acquireShareBundleButton.setText("Acquire Shared Bundle");
109     acquireShareBundleButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
110     {
111       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
112       {
113         acquireShareBundleButtonActionPerformed(evt);
114       }
115     });
116
117     jPanel3.add(acquireShareBundleButton);
118
119     cancelButton.setText("Cancel");
120     cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
121     {
122       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
123       {
124         cancelButtonActionPerformed(evt);
125       }
126     });
127
128     jPanel3.add(cancelButton);
129
130     jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH);
131
132     getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);
133
134     pack();
135   }//GEN-END:initComponents
136

137   private void acquireShareBundleButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_acquireShareBundleButtonActionPerformed
138
{//GEN-HEADEREND:event_acquireShareBundleButtonActionPerformed
139
String JavaDoc bundleName = bundleNameTextField.getText();
140     String JavaDoc nodeName = nodeNameTextField.getText();
141     boolean tryNoShareClient = tryNoShareClientCheckBox.isSelected();
142
143     BundleInfo bundleInfo = new BundleInfo();
144     try
145     {
146       bundleInfo.fromBundleName(bundleName);
147     }
148     catch (BundleInfo.InvalidBundleNameException e)
149     {
150       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
151       return;
152     }
153     
154     NodeInfo nodeInfo = new NodeInfo();
155     try
156     {
157       nodeInfo.setNodeName(nodeName);
158     }
159     catch (NodeInfo.InvalidNodeNameException e)
160     {
161       JOptionPane.showMessageDialog(this, "Invalid name of SOFA node:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
162       return;
163     }
164     
165     try
166     {
167       admin.acquireSharedBundle(bundleName, nodeName, tryNoShareClient);
168     }
169     catch (RemoteException JavaDoc e)
170     {
171       JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE);
172       dispose();
173       return;
174     }
175     catch (RMIAdminException e)
176     {
177       JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
178       dispose();
179       return;
180     }
181     
182     JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' successfully acquired from '" + nodeName + "'");
183     
184     isOK = true;
185     dispose();
186   }//GEN-LAST:event_acquireShareBundleButtonActionPerformed
187

188   private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
189
{//GEN-HEADEREND:event_cancelButtonActionPerformed
190
dispose();
191   }//GEN-LAST:event_cancelButtonActionPerformed
192

193   
194   // Variables declaration - do not modify//GEN-BEGIN:variables
195
private javax.swing.JButton JavaDoc acquireShareBundleButton;
196   private javax.swing.JLabel JavaDoc bundleNameLabel;
197   private javax.swing.JTextField JavaDoc bundleNameTextField;
198   private javax.swing.JButton JavaDoc cancelButton;
199   private javax.swing.JPanel JavaDoc jPanel1;
200   private javax.swing.JPanel JavaDoc jPanel3;
201   private javax.swing.JPanel JavaDoc jPanel4;
202   private javax.swing.JPanel JavaDoc jPanel5;
203   private javax.swing.JLabel JavaDoc nodeNameLabel;
204   private javax.swing.JTextField JavaDoc nodeNameTextField;
205   private javax.swing.JCheckBox JavaDoc tryNoShareClientCheckBox;
206   // End of variables declaration//GEN-END:variables
207

208 }
209
Popular Tags