KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > specifier > dialogs > FilterDialog


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, is permitted
5  * provided that the following conditions are met:
6  * - Redistributions of source code must retain the above copyright notice, this list of conditions
7  * and the following disclaimer.
8  * - Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * - All advertising materials mentioning features or use of this software must display the
12  * following acknowledgment: "This product includes Djeneric."
13  * - Products derived from this software may not be called "Djeneric" nor may
14  * "Djeneric" appear in their names without prior written permission of Genimen BV.
15  * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
16  * product includes Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.tools.specifier.dialogs;
31
32 import java.awt.BorderLayout JavaDoc;
33 import java.awt.Dimension JavaDoc;
34 import java.awt.Frame JavaDoc;
35 import java.awt.Toolkit JavaDoc;
36 import java.awt.event.ActionEvent JavaDoc;
37 import java.util.ArrayList JavaDoc;
38
39 import javax.swing.JButton JavaDoc;
40 import javax.swing.JDialog JavaDoc;
41 import javax.swing.JOptionPane JavaDoc;
42 import javax.swing.JPanel JavaDoc;
43
44 import com.genimen.djeneric.language.Messages;
45 import com.genimen.djeneric.repository.DjOql;
46 import com.genimen.djeneric.repository.DjSession;
47 import com.genimen.djeneric.repository.exceptions.DjenericException;
48 import com.genimen.djeneric.structure.ExtentUsage;
49 import com.genimen.djeneric.tools.specifier.base.FilterPanel;
50 import com.genimen.djeneric.ui.Util;
51 import com.genimen.djeneric.util.DjLogger;
52
53 public class FilterDialog extends JDialog JavaDoc
54 {
55   private static final long serialVersionUID = 1L;
56   JPanel JavaDoc panel1 = new JPanel JavaDoc();
57   BorderLayout JavaDoc borderLayout1 = new BorderLayout JavaDoc();
58   FilterPanel _propPanel;
59   JPanel JavaDoc _buttonPanel = new JPanel JavaDoc();
60   BorderLayout JavaDoc borderLayout2 = new BorderLayout JavaDoc();
61   JPanel JavaDoc jPanel3 = new JPanel JavaDoc();
62   JButton JavaDoc _butOk = new JButton JavaDoc();
63   JButton JavaDoc _butCancel = new JButton JavaDoc();
64   boolean _wasCancelled = true;
65
66   public FilterDialog(Frame JavaDoc frame, DjOql restrictingOql, DjSession session, ExtentUsage usage,
67                       ArrayList JavaDoc excludeTheseProperties)
68   {
69     super(frame, Messages.getString("FilterDialog.Find", usage.getExtent().getNamePlural()), true);
70     try
71     {
72       _propPanel = new FilterPanel(restrictingOql, session, usage.getExtent(), excludeTheseProperties)
73       {
74         private static final long serialVersionUID = 1L;
75
76         public void enterHit()
77         {
78           _butOk_actionPerformed(null);
79         }
80
81         public void escapeHit()
82         {
83           _butCancel_actionPerformed(null);
84         }
85       };
86
87       jbInit();
88       pack();
89       if (_propPanel.getQueryableProperties().length > 5)
90       {
91         int w = getWidth() * 2 + 20;
92         int h = (getHeight() - _buttonPanel.getHeight()) / 2 + _buttonPanel.getHeight() + 30;
93         setSize(w, h);
94       }
95       Dimension JavaDoc screenSize = Toolkit.getDefaultToolkit().getScreenSize();
96       Dimension JavaDoc frameSize = getSize();
97       setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
98       setVisible(true);
99     }
100     catch (Exception JavaDoc x)
101     {
102       DjLogger.log(x);
103     }
104   }
105
106   public FilterDialog(Frame JavaDoc frame, DjSession session, ExtentUsage usage, ArrayList JavaDoc excludeTheseProperties)
107   {
108     this(frame, null, session, usage, excludeTheseProperties);
109   }
110
111   void jbInit() throws Exception JavaDoc
112   {
113     panel1.setLayout(borderLayout1);
114     _buttonPanel.setLayout(borderLayout2);
115     _butOk.setText(Messages.getString("global.Ok"));
116     _butOk.addActionListener(new java.awt.event.ActionListener JavaDoc()
117     {
118       public void actionPerformed(ActionEvent JavaDoc e)
119       {
120         _butOk_actionPerformed(e);
121       }
122     });
123     _butCancel.setText(Messages.getString("global.Cancel"));
124     _butCancel.addActionListener(new java.awt.event.ActionListener JavaDoc()
125     {
126       public void actionPerformed(ActionEvent JavaDoc e)
127       {
128         _butCancel_actionPerformed(e);
129       }
130     });
131     getContentPane().add(panel1);
132     panel1.add(_propPanel, BorderLayout.CENTER);
133     panel1.add(_buttonPanel, BorderLayout.SOUTH);
134     _buttonPanel.add(jPanel3, BorderLayout.EAST);
135     jPanel3.add(_butCancel, null);
136     jPanel3.add(_butOk, null);
137     Util.sizeButtons(jPanel3);
138   }
139
140   public boolean wasCancelled()
141   {
142     return _wasCancelled;
143   }
144
145   void _butOk_actionPerformed(ActionEvent JavaDoc e)
146   {
147     try
148     {
149       _propPanel.validateValues();
150       _wasCancelled = false;
151       setVisible(false);
152     }
153     catch (Exception JavaDoc x)
154     {
155       JOptionPane.showMessageDialog(this, x.getMessage(), Messages.getString("global.InvalidEntry"),
156                                     JOptionPane.WARNING_MESSAGE);
157     }
158   }
159
160   void _butCancel_actionPerformed(ActionEvent JavaDoc e)
161   {
162     setVisible(false);
163
164   }
165
166   public DjOql getOql() throws DjenericException
167   {
168     return _propPanel.getOql();
169   }
170
171   public void setAdditionalFilter(String JavaDoc oqlExpression)
172   {
173     _propPanel.setAdditionalFilter(oqlExpression);
174   }
175
176 }
Popular Tags