KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * RMISearchConfigurationEditDialog.java
3  *
4  * Created on 21. květen 2004, 14:22
5  */

6
7 package SOFA.SOFAnet.Browser;
8
9 import javax.swing.*;
10 import SOFA.SOFAnet.Repository.NodeNameFilter;
11 import SOFA.SOFAnet.Search.RMI.RMISearchConfiguration;
12 import java.util.*;
13 import java.awt.Component JavaDoc;
14 import java.awt.Frame JavaDoc;
15
16 /**
17  *
18  * @author Ladislav Sobr
19  */

20 public class RMISearchConfigurationEditDialog extends javax.swing.JDialog JavaDoc
21 {
22   private RMISearchConfiguration configuration;
23   private DefaultListModel content;
24   private NodeNameFilter nodeFilter;
25   private boolean isOK;
26   private boolean apply;
27
28   public static boolean showDialog(Component JavaDoc frameComp, RMISearchConfiguration configuration)
29   {
30     Frame JavaDoc frame = JOptionPane.getFrameForComponent(frameComp);
31     RMISearchConfigurationEditDialog dialog = new RMISearchConfigurationEditDialog(frame, true, configuration);
32     dialog.setLocationRelativeTo(frameComp);
33     dialog.setVisible(true);
34     return dialog.isOK();
35   }
36   
37   /** Creates new form RMISearchConfigurationEditDialog */
38   public RMISearchConfigurationEditDialog(java.awt.Frame JavaDoc parent, boolean modal, RMISearchConfiguration configuration)
39   {
40     super(parent, modal);
41     this.configuration = configuration;
42     content = new DefaultListModel();
43     isOK = false;
44     apply = false;
45     nodeFilter = configuration.getNodeFilter();
46     
47     initComponents();
48     
49     if (nodeFilter != null)
50     {
51       nodeFilterCheckBox.setSelected(true);
52       nodeFilterButton.setEnabled(true);
53     }
54     else
55     {
56       nodeFilterCheckBox.setSelected(false);
57       nodeFilterButton.setEnabled(false);
58     }
59
60     if (nodeFilter != null) nodeFilter = (NodeNameFilter)nodeFilter.clone();
61     else nodeFilter = new NodeNameFilter();
62
63     List connections = configuration.getConnections();
64     synchronized (connections)
65     {
66       Iterator it = connections.iterator();
67       while (it.hasNext())
68       {
69         RMISearchConfiguration.Connection connection = (RMISearchConfiguration.Connection)it.next();
70         content.addElement(connection.clone());
71       }
72     }
73   }
74   
75   public boolean isOK()
76   {
77     return isOK;
78   }
79   
80   public boolean apply()
81   {
82     return apply;
83   }
84   
85   
86   /** This method is called from within the constructor to
87    * initialize the form.
88    * WARNING: Do NOT modify this code. The content of this method is
89    * always regenerated by the Form Editor.
90    */

91   private void initComponents()//GEN-BEGIN:initComponents
92
{
93     jPanel1 = new javax.swing.JPanel JavaDoc();
94     nodeFilterPanel = new javax.swing.JPanel JavaDoc();
95     nodeFilterCheckBox = new javax.swing.JCheckBox JavaDoc();
96     nodeFilterButton = new javax.swing.JButton JavaDoc();
97     jLabel1 = new javax.swing.JLabel JavaDoc();
98     jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
99     connectionsList = new javax.swing.JList JavaDoc();
100     jPanel2 = new javax.swing.JPanel JavaDoc();
101     jPanel4 = new javax.swing.JPanel JavaDoc();
102     editButton = new javax.swing.JButton JavaDoc();
103     addButton = new javax.swing.JButton JavaDoc();
104     deleteSelectedButton = new javax.swing.JButton JavaDoc();
105     jPanel3 = new javax.swing.JPanel JavaDoc();
106     OKButton = new javax.swing.JButton JavaDoc();
107     OKAndApplyButton = new javax.swing.JButton JavaDoc();
108     cancelButton = new javax.swing.JButton JavaDoc();
109
110     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
111     setTitle("RMI Search Subsystem Configuration");
112     jPanel1.setLayout(new java.awt.GridLayout JavaDoc(2, 0));
113
114     jPanel1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(5, 1, 1, 1)));
115     nodeFilterPanel.setLayout(new javax.swing.BoxLayout JavaDoc(nodeFilterPanel, javax.swing.BoxLayout.X_AXIS));
116
117     nodeFilterCheckBox.setText("Node Filter");
118     nodeFilterCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc()
119     {
120       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
121       {
122         nodeFilterCheckBoxActionPerformed(evt);
123       }
124     });
125
126     nodeFilterPanel.add(nodeFilterCheckBox);
127
128     nodeFilterButton.setText("Edit Node Filter");
129     nodeFilterButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
130     {
131       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
132       {
133         nodeFilterButtonActionPerformed(evt);
134       }
135     });
136
137     nodeFilterPanel.add(nodeFilterButton);
138
139     jPanel1.add(nodeFilterPanel);
140
141     jLabel1.setText("Connections:");
142     jPanel1.add(jLabel1);
143
144     getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
145
146     jScrollPane1.setMinimumSize(new java.awt.Dimension JavaDoc(260, 132));
147     connectionsList.setModel(content);
148     connectionsList.addMouseListener(new java.awt.event.MouseAdapter JavaDoc()
149     {
150       public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt)
151       {
152         connectionsListMouseClicked(evt);
153       }
154     });
155
156     jScrollPane1.setViewportView(connectionsList);
157
158     getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
159
160     jPanel2.setLayout(new java.awt.BorderLayout JavaDoc());
161
162     jPanel4.setLayout(new java.awt.GridLayout JavaDoc(3, 0));
163
164     jPanel4.setBorder(new javax.swing.border.TitledBorder JavaDoc("Search Connections"));
165     editButton.setText("Edit Connection");
166     editButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
167     {
168       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
169       {
170         editButtonActionPerformed(evt);
171       }
172     });
173
174     jPanel4.add(editButton);
175
176     addButton.setText("Add New Connection");
177     addButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
178     {
179       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
180       {
181         addButtonActionPerformed(evt);
182       }
183     });
184
185     jPanel4.add(addButton);
186
187     deleteSelectedButton.setText("Delete Selected");
188     deleteSelectedButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
189     {
190       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
191       {
192         deleteSelectedButtonActionPerformed(evt);
193       }
194     });
195
196     jPanel4.add(deleteSelectedButton);
197
198     jPanel2.add(jPanel4, java.awt.BorderLayout.NORTH);
199
200     getContentPane().add(jPanel2, java.awt.BorderLayout.EAST);
201
202     OKButton.setText("OK");
203     OKButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
204     {
205       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
206       {
207         OKButtonActionPerformed(evt);
208       }
209     });
210
211     jPanel3.add(OKButton);
212
213     OKAndApplyButton.setText("Save and Apply Configuration");
214     OKAndApplyButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
215     {
216       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
217       {
218         OKAndApplyButtonActionPerformed(evt);
219       }
220     });
221
222     jPanel3.add(OKAndApplyButton);
223
224     cancelButton.setText("Cancel");
225     cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
226     {
227       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
228       {
229         cancelButtonActionPerformed(evt);
230       }
231     });
232
233     jPanel3.add(cancelButton);
234
235     getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH);
236
237     pack();
238   }//GEN-END:initComponents
239

240   private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
241
{//GEN-HEADEREND:event_cancelButtonActionPerformed
242
dispose();
243   }//GEN-LAST:event_cancelButtonActionPerformed
244

245   private void saveResults()
246   {
247     if (!nodeFilterCheckBox.isSelected()) nodeFilter = null;
248     
249     configuration.setNodeFilter(nodeFilter);
250     
251     List connections = configuration.getConnections();
252     connections.clear();
253     Enumeration en = content.elements();
254     while (en.hasMoreElements()) connections.add((RMISearchConfiguration.Connection)en.nextElement());
255   }
256   
257   private void OKAndApplyButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_OKAndApplyButtonActionPerformed
258
{//GEN-HEADEREND:event_OKAndApplyButtonActionPerformed
259
saveResults();
260     isOK = true;
261     apply = true;
262     dispose();
263   }//GEN-LAST:event_OKAndApplyButtonActionPerformed
264

265   private void OKButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_OKButtonActionPerformed
266
{//GEN-HEADEREND:event_OKButtonActionPerformed
267
saveResults();
268     isOK = true;
269     dispose();
270   }//GEN-LAST:event_OKButtonActionPerformed
271

272   private void connectionsListMouseClicked(java.awt.event.MouseEvent JavaDoc evt)//GEN-FIRST:event_connectionsListMouseClicked
273
{//GEN-HEADEREND:event_connectionsListMouseClicked
274
if (evt.getClickCount() == 2)
275     {
276       editButton.doClick(); //emulate button click
277
}
278   }//GEN-LAST:event_connectionsListMouseClicked
279

280   private void deleteSelectedButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_deleteSelectedButtonActionPerformed
281
{//GEN-HEADEREND:event_deleteSelectedButtonActionPerformed
282
Object JavaDoc[] selected = connectionsList.getSelectedValues();
283     for (int i = 0; i < selected.length; i++) content.removeElement(selected[i]);
284   }//GEN-LAST:event_deleteSelectedButtonActionPerformed
285

286   private void addButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_addButtonActionPerformed
287
{//GEN-HEADEREND:event_addButtonActionPerformed
288
RMISearchConfiguration.Connection connection = new RMISearchConfiguration.Connection("", null);
289     if (RMISearchConfigurationConnectionEditDialog.showDialog(this, connection))
290     {
291       content.addElement(connection);
292     }
293   }//GEN-LAST:event_addButtonActionPerformed
294

295   private void editButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_editButtonActionPerformed
296
{//GEN-HEADEREND:event_editButtonActionPerformed
297
RMISearchConfiguration.Connection connection = (RMISearchConfiguration.Connection)connectionsList.getSelectedValue();
298     
299     if (connection == null)
300     {
301       JOptionPane.showMessageDialog(this, "No Connection selected", "Warning", JOptionPane.WARNING_MESSAGE);
302       return;
303     }
304     
305     if (RMISearchConfigurationConnectionEditDialog.showDialog(this, connection))
306     {
307     }
308   }//GEN-LAST:event_editButtonActionPerformed
309

310   private void nodeFilterButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_nodeFilterButtonActionPerformed
311
{//GEN-HEADEREND:event_nodeFilterButtonActionPerformed
312
StringListEditDialog.showDialog(this, nodeFilter.getPatterns(), "Node Name Pattern", "Node Filter Editor");
313   }//GEN-LAST:event_nodeFilterButtonActionPerformed
314

315   private void nodeFilterCheckBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_nodeFilterCheckBoxActionPerformed
316
{//GEN-HEADEREND:event_nodeFilterCheckBoxActionPerformed
317
nodeFilterButton.setEnabled(nodeFilterCheckBox.isSelected());
318   }//GEN-LAST:event_nodeFilterCheckBoxActionPerformed
319

320  
321   // Variables declaration - do not modify//GEN-BEGIN:variables
322
private javax.swing.JButton JavaDoc OKAndApplyButton;
323   private javax.swing.JButton JavaDoc OKButton;
324   private javax.swing.JButton JavaDoc addButton;
325   private javax.swing.JButton JavaDoc cancelButton;
326   private javax.swing.JList JavaDoc connectionsList;
327   private javax.swing.JButton JavaDoc deleteSelectedButton;
328   private javax.swing.JButton JavaDoc editButton;
329   private javax.swing.JLabel JavaDoc jLabel1;
330   private javax.swing.JPanel JavaDoc jPanel1;
331   private javax.swing.JPanel JavaDoc jPanel2;
332   private javax.swing.JPanel JavaDoc jPanel3;
333   private javax.swing.JPanel JavaDoc jPanel4;
334   private javax.swing.JScrollPane JavaDoc jScrollPane1;
335   private javax.swing.JButton JavaDoc nodeFilterButton;
336   private javax.swing.JCheckBox JavaDoc nodeFilterCheckBox;
337   private javax.swing.JPanel JavaDoc nodeFilterPanel;
338   // End of variables declaration//GEN-END:variables
339

340 }
341
Popular Tags