diff options
| author | Nan Li | 2012-09-25 20:06:29 +0000 |
|---|---|---|
| committer | Karen Butzke | 2012-09-25 20:09:10 +0000 |
| commit | 48e3be26113e3e07ab30435d52ac78f42bab3e67 (patch) | |
| tree | cadfa74e2f1e6a237f5805e7f16d17d7cb0e25d9 | |
| parent | ad3b284302d6168f351d4d25fcd92a57da22ea78 (diff) | |
| download | webtools.dali-48e3be26113e3e07ab30435d52ac78f42bab3e67.tar.gz webtools.dali-48e3be26113e3e07ab30435d52ac78f42bab3e67.tar.xz webtools.dali-48e3be26113e3e07ab30435d52ac78f42bab3e67.zip | |
Bug 340749 - Add Search field above the Tables list in Generate Custom Entities wizard page
| -rw-r--r-- | common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringMatcher.java | 559 | ||||
| -rw-r--r-- | common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/swing/FilteringListPanel.java | 4 | ||||
| -rw-r--r-- | common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/swing/SimpleStringMatcher.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleStringMatcher.java) | 7 | ||||
| -rw-r--r-- | common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/swing/StringMatcher.java | 68 | ||||
| -rw-r--r-- | jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui_entity_gen.properties | 1 | ||||
| -rw-r--r-- | jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/JptUiEntityGenMessages.java | 1 | ||||
| -rw-r--r-- | jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesSelectorWizardPage.java | 93 |
7 files changed, 660 insertions, 73 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringMatcher.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringMatcher.java index ceab04044c..196400c517 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringMatcher.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringMatcher.java @@ -1,66 +1,493 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.utility.internal; - -import java.io.Serializable; - -/** - * This interface defines a simple API for allowing "pluggable" - * string matchers that can be configured with a pattern string - * then used to determine what strings match the pattern. - */ -public interface StringMatcher { - - /** - * Set the pattern string used to determine future - * matches. The format and semantics of the pattern - * string are determined by the contract between the - * client and the server. - */ - void setPatternString(String patternString); - - /** - * Return whether the specified string matches the - * established pattern string. The semantics of a match - * is determined by the contract between the - * client and the server. - */ - boolean matches(String string); - - - final class Null - implements StringMatcher, Serializable - { - public static final StringMatcher INSTANCE = new Null(); - public static StringMatcher instance() { - return INSTANCE; - } - // ensure single instance - private Null() { - super(); - } - public void setPatternString(String patternString) { - // ignore the pattern string - } - public boolean matches(String string) { - // everything is a match - return true; - } - @Override - public String toString() { - return StringTools.buildSingletonToString(this); - } - private static final long serialVersionUID = 1L; - private Object readResolve() { - // replace this object with the singleton - return INSTANCE; - } - } -} +/*******************************************************************************
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.common.utility.internal;
+
+import java.util.Vector;
+
+/**
+ * A string pattern matcher, suppporting "*" and "?" wildcards.
+ * <p>
+ * Copied from org.eclipse.ui.internal.navigator.StringMatcher
+ */
+public class StringMatcher {
+ protected String fPattern;
+
+ protected int fLength; // pattern length
+
+ protected boolean fIgnoreWildCards;
+
+ protected boolean fIgnoreCase;
+
+ protected boolean fHasLeadingStar;
+
+ protected boolean fHasTrailingStar;
+
+ protected String fSegments[]; // the given pattern is split into *
+
+ // separated segments
+
+ /* boundary value beyond which we don't need to search in the text */
+ protected int fBound = 0;
+
+ protected static final char fSingleWildCard = '\u0000';
+
+ /**
+ *
+ */
+ static class Position {
+ int start; // inclusive
+
+ int end; // exclusive
+
+ Position(int start, int end) {
+ this.start = start;
+ this.end = end;
+ }
+
+ int getStart() {
+ return start;
+ }
+
+ int getEnd() {
+ return end;
+ }
+ }
+
+ /**
+ * StringMatcher constructor takes in a String object that is a simple
+ * pattern which may contain '*' for 0 and many characters and '?' for
+ * exactly one character.
+ *
+ * Literal '*' and '?' characters must be escaped in the pattern e.g., "\*"
+ * means literal "*", etc.
+ *
+ * Escaping any other character (including the escape character itself),
+ * just results in that character in the pattern. e.g., "\a" means "a" and
+ * "\\" means "\"
+ *
+ * If invoking the StringMatcher with string literals in Java, don't forget
+ * escape characters are represented by "\\".
+ *
+ * @param pattern
+ * the pattern to match text against
+ * @param ignoreCase
+ * if true, case is ignored
+ * @param ignoreWildCards
+ * if true, wild cards and their escape sequences are ignored
+ * (everything is taken literally).
+ */
+ public StringMatcher(String pattern, boolean ignoreCase,
+ boolean ignoreWildCards) {
+ if (pattern == null) {
+ throw new IllegalArgumentException();
+ }
+ fIgnoreCase = ignoreCase;
+ fIgnoreWildCards = ignoreWildCards;
+ fPattern = pattern;
+ fLength = pattern.length();
+
+ if (fIgnoreWildCards) {
+ parseNoWildCards();
+ } else {
+ parseWildCards();
+ }
+ }
+
+ /**
+ * Find the first occurrence of the pattern between
+ * <code>start</code)(inclusive)
+ * and <code>end</code>(exclusive).
+ * @param text the String object to search in
+ * @param start the starting index of the search range, inclusive
+ * @param end the ending index of the search range, exclusive
+ * @return an <code>StringMatcher.Position</code> object that keeps the starting
+ * (inclusive) and ending positions (exclusive) of the first occurrence of the
+ * pattern in the specified range of the text; return null if not found or subtext
+ * is empty (start==end). A pair of zeros is returned if pattern is empty string
+ * Note that for pattern like "*abc*" with leading and trailing stars, position of "abc"
+ * is returned. For a pattern like"*??*" in text "abcdf", (1,3) is returned
+ */
+ public StringMatcher.Position find(String text, int start, int end) {
+ if (text == null) {
+ throw new IllegalArgumentException();
+ }
+
+ int tlen = text.length();
+ if (start < 0) {
+ start = 0;
+ }
+ if (end > tlen) {
+ end = tlen;
+ }
+ if (end < 0 || start >= end) {
+ return null;
+ }
+ if (fLength == 0) {
+ return new Position(start, start);
+ }
+ if (fIgnoreWildCards) {
+ int x = posIn(text, start, end);
+ if (x < 0) {
+ return null;
+ }
+ return new Position(x, x + fLength);
+ }
+
+ int segCount = fSegments.length;
+ if (segCount == 0) {
+ return new Position(start, end);
+ }
+
+ int curPos = start;
+ int matchStart = -1;
+ int i;
+ for (i = 0; i < segCount && curPos < end; ++i) {
+ String current = fSegments[i];
+ int nextMatch = regExpPosIn(text, curPos, end, current);
+ if (nextMatch < 0) {
+ return null;
+ }
+ if (i == 0) {
+ matchStart = nextMatch;
+ }
+ curPos = nextMatch + current.length();
+ }
+ if (i < segCount) {
+ return null;
+ }
+ return new Position(matchStart, curPos);
+ }
+
+ /**
+ * match the given <code>text</code> with the pattern
+ *
+ * @return true if matched eitherwise false
+ * @param text
+ * a String object
+ */
+ public boolean match(String text) {
+ if (text == null) {
+ return false;
+ }
+ return match(text, 0, text.length());
+ }
+
+ /**
+ * Given the starting (inclusive) and the ending (exclusive) positions in
+ * the <code>text</code>, determine if the given substring matches with
+ * aPattern
+ *
+ * @return true if the specified portion of the text matches the pattern
+ * @param text
+ * a String object that contains the substring to match
+ * @param start
+ * marks the starting position (inclusive) of the substring
+ * @param end
+ * marks the ending index (exclusive) of the substring
+ */
+ public boolean match(String text, int start, int end) {
+ if (null == text) {
+ throw new IllegalArgumentException();
+ }
+
+ if (start > end) {
+ return false;
+ }
+
+ if (fIgnoreWildCards) {
+ return (end - start == fLength)
+ && fPattern.regionMatches(fIgnoreCase, 0, text, start,
+ fLength);
+ }
+ int segCount = fSegments.length;
+ if (segCount == 0 && (fHasLeadingStar || fHasTrailingStar)) {
+ // contains
+ // only
+ // '*'(s)
+ return true;
+ }
+ if (start == end) {
+ return fLength == 0;
+ }
+ if (fLength == 0) {
+ return start == end;
+ }
+
+ int tlen = text.length();
+ if (start < 0) {
+ start = 0;
+ }
+ if (end > tlen) {
+ end = tlen;
+ }
+
+ int tCurPos = start;
+ int bound = end - fBound;
+ if (bound < 0) {
+ return false;
+ }
+ int i = 0;
+ String current = fSegments[i];
+ int segLength = current.length();
+
+ /* process first segment */
+ if (!fHasLeadingStar) {
+ if (!regExpRegionMatches(text, start, current, 0, segLength)) {
+ return false;
+ }
+ ++i;
+ tCurPos = tCurPos + segLength;
+
+ }
+ if ((fSegments.length == 1) && (!fHasLeadingStar)
+ && (!fHasTrailingStar)) {
+ // only one segment to match, no wildcards specified
+ return tCurPos == end;
+ }
+ /* process middle segments */
+ while (i < segCount) {
+ current = fSegments[i];
+ int currentMatch;
+ int k = current.indexOf(fSingleWildCard);
+ if (k < 0) {
+ currentMatch = textPosIn(text, tCurPos, end, current);
+ if (currentMatch < 0) {
+ return false;
+ }
+ } else {
+ currentMatch = regExpPosIn(text, tCurPos, end, current);
+ if (currentMatch < 0) {
+ return false;
+ }
+ }
+ tCurPos = currentMatch + current.length();
+ i++;
+ }
+
+ /* process final segment */
+ if (!fHasTrailingStar && tCurPos != end) {
+ int clen = current.length();
+ return regExpRegionMatches(text, end - clen, current, 0, clen);
+ }
+ return i == segCount;
+ }
+
+ /**
+ * This method parses the given pattern into segments seperated by wildcard
+ * '*' characters. Since wildcards are not being used in this case, the
+ * pattern consists of a single segment.
+ */
+ private void parseNoWildCards() {
+ fSegments = new String[1];
+ fSegments[0] = fPattern;
+ fBound = fLength;
+ }
+
+ /**
+ * Parses the given pattern into segments seperated by wildcard '*'
+ * characters.
+ *
+ */
+ private void parseWildCards() {
+ if (fPattern.startsWith("*")) { //$NON-NLS-1$
+ fHasLeadingStar = true;
+ }
+ if (fPattern.endsWith("*")) {//$NON-NLS-1$
+ /* make sure it's not an escaped wildcard */
+ if (fLength > 1 && fPattern.charAt(fLength - 2) != '\\') {
+ fHasTrailingStar = true;
+ }
+ }
+
+ Vector temp = new Vector();
+
+ int pos = 0;
+ StringBuffer buf = new StringBuffer();
+ while (pos < fLength) {
+ char c = fPattern.charAt(pos++);
+ switch (c) {
+ case '\\':
+ if (pos >= fLength) {
+ buf.append(c);
+ } else {
+ char next = fPattern.charAt(pos++);
+ /* if it's an escape sequence */
+ if (next == '*' || next == '?' || next == '\\') {
+ buf.append(next);
+ } else {
+ /* not an escape sequence, just insert literally */
+ buf.append(c);
+ buf.append(next);
+ }
+ }
+ break;
+ case '*':
+ if (buf.length() > 0) {
+ /* new segment */
+ temp.addElement(buf.toString());
+ fBound += buf.length();
+ buf.setLength(0);
+ }
+ break;
+ case '?':
+ /* append special character representing single match wildcard */
+ buf.append(fSingleWildCard);
+ break;
+ default:
+ buf.append(c);
+ }
+ }
+
+ /* add last buffer to segment list */
+ if (buf.length() > 0) {
+ temp.addElement(buf.toString());
+ fBound += buf.length();
+ }
+
+ fSegments = new String[temp.size()];
+ temp.copyInto(fSegments);
+ }
+
+ /**
+ * @param text
+ * a string which contains no wildcard
+ * @param start
+ * the starting index in the text for search, inclusive
+ * @param end
+ * the stopping point of search, exclusive
+ * @return the starting index in the text of the pattern , or -1 if not
+ * found
+ */
+ protected int posIn(String text, int start, int end) {// no wild card in
+ // pattern
+ int max = end - fLength;
+
+ if (!fIgnoreCase) {
+ int i = text.indexOf(fPattern, start);
+ if (i == -1 || i > max) {
+ return -1;
+ }
+ return i;
+ }
+
+ for (int i = start; i <= max; ++i) {
+ if (text.regionMatches(true, i, fPattern, 0, fLength)) {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+ /**
+ * @param text
+ * a simple regular expression that may only contain '?'(s)
+ * @param start
+ * the starting index in the text for search, inclusive
+ * @param end
+ * the stopping point of search, exclusive
+ * @param p
+ * a simple regular expression that may contains '?'
+ * @return the starting index in the text of the pattern , or -1 if not
+ * found
+ */
+ protected int regExpPosIn(String text, int start, int end, String p) {
+ int plen = p.length();
+
+ int max = end - plen;
+ for (int i = start; i <= max; ++i) {
+ if (regExpRegionMatches(text, i, p, 0, plen)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ *
+ * @return boolean
+ * @param text
+ * a String to match
+ * @param tStart
+ * indicates the starting index of match, inclusive
+ * @param p
+ * a simple regular expression that may contain '?'
+ * @param pStart
+ * @param plen
+ */
+ protected boolean regExpRegionMatches(String text, int tStart, String p,
+ int pStart, int plen) {
+ while (plen-- > 0) {
+ char tchar = text.charAt(tStart++);
+ char pchar = p.charAt(pStart++);
+
+ /* process wild cards */
+ if (!fIgnoreWildCards) {
+ /* skip single wild cards */
+ if (pchar == fSingleWildCard) {
+ continue;
+ }
+ }
+ if (pchar == tchar) {
+ continue;
+ }
+ if (fIgnoreCase) {
+ if (Character.toUpperCase(tchar) == Character
+ .toUpperCase(pchar)) {
+ continue;
+ }
+ // comparing after converting to upper case doesn't handle all
+ // cases;
+ // also compare after converting to lower case
+ if (Character.toLowerCase(tchar) == Character
+ .toLowerCase(pchar)) {
+ continue;
+ }
+ }
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * @param text
+ * the string to match
+ * @param start
+ * the starting index in the text for search, inclusive
+ * @param end
+ * the stopping point of search, exclusive
+ * @param p
+ * a string that has no wildcard
+ * @return the starting index in the text of the pattern , or -1 if not
+ * found
+ */
+ protected int textPosIn(String text, int start, int end, String p) {
+
+ int plen = p.length();
+ int max = end - plen;
+
+ if (!fIgnoreCase) {
+ int i = text.indexOf(p, start);
+ if (i == -1 || i > max) {
+ return -1;
+ }
+ return i;
+ }
+
+ for (int i = start; i <= max; ++i) {
+ if (text.regionMatches(true, i, p, 0, plen)) {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/swing/FilteringListPanel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/swing/FilteringListPanel.java index e58608c9e4..de745ac5c5 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/swing/FilteringListPanel.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/swing/FilteringListPanel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -24,9 +24,7 @@ import javax.swing.ListSelectionModel; import javax.swing.border.Border; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import org.eclipse.jpt.common.utility.internal.SimpleStringMatcher; import org.eclipse.jpt.common.utility.internal.StringConverter; -import org.eclipse.jpt.common.utility.internal.StringMatcher; /** * This panel presents an entry field and a list box of choices that diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleStringMatcher.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/swing/SimpleStringMatcher.java index 5f85f7895c..560e10b6c1 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleStringMatcher.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/swing/SimpleStringMatcher.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. + * Copyright (c) 2007, 2012 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -7,11 +7,14 @@ * Contributors: * Oracle - initial API and implementation ******************************************************************************/ -package org.eclipse.jpt.common.utility.internal; +package org.eclipse.jpt.common.utility.internal.swing; import java.io.Serializable; import java.util.regex.Pattern; import org.eclipse.jpt.common.utility.Filter; +import org.eclipse.jpt.common.utility.internal.ArrayTools; +import org.eclipse.jpt.common.utility.internal.StringConverter; +import org.eclipse.jpt.common.utility.internal.StringConverter.Default; // TODO the regex code is not very fast - we could probably do better, // hand-coding the matching algorithm (eclipse StringMatcher?) diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/swing/StringMatcher.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/swing/StringMatcher.java new file mode 100644 index 0000000000..962ebd18dc --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/swing/StringMatcher.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2007, 2012 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.utility.internal.swing; + +import java.io.Serializable; + +import org.eclipse.jpt.common.utility.internal.StringTools; + +/** + * This interface defines a simple API for allowing "pluggable" + * string matchers that can be configured with a pattern string + * then used to determine what strings match the pattern. + */ +public interface StringMatcher { + + /** + * Set the pattern string used to determine future + * matches. The format and semantics of the pattern + * string are determined by the contract between the + * client and the server. + */ + void setPatternString(String patternString); + + /** + * Return whether the specified string matches the + * established pattern string. The semantics of a match + * is determined by the contract between the + * client and the server. + */ + boolean matches(String string); + + + final class Null + implements StringMatcher, Serializable + { + public static final StringMatcher INSTANCE = new Null(); + public static StringMatcher instance() { + return INSTANCE; + } + // ensure single instance + private Null() { + super(); + } + public void setPatternString(String patternString) { + // ignore the pattern string + } + public boolean matches(String string) { + // everything is a match + return true; + } + @Override + public String toString() { + return StringTools.buildSingletonToString(this); + } + private static final long serialVersionUID = 1L; + private Object readResolve() { + // replace this object with the singleton + return INSTANCE; + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui_entity_gen.properties b/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui_entity_gen.properties index 2388c29773..658fa57bca 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui_entity_gen.properties +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui_entity_gen.properties @@ -39,6 +39,7 @@ GenerateEntitiesWizard_tableSelectPage_updatePersistenceXml=Update class list in GenerateEntitiesWizard_tableSelectPage_tables=&Tables: GenerateEntitiesWizard_tableSelectPage_tableColumn=Table GenerateEntitiesWizard_tableSelectPage_Restore_Defaults=Restore Defaults +GenerateEntitiesWizard_tableSelectPage_tableSearch=type filter text GenerateEntitiesWizard_tableSelectPage_getTables_jobName=Getting Tables GenerateEntitiesWizard_tableSelectPage_getTables_taskName=Schema get tables diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/JptUiEntityGenMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/JptUiEntityGenMessages.java index d6c1a00b41..0827a6b240 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/JptUiEntityGenMessages.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/JptUiEntityGenMessages.java @@ -30,6 +30,7 @@ public class JptUiEntityGenMessages { public static String GenerateEntitiesWizard_tableSelectPage_updatePersistenceXml; public static String GenerateEntitiesWizard_tableSelectPage_tables; public static String GenerateEntitiesWizard_tableSelectPage_tableColumn; + public static String GenerateEntitiesWizard_tableSelectPage_tableSearch; public static String GenerateEntitiesWizard_tableSelectPage_getTables_jobName; public static String GenerateEntitiesWizard_tableSelectPage_getTables_taskName; diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesSelectorWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesSelectorWizardPage.java index 277cde2fab..36ce111feb 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesSelectorWizardPage.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesSelectorWizardPage.java @@ -39,12 +39,14 @@ import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.jpt.common.ui.internal.util.SWTUtil; import org.eclipse.jpt.common.ui.internal.util.TableLayoutComposite; import org.eclipse.jpt.common.utility.internal.CollectionTools; +import org.eclipse.jpt.common.utility.internal.StringMatcher; import org.eclipse.jpt.jpa.core.JpaProject; import org.eclipse.jpt.jpa.db.ConnectionProfile; import org.eclipse.jpt.jpa.db.Schema; @@ -58,6 +60,8 @@ import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Color; @@ -67,10 +71,10 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.help.IWorkbenchHelpSystem; @@ -90,6 +94,8 @@ public class TablesSelectorWizardPage extends WizardPage { private Button refreshTablesButton; private Button selectAllButton; private Button deselectAllButton; + private Text searchText; + private TableFilter filter; private WorkspaceJob fetchTablesJob; protected final ResourceManager resourceManager; @@ -192,10 +198,18 @@ public class TablesSelectorWizardPage extends WizardPage { tableLabel.setLayoutData(gridData); tableLabel.setText(JptUiEntityGenMessages.GenerateEntitiesWizard_tableSelectPage_tables ); + this.searchText = this.buildSearchText(parent); + + // build two empty labels to align the components + new Label(parent, SWT.NONE); + new Label(parent, SWT.NONE); + TableLayoutComposite layout = new TableLayoutComposite(parent, SWT.NONE); this.addColumnLayoutData(layout); + filter = new TableFilter(); this.tableTable = this.buildCheckboxTableViewer(this.buildTable(layout)); + this.tableTable.addFilter(filter); this.createButtonComposite(parent); this.initTablesSelectionControl(this.possibleTables()); @@ -454,6 +468,16 @@ public class TablesSelectorWizardPage extends WizardPage { return new TableTableContentProvider(); } + private Text buildSearchText(Composite parent) { + GridData gridData = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL); + Text text = new Text(parent, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL); + text.setMessage(JptUiEntityGenMessages.GenerateEntitiesWizard_tableSelectPage_tableSearch); + text.setLayoutData(gridData); + text.addSelectionListener(this.buildClearSearchTextSelectionListener()); + text.addKeyListener(this.buildSearchTextKeyListener()); + return text; + } + // ********** listeners callbacks ********** private void handleTablesListSelectionChanged(SelectionChangedEvent event) { @@ -538,6 +562,26 @@ public class TablesSelectorWizardPage extends WizardPage { }; } + private SelectionListener buildClearSearchTextSelectionListener() { + return new SelectionAdapter() { + @Override + public void widgetDefaultSelected(SelectionEvent e) { + filter.setPattern(""); + tableTable.refresh(); + } + }; + } + + private KeyListener buildSearchTextKeyListener() { + return new KeyAdapter() { + @Override + public void keyReleased(KeyEvent event) { + filter.setPattern(searchText.getText()); + tableTable.refresh(); + } + }; + } + // ********** table behaviors ********** private void editEntityNameIfPossible() { @@ -764,4 +808,49 @@ public class TablesSelectorWizardPage extends WizardPage { return ((Collection<?>) inputElement).toArray(); } } -} + + private class TableFilter extends ViewerFilter { + + private String pattern; + private StringMatcher matcher; + private static final String ALL = "*"; //$NON-NLS-1$ + + /** + * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + @Override + public boolean select (Viewer viewer, Object parentElement, Object element) { + Table table = (Table) element; + if (pattern == null || pattern.length() == 0) { + return true; + } + // if a table is previously selected, it will show up + // in the viewer along with the list of tables filtered out + if (tableTable.getChecked(table)) { + return true; + } + if (matcher.match(table.getName())) { + return true; + } + return false; + } + + /** + * Set the pattern to filter out tables for the table viewer + * <p> + * The following characters have special meaning: + * ? => any character + * * => any string + * </p> + * @param newPattern the new search pattern + */ + protected void setPattern(String newPattern) { + if (newPattern == null || newPattern.trim().length() == 0) { + matcher = new StringMatcher(ALL, true, false); + } else { + pattern = newPattern + ALL; + matcher = new StringMatcher(pattern, true, false); + } + } + } +}
\ No newline at end of file |
