PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mpv5/ui/dialogs/Search2.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 295 lines | 226 code | 38 blank | 31 comment | 12 complexity | e192617d9acda924bf1624ef5a57d97b MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. /*
  6. * SplashScreen.java
  7. *
  8. * Created on 30.03.2009, 21:55:52
  9. */
  10. package mpv5.ui.dialogs;
  11. import java.awt.Component;
  12. import javax.swing.DefaultComboBoxModel;
  13. import javax.swing.JComponent;
  14. import javax.swing.table.TableCellRenderer;
  15. import mpv5.db.common.Context;
  16. import mpv5.db.common.DatabaseObject;
  17. import mpv5.db.common.DatabaseSearch;
  18. import mpv5.db.common.NodataFoundException;
  19. import mpv5.ui.frames.MPView;
  20. import mpv5.utils.html.HtmlParser;
  21. import mpv5.utils.models.MPTableModel;
  22. import mpv5.utils.tables.TableFormat;
  23. /**
  24. *
  25. *
  26. */
  27. public class Search2 extends javax.swing.JDialog {
  28. private static final long serialVersionUID = 1L;
  29. private String additionalSearchCondition = "";
  30. private static String oldSelection;
  31. public static DatabaseObject showSearchFor(Context t) {
  32. Search2 s = new Search2(t);
  33. s.setVisible(true);
  34. s.requestFocus();
  35. return s.getSelectedObject();
  36. }
  37. private Context context;
  38. private DatabaseObject selection;
  39. @Override
  40. public void dispose() {
  41. setVisible(false);
  42. }
  43. /** Creates new form SplashScreen
  44. * @param addtabs Add the selected Object to the main tab pane
  45. */
  46. private Search2(Context t) {
  47. super(mpv5.YabsViewProxy.instance().getIdentifierFrame());
  48. initComponents();
  49. context = t;
  50. typelabel.setText(t.getDbIdentity().toUpperCase());
  51. setModalityType(ModalityType.APPLICATION_MODAL);
  52. setLocationRelativeTo(mpv5.YabsViewProxy.instance().getIdentifierFrame());
  53. }
  54. /** This method is called from within the constructor to
  55. * initialize the form.
  56. * WARNING: Do NOT modify this code. The content of this method is
  57. * always regenerated by the Form Editor.
  58. */
  59. @SuppressWarnings("unchecked")
  60. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  61. private void initComponents() {
  62. jPanel1 = new javax.swing.JPanel();
  63. jLabel1 = new javax.swing.JLabel();
  64. jLabel2 = new javax.swing.JLabel();
  65. key = new javax.swing.JComboBox();
  66. jCheckBox1 = new javax.swing.JCheckBox();
  67. jButton1 = new javax.swing.JButton();
  68. jButton2 = new javax.swing.JButton();
  69. jScrollPane1 = new javax.swing.JScrollPane();
  70. jTable1 = new mpv5.ui.misc.MPTable(this) {
  71. public Component prepareRenderer(TableCellRenderer renderer,
  72. int rowIndex, int vColIndex) {
  73. Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
  74. if (c instanceof JComponent) {
  75. JComponent jc = (JComponent)c;
  76. jc.setToolTipText(String.valueOf(getValueAt(rowIndex, vColIndex)));
  77. }
  78. return c;
  79. }
  80. };
  81. typelabel = new javax.swing.JLabel();
  82. setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  83. setName("Form"); // NOI18N
  84. java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
  85. jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("Search2.jPanel1.border.title"))); // NOI18N
  86. jPanel1.setName("jPanel1"); // NOI18N
  87. jLabel1.setText(bundle.getString("Search2.jLabel1.text")); // NOI18N
  88. jLabel1.setToolTipText(bundle.getString("Search2.jLabel1.toolTipText")); // NOI18N
  89. jLabel1.setName("jLabel1"); // NOI18N
  90. jLabel2.setText(bundle.getString("Search2.jLabel2.text")); // NOI18N
  91. jLabel2.setToolTipText(bundle.getString("Search2.jLabel2.toolTipText")); // NOI18N
  92. jLabel2.setName("jLabel2"); // NOI18N
  93. key.setEditable(true);
  94. key.setName("key"); // NOI18N
  95. key.addActionListener(new java.awt.event.ActionListener() {
  96. public void actionPerformed(java.awt.event.ActionEvent evt) {
  97. keyActionPerformed(evt);
  98. }
  99. });
  100. jCheckBox1.setText(bundle.getString("Search2.jCheckBox1.text")); // NOI18N
  101. jCheckBox1.setToolTipText(bundle.getString("Search2.jCheckBox1.toolTipText")); // NOI18N
  102. jCheckBox1.setName("jCheckBox1"); // NOI18N
  103. jButton1.setText(bundle.getString("Search2.jButton1.text")); // NOI18N
  104. jButton1.setToolTipText(bundle.getString("Search2.jButton1.toolTipText")); // NOI18N
  105. jButton1.setName("jButton1"); // NOI18N
  106. jButton1.addActionListener(new java.awt.event.ActionListener() {
  107. public void actionPerformed(java.awt.event.ActionEvent evt) {
  108. jButton1ActionPerformed(evt);
  109. }
  110. });
  111. jButton2.setText(bundle.getString("Search2.jButton2.text")); // NOI18N
  112. jButton2.setName("jButton2"); // NOI18N
  113. jButton2.addActionListener(new java.awt.event.ActionListener() {
  114. public void actionPerformed(java.awt.event.ActionEvent evt) {
  115. jButton2ActionPerformed(evt);
  116. }
  117. });
  118. jScrollPane1.setName("jScrollPane1"); // NOI18N
  119. jTable1.setAutoCreateRowSorter(true);
  120. jTable1.setModel(new javax.swing.table.DefaultTableModel(
  121. new Object [][] {
  122. {},
  123. {},
  124. {},
  125. {}
  126. },
  127. new String [] {
  128. }
  129. ));
  130. jTable1.setName("result"); // NOI18N
  131. jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
  132. public void mouseClicked(java.awt.event.MouseEvent evt) {
  133. jTable1MouseClicked(evt);
  134. }
  135. });
  136. jScrollPane1.setViewportView(jTable1);
  137. typelabel.setText(bundle.getString("Search2.typelabel.text")); // NOI18N
  138. typelabel.setName("typelabel"); // NOI18N
  139. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  140. jPanel1.setLayout(jPanel1Layout);
  141. jPanel1Layout.setHorizontalGroup(
  142. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  143. .addGroup(jPanel1Layout.createSequentialGroup()
  144. .addContainerGap()
  145. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  146. .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  147. .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  148. .addGap(65, 65, 65)
  149. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  150. .addComponent(typelabel, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)
  151. .addGroup(jPanel1Layout.createSequentialGroup()
  152. .addComponent(jCheckBox1)
  153. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
  154. .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
  155. .addComponent(key, 0, 215, Short.MAX_VALUE)))
  156. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  157. .addContainerGap()
  158. .addComponent(jButton2))
  159. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE)
  160. );
  161. jPanel1Layout.setVerticalGroup(
  162. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  163. .addGroup(jPanel1Layout.createSequentialGroup()
  164. .addContainerGap()
  165. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
  166. .addComponent(typelabel, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
  167. .addComponent(jLabel1))
  168. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  169. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  170. .addComponent(jLabel2)
  171. .addComponent(key, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  172. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  173. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  174. .addComponent(jCheckBox1)
  175. .addComponent(jButton1))
  176. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  177. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
  178. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  179. .addComponent(jButton2))
  180. );
  181. getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
  182. pack();
  183. }// </editor-fold>//GEN-END:initComponents
  184. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
  185. if (context != null) {
  186. try {
  187. selection = DatabaseObject.getObject(context, Integer.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(), 0).toString()));
  188. } catch (Exception ex) {
  189. mpv5.logging.Log.Debug(this, ex.getMessage());
  190. }
  191. this.dispose();
  192. }
  193. }//GEN-LAST:event_jButton2ActionPerformed
  194. private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
  195. if (evt.getClickCount() > 1) {
  196. if (context != null) {
  197. try {
  198. selection = DatabaseObject.getObject(context, Integer.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(), 0).toString()));
  199. } catch (NodataFoundException ex) {
  200. mpv5.logging.Log.Debug(ex);
  201. }
  202. this.dispose();
  203. }
  204. }
  205. }//GEN-LAST:event_jTable1MouseClicked
  206. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  207. search();
  208. }//GEN-LAST:event_jButton1ActionPerformed
  209. private void keyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_keyActionPerformed
  210. search();
  211. }//GEN-LAST:event_keyActionPerformed
  212. // Variables declaration - do not modify//GEN-BEGIN:variables
  213. private javax.swing.JButton jButton1;
  214. private javax.swing.JButton jButton2;
  215. private javax.swing.JCheckBox jCheckBox1;
  216. private javax.swing.JLabel jLabel1;
  217. private javax.swing.JLabel jLabel2;
  218. private javax.swing.JPanel jPanel1;
  219. private javax.swing.JScrollPane jScrollPane1;
  220. private javax.swing.JTable jTable1;
  221. private javax.swing.JComboBox key;
  222. private javax.swing.JLabel typelabel;
  223. // End of variables declaration//GEN-END:variables
  224. private void search() {
  225. String newSelection = (String) key.getSelectedItem();
  226. if (newSelection != null && !newSelection.equals(oldSelection)) {
  227. key.addItem(newSelection);
  228. oldSelection = newSelection;
  229. }
  230. if (newSelection == null || newSelection.equals("null")) {
  231. newSelection = "";
  232. }
  233. Object[][] data = null;
  234. context.addReference(Context.getGroup());
  235. DatabaseSearch s = new DatabaseSearch(context);
  236. data = s.getValuesFor(context.getDbIdentity() + ".ids," + context.getDbIdentity() + ".cname," + "groups.cname," + context.getDbIdentity() + ".dateadded", new String[]{"cname"}, newSelection, !jCheckBox1.isSelected());
  237. jTable1.setModel(new MPTableModel(data));
  238. TableFormat.hideHeader(jTable1);
  239. TableFormat.stripFirstColumn(jTable1);
  240. //TableFormat.format(jTable1, 1, 100);
  241. }
  242. private DatabaseObject getSelectedObject() {
  243. return selection;
  244. }
  245. /**
  246. * @return the additionalSearchCondition
  247. */
  248. public String getAdditionalSearchCondition() {
  249. return additionalSearchCondition;
  250. }
  251. /**
  252. * @param additionalSearchCondition the additionalSearchCondition to set
  253. */
  254. public void setAdditionalSearchCondition(String additionalSearchCondition) {
  255. this.additionalSearchCondition = additionalSearchCondition;
  256. }
  257. }