001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.server.core.partition.impl.btree.gui;
021
022
023 import java.awt.Frame;
024 import java.awt.event.ActionEvent;
025 import java.awt.event.ActionListener;
026 import java.awt.event.WindowEvent;
027
028 import javax.swing.JButton;
029 import javax.swing.JDialog;
030 import javax.swing.JPanel;
031 import javax.swing.JScrollPane;
032 import javax.swing.JTable;
033 import javax.swing.JTextArea;
034 import javax.swing.JTree;
035 import javax.swing.ListSelectionModel;
036 import javax.swing.event.ListSelectionEvent;
037 import javax.swing.event.ListSelectionListener;
038 import javax.swing.table.TableModel;
039 import javax.swing.tree.TreeModel;
040
041
042 /**
043 * Dialog showing the search results.
044 *
045 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
046 * @version $Rev: 517448 $
047 */
048 public class SearchResultDialog extends JDialog implements ListSelectionListener
049 {
050 private static final long serialVersionUID = 3256999964914757684L;
051
052 private JPanel jPanel1 = new JPanel();
053 private JTree jTree1 = new JTree();
054 private JPanel jPanel2 = new JPanel();
055 private JPanel jPanel3 = new JPanel();
056 private JTextArea jTextArea1 = new JTextArea();
057 private JScrollPane jScrollPane1 = new JScrollPane();
058 private JButton jButton1 = new JButton();
059 private JPanel jPanel4 = new JPanel();
060 private JScrollPane jScrollPane2 = new JScrollPane();
061 private JTable m_resultsTbl = new JTable();
062
063
064 /** Creates new form JDialog */
065 public SearchResultDialog(Frame parent, boolean modal)
066 {
067 super( parent, modal );
068 initGUI();
069 }
070
071
072 /**
073 * This method is called from within the constructor to initialize the form.
074 */
075 private void initGUI()
076 {
077 addWindowListener( new java.awt.event.WindowAdapter()
078 {
079 public void windowClosing( java.awt.event.WindowEvent evt )
080 {
081 closeDialog( evt );
082 }
083 } );
084 pack();
085 getContentPane().setLayout( new java.awt.GridBagLayout() );
086 getContentPane().add(
087 jPanel1,
088 new java.awt.GridBagConstraints( 0, 0, 1, 1, 1.0, 0.1, java.awt.GridBagConstraints.NORTH,
089 java.awt.GridBagConstraints.BOTH, new java.awt.Insets( 10, 5, 5, 5 ), 0, 0 ) );
090 getContentPane().add(
091 jPanel2,
092 new java.awt.GridBagConstraints( 0, 1, 1, 1, 1.0, 0.4, java.awt.GridBagConstraints.CENTER,
093 java.awt.GridBagConstraints.BOTH, new java.awt.Insets( 5, 5, 5, 5 ), 0, 0 ) );
094 getContentPane().add(
095 jPanel3,
096 new java.awt.GridBagConstraints( 0, 3, 1, 1, 1.0, 0.1, java.awt.GridBagConstraints.SOUTH,
097 java.awt.GridBagConstraints.BOTH, new java.awt.Insets( 0, 0, 0, 0 ), 0, 0 ) );
098 getContentPane().add(
099 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 }