View Javadoc

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.partition.impl.btree.gui ;
18  
19  
20  import java.awt.Frame;
21  import java.awt.event.ActionEvent;
22  import java.awt.event.ActionListener;
23  import java.awt.event.WindowEvent;
24  import java.math.BigInteger;
25  
26  import javax.swing.JButton;
27  import javax.swing.JDialog;
28  import javax.swing.JPanel;
29  import javax.swing.JScrollPane;
30  import javax.swing.JTable;
31  import javax.swing.JTextArea;
32  import javax.swing.JTree;
33  import javax.swing.ListSelectionModel;
34  import javax.swing.event.ListSelectionEvent;
35  import javax.swing.event.ListSelectionListener;
36  import javax.swing.table.TableModel;
37  import javax.swing.tree.TreeModel;
38  
39  
40  /***
41   * Dialog showing the search results.
42   *
43   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
44   * @version $Rev: 264732 $
45   */
46  public class SearchResultDialog extends JDialog implements ListSelectionListener
47  {
48      private static final long serialVersionUID = 3256999964914757684L;
49  
50      private JPanel jPanel1 = new JPanel();
51      private JTree jTree1 = new JTree();
52      private JPanel jPanel2 = new JPanel();
53      private JPanel jPanel3 = new JPanel();
54      private JTextArea jTextArea1 = new JTextArea();
55      private JScrollPane jScrollPane1 = new JScrollPane();
56      private JButton jButton1 = new JButton();
57      private JPanel jPanel4 = new JPanel();
58      private JScrollPane jScrollPane2 = new JScrollPane();
59      private JTable m_resultsTbl = new JTable();
60  
61      /*** Creates new form JDialog */
62      public SearchResultDialog(Frame parent, boolean modal) {
63          super(parent, modal);
64          initGUI();
65      }
66  
67      /***
68       * This method is called from within the constructor to initialize the form.
69       */
70      private void initGUI() {
71          addWindowListener(
72              new java.awt.event.WindowAdapter() {
73                  public void windowClosing(java.awt.event.WindowEvent evt) {
74                      closeDialog(evt);
75                  }
76              });
77          pack();
78          getContentPane().setLayout(new java.awt.GridBagLayout());
79          getContentPane().add(jPanel1,
80          new java.awt.GridBagConstraints(0, 0, 1, 1, 1.0, 0.1, java.awt.GridBagConstraints.NORTH, java.awt.GridBagConstraints.BOTH,
81          new java.awt.Insets(10, 5, 5, 5), 0, 0));
82          getContentPane().add(jPanel2,
83          new java.awt.GridBagConstraints(0, 1, 1, 1, 1.0, 0.4, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.BOTH,
84          new java.awt.Insets(5, 5, 5, 5), 0, 0));
85          getContentPane().add(jPanel3,
86          new java.awt.GridBagConstraints(0, 3, 1, 1, 1.0, 0.1, java.awt.GridBagConstraints.SOUTH, java.awt.GridBagConstraints.BOTH,
87          new java.awt.Insets(0, 0, 0, 0), 0, 0));
88          getContentPane().add(jPanel4,
89          new java.awt.GridBagConstraints(0, 2, 1, 1, 1.0, 0.4, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.BOTH,
90          new java.awt.Insets(5, 5, 5, 5), 0, 0));
91          jPanel1.setLayout(new java.awt.BorderLayout(10, 10));
92          jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(
93          new java.awt.Color(153, 153, 153), 1), "Specifications", javax.swing.border.TitledBorder.LEADING, javax.swing.border.TitledBorder.TOP,
94          new java.awt.Font("SansSerif", 0, 14), new java.awt.Color(60, 60, 60)));
95          jPanel1.add(jTextArea1, java.awt.BorderLayout.CENTER);
96          jScrollPane1.getViewport().add(jTree1);
97          jTree1.setBounds(new java.awt.Rectangle(238,142,82,80));
98          jTextArea1.setText("");
99          jTextArea1.setEditable(false);
100         setBounds(new java.awt.Rectangle(0, 0, 485, 434));
101         setTitle("Search Results");
102         jPanel2.setLayout(new java.awt.BorderLayout());
103         jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(
104         new java.awt.Color(153, 153, 153), 1),
105         "Filter Expression Tree", javax.swing.border.TitledBorder.LEADING, javax.swing.border.TitledBorder.TOP,
106         new java.awt.Font("SansSerif", 0, 14), new java.awt.Color(60, 60, 60)));
107         jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);
108         jButton1.setText("Done");
109         jButton1.setActionCommand("Done");
110 		jButton1.addActionListener(new ActionListener() {
111             public void actionPerformed(ActionEvent event) {
112                 SearchResultDialog.this.setVisible(false) ;
113 				SearchResultDialog.this.dispose() ;
114             }
115         }) ;
116         jButton1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
117         jButton1.setAlignmentX(0.5f);
118         jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
119         jPanel3.setPreferredSize(new java.awt.Dimension(79, 41));
120         jPanel3.setMinimumSize(new java.awt.Dimension(79, 41));
121         jPanel3.setSize(new java.awt.Dimension(471,35));
122         jPanel3.setToolTipText("");
123         jPanel3.add(jButton1);
124         jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(
125         new java.awt.Color(153, 153, 153), 1), "Search Results", javax.swing.border.TitledBorder.LEADING, javax.swing.border.TitledBorder.TOP,
126         new java.awt.Font("SansSerif", 0, 14), new java.awt.Color(60, 60, 60)));
127         jPanel4.setLayout(new java.awt.BorderLayout());
128         jPanel4.add(jScrollPane2, java.awt.BorderLayout.CENTER);
129         jScrollPane2.getViewport().add(m_resultsTbl);
130         m_resultsTbl.setSize(new java.awt.Dimension(450,10));
131         m_resultsTbl.getSelectionModel().addListSelectionListener(this) ;
132     }
133 
134 
135     public void valueChanged(ListSelectionEvent an_event)
136     {
137         ListSelectionModel selectionModel = (ListSelectionModel) an_event.getSource() ;
138         int minIndex = selectionModel.getMinSelectionIndex() ;
139         int maxIndex = selectionModel.getMaxSelectionIndex() ;
140 
141         for(int ii = minIndex ; ii <= maxIndex; ii++) {
142             if(selectionModel.isSelectedIndex(ii) && !an_event.getValueIsAdjusting()) {
143                 BigInteger id = (BigInteger)
144                     m_resultsTbl.getModel().getValueAt(ii, 0) ;
145                 ((MainFrame) getParent()).selectTreeNode(id) ;
146             }
147         }
148     }
149 
150 
151     /*** Closes the dialog */
152     private void closeDialog(WindowEvent evt) {
153         evt.getWindow();
154         setVisible(false);
155         dispose();
156     }
157 
158 
159     public void setTreeModel(TreeModel model)
160     {
161         this.jTree1.setModel(model) ;
162     }
163 
164 
165     public void setFilter(String filter)
166     {
167         this.jTextArea1.setText(filter) ;
168     }
169 
170 
171     public void setTableModel(TableModel model)
172     {
173         m_resultsTbl.setModel(model) ;
174     }
175 }