KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * ContractsPanel.java
3  *
4  * Created on 17. květen 2004, 20:37
5  */

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

19 public class ContractsPanel extends javax.swing.JPanel JavaDoc
20 {
21   private RMIAdminInterface admin;
22   private DefaultListModel content;
23   
24   
25   /** Creates new form ContractsPanel */
26   public ContractsPanel(RMIAdminInterface admin)
27   {
28     this.admin = admin;
29     content = new DefaultListModel();
30     initComponents();
31   }
32   
33   private void reload()
34   {
35     content.clear();
36     
37     ContractDesc[] contractDescs = null;
38     try
39     {
40       contractDescs = admin.contractDescsList();
41     }
42     catch (RemoteException JavaDoc e)
43     {
44       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
45       return;
46     }
47     
48     Arrays.sort(contractDescs);
49     
50     content.ensureCapacity(contractDescs.length);
51     for (int i = 0; i < contractDescs.length; i++) content.addElement(contractDescs[i]);
52   }
53   
54   private String JavaDoc getSelectedContractName()
55   {
56     String JavaDoc contractName = "";
57
58     int index = contentList.getSelectedIndex();
59     if (index != -1) contractName = ((ContractDesc)content.getElementAt(index)).name;
60     return contractName;
61   }
62   
63   /** This method is called from within the constructor to
64    * initialize the form.
65    * WARNING: Do NOT modify this code. The content of this method is
66    * always regenerated by the Form Editor.
67    */

68   private void initComponents()//GEN-BEGIN:initComponents
69
{
70     jPanel2 = new javax.swing.JPanel JavaDoc();
71     jPanel4 = new javax.swing.JPanel JavaDoc();
72     editButton = new javax.swing.JButton JavaDoc();
73     addButton = new javax.swing.JButton JavaDoc();
74     deleteButton = new javax.swing.JButton JavaDoc();
75     generateTriggersButton = new javax.swing.JButton JavaDoc();
76     deleteTriggersButton = new javax.swing.JButton JavaDoc();
77     jPanel1 = new javax.swing.JPanel JavaDoc();
78     jPanel3 = new javax.swing.JPanel JavaDoc();
79     refreshButton = new javax.swing.JButton JavaDoc();
80     jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
81     contentList = new javax.swing.JList JavaDoc();
82
83     setLayout(new java.awt.BorderLayout JavaDoc());
84
85     addComponentListener(new java.awt.event.ComponentAdapter JavaDoc()
86     {
87       public void componentShown(java.awt.event.ComponentEvent JavaDoc evt)
88       {
89         formComponentShown(evt);
90       }
91     });
92
93     jPanel2.setLayout(new java.awt.BorderLayout JavaDoc());
94
95     jPanel2.setPreferredSize(new java.awt.Dimension JavaDoc(200, 204));
96     jPanel4.setLayout(new java.awt.GridLayout JavaDoc(5, 0));
97
98     jPanel4.setBorder(new javax.swing.border.TitledBorder JavaDoc("Contract Specific"));
99     editButton.setText("Edit Contract");
100     editButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
101     {
102       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
103       {
104         editButtonActionPerformed(evt);
105       }
106     });
107
108     jPanel4.add(editButton);
109
110     addButton.setText("Add New Contract");
111     addButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
112     {
113       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
114       {
115         addButtonActionPerformed(evt);
116       }
117     });
118
119     jPanel4.add(addButton);
120
121     deleteButton.setText("Delete Contract");
122     deleteButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
123     {
124       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
125       {
126         deleteButtonActionPerformed(evt);
127       }
128     });
129
130     jPanel4.add(deleteButton);
131
132     generateTriggersButton.setText("Generate Triggers");
133     generateTriggersButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
134     {
135       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
136       {
137         generateTriggersButtonActionPerformed(evt);
138       }
139     });
140
141     jPanel4.add(generateTriggersButton);
142
143     deleteTriggersButton.setText("Delete Triggers");
144     deleteTriggersButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
145     {
146       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
147       {
148         deleteTriggersButtonActionPerformed(evt);
149       }
150     });
151
152     jPanel4.add(deleteTriggersButton);
153
154     jPanel2.add(jPanel4, java.awt.BorderLayout.NORTH);
155
156     jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
157
158     jPanel1.setBorder(new javax.swing.border.TitledBorder JavaDoc("General"));
159     jPanel3.setLayout(new java.awt.GridLayout JavaDoc(1, 0));
160
161     refreshButton.setText("Refresh");
162     refreshButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
163     {
164       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
165       {
166         refreshButtonActionPerformed(evt);
167       }
168     });
169
170     jPanel3.add(refreshButton);
171
172     jPanel1.add(jPanel3, java.awt.BorderLayout.NORTH);
173
174     jPanel2.add(jPanel1, java.awt.BorderLayout.CENTER);
175
176     add(jPanel2, java.awt.BorderLayout.EAST);
177
178     contentList.setModel(content);
179     contentList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
180     contentList.setVisibleRowCount(-1);
181     contentList.addMouseListener(new java.awt.event.MouseAdapter JavaDoc()
182     {
183       public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt)
184       {
185         contentListMouseClicked(evt);
186       }
187     });
188
189     jScrollPane1.setViewportView(contentList);
190
191     add(jScrollPane1, java.awt.BorderLayout.CENTER);
192
193   }//GEN-END:initComponents
194

195   private void deleteTriggersButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_deleteTriggersButtonActionPerformed
196
{//GEN-HEADEREND:event_deleteTriggersButtonActionPerformed
197
DeleteTriggersOfContractDialog.showDialog(this, admin, getSelectedContractName());
198   }//GEN-LAST:event_deleteTriggersButtonActionPerformed
199

200   private void generateTriggersButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_generateTriggersButtonActionPerformed
201
{//GEN-HEADEREND:event_generateTriggersButtonActionPerformed
202
GenerateTriggersOfContractDialog.showDialog(this, admin, getSelectedContractName());
203   }//GEN-LAST:event_generateTriggersButtonActionPerformed
204

205   private void refreshButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_refreshButtonActionPerformed
206
{//GEN-HEADEREND:event_refreshButtonActionPerformed
207
reload();
208   }//GEN-LAST:event_refreshButtonActionPerformed
209

210   private void deleteButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_deleteButtonActionPerformed
211
{//GEN-HEADEREND:event_deleteButtonActionPerformed
212
String JavaDoc contractName = getSelectedContractName();
213     
214     if (contractName.length() == 0)
215     {
216       JOptionPane.showMessageDialog(this, "No Contract selected", "Warning", JOptionPane.WARNING_MESSAGE);
217       return;
218     }
219     else
220     {
221       if (JOptionPane.showConfirmDialog(this, "Do you really want to delete Contract '" + contractName + "'?") != JOptionPane.YES_OPTION) return;
222     }
223     
224     try
225     {
226       admin.updateContract(contractName, null);
227     }
228     catch (RemoteException JavaDoc e)
229     {
230       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
231       return;
232     }
233     catch (RMIAdminException e)
234     {
235       JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
236       return;
237     }
238
239     reload();
240   }//GEN-LAST:event_deleteButtonActionPerformed
241

242   private void addButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_addButtonActionPerformed
243
{//GEN-HEADEREND:event_addButtonActionPerformed
244
String JavaDoc contractName = JOptionPane.showInputDialog(this, "ID of New Contract:", "New Contract", JOptionPane.INFORMATION_MESSAGE);
245     if (contractName != null)
246     {
247       Contract contract = new Contract();
248       
249       try
250       {
251         admin.updateContract(contractName, contract);
252       }
253       catch (RemoteException JavaDoc e)
254       {
255         JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
256         return;
257       }
258       catch (RMIAdminException e)
259       {
260         JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
261         return;
262       }
263       
264       reload();
265     }
266   }//GEN-LAST:event_addButtonActionPerformed
267

268   private void editButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_editButtonActionPerformed
269
{//GEN-HEADEREND:event_editButtonActionPerformed
270
String JavaDoc contractName = getSelectedContractName();
271     
272     if (contractName.length() == 0)
273     {
274       JOptionPane.showMessageDialog(this, "No Contract selected", "Warning", JOptionPane.WARNING_MESSAGE);
275       return;
276     }
277     
278     Contract contract = null;
279     try
280     {
281       contract = admin.getContract(contractName);
282     }
283     catch (RemoteException JavaDoc e)
284     {
285       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
286       return;
287     }
288
289     if (contract == null)
290     {
291       JOptionPane.showMessageDialog(this, "Selected Contract doesn't exist on the node anymore", "Error", JOptionPane.ERROR_MESSAGE);
292       return;
293     }
294     
295     if (ContractEditDialog.showDialog(this, contract, "Contract Editor"))
296     {
297       try
298       {
299         admin.updateContract(contractName, contract);
300       }
301       catch (RemoteException JavaDoc e)
302       {
303         JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
304         return;
305       }
306       catch (RMIAdminException e)
307       {
308         JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
309         return;
310       }
311       
312       reload();
313     }
314   }//GEN-LAST:event_editButtonActionPerformed
315

316   private void contentListMouseClicked(java.awt.event.MouseEvent JavaDoc evt)//GEN-FIRST:event_contentListMouseClicked
317
{//GEN-HEADEREND:event_contentListMouseClicked
318
if (evt.getClickCount() == 2)
319     {
320       editButton.doClick(); //emulate button click
321
}
322   }//GEN-LAST:event_contentListMouseClicked
323

324   private void formComponentShown(java.awt.event.ComponentEvent JavaDoc evt)//GEN-FIRST:event_formComponentShown
325
{//GEN-HEADEREND:event_formComponentShown
326
reload();
327   }//GEN-LAST:event_formComponentShown
328

329   
330   // Variables declaration - do not modify//GEN-BEGIN:variables
331
private javax.swing.JButton JavaDoc addButton;
332   private javax.swing.JList JavaDoc contentList;
333   private javax.swing.JButton JavaDoc deleteButton;
334   private javax.swing.JButton JavaDoc deleteTriggersButton;
335   private javax.swing.JButton JavaDoc editButton;
336   private javax.swing.JButton JavaDoc generateTriggersButton;
337   private javax.swing.JPanel JavaDoc jPanel1;
338   private javax.swing.JPanel JavaDoc jPanel2;
339   private javax.swing.JPanel JavaDoc jPanel3;
340   private javax.swing.JPanel JavaDoc jPanel4;
341   private javax.swing.JScrollPane JavaDoc jScrollPane1;
342   private javax.swing.JButton JavaDoc refreshButton;
343   // End of variables declaration//GEN-END:variables
344

345 }
346
Popular Tags