1 30 package com.genimen.djeneric.tools.specifier.dialogs; 31 32 import java.awt.BorderLayout ; 33 import java.awt.Dimension ; 34 import java.awt.Frame ; 35 import java.awt.Toolkit ; 36 import java.awt.event.ActionEvent ; 37 import java.util.ArrayList ; 38 39 import javax.swing.JButton ; 40 import javax.swing.JDialog ; 41 import javax.swing.JOptionPane ; 42 import javax.swing.JPanel ; 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 54 { 55 private static final long serialVersionUID = 1L; 56 JPanel panel1 = new JPanel (); 57 BorderLayout borderLayout1 = new BorderLayout (); 58 FilterPanel _propPanel; 59 JPanel _buttonPanel = new JPanel (); 60 BorderLayout borderLayout2 = new BorderLayout (); 61 JPanel jPanel3 = new JPanel (); 62 JButton _butOk = new JButton (); 63 JButton _butCancel = new JButton (); 64 boolean _wasCancelled = true; 65 66 public FilterDialog(Frame frame, DjOql restrictingOql, DjSession session, ExtentUsage usage, 67 ArrayList 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 screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 96 Dimension frameSize = getSize(); 97 setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); 98 setVisible(true); 99 } 100 catch (Exception x) 101 { 102 DjLogger.log(x); 103 } 104 } 105 106 public FilterDialog(Frame frame, DjSession session, ExtentUsage usage, ArrayList excludeTheseProperties) 107 { 108 this(frame, null, session, usage, excludeTheseProperties); 109 } 110 111 void jbInit() throws Exception 112 { 113 panel1.setLayout(borderLayout1); 114 _buttonPanel.setLayout(borderLayout2); 115 _butOk.setText(Messages.getString("global.Ok")); 116 _butOk.addActionListener(new java.awt.event.ActionListener () 117 { 118 public void actionPerformed(ActionEvent e) 119 { 120 _butOk_actionPerformed(e); 121 } 122 }); 123 _butCancel.setText(Messages.getString("global.Cancel")); 124 _butCancel.addActionListener(new java.awt.event.ActionListener () 125 { 126 public void actionPerformed(ActionEvent 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 e) 146 { 147 try 148 { 149 _propPanel.validateValues(); 150 _wasCancelled = false; 151 setVisible(false); 152 } 153 catch (Exception x) 154 { 155 JOptionPane.showMessageDialog(this, x.getMessage(), Messages.getString("global.InvalidEntry"), 156 JOptionPane.WARNING_MESSAGE); 157 } 158 } 159 160 void _butCancel_actionPerformed(ActionEvent 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 oqlExpression) 172 { 173 _propPanel.setAdditionalFilter(oqlExpression); 174 } 175 176 } | Popular Tags |