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.BorderLayout;
21  import java.awt.Color;
22  import java.awt.Dimension;
23  import java.awt.FlowLayout;
24  import java.awt.Font;
25  import java.awt.GridBagConstraints;
26  import java.awt.GridBagLayout;
27  import java.awt.Insets;
28  import java.awt.event.ActionListener;
29  import java.awt.event.WindowAdapter;
30  import java.awt.event.WindowEvent;
31  
32  import javax.swing.BorderFactory;
33  import javax.swing.JButton;
34  import javax.swing.JComboBox;
35  import javax.swing.JDialog;
36  import javax.swing.JFrame;
37  import javax.swing.JLabel;
38  import javax.swing.JPanel;
39  import javax.swing.JScrollPane;
40  import javax.swing.JTextArea;
41  import javax.swing.JTextField;
42  import javax.swing.border.TitledBorder;
43  
44  
45  /***
46   * A dialog for the filter.
47   *
48   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
49   * @version $Rev: 264732 $
50   */
51  public class FilterDialog extends JDialog
52  {
53  	private static final long serialVersionUID = 3760565295319626294L;
54  
55      public static final String RUN_MODE = "Run" ;
56      public static final String LOAD_MODE = "Load" ;
57      public static final String DEBUG_MODE = "Debug" ;
58  	public static final String ANNOTATE_MODE = "Annotate" ;
59  
60      public static final String UNLIMITED = "Unlimited" ;
61  
62  	public static final String BASE_SCOPE = "Base Object" ;
63  	public static final String SINGLE_SCOPE = "Single Level" ;
64  	public static final String SUBTREE_SCOPE = "Subtree Level" ;
65  
66      public static final String LOAD_CMD = "Load" ;
67      public static final String SEARCH_CMD = "Search" ;
68      public static final String CANCEL_CMD = "Cancel" ;
69  
70      private JPanel m_northPnl = new JPanel() ;
71      private JPanel m_centerPnl = new JPanel() ;
72      private JTextArea m_filterText = new JTextArea() ;
73      private JLabel m_scopeLbl = new JLabel() ;
74      private JComboBox m_scopeChoice = new JComboBox() ;
75      private JLabel m_limitLbl = new JLabel() ;
76      private JTextField m_limitField = new JTextField() ;
77      private JPanel m_southPnl = new JPanel() ;
78      private JButton m_searchBut = new JButton() ;
79      private JButton m_cancelBut = new JButton() ;
80      private JScrollPane m_scrollPane = new JScrollPane() ;
81      private final String m_mode ;
82      private JTextField m_baseText = new JTextField();
83      private JPanel m_basePnl = new JPanel();
84      private JLabel jLabel1 = new JLabel();
85  
86      /*** Creates new form JDialog */
87      public FilterDialog(String a_mode, JFrame parent, boolean modal)
88      {
89          super(parent, modal) ;
90          m_mode = a_mode ;
91          initGUI() ;
92      }
93  
94  
95  	public void addActionListener(ActionListener l_listener)
96      {
97          m_searchBut.addActionListener(l_listener) ;
98          m_cancelBut.addActionListener(l_listener) ;
99      }
100 
101 
102 
103 	/***
104      * This method is called from within the constructor to initialize the form
105      */
106     private void initGUI() {
107         m_baseText.setText("");
108         addWindowListener(
109             new WindowAdapter() {
110                 public void windowClosing(WindowEvent evt) {
111                     closeDialog(evt);
112                 }
113             }) ;
114         pack() ;
115 
116         getContentPane().setLayout(new java.awt.GridBagLayout()) ;
117         getContentPane().add(m_northPnl,
118         new java.awt.GridBagConstraints(0, 0, 1, 1, 0.9, 0.0, java.awt.GridBagConstraints.NORTH, java.awt.GridBagConstraints.BOTH,
119         new java.awt.Insets(5, 5, 6, 0), 0, 0));
120         getContentPane().add(m_centerPnl,
121         new GridBagConstraints(0, 1, 1, 1, 0.9, 0.9,
122         GridBagConstraints.CENTER, GridBagConstraints.BOTH,
123         new Insets(10, 10, 10, 10), 0, 0));
124         getContentPane().add(m_southPnl,
125 	        new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0,
126         	GridBagConstraints.SOUTH, GridBagConstraints.BOTH,
127     	    new Insets(0, 0, 2, 0), 0, 0)) ;
128         m_northPnl.setLayout(new GridBagLayout()) ;
129         m_northPnl.setBorder(null) ;
130         m_northPnl.add(m_scopeLbl,
131         new java.awt.GridBagConstraints(0, 0, 1, 1, 0.2, 0.0, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.NONE,
132         new java.awt.Insets(5, 0, 5, 0), 0, 0));
133         m_northPnl.add(m_scopeChoice,
134         new java.awt.GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.HORIZONTAL,
135         new java.awt.Insets(9, 0, 7, 5), 0, 0));
136         m_northPnl.add(m_limitLbl,
137 	        new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
138             GridBagConstraints.CENTER, GridBagConstraints.NONE,
139         	new Insets(5, 10, 5, 5), 0, 0)) ;
140         m_northPnl.add(m_limitField,
141         new java.awt.GridBagConstraints(3, 0, 1, 1, 1.0, 0.0, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.HORIZONTAL,
142         new java.awt.Insets(11, 0, 9, 10), 0, 0));
143         m_northPnl.add(m_basePnl,
144         new java.awt.GridBagConstraints(0, 1, 4, 1, 0.0, 0.0, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.BOTH,
145         new java.awt.Insets(5, 10, 5, 10), 0, 0));
146         m_filterText.setText("") ;
147         m_filterText.setBorder(null) ;
148         m_centerPnl.setLayout(new BorderLayout()) ;
149         m_centerPnl.setBorder(BorderFactory.createTitledBorder(
150             BorderFactory.createLineBorder(
151         		new Color(153, 153, 153), 1), "Search Filter",
152                 TitledBorder.LEADING, TitledBorder.TOP,
153         		new Font("SansSerif", 0, 14), new Color(60, 60, 60))) ;
154         m_scrollPane.getViewport().add(m_filterText);
155         m_centerPnl.add(m_scrollPane, BorderLayout.CENTER) ;
156         m_scopeLbl.setText("Scope:") ;
157         m_scopeLbl.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 14));
158         m_scopeChoice.setSize(new java.awt.Dimension(115, 25));
159         m_scopeChoice.setMaximumSize(new Dimension(32767,25)) ;
160         m_scopeChoice.setMinimumSize(new java.awt.Dimension(115, 25));
161         m_scopeChoice.setPreferredSize(new Dimension(115, 25)) ;
162 		m_scopeChoice.addItem(BASE_SCOPE) ;
163 		m_scopeChoice.addItem(SINGLE_SCOPE) ;
164 		m_scopeChoice.addItem(SUBTREE_SCOPE) ;
165 
166         m_limitLbl.setText("Limit:") ;
167         m_limitField.setText("Unlimited") ;
168         m_limitField.setHorizontalAlignment(JTextField.CENTER) ;
169         m_southPnl.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 5)) ;
170         m_southPnl.add(m_searchBut) ;
171 
172         if ( m_mode != LOAD_MODE ) 
173         {
174             m_searchBut.setText( SEARCH_CMD ) ;
175             m_searchBut.setActionCommand( SEARCH_CMD ) ;
176             m_southPnl.add( m_cancelBut ) ;
177         } 
178         else 
179         {
180             m_searchBut.setText( LOAD_CMD ) ;
181             m_searchBut.setActionCommand( LOAD_CMD ) ;
182         }
183 
184         m_cancelBut.setText(CANCEL_CMD) ;
185         m_cancelBut.setActionCommand(CANCEL_CMD) ;
186         setBounds(new java.awt.Rectangle(0,0,595,331));
187         m_basePnl.setLayout(new java.awt.GridBagLayout());
188         m_basePnl.add(jLabel1,
189         new java.awt.GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, java.awt.GridBagConstraints.WEST, java.awt.GridBagConstraints.NONE,
190         new java.awt.Insets(0, 0, 0, 0), 0, 0));
191         m_basePnl.add(m_baseText,
192         new java.awt.GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, java.awt.GridBagConstraints.EAST, java.awt.GridBagConstraints.HORIZONTAL,
193         new java.awt.Insets(5, 5, 5, 0), 0, 0));
194         jLabel1.setText("Search Base:");
195         jLabel1.setFont(new java.awt.Font("SansSerif", java.awt.Font.PLAIN, 14));
196 
197         if(m_mode == RUN_MODE) {
198 	        setTitle("Search Filter Dialog: Execute mode") ;
199         } else if(m_mode == LOAD_MODE) {
200             setTitle("Search Filter Dialog: Load mode") ;
201         } else if(m_mode == DEBUG_MODE) {
202 	        setTitle("Search Filter Dialog: Debug mode") ;
203         } else if(m_mode == ANNOTATE_MODE) {
204 	        setTitle("Search Filter Dialog: Annotate mode") ;
205             this.m_scopeChoice.setEnabled(false) ;
206             this.m_limitField.setEnabled(false) ;
207             this.m_baseText.setEnabled(false) ;
208         } else {
209             throw new RuntimeException("Unrecognized mode.") ;
210         }
211     }
212 
213 
214     /***
215      * Closes the dialog
216      */
217     public void closeDialog(WindowEvent evt)
218     {
219         setVisible(false) ;
220         dispose() ;
221     }
222 
223 
224 	public String getScope()
225     {
226 		int l_selected = m_scopeChoice.getSelectedIndex() ;
227         return (String) m_scopeChoice.getItemAt(l_selected) ;
228     }
229 
230 
231     /*
232 	public int getScope()
233     {
234 		int l_selected = m_scopeChoice.getSelectedIndex() ;
235         String l_scope = (String) m_scopeChoice.getItemAt(l_selected) ;
236 
237 		if(l_scope == BASE_SCOPE) {
238 			return Backend.BASE_SCOPE ;
239         } else if(l_scope == SINGLE_SCOPE) {
240             return Backend.SINGLE_SCOPE ;
241         } else if(l_scope == SUBTREE_SCOPE) {
242             return Backend.SUBTREE_SCOPE ;
243         }
244 
245         throw new RuntimeException("Unexpected scope parameter: " + l_scope) ;
246     }
247 	*/
248 
249     public String getLimit()
250     {
251 		return m_limitField.getText() ;
252     }
253 
254 /*
255     public String getLimit()
256     {
257         String l_limit = m_limitField.getText() ;
258 
259 		if(l_limit.equals(UNLIMITED)) {
260             return -1 ;
261         }
262 
263         return Integer.parseInt(l_limit) ;
264     }
265 */
266 
267     public String getFilter()
268     {
269 		return this.m_filterText.getText() ;
270     }
271 
272 
273     public void setBase(String a_base)
274     {
275         this.m_baseText.setText(a_base) ;
276     }
277 
278 
279     public void setScope(String a_scope)
280     {
281         this.m_scopeChoice.setSelectedItem(a_scope) ;
282     }
283 
284 
285     public String getBase()
286     {
287         return this.m_baseText.getText() ;
288     }
289 }