KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ldap > server > db > gui > SearchResultDialog


1 /*
2  * Copyright 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package org.apache.ldap.server.db.gui ;
18
19
20 import javax.swing.*;
21 import javax.swing.event.ListSelectionEvent JavaDoc;
22 import javax.swing.event.ListSelectionListener JavaDoc;
23 import javax.swing.table.TableModel JavaDoc;
24 import javax.swing.tree.TreeModel JavaDoc;
25 import java.awt.*;
26 import java.awt.event.ActionEvent JavaDoc;
27 import java.awt.event.ActionListener JavaDoc;
28 import java.awt.event.WindowEvent JavaDoc;
29 import java.math.BigInteger JavaDoc;
30
31
32 /**
33  * Dialog showing the search results.
34  *
35  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
36  * @version $Rev: 169198 $
37  */

38 public class SearchResultDialog extends JDialog implements ListSelectionListener JavaDoc
39 {
40     private static final long serialVersionUID = 3256999964914757684L;
41
42     private JPanel jPanel1 = new JPanel();
43     private JTree jTree1 = new JTree();
44     private JPanel jPanel2 = new JPanel();
45     private JPanel jPanel3 = new JPanel();
46     private JTextArea jTextArea1 = new JTextArea();
47     private JScrollPane jScrollPane1 = new JScrollPane();
48     private JButton jButton1 = new JButton();
49     private JPanel jPanel4 = new JPanel();
50     private JScrollPane jScrollPane2 = new JScrollPane();
51     private JTable m_resultsTbl = new JTable();
52
53     /** Creates new form JDialog */
54     public SearchResultDialog(Frame parent, boolean modal) {
55         super(parent, modal);
56         initGUI();
57     }
58
59     /**
60      * This method is called from within the constructor to initialize the form.
61      */

62     private void initGUI() {
63         addWindowListener(
64             new java.awt.event.WindowAdapter JavaDoc() {
65                 public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
66                     closeDialog(evt);
67                 }
68             });
69         pack();
70         getContentPane().setLayout(new java.awt.GridBagLayout JavaDoc());
71         getContentPane().add(jPanel1,
72         new java.awt.GridBagConstraints JavaDoc(0, 0, 1, 1, 1.0, 0.1, java.awt.GridBagConstraints.NORTH, java.awt.GridBagConstraints.BOTH,
73         new java.awt.Insets JavaDoc(10, 5, 5, 5), 0, 0));
74         getContentPane().add(jPanel2,
75         new java.awt.GridBagConstraints JavaDoc(0, 1, 1, 1, 1.0, 0.4, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.BOTH,
76         new java.awt.Insets JavaDoc(5, 5, 5, 5), 0, 0));
77         getContentPane().add(jPanel3,
78         new java.awt.GridBagConstraints JavaDoc(0, 3, 1, 1, 1.0, 0.1, java.awt.GridBagConstraints.SOUTH, java.awt.GridBagConstraints.BOTH,
79         new java.awt.Insets JavaDoc(0, 0, 0, 0), 0, 0));
80         getContentPane().add(jPanel4,
81         new java.awt.GridBagConstraints JavaDoc(0, 2, 1, 1, 1.0, 0.4, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.BOTH,
82         new java.awt.Insets JavaDoc(5, 5, 5, 5), 0, 0));
83         jPanel1.setLayout(new java.awt.BorderLayout JavaDoc(10, 10));
84         jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(
85         new java.awt.Color JavaDoc(153, 153, 153), 1), "Specifications", javax.swing.border.TitledBorder.LEADING, javax.swing.border.TitledBorder.TOP,
86         new java.awt.Font JavaDoc("SansSerif", 0, 14), new java.awt.Color JavaDoc(60, 60, 60)));
87         jPanel1.add(jTextArea1, java.awt.BorderLayout.CENTER);
88         jScrollPane1.getViewport().add(jTree1);
89         jTree1.setBounds(new java.awt.Rectangle JavaDoc(238,142,82,80));
90         jTextArea1.setText("");
91         jTextArea1.setEditable(false);
92         setBounds(new java.awt.Rectangle JavaDoc(0, 0, 485, 434));
93         setTitle("Search Results");
94         jPanel2.setLayout(new java.awt.BorderLayout JavaDoc());
95         jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(
96         new java.awt.Color JavaDoc(153, 153, 153), 1),
97         "Filter Expression Tree", javax.swing.border.TitledBorder.LEADING, javax.swing.border.TitledBorder.TOP,
98         new java.awt.Font JavaDoc("SansSerif", 0, 14), new java.awt.Color JavaDoc(60, 60, 60)));
99         jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);
100         jButton1.setText("Done");
101         jButton1.setActionCommand("Done");
102         jButton1.addActionListener(new ActionListener JavaDoc() {
103             public void actionPerformed(ActionEvent JavaDoc event) {
104                 SearchResultDialog.this.setVisible(false) ;
105                 SearchResultDialog.this.dispose() ;
106             }
107         }) ;
108         jButton1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
109         jButton1.setAlignmentX(0.5f);
110         jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
111         jPanel3.setPreferredSize(new java.awt.Dimension JavaDoc(79, 41));
112         jPanel3.setMinimumSize(new java.awt.Dimension JavaDoc(79, 41));
113         jPanel3.setSize(new java.awt.Dimension JavaDoc(471,35));
114         jPanel3.setToolTipText("");
115         jPanel3.add(jButton1);
116         jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(
117         new java.awt.Color JavaDoc(153, 153, 153), 1), "Search Results", javax.swing.border.TitledBorder.LEADING, javax.swing.border.TitledBorder.TOP,
118         new java.awt.Font JavaDoc("SansSerif", 0, 14), new java.awt.Color JavaDoc(60, 60, 60)));
119         jPanel4.setLayout(new java.awt.BorderLayout JavaDoc());
120         jPanel4.add(jScrollPane2, java.awt.BorderLayout.CENTER);
121         jScrollPane2.getViewport().add(m_resultsTbl);
122         m_resultsTbl.setSize(new java.awt.Dimension JavaDoc(450,10));
123         m_resultsTbl.getSelectionModel().addListSelectionListener(this) ;
124     }
125
126
127     public void valueChanged(ListSelectionEvent JavaDoc an_event)
128     {
129         ListSelectionModel selectionModel = (ListSelectionModel) an_event.getSource() ;
130         int minIndex = selectionModel.getMinSelectionIndex() ;
131         int maxIndex = selectionModel.getMaxSelectionIndex() ;
132
133         for(int ii = minIndex ; ii <= maxIndex; ii++) {
134             if(selectionModel.isSelectedIndex(ii) && !an_event.getValueIsAdjusting()) {
135                 BigInteger JavaDoc id = (BigInteger JavaDoc)
136                     m_resultsTbl.getModel().getValueAt(ii, 0) ;
137                 ((MainFrame) getParent()).selectTreeNode(id) ;
138             }
139         }
140     }
141
142
143     /** Closes the dialog */
144     private void closeDialog(WindowEvent JavaDoc evt) {
145         evt.getWindow();
146         setVisible(false);
147         dispose();
148     }
149
150
151     public void setTreeModel(TreeModel JavaDoc model)
152     {
153         this.jTree1.setModel(model) ;
154     }
155
156
157     public void setFilter(String JavaDoc filter)
158     {
159         this.jTextArea1.setText(filter) ;
160     }
161
162
163     public void setTableModel(TableModel JavaDoc model)
164     {
165         m_resultsTbl.setModel(model) ;
166     }
167 }
168
Popular Tags