Author: thomasobrien95
Date: Mon Jan 12 07:49:50 2009
New Revision: 2911

Modified:
   trunk/src/ca/sqlpower/architect/swingui/ProfileManagerView.java
   trunk/src/ca/sqlpower/architect/swingui/messages.properties
   trunk/src/ca/sqlpower/architect/swingui/messages_ko.properties
   trunk/src/ca/sqlpower/architect/swingui/messages_ru.properties

Log:
The ProfileManagerView uses the new SearchTextField in the library to allow regular expression searching on profiles.

Modified: trunk/src/ca/sqlpower/architect/swingui/ProfileManagerView.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/ProfileManagerView.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/ProfileManagerView.java Mon Jan 12 07:49:50 2009
@@ -33,6 +33,7 @@
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
+import java.util.regex.Pattern;

 import javax.swing.AbstractAction;
 import javax.swing.Action;
@@ -44,7 +45,6 @@
 import javax.swing.JRadioButton;
 import javax.swing.JScrollBar;
 import javax.swing.JScrollPane;
-import javax.swing.JTextField;
 import javax.swing.KeyStroke;
 import javax.swing.ScrollPaneConstants;
 import javax.swing.Scrollable;
@@ -60,6 +60,8 @@
 import ca.sqlpower.architect.profile.event.ProfileChangeListener;
 import ca.sqlpower.architect.swingui.event.SelectionEvent;
 import ca.sqlpower.architect.swingui.event.SelectionListener;
+import ca.sqlpower.swingui.Search;
+import ca.sqlpower.swingui.SearchTextField;

 /**
* The controlling view for the Profile Manager. Vaguely patterned on e.g., the
@@ -71,7 +73,7 @@
  * <li>a progressbar and a Stop button.
  * <p>
  */
-public class ProfileManagerView extends JPanel implements ProfileChangeListener { +public class ProfileManagerView extends JPanel implements ProfileChangeListener, Search {

private static Logger logger = Logger.getLogger(ProfileManagerView.class);

@@ -91,7 +93,7 @@

     private final JLabel statusText;

-    private final JTextField searchText;
+    private final SearchTextField searchText;

     private final PageListener pageListener;

@@ -112,6 +114,12 @@
      * The list of row components we will be showing in the results panel.
      */
final List<ProfileRowComponent> showingRows = new ArrayList<ProfileRowComponent>();
+
+    /**
+ * This is the last pattern searched on from a change to the search text field.
+     * This will be null until the first search is executed.
+     */
+    private Pattern lastSearchPattern;

private class ResultListPanel extends JPanel implements Scrollable, SelectionListener {

@@ -375,27 +383,15 @@
         JPanel topPanel = new JPanel();
         add(topPanel, BorderLayout.NORTH);

- topPanel.add(new JLabel(Messages.getString("ProfileManagerView.search"))); //$NON-NLS-1$
-        searchText = new JTextField(10);
-        searchText.addKeyListener(pageListener);
-        searchText.addKeyListener(new KeyListener() {
-
-            public void keyPressed(KeyEvent e) {}
-
-            public void keyReleased(KeyEvent e) {
-                doSearch(searchText.getText());
-            }
-
-            public void keyTyped(KeyEvent e) {}
-        });
-        topPanel.add(searchText);
+        searchText = new SearchTextField(this, 10);
+        searchText.getTextField().addKeyListener(pageListener);
+        topPanel.add(searchText.getPanel());

JButton clearSearchButton = new JButton(Messages.getString("ProfileManagerView.clearSearch")); //$NON-NLS-1$
         clearSearchButton.addKeyListener(pageListener);
         clearSearchButton.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
-                searchText.setText(""); //$NON-NLS-1$
-                doSearch(""); //$NON-NLS-1$
+                searchText.clear();
             }
         });
         topPanel.add(clearSearchButton);
@@ -529,16 +525,18 @@
      * Search the list for profiles matching the given string.
      * XXX match on date fields too??
      */
-    protected void doSearch(final String text) {
+    public void doSearch(Pattern p) {
+        lastSearchPattern = p;
         showingRows.clear();
-        if (text == null || text.length() == 0) {
+ if (p == null || p.pattern() == null || p.pattern().length() == 0) {
             for (ProfileRowComponent r : list) {
                 showingRows.add(r);
             }
         } else {
-            String searchText = text.toLowerCase();
             for (ProfileRowComponent r : list) {
- if (r.getResult().getProfiledObject().getName().toLowerCase().contains(searchText)) { + if ((p.flags() & Pattern.LITERAL) == 0 && p.matcher(r.getResult().getProfiledObject().getName()).matches()) {
+                    showingRows.add(r);
+ } else if ((p.flags() & Pattern.LITERAL) > 0 && p.matcher(r.getResult().getProfiledObject().getName()).find()) {
                     showingRows.add(r);
                 }
             }
@@ -550,7 +548,7 @@

     private void setComparator(Comparator comparator) {
         this.comparator = comparator;
-        doSearch(searchText.getText());
+        doSearch(lastSearchPattern);
     }


@@ -575,7 +573,7 @@
logger.debug("Cannot create a component based on the profile result " + pr); //$NON-NLS-1$
             }
         }
-        doSearch(searchText.getText());
+        doSearch(lastSearchPattern);
     }

     /** Part of the ProfileChangeListener interface; called
@@ -594,7 +592,7 @@
                 }
             }
         }
-        doSearch(searchText.getText());
+        doSearch(lastSearchPattern);
     }

     public void profileListChanged(ProfileChangeEvent e) {

Modified: trunk/src/ca/sqlpower/architect/swingui/messages.properties
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/messages.properties (original)
+++ trunk/src/ca/sqlpower/architect/swingui/messages.properties Mon Jan 12 07:49:50 2009
@@ -248,7 +248,6 @@
 ProfileManagerView.nameOption=Name
 ProfileManagerView.orderBy=Order by
 ProfileManagerView.profileDisplayStatus=Showing %d of %d Profiles
-ProfileManagerView.search=Search
 ProfileManagerView.viewAllActionName=View All
 ProfileManagerView.viewSelectedActionName=View Selected
 ProfileResultsViewer.closeButton=Close

Modified: trunk/src/ca/sqlpower/architect/swingui/messages_ko.properties
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/messages_ko.properties (original) +++ trunk/src/ca/sqlpower/architect/swingui/messages_ko.properties Mon Jan 12 07:49:50 2009
@@ -259,7 +259,6 @@
 ProfileManagerView.nameOption=\uc774\ub984
 ProfileManagerView.orderBy=\uc815\ub82c\uc870\uac74
 ProfileManagerView.profileDisplayStatus=
-ProfileManagerView.search=\uac80\uc0c9
 ProfileManagerView.viewAllActionName=\ubaa8\ub450 \ubcf4\uae30
ProfileManagerView.viewSelectedActionName=\uc120\ud0dd\ud56d\ubaa9 \ubcf4\uae30
 ProfileResultsViewer.closeButton=\ub2eb\uae30

Modified: trunk/src/ca/sqlpower/architect/swingui/messages_ru.properties
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/messages_ru.properties (original) +++ trunk/src/ca/sqlpower/architect/swingui/messages_ru.properties Mon Jan 12 07:49:50 2009
@@ -249,7 +249,6 @@
ProfileManagerView.nameOption=\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 ProfileManagerView.orderBy=\u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e: ProfileManagerView.profileDisplayStatus=\u041f\u043e\u043a\u0430\u0437\u0430\u043d\u043e %d \u0438\u0437 %d \u041f\u0440\u043e\u0444\u0438\u043b\u0435\u0439
-ProfileManagerView.search=\u041f\u043e\u0438\u0441\u043a
ProfileManagerView.viewAllActionName=\u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0441\u0435 ProfileManagerView.viewSelectedActionName= \u0421\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435
 ProfileResultsViewer.closeButton=\u0417\u0430\u043a\u0440\u044b\u0442\u044c

Reply via email to