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.BorderLayout;
024 import java.awt.Color;
025 import java.awt.Dimension;
026 import java.awt.FlowLayout;
027 import java.awt.Font;
028 import java.awt.GridBagConstraints;
029 import java.awt.GridBagLayout;
030 import java.awt.Insets;
031 import java.awt.event.ActionListener;
032 import java.awt.event.WindowAdapter;
033 import java.awt.event.WindowEvent;
034
035 import javax.swing.BorderFactory;
036 import javax.swing.JButton;
037 import javax.swing.JComboBox;
038 import javax.swing.JDialog;
039 import javax.swing.JFrame;
040 import javax.swing.JLabel;
041 import javax.swing.JPanel;
042 import javax.swing.JScrollPane;
043 import javax.swing.JTextArea;
044 import javax.swing.JTextField;
045 import javax.swing.border.TitledBorder;
046
047 import org.apache.directory.server.i18n.I18n;
048
049
050 /**
051 * A dialog for the filter.
052 *
053 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
054 * @version $Rev: 902558 $
055 */
056 public class FilterDialog extends JDialog
057 {
058 private static final long serialVersionUID = 3760565295319626294L;
059
060 public static final String RUN_MODE = "Run";
061 public static final String LOAD_MODE = "Load";
062 public static final String DEBUG_MODE = "Debug";
063 public static final String ANNOTATE_MODE = "Annotate";
064
065 public static final String UNLIMITED = "Unlimited";
066
067 public static final String BASE_SCOPE = "Base Object";
068 public static final String SINGLE_SCOPE = "Single Level";
069 public static final String SUBTREE_SCOPE = "Subtree Level";
070
071 public static final String LOAD_CMD = "Load";
072 public static final String SEARCH_CMD = "Search";
073 public static final String CANCEL_CMD = "Cancel";
074
075 private JPanel m_northPnl = new JPanel();
076 private JPanel m_centerPnl = new JPanel();
077 private JTextArea m_filterText = new JTextArea();
078 private JLabel m_scopeLbl = new JLabel();
079 private JComboBox m_scopeChoice = new JComboBox();
080 private JLabel m_limitLbl = new JLabel();
081 private JTextField m_limitField = new JTextField();
082 private JPanel m_southPnl = new JPanel();
083 private JButton m_searchBut = new JButton();
084 private JButton m_cancelBut = new JButton();
085 private JScrollPane m_scrollPane = new JScrollPane();
086 private final String m_mode;
087 private JTextField m_baseText = new JTextField();
088 private JPanel m_basePnl = new JPanel();
089 private JLabel jLabel1 = new JLabel();
090
091
092 /** Creates new form JDialog */
093 public FilterDialog(String a_mode, JFrame parent, boolean modal)
094 {
095 super( parent, modal );
096 m_mode = a_mode;
097 initGUI();
098 }
099
100
101 public void addActionListener( ActionListener l_listener )
102 {
103 m_searchBut.addActionListener( l_listener );
104 m_cancelBut.addActionListener( l_listener );
105 }
106
107
108 /**
109 * This method is called from within the constructor to initialize the form
110 */
111 private void initGUI()
112 {
113 m_baseText.setText( "" );
114 addWindowListener( new WindowAdapter()
115 {
116 public void windowClosing( WindowEvent evt )
117 {
118 closeDialog( evt );
119 }
120 } );
121 pack();
122
123 getContentPane().setLayout( new java.awt.GridBagLayout() );
124 getContentPane().add(
125 m_northPnl,
126 new java.awt.GridBagConstraints( 0, 0, 1, 1, 0.9, 0.0, java.awt.GridBagConstraints.NORTH,
127 java.awt.GridBagConstraints.BOTH, new java.awt.Insets( 5, 5, 6, 0 ), 0, 0 ) );
128 getContentPane().add(
129 m_centerPnl,
130 new GridBagConstraints( 0, 1, 1, 1, 0.9, 0.9, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
131 new Insets( 10, 10, 10, 10 ), 0, 0 ) );
132 getContentPane().add(
133 m_southPnl,
134 new GridBagConstraints( 0, 2, 1, 1, 1.0, 0.0, GridBagConstraints.SOUTH, GridBagConstraints.BOTH,
135 new Insets( 0, 0, 2, 0 ), 0, 0 ) );
136 m_northPnl.setLayout( new GridBagLayout() );
137 m_northPnl.setBorder( null );
138 m_northPnl.add( m_scopeLbl, new java.awt.GridBagConstraints( 0, 0, 1, 1, 0.2, 0.0,
139 java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.NONE, new java.awt.Insets( 5, 0, 5, 0 ), 0,
140 0 ) );
141 m_northPnl.add( m_scopeChoice, new java.awt.GridBagConstraints( 1, 0, 1, 1, 1.0, 0.0,
142 java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.HORIZONTAL,
143 new java.awt.Insets( 9, 0, 7, 5 ), 0, 0 ) );
144 m_northPnl.add( m_limitLbl, new GridBagConstraints( 2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
145 GridBagConstraints.NONE, new Insets( 5, 10, 5, 5 ), 0, 0 ) );
146 m_northPnl.add( m_limitField, new java.awt.GridBagConstraints( 3, 0, 1, 1, 1.0, 0.0,
147 java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.HORIZONTAL, new java.awt.Insets( 11, 0, 9,
148 10 ), 0, 0 ) );
149 m_northPnl.add( m_basePnl, new java.awt.GridBagConstraints( 0, 1, 4, 1, 0.0, 0.0,
150 java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.BOTH, new java.awt.Insets( 5, 10, 5, 10 ),
151 0, 0 ) );
152 m_filterText.setText( "" );
153 m_filterText.setBorder( null );
154 m_centerPnl.setLayout( new BorderLayout() );
155 m_centerPnl.setBorder( BorderFactory.createTitledBorder( BorderFactory.createLineBorder( new Color( 153, 153,
156 153 ), 1 ), "Search Filter", TitledBorder.LEADING, TitledBorder.TOP, new Font( "SansSerif", 0, 14 ),
157 new Color( 60, 60, 60 ) ) );
158 m_scrollPane.getViewport().add( m_filterText );
159 m_centerPnl.add( m_scrollPane, BorderLayout.CENTER );
160 m_scopeLbl.setText( "Scope:" );
161 m_scopeLbl.setFont( new java.awt.Font( "Dialog", java.awt.Font.PLAIN, 14 ) );
162 m_scopeChoice.setSize( new java.awt.Dimension( 115, 25 ) );
163 m_scopeChoice.setMaximumSize( new Dimension( 32767, 25 ) );
164 m_scopeChoice.setMinimumSize( new java.awt.Dimension( 115, 25 ) );
165 m_scopeChoice.setPreferredSize( new Dimension( 115, 25 ) );
166 m_scopeChoice.addItem( BASE_SCOPE );
167 m_scopeChoice.addItem( SINGLE_SCOPE );
168 m_scopeChoice.addItem( SUBTREE_SCOPE );
169
170 m_limitLbl.setText( "Limit:" );
171 m_limitField.setText( "Unlimited" );
172 m_limitField.setHorizontalAlignment( JTextField.CENTER );
173 m_southPnl.setLayout( new FlowLayout( FlowLayout.CENTER, 15, 5 ) );
174 m_southPnl.add( m_searchBut );
175
176 if ( m_mode != LOAD_MODE )
177 {
178 m_searchBut.setText( SEARCH_CMD );
179 m_searchBut.setActionCommand( SEARCH_CMD );
180 m_southPnl.add( m_cancelBut );
181 }
182 else
183 {
184 m_searchBut.setText( LOAD_CMD );
185 m_searchBut.setActionCommand( LOAD_CMD );
186 }
187
188 m_cancelBut.setText( CANCEL_CMD );
189 m_cancelBut.setActionCommand( CANCEL_CMD );
190 setBounds( new java.awt.Rectangle( 0, 0, 595, 331 ) );
191 m_basePnl.setLayout( new java.awt.GridBagLayout() );
192 m_basePnl.add( jLabel1,
193 new java.awt.GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, java.awt.GridBagConstraints.WEST,
194 java.awt.GridBagConstraints.NONE, new java.awt.Insets( 0, 0, 0, 0 ), 0, 0 ) );
195 m_basePnl.add( m_baseText, new java.awt.GridBagConstraints( 1, 0, 1, 1, 1.0, 0.0,
196 java.awt.GridBagConstraints.EAST, java.awt.GridBagConstraints.HORIZONTAL,
197 new java.awt.Insets( 5, 5, 5, 0 ), 0, 0 ) );
198 jLabel1.setText( "Search Base:" );
199 jLabel1.setFont( new java.awt.Font( "SansSerif", java.awt.Font.PLAIN, 14 ) );
200
201 if ( m_mode == RUN_MODE )
202 {
203 setTitle( "Search Filter Dialog: Execute mode" );
204 }
205 else if ( m_mode == LOAD_MODE )
206 {
207 setTitle( "Search Filter Dialog: Load mode" );
208 }
209 else if ( m_mode == DEBUG_MODE )
210 {
211 setTitle( "Search Filter Dialog: Debug mode" );
212 }
213 else if ( m_mode == ANNOTATE_MODE )
214 {
215 setTitle( "Search Filter Dialog: Annotate mode" );
216 this.m_scopeChoice.setEnabled( false );
217 this.m_limitField.setEnabled( false );
218 this.m_baseText.setEnabled( false );
219 }
220 else
221 {
222 throw new RuntimeException( I18n.err( I18n.ERR_730 ) );
223 }
224 }
225
226
227 /**
228 * Closes the dialog
229 */
230 public void closeDialog( WindowEvent evt )
231 {
232 setVisible( false );
233 dispose();
234 }
235
236
237 public String getScope()
238 {
239 int l_selected = m_scopeChoice.getSelectedIndex();
240 return ( String ) m_scopeChoice.getItemAt( l_selected );
241 }
242
243
244 /*
245 public int getScope()
246 {
247 int l_selected = m_scopeChoice.getSelectedIndex() ;
248 String l_scope = (String) m_scopeChoice.getItemAt(l_selected) ;
249
250 if(l_scope == BASE_SCOPE) {
251 return Backend.BASE_SCOPE ;
252 } else if(l_scope == SINGLE_SCOPE) {
253 return Backend.SINGLE_SCOPE ;
254 } else if(l_scope == SUBTREE_SCOPE) {
255 return Backend.SUBTREE_SCOPE ;
256 }
257
258 throw new RuntimeException("Unexpected scope parameter: " + l_scope) ;
259 }
260 */
261
262 public String getLimit()
263 {
264 return m_limitField.getText();
265 }
266
267
268 /*
269 public String getLimit()
270 {
271 String l_limit = m_limitField.getText() ;
272
273 if(l_limit.equals(UNLIMITED)) {
274 return -1 ;
275 }
276
277 return Integer.parseInt(l_limit) ;
278 }
279 */
280
281 public String getFilter()
282 {
283 return this.m_filterText.getText();
284 }
285
286
287 public void setBase( String a_base )
288 {
289 this.m_baseText.setText( a_base );
290 }
291
292
293 public void setScope( String a_scope )
294 {
295 this.m_scopeChoice.setSelectedItem( a_scope );
296 }
297
298
299 public String getBase()
300 {
301 return this.m_baseText.getText();
302 }
303 }