View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server.core.partition.impl.btree.gui;
21  
22  
23  import java.awt.Frame;
24  import java.awt.event.ActionEvent;
25  import java.awt.event.ActionListener;
26  import java.awt.event.WindowEvent;
27  
28  import javax.swing.JButton;
29  import javax.swing.JDialog;
30  import javax.swing.JPanel;
31  import javax.swing.JScrollPane;
32  import javax.swing.JTable;
33  import javax.swing.JTextArea;
34  import javax.swing.JTree;
35  import javax.swing.ListSelectionModel;
36  import javax.swing.event.ListSelectionEvent;
37  import javax.swing.event.ListSelectionListener;
38  import javax.swing.table.TableModel;
39  import javax.swing.tree.TreeModel;
40  
41  
42  /**
43   * Dialog showing the search results.
44   *
45   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
46   * @version $Rev: 517448 $
47   */
48  public class SearchResultDialog extends JDialog implements ListSelectionListener
49  {
50      private static final long serialVersionUID = 3256999964914757684L;
51  
52      private JPanel jPanel1 = new JPanel();
53      private JTree jTree1 = new JTree();
54      private JPanel jPanel2 = new JPanel();
55      private JPanel jPanel3 = new JPanel();
56      private JTextArea jTextArea1 = new JTextArea();
57      private JScrollPane jScrollPane1 = new JScrollPane();
58      private JButton jButton1 = new JButton();
59      private JPanel jPanel4 = new JPanel();
60      private JScrollPane jScrollPane2 = new JScrollPane();
61      private JTable m_resultsTbl = new JTable();
62  
63  
64      /** Creates new form JDialog */
65      public SearchResultDialog(Frame parent, boolean modal)
66      {
67          super( parent, modal );
68          initGUI();
69      }
70  
71  
72      /**
73       * This method is called from within the constructor to initialize the form.
74       */
75      private void initGUI()
76      {
77          addWindowListener( new java.awt.event.WindowAdapter()
78          {
79              public void windowClosing( java.awt.event.WindowEvent evt )
80              {
81                  closeDialog( evt );
82              }
83          } );
84          pack();
85          getContentPane().setLayout( new java.awt.GridBagLayout() );
86          getContentPane().add(
87              jPanel1,
88              new java.awt.GridBagConstraints( 0, 0, 1, 1, 1.0, 0.1, java.awt.GridBagConstraints.NORTH,
89                  java.awt.GridBagConstraints.BOTH, new java.awt.Insets( 10, 5, 5, 5 ), 0, 0 ) );
90          getContentPane().add(
91              jPanel2,
92              new java.awt.GridBagConstraints( 0, 1, 1, 1, 1.0, 0.4, java.awt.GridBagConstraints.CENTER,
93                  java.awt.GridBagConstraints.BOTH, new java.awt.Insets( 5, 5, 5, 5 ), 0, 0 ) );
94          getContentPane().add(
95              jPanel3,
96              new java.awt.GridBagConstraints( 0, 3, 1, 1, 1.0, 0.1, java.awt.GridBagConstraints.SOUTH,
97                  java.awt.GridBagConstraints.BOTH, new java.awt.Insets( 0, 0, 0, 0 ), 0, 0 ) );
98          getContentPane().add(
99              jPanel4,
100             new java.awt.GridBagConstraints( 0, 2, 1, 1, 1.0, 0.4, java.awt.GridBagConstraints.CENTER,
101                 java.awt.GridBagConstraints.BOTH, new java.awt.Insets( 5, 5, 5, 5 ), 0, 0 ) );
102         jPanel1.setLayout( new java.awt.BorderLayout( 10, 10 ) );
103         jPanel1.setBorder( javax.swing.BorderFactory.createTitledBorder( javax.swing.BorderFactory.createLineBorder(
104             new java.awt.Color( 153, 153, 153 ), 1 ), "Specifications", javax.swing.border.TitledBorder.LEADING,
105             javax.swing.border.TitledBorder.TOP, new java.awt.Font( "SansSerif", 0, 14 ), new java.awt.Color( 60, 60,
106                 60 ) ) );
107         jPanel1.add( jTextArea1, java.awt.BorderLayout.CENTER );
108         jScrollPane1.getViewport().add( jTree1 );
109         jTree1.setBounds( new java.awt.Rectangle( 238, 142, 82, 80 ) );
110         jTextArea1.setText( "" );
111         jTextArea1.setEditable( false );
112         setBounds( new java.awt.Rectangle( 0, 0, 485, 434 ) );
113         setTitle( "Search Results" );
114         jPanel2.setLayout( new java.awt.BorderLayout() );
115         jPanel2.setBorder( javax.swing.BorderFactory.createTitledBorder( javax.swing.BorderFactory.createLineBorder(
116             new java.awt.Color( 153, 153, 153 ), 1 ), "Filter Expression Tree",
117             javax.swing.border.TitledBorder.LEADING, javax.swing.border.TitledBorder.TOP, new java.awt.Font(
118                 "SansSerif", 0, 14 ), new java.awt.Color( 60, 60, 60 ) ) );
119         jPanel2.add( jScrollPane1, java.awt.BorderLayout.CENTER );
120         jButton1.setText( "Done" );
121         jButton1.setActionCommand( "Done" );
122         jButton1.addActionListener( new ActionListener()
123         {
124             public void actionPerformed( ActionEvent event )
125             {
126                 SearchResultDialog.this.setVisible( false );
127                 SearchResultDialog.this.dispose();
128             }
129         } );
130         jButton1.setHorizontalAlignment( javax.swing.SwingConstants.CENTER );
131         jButton1.setAlignmentX( 0.5f );
132         jButton1.setHorizontalTextPosition( javax.swing.SwingConstants.CENTER );
133         jPanel3.setPreferredSize( new java.awt.Dimension( 79, 41 ) );
134         jPanel3.setMinimumSize( new java.awt.Dimension( 79, 41 ) );
135         jPanel3.setSize( new java.awt.Dimension( 471, 35 ) );
136         jPanel3.setToolTipText( "" );
137         jPanel3.add( jButton1 );
138         jPanel4.setBorder( javax.swing.BorderFactory.createTitledBorder( javax.swing.BorderFactory.createLineBorder(
139             new java.awt.Color( 153, 153, 153 ), 1 ), "Search Results", javax.swing.border.TitledBorder.LEADING,
140             javax.swing.border.TitledBorder.TOP, new java.awt.Font( "SansSerif", 0, 14 ), new java.awt.Color( 60, 60,
141                 60 ) ) );
142         jPanel4.setLayout( new java.awt.BorderLayout() );
143         jPanel4.add( jScrollPane2, java.awt.BorderLayout.CENTER );
144         jScrollPane2.getViewport().add( m_resultsTbl );
145         m_resultsTbl.setSize( new java.awt.Dimension( 450, 10 ) );
146         m_resultsTbl.getSelectionModel().addListSelectionListener( this );
147     }
148 
149 
150     public void valueChanged( ListSelectionEvent an_event )
151     {
152         ListSelectionModel selectionModel = ( ListSelectionModel ) an_event.getSource();
153         int minIndex = selectionModel.getMinSelectionIndex();
154         int maxIndex = selectionModel.getMaxSelectionIndex();
155 
156         for ( int ii = minIndex; ii <= maxIndex; ii++ )
157         {
158             if ( selectionModel.isSelectedIndex( ii ) && !an_event.getValueIsAdjusting() )
159             {
160                 Long id = ( Long ) m_resultsTbl.getModel().getValueAt( ii, 0 );
161                 ( ( PartitionFrame ) getParent() ).selectTreeNode( id );
162             }
163         }
164     }
165 
166 
167     /** Closes the dialog */
168     private void closeDialog( WindowEvent evt )
169     {
170         evt.getWindow();
171         setVisible( false );
172         dispose();
173     }
174 
175 
176     public void setTreeModel( TreeModel model )
177     {
178         this.jTree1.setModel( model );
179     }
180 
181 
182     public void setFilter( String filter )
183     {
184         this.jTextArea1.setText( filter );
185     }
186 
187 
188     public void setTableModel( TableModel model )
189     {
190         m_resultsTbl.setModel( model );
191     }
192 }