KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * TRPanel.java
3  *
4  * Created on 17. květen 2004, 17:23
5  */

6
7 package SOFA.SOFAnet.Browser;
8
9 import javax.swing.*;
10 import SOFA.SOFAnet.Admin.RMI.*;
11 import SOFA.SOFAnode.TR.ComponentInfo;
12 import SOFA.SOFAnode.TR.Impl.ComponentInfoImpl;
13 import java.rmi.RemoteException JavaDoc;
14 import java.util.Arrays JavaDoc;
15
16 /**
17  *
18  * @author Ladislav Sobr
19  */

20 public class TRPanel extends javax.swing.JPanel JavaDoc
21 {
22   private RMIAdminInterface admin;
23   private DefaultListModel content;
24   
25   private static class CompInfo implements Comparable JavaDoc
26   {
27     public ComponentInfo componentInfo;
28     public String JavaDoc componentName;
29     
30     CompInfo(ComponentInfo componentInfo)
31     {
32       this.componentInfo = componentInfo;
33       this.componentName = componentInfo.getName() + "[" + componentInfo.getImplementationVersion() + "]";
34     }
35     
36     public boolean equals(Object JavaDoc o)
37     {
38       if (this == o) return true;
39       if (o instanceof CompInfo)
40       {
41         CompInfo compInfo = (CompInfo)o;
42         return componentName.compareTo(compInfo.componentName) == 0;
43       }
44       else return false;
45     }
46
47     public int compareTo(Object JavaDoc o)
48     {
49       CompInfo compInfo = (CompInfo)o;
50       return componentName.compareTo(compInfo.componentName);
51     }
52     
53     public String JavaDoc toString()
54     {
55       return componentName;
56     }
57   }
58   
59   /** Creates new form TRPanel */
60   public TRPanel(RMIAdminInterface admin)
61   {
62     this.admin = admin;
63     content = new DefaultListModel();
64     initComponents();
65   }
66   
67   private void reload()
68   {
69     content.clear();
70     
71     ComponentInfo[] componentInfos = null;
72     try
73     {
74       componentInfos = admin.componentsInTRList();
75     }
76     catch (RemoteException JavaDoc e)
77     {
78       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
79       return;
80     }
81     
82     CompInfo[] compInfos = new CompInfo[componentInfos.length];
83     for (int i = 0; i < compInfos.length; i++) compInfos[i] = new CompInfo(componentInfos[i]);
84     Arrays.sort(compInfos);
85     
86     content.ensureCapacity(compInfos.length);
87     for (int i = 0; i < compInfos.length; i++) content.addElement(compInfos[i]);
88   }
89   
90   /** This method is called from within the constructor to
91    * initialize the form.
92    * WARNING: Do NOT modify this code. The content of this method is
93    * always regenerated by the Form Editor.
94    */

95   private void initComponents()//GEN-BEGIN:initComponents
96
{
97     jPanel2 = new javax.swing.JPanel JavaDoc();
98     jPanel4 = new javax.swing.JPanel JavaDoc();
99     createUserBundleButton = new javax.swing.JButton JavaDoc();
100     createComponentBundleButton = new javax.swing.JButton JavaDoc();
101     deleteButton = new javax.swing.JButton JavaDoc();
102     jPanel1 = new javax.swing.JPanel JavaDoc();
103     jPanel3 = new javax.swing.JPanel JavaDoc();
104     refreshButton = new javax.swing.JButton JavaDoc();
105     jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
106     contentList = new javax.swing.JList JavaDoc();
107
108     setLayout(new java.awt.BorderLayout JavaDoc());
109
110     addComponentListener(new java.awt.event.ComponentAdapter JavaDoc()
111     {
112       public void componentShown(java.awt.event.ComponentEvent JavaDoc evt)
113       {
114         formComponentShown(evt);
115       }
116     });
117
118     jPanel2.setLayout(new java.awt.BorderLayout JavaDoc());
119
120     jPanel2.setPreferredSize(new java.awt.Dimension JavaDoc(200, 154));
121     jPanel4.setLayout(new java.awt.GridLayout JavaDoc(3, 0));
122
123     jPanel4.setBorder(new javax.swing.border.TitledBorder JavaDoc("Components Specific"));
124     createUserBundleButton.setText("Create User Bundle");
125     createUserBundleButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
126     {
127       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
128       {
129         createUserBundleButtonActionPerformed(evt);
130       }
131     });
132
133     jPanel4.add(createUserBundleButton);
134
135     createComponentBundleButton.setText("Create Component Bundle");
136     createComponentBundleButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
137     {
138       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
139       {
140         createComponentBundleButtonActionPerformed(evt);
141       }
142     });
143
144     jPanel4.add(createComponentBundleButton);
145
146     deleteButton.setText("Delete Components");
147     deleteButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
148     {
149       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
150       {
151         deleteButtonActionPerformed(evt);
152       }
153     });
154
155     jPanel4.add(deleteButton);
156
157     jPanel2.add(jPanel4, java.awt.BorderLayout.NORTH);
158
159     jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
160
161     jPanel1.setBorder(new javax.swing.border.TitledBorder JavaDoc("General"));
162     jPanel3.setLayout(new java.awt.GridLayout JavaDoc(1, 0));
163
164     refreshButton.setText("Refresh");
165     refreshButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
166     {
167       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
168       {
169         refreshButtonActionPerformed(evt);
170       }
171     });
172
173     jPanel3.add(refreshButton);
174
175     jPanel1.add(jPanel3, java.awt.BorderLayout.NORTH);
176
177     jPanel2.add(jPanel1, java.awt.BorderLayout.CENTER);
178
179     add(jPanel2, java.awt.BorderLayout.EAST);
180
181     contentList.setModel(content);
182     contentList.setVisibleRowCount(-1);
183     jScrollPane1.setViewportView(contentList);
184
185     add(jScrollPane1, java.awt.BorderLayout.CENTER);
186
187   }//GEN-END:initComponents
188

189   private void refreshButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_refreshButtonActionPerformed
190
{//GEN-HEADEREND:event_refreshButtonActionPerformed
191
reload();
192   }//GEN-LAST:event_refreshButtonActionPerformed
193

194   private void deleteButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_deleteButtonActionPerformed
195
{//GEN-HEADEREND:event_deleteButtonActionPerformed
196
Object JavaDoc[] selectedCompInfos = contentList.getSelectedValues();
197     ComponentInfo[] componentInfos = null;
198     if (selectedCompInfos != null)
199     {
200       componentInfos = new ComponentInfo[selectedCompInfos.length];
201       for (int i = 0; i < selectedCompInfos.length; i++) componentInfos[i] = ((CompInfo)selectedCompInfos[i]).componentInfo;
202       if (DeleteComponentsDialog.showDialog(this, admin, componentInfos)) reload();
203     }
204   }//GEN-LAST:event_deleteButtonActionPerformed
205

206   private void createComponentBundleButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_createComponentBundleButtonActionPerformed
207
{//GEN-HEADEREND:event_createComponentBundleButtonActionPerformed
208
CompInfo selectedCompInfo = (CompInfo)contentList.getSelectedValue();
209     String JavaDoc componentName = "";
210     if (selectedCompInfo != null) componentName = selectedCompInfo.componentName;
211     CreateComponentBundleDialog.showDialog(this, admin, componentName);
212   }//GEN-LAST:event_createComponentBundleButtonActionPerformed
213

214   private void createUserBundleButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_createUserBundleButtonActionPerformed
215
{//GEN-HEADEREND:event_createUserBundleButtonActionPerformed
216
Object JavaDoc[] selectedCompInfos = contentList.getSelectedValues();
217     ComponentInfo[] componentInfos = null;
218     if (selectedCompInfos != null)
219     {
220       componentInfos = new ComponentInfo[selectedCompInfos.length];
221       for (int i = 0; i < selectedCompInfos.length; i++) componentInfos[i] = ((CompInfo)selectedCompInfos[i]).componentInfo;
222     }
223     CreateUserBundleDialog.showDialog(this, admin, "", componentInfos);
224   }//GEN-LAST:event_createUserBundleButtonActionPerformed
225

226   private void formComponentShown(java.awt.event.ComponentEvent JavaDoc evt)//GEN-FIRST:event_formComponentShown
227
{//GEN-HEADEREND:event_formComponentShown
228
reload();
229   }//GEN-LAST:event_formComponentShown
230

231   
232   // Variables declaration - do not modify//GEN-BEGIN:variables
233
private javax.swing.JList JavaDoc contentList;
234   private javax.swing.JButton JavaDoc createComponentBundleButton;
235   private javax.swing.JButton JavaDoc createUserBundleButton;
236   private javax.swing.JButton JavaDoc deleteButton;
237   private javax.swing.JPanel JavaDoc jPanel1;
238   private javax.swing.JPanel JavaDoc jPanel2;
239   private javax.swing.JPanel JavaDoc jPanel3;
240   private javax.swing.JPanel JavaDoc jPanel4;
241   private javax.swing.JScrollPane JavaDoc jScrollPane1;
242   private javax.swing.JButton JavaDoc refreshButton;
243   // End of variables declaration//GEN-END:variables
244

245 }
246
Popular Tags