/src/mpv5/ui/dialogs/Search.java
Java | 325 lines | 253 code | 40 blank | 32 comment | 17 complexity | 3c810ba219a2b5c57fa7e3b710039e6f 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
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * SplashScreen.java
- *
- * Created on 30.03.2009, 21:55:52
- */
- package mpv5.ui.dialogs;
- import java.awt.Component;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JComponent;
- import javax.swing.table.TableCellRenderer;
- import mpv5.db.common.Context;
- import mpv5.db.common.DatabaseObject;
- import mpv5.db.common.DatabaseSearch;
- import mpv5.db.common.NodataFoundException;
- import mpv5.ui.frames.MPView;
- import mpv5.ui.misc.Position;
- import mpv5.utils.arrays.ArrayUtilities;
- import mpv5.utils.html.HtmlParser;
- import mpv5.utils.models.MPTableModel;
- import mpv5.utils.tables.Selection;
- import mpv5.utils.tables.TableFormat;
- /**
- *
- *
- */
- public class Search extends javax.swing.JDialog {
- private static final long serialVersionUID = 1L;
- private static Search f;
- private String additionalSearchCondition = "";
- public static Search instanceOf() {
- if (f == null) {
- f = new Search(true);
- }
- f.setVisible(true);
- f.requestFocus();
- return f;
- }
- private static String oldSelection;
- private DatabaseObject selection;
- private boolean addTabs = false;
- @Override
- public void dispose() {
- setVisible(false);
- }
- /** Creates new form SplashScreen
- * @param addtabs Add the selected Object to the main tab pane
- */
- public Search(boolean addtabs) {
- super(mpv5.YabsViewProxy.instance().getIdentifierFrame());
- initComponents();
- this.addTabs = addtabs;
- setModalityType(ModalityType.APPLICATION_MODAL);
- setLocationRelativeTo(mpv5.YabsViewProxy.instance().getIdentifierFrame());
- }
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- jLabel2 = new javax.swing.JLabel();
- key = new javax.swing.JComboBox();
- jCheckBox1 = new javax.swing.JCheckBox();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTable1 = new mpv5.ui.misc.MPTable(this) {
- public Component prepareRenderer(TableCellRenderer renderer,
- int rowIndex, int vColIndex) {
- Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
- if (c instanceof JComponent) {
- JComponent jc = (JComponent)c;
- jc.setToolTipText(String.valueOf(getValueAt(rowIndex, vColIndex)));
- }
- return c;
- }
- };
- jCheckBox2 = new javax.swing.JCheckBox();
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- setName("Form"); // NOI18N
- java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();// NOI18N
- jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("Search.jPanel1.border.title"))); // NOI18N
- jPanel1.setName("jPanel1"); // NOI18N
- jLabel2.setText(bundle.getString("Search.jLabel2.text")); // NOI18N
- jLabel2.setToolTipText(bundle.getString("Search.jLabel2.toolTipText")); // NOI18N
- jLabel2.setName("jLabel2"); // NOI18N
- key.setEditable(true);
- key.setName("key"); // NOI18N
- key.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- keyActionPerformed(evt);
- }
- });
- jCheckBox1.setText(bundle.getString("Search.jCheckBox1.text")); // NOI18N
- jCheckBox1.setToolTipText(bundle.getString("Search.jCheckBox1.toolTipText")); // NOI18N
- jCheckBox1.setFocusable(false);
- jCheckBox1.setName("jCheckBox1"); // NOI18N
- jButton1.setText(bundle.getString("Search.jButton1.text")); // NOI18N
- jButton1.setToolTipText(bundle.getString("Search.jButton1.toolTipText")); // NOI18N
- jButton1.setFocusPainted(false);
- jButton1.setName("jButton1"); // NOI18N
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setText(bundle.getString("Search.jButton2.text")); // NOI18N
- jButton2.setName("jButton2"); // NOI18N
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jScrollPane1.setName("jScrollPane1"); // NOI18N
- jTable1.setAutoCreateRowSorter(true);
- jTable1.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {},
- {},
- {},
- {}
- },
- new String [] {
- }
- ));
- jTable1.setName("jTable1"); // NOI18N
- jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jTable1MouseClicked(evt);
- }
- });
- jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
- public void keyTyped(java.awt.event.KeyEvent evt) {
- jTable1KeyTyped(evt);
- }
- });
- jScrollPane1.setViewportView(jTable1);
- jCheckBox2.setText(bundle.getString("Search.jCheckBox2.text")); // NOI18N
- jCheckBox2.setToolTipText(bundle.getString("Search.jCheckBox2.toolTipText")); // NOI18N
- jCheckBox2.setFocusable(false);
- jCheckBox2.setName("jCheckBox2"); // NOI18N
- jCheckBox2.addItemListener(new java.awt.event.ItemListener() {
- public void itemStateChanged(java.awt.event.ItemEvent evt) {
- jCheckBox2ItemStateChanged(evt);
- }
- });
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jButton2))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jCheckBox2, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jCheckBox1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(27, 27, 27)
- .addComponent(key, 0, 234, Short.MAX_VALUE))))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(key, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jCheckBox1)
- .addComponent(jCheckBox2)
- .addComponent(jButton1))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton2))
- );
- getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
- pack();
- }// </editor-fold>//GEN-END:initComponents
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
- open();
- }//GEN-LAST:event_jButton2ActionPerformed
- private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
- if (evt.getClickCount() > 1) {
- open();
- }
- }//GEN-LAST:event_jTable1MouseClicked
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
- search();
- }//GEN-LAST:event_jButton1ActionPerformed
- private void jCheckBox2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCheckBox2ItemStateChanged
- // scope.setEnabled(!jCheckBox2.isSelected());
- }//GEN-LAST:event_jCheckBox2ItemStateChanged
- private void keyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_keyActionPerformed
- search();
- }//GEN-LAST:event_keyActionPerformed
- private void jTable1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyTyped
- }//GEN-LAST:event_jTable1KeyTyped
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JCheckBox jCheckBox1;
- private javax.swing.JCheckBox jCheckBox2;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTable jTable1;
- private javax.swing.JComboBox key;
- // End of variables declaration//GEN-END:variables
- private void search() {
- String newSelection = (String) key.getSelectedItem();
- if (newSelection != null && !newSelection.equals(oldSelection)) {
- key.addItem(newSelection);
- oldSelection = newSelection;
- }
- if (newSelection == null || newSelection.equals("null")) {
- newSelection = "";
- }
- Object[][] data = null;
- if (!jCheckBox2.isSelected()) {
- for (int i = 0; i < Context.getSearchableContexts().size(); i++) {
- Context c = Context.getSearchableContexts().get(i);
- c.addReference(Context.getGroup());
- DatabaseSearch s = new DatabaseSearch(c);
- data = ArrayUtilities.merge(data, s.getValuesFor(c.getDbIdentity() + ".ids, '" + c.getDbIdentity() + "', " + c.getDbIdentity() + ".cname," + "groups.cname," + c.getDbIdentity() + ".dateadded", DatabaseObject.getObject(c).getStringVars().toArray(new String[]{}), newSelection, !jCheckBox1.isSelected()));
- }
- jTable1.setModel(new MPTableModel(data));
- } else {
- DatabaseSearch s = new DatabaseSearch(Context.getSearchIndex());
- data = s.getValuesFor("rowid, dbidentity, text", "text", newSelection, !jCheckBox1.isSelected());
- jTable1.setModel(new MPTableModel(HtmlParser.getMarkedHtml(data, 2, newSelection)));
- }
- TableFormat.hideHeader(jTable1);
- TableFormat.stripFirstColumn(jTable1);
- //TableFormat.format(jTable1, 1, 100);
- }
- private DatabaseObject getSelectedObject() {
- return selection;
- }
- /**
- * @return the additionalSearchCondition
- */
- public String getAdditionalSearchCondition() {
- return additionalSearchCondition;
- }
- /**
- * @param additionalSearchCondition the additionalSearchCondition to set
- */
- public void setAdditionalSearchCondition(String additionalSearchCondition) {
- this.additionalSearchCondition = additionalSearchCondition;
- }
- private void open() {
- Context lastContext = null;
- if (jTable1.getSelectedRow() >= 0) {
- Selection s = new Selection(jTable1);
- lastContext = Context.getMatchingContext(jTable1.getValueAt(jTable1.getSelectedRow(), jTable1.convertColumnIndexToView(1)).toString());
- if (lastContext != null) {
- try {
- selection = DatabaseObject.getObject(lastContext, Integer.valueOf(jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 0).toString()));
- if (addTabs) {
- mpv5.YabsViewProxy.instance().getIdentifierView().addTab(selection);
- }
- } catch (NodataFoundException ex) {
- mpv5.logging.Log.Debug(ex);
- }
- this.dispose();
- }
- }
- }
- }