KickJava   Java API By Example, From Geeks To Geeks.

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


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.SOFAnode.TR.ComponentInfo;
12 import SOFA.SOFAnode.TR.Impl.ComponentInfoImpl;
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 CreateComponentBundleDialog 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 defaultComponentName)
29   {
30     Frame JavaDoc frame = JOptionPane.getFrameForComponent(frameComp);
31     CreateComponentBundleDialog dialog = new CreateComponentBundleDialog(frame, true, admin, defaultComponentName);
32     dialog.setLocationRelativeTo(frameComp);
33     dialog.setVisible(true);
34     return dialog.isOK();
35   }
36   
37   /** Creates new form CreateComponentBundleDialog */
38   public CreateComponentBundleDialog(java.awt.Frame JavaDoc parent, boolean modal, RMIAdminInterface admin, String JavaDoc defaultComponentName)
39   {
40     super(parent, modal);
41     this.admin = admin;
42     isOK = false;
43     initComponents();
44     
45     componentNameTextField.setText(defaultComponentName);
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     jPanel4 = new javax.swing.JPanel JavaDoc();
61     jPanel1 = new javax.swing.JPanel JavaDoc();
62     jPanel5 = new javax.swing.JPanel JavaDoc();
63     componentNameLabel = new javax.swing.JLabel JavaDoc();
64     componentNameTextField = new javax.swing.JTextField JavaDoc();
65     completeComponentCheckBox = new javax.swing.JCheckBox JavaDoc();
66     jPanel2 = new javax.swing.JPanel JavaDoc();
67     chooseComponentButton = new javax.swing.JButton JavaDoc();
68     jPanel3 = new javax.swing.JPanel JavaDoc();
69     createComponentBundleButton = new javax.swing.JButton JavaDoc();
70     cancelButton = new javax.swing.JButton JavaDoc();
71
72     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
73     setTitle("Create Component Bundle");
74     jPanel4.setLayout(new java.awt.BorderLayout JavaDoc());
75
76     jPanel4.setMinimumSize(new java.awt.Dimension JavaDoc(400, 93));
77     jPanel4.setPreferredSize(new java.awt.Dimension JavaDoc(400, 150));
78     jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
79
80     jPanel1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(1, 10, 1, 10)));
81     jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(26, 23));
82     jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(26, 23));
83     jPanel5.setLayout(new java.awt.GridLayout JavaDoc(3, 0));
84
85     componentNameLabel.setText("Component Name:");
86     jPanel5.add(componentNameLabel);
87
88     componentNameTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
89     componentNameTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
90     jPanel5.add(componentNameTextField);
91
92     completeComponentCheckBox.setText("Complete Component (including subcomponents)");
93     jPanel5.add(completeComponentCheckBox);
94
95     jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH);
96
97     jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER);
98
99     chooseComponentButton.setText("Choose Component from TR");
100     chooseComponentButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
101     {
102       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
103       {
104         chooseComponentButtonActionPerformed(evt);
105       }
106     });
107
108     jPanel2.add(chooseComponentButton);
109
110     jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH);
111
112     createComponentBundleButton.setText("Create Component Bundle");
113     createComponentBundleButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
114     {
115       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
116       {
117         createComponentBundleButtonActionPerformed(evt);
118       }
119     });
120
121     jPanel3.add(createComponentBundleButton);
122
123     cancelButton.setText("Cancel");
124     cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
125     {
126       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
127       {
128         cancelButtonActionPerformed(evt);
129       }
130     });
131
132     jPanel3.add(cancelButton);
133
134     jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH);
135
136     getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);
137
138     pack();
139   }//GEN-END:initComponents
140

141   private void chooseComponentButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_chooseComponentButtonActionPerformed
142
{//GEN-HEADEREND:event_chooseComponentButtonActionPerformed
143
ComponentInfo[] componentInfos = null;
144     try
145     {
146       componentInfos = admin.componentsInTRList();
147     }
148     catch (RemoteException JavaDoc e)
149     {
150       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
151       return;
152     }
153     
154     String JavaDoc[] compNames = new String JavaDoc[componentInfos.length];
155     int i;
156     for (i = 0; i < componentInfos.length; i++) compNames[i] = componentInfos[i].getName() + "[" + componentInfos[i].getImplementationVersion() + "]";
157     
158     Arrays.sort(compNames);
159     
160     String JavaDoc result = ListDialog.showDialog(this, this, "Components in TR:", "Choose Components from TR to create Component Bundle", compNames, null, null, false, true);
161     if (result.length() != 0) componentNameTextField.setText(result);
162     
163   }//GEN-LAST:event_chooseComponentButtonActionPerformed
164

165   private void createComponentBundleButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_createComponentBundleButtonActionPerformed
166
{//GEN-HEADEREND:event_createComponentBundleButtonActionPerformed
167
String JavaDoc componentName = componentNameTextField.getText();
168     boolean completeComponent = completeComponentCheckBox.isSelected();
169
170     BundleInfo bundleInfo = new BundleInfo();
171     try
172     {
173       bundleInfo.fromBundleName(componentName);
174     }
175     catch (BundleInfo.InvalidBundleNameException e)
176     {
177       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
178       return;
179     }
180     
181     if (!bundleInfo.isComponent() || bundleInfo.isCompleteComponent())
182     {
183       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\nName of Component expected", "Error", JOptionPane.ERROR_MESSAGE);
184       return;
185     }
186  
187     ComponentInfo componentInfo = new ComponentInfoImpl(bundleInfo.getShortName(), bundleInfo.getVersion());
188     String JavaDoc bundleName = null;
189     try
190     {
191       bundleName = admin.createComponentBundle(componentInfo, completeComponent);
192     }
193     catch (RemoteException JavaDoc e)
194     {
195       JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE);
196       dispose();
197       return;
198     }
199     catch (RMIAdminException e)
200     {
201       JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
202       dispose();
203       return;
204     }
205     
206     JOptionPane.showMessageDialog(this, "Component Bundle '" + bundleName + "' successfully created");
207     
208     isOK = true;
209     dispose();
210   }//GEN-LAST:event_createComponentBundleButtonActionPerformed
211

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

217   
218   // Variables declaration - do not modify//GEN-BEGIN:variables
219
private javax.swing.JButton JavaDoc cancelButton;
220   private javax.swing.JButton JavaDoc chooseComponentButton;
221   private javax.swing.JCheckBox JavaDoc completeComponentCheckBox;
222   private javax.swing.JLabel JavaDoc componentNameLabel;
223   private javax.swing.JTextField JavaDoc componentNameTextField;
224   private javax.swing.JButton JavaDoc createComponentBundleButton;
225   private javax.swing.JPanel JavaDoc jPanel1;
226   private javax.swing.JPanel JavaDoc jPanel2;
227   private javax.swing.JPanel JavaDoc jPanel3;
228   private javax.swing.JPanel JavaDoc jPanel4;
229   private javax.swing.JPanel JavaDoc jPanel5;
230   // End of variables declaration//GEN-END:variables
231

232 }
233
Popular Tags