KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * InputTriggersPanel.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.InputTrigger;
12 import java.rmi.RemoteException JavaDoc;
13 import java.util.Arrays JavaDoc;
14
15 /**
16  *
17  * @author Ladislav Sobr
18  */

19 public class InputTriggersPanel extends javax.swing.JPanel JavaDoc
20 {
21   private RMIAdminInterface admin;
22   private DefaultListModel content;
23   
24   
25   /** Creates new form InputTriggersPanel */
26   public InputTriggersPanel(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     InputTriggerDesc[] inputTriggerDescs = null;
38     try
39     {
40       inputTriggerDescs = admin.inputTriggerDescsList();
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(inputTriggerDescs);
49     
50     content.ensureCapacity(inputTriggerDescs.length);
51     for (int i = 0; i < inputTriggerDescs.length; i++) content.addElement(inputTriggerDescs[i]);
52   }
53   
54   private String JavaDoc getSelectedInputTriggerName()
55   {
56     String JavaDoc inputTriggerName = "";
57
58     int index = contentList.getSelectedIndex();
59     if (index != -1) inputTriggerName = ((InputTriggerDesc)content.getElementAt(index)).name;
60     return inputTriggerName;
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     jPanel1 = new javax.swing.JPanel JavaDoc();
76     jPanel3 = new javax.swing.JPanel JavaDoc();
77     refreshButton = new javax.swing.JButton JavaDoc();
78     generateTriggersOfContractButton = new javax.swing.JButton JavaDoc();
79     deleteTriggersOfContractButton = 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(3, 0));
97
98     jPanel4.setBorder(new javax.swing.border.TitledBorder JavaDoc("Input Trigger Specific"));
99     editButton.setText("Edit Input Tigger");
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 InputTrigger");
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 Input Trigger");
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     jPanel2.add(jPanel4, java.awt.BorderLayout.NORTH);
133
134     jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
135
136     jPanel1.setBorder(new javax.swing.border.TitledBorder JavaDoc("General"));
137     jPanel3.setLayout(new java.awt.GridLayout JavaDoc(3, 0));
138
139     refreshButton.setText("Refresh");
140     refreshButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
141     {
142       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
143       {
144         refreshButtonActionPerformed(evt);
145       }
146     });
147
148     jPanel3.add(refreshButton);
149
150     generateTriggersOfContractButton.setText("Generate Triggers of Contract");
151     generateTriggersOfContractButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
152     {
153       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
154       {
155         generateTriggersOfContractButtonActionPerformed(evt);
156       }
157     });
158
159     jPanel3.add(generateTriggersOfContractButton);
160
161     deleteTriggersOfContractButton.setText("Delete Triggers of Contract");
162     deleteTriggersOfContractButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
163     {
164       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
165       {
166         deleteTriggersOfContractButtonActionPerformed(evt);
167       }
168     });
169
170     jPanel3.add(deleteTriggersOfContractButton);
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 deleteTriggersOfContractButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_deleteTriggersOfContractButtonActionPerformed
196
{//GEN-HEADEREND:event_deleteTriggersOfContractButtonActionPerformed
197
if (DeleteTriggersOfContractDialog.showDialog(this, admin, "")) reload();
198   }//GEN-LAST:event_deleteTriggersOfContractButtonActionPerformed
199

200   private void generateTriggersOfContractButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_generateTriggersOfContractButtonActionPerformed
201
{//GEN-HEADEREND:event_generateTriggersOfContractButtonActionPerformed
202
if (GenerateTriggersOfContractDialog.showDialog(this, admin, "")) reload();
203   }//GEN-LAST:event_generateTriggersOfContractButtonActionPerformed
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 inputTriggerName = getSelectedInputTriggerName();
213     
214     if (inputTriggerName.length() == 0)
215     {
216       JOptionPane.showMessageDialog(this, "No Input Trigger selected", "Warning", JOptionPane.WARNING_MESSAGE);
217       return;
218     }
219     else
220     {
221       if (JOptionPane.showConfirmDialog(this, "Do you really want to delete Input Trigger '" + inputTriggerName + "'?") != JOptionPane.YES_OPTION) return;
222     }
223     
224     try
225     {
226       admin.updateInputTrigger(inputTriggerName, 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 inputTriggerName = JOptionPane.showInputDialog(this, "Name of New Input Trigger:", "New Input Trigger", JOptionPane.INFORMATION_MESSAGE);
245     if (inputTriggerName != null)
246     {
247       InputTrigger inputTrigger = new InputTrigger();
248       
249       try
250       {
251         admin.updateInputTrigger(inputTriggerName, inputTrigger);
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 inputTriggerName = getSelectedInputTriggerName();
271     
272     if (inputTriggerName.length() == 0)
273     {
274       JOptionPane.showMessageDialog(this, "No Input Trigger selected", "Warning", JOptionPane.WARNING_MESSAGE);
275       return;
276     }
277     
278     InputTrigger inputTrigger = null;
279     try
280     {
281       inputTrigger = admin.getInputTrigger(inputTriggerName);
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 (inputTrigger == null)
290     {
291       JOptionPane.showMessageDialog(this, "Selected Input Trigger doesn't exist on the node anymore", "Error", JOptionPane.ERROR_MESSAGE);
292       return;
293     }
294     
295     if (InputTriggerEditDialog.showDialog(this, inputTrigger, "Input Trigger Editor"))
296     {
297       try
298       {
299         admin.updateInputTrigger(inputTriggerName, inputTrigger);
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 deleteTriggersOfContractButton;
335   private javax.swing.JButton JavaDoc editButton;
336   private javax.swing.JButton JavaDoc generateTriggersOfContractButton;
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