summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorCurtis Windatt2013-04-22 14:36:31 (EDT)
committer Curtis Windatt2013-04-22 14:37:23 (EDT)
commiteae2d7dbc158d384b4687cd2be8527b1da2c6832 (patch)
treecaf2507e597660d38c864d2d81ed47fc26b7c35f
parentef30d0e0c481e9acde815c8d0f97746971fad1c5 (diff)
downloadeclipse.platform.ui-eae2d7dbc158d384b4687cd2be8527b1da2c6832.zip
eclipse.platform.ui-eae2d7dbc158d384b4687cd2be8527b1da2c6832.tar.gz
eclipse.platform.ui-eae2d7dbc158d384b4687cd2be8527b1da2c6832.tar.bz2
Bug 405867 - Quick Access doesn't allow to show all matches any more
Redo the quick access tests Change-Id: Ia535381304934c028a070095f8bea711594a3969
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java25
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/SearchField.java33
-rw-r--r--tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessDialogTest.java212
3 files changed, 235 insertions, 35 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java
index f519009..7cf5c01 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/QuickAccessContents.java
@@ -118,15 +118,11 @@ public abstract class QuickAccessContents {
*/
public void refresh(String filter) {
if (table != null) {
- int numItems = computeNumberOfItems();
boolean filterTextEmpty = filter.length() == 0;
// perfect match, to be selected in the table if not null
QuickAccessElement perfectMatch = getPerfectMatch(filter);
-
- List<QuickAccessEntry>[] entries = computeMatchingEntries(filter, perfectMatch,
- numItems);
-
+ List<QuickAccessEntry>[] entries = computeMatchingEntries(filter, perfectMatch);
int selectionIndex = refreshTable(perfectMatch, entries);
if (table.getItemCount() > 0) {
@@ -277,11 +273,28 @@ public abstract class QuickAccessContents {
return selectionIndex;
}
+ /**
+ * Returns a list per provider containing matching {@link QuickAccessEntry}
+ * that should be displayed in the table given a text filter and a perfect
+ * match entry that should be given priority. The number of items returned
+ * is affected by {@link #getShowAllMatches()} and the size of the table's
+ * composite.
+ *
+ * @param filter
+ * the string text filter to apply, possibly empty
+ * @param perfectMatch
+ * a quick access element that should be given priority or
+ * <code>null</code>
+ * @return the array of lists (one per provider) containg the quick access
+ * entries that should be added to the table, possibly empty
+ */
private List<QuickAccessEntry>[] computeMatchingEntries(String filter,
- QuickAccessElement perfectMatch, int maxCount) {
+ QuickAccessElement perfectMatch) {
// collect matches in an array of lists
@SuppressWarnings("unchecked")
List<QuickAccessEntry>[] entries = new List[providers.length];
+
+ int maxCount = computeNumberOfItems();
int[] indexPerProvider = new int[providers.length];
int countPerProvider = Math.min(maxCount / 4,
INITIAL_COUNT_PER_PROVIDER);
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/SearchField.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/SearchField.java
index 1459673..aa137d9 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/SearchField.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/SearchField.java
@@ -97,6 +97,7 @@ public class SearchField {
@Inject
private EPartService partService;
+ private Table table;
// private Object invokingCommandKeySequences;
// private Object invokingCommand;
@@ -193,7 +194,7 @@ public class SearchField {
}
});
GridLayoutFactory.fillDefaults().applyTo(shell);
- final Table table = quickAccessContents.createTable(shell, Window.getDefaultOrientation());
+ table = quickAccessContents.createTable(shell, Window.getDefaultOrientation());
text.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent e) {
// Once the focus event is complete, check if we should close the shell
@@ -592,4 +593,34 @@ public class SearchField {
return true;
}
}
+
+ /**
+ * Returns the quick access shell for testing. Should not be referenced
+ * outside of the tests.
+ *
+ * @return the current quick access shell or <code>null</code>
+ */
+ public Shell getQuickAccessShell() {
+ return shell;
+ }
+
+ /**
+ * Returns the quick access search text for testing. Should not be
+ * referenced outside of the tests.
+ *
+ * @return the search text in the workbench window or <code>null</code>
+ */
+ public Text getQuickAccessSearchText() {
+ return text;
+ }
+
+ /**
+ * Returns the table in the shell for testing. Should not be referenced
+ * outside of the tests.
+ *
+ * @return the table created in the shell or <code>null</code>
+ */
+ public Table getQuickAccessTable(){
+ return table;
+ }
}
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessDialogTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessDialogTest.java
index b60db9f..bab96c4 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessDialogTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/quickaccess/QuickAccessDialogTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 IBM Corporation and others.
+ * Copyright (c) 2008, 2013 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
@@ -14,17 +14,23 @@ package org.eclipse.ui.tests.quickaccess;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.model.application.ui.menu.MToolControl;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.internal.WorkbenchWindow;
+import org.eclipse.ui.internal.quickaccess.QuickAccessMessages;
import org.eclipse.ui.internal.quickaccess.SearchField;
import org.eclipse.ui.tests.harness.util.UITestCase;
/**
+ * Tests the quick access UI
* @since 3.4
- *
*/
public class QuickAccessDialogTest extends UITestCase {
+ private SearchField searchField;
+
/**
* @param testName
*/
@@ -32,40 +38,190 @@ public class QuickAccessDialogTest extends UITestCase {
super(testName);
}
- public void testOpenQuickAccess() throws Exception {
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.tests.harness.util.UITestCase#doSetUp()
+ */
+ @Override
+ protected void doSetUp() throws Exception {
WorkbenchWindow workbenchWindow = (WorkbenchWindow) getWorkbench()
.getActiveWorkbenchWindow();
MWindow window = workbenchWindow.getModel();
- IHandlerService handlerService = (IHandlerService) workbenchWindow
- .getService(IHandlerService.class);
- handlerService
- .executeCommand("org.eclipse.ui.window.quickAccess", null); //$NON-NLS-1$
EModelService modelService = window.getContext().get(
EModelService.class);
MToolControl control = (MToolControl) modelService.find(
"SearchField", window); //$NON-NLS-1$
- final SearchField searchField = (SearchField) control.getObject();
-
- try {
- assertTrue("expecting items", processEventsUntil(new Condition() {
- public boolean compute() {
- return searchField.getTable().getItemCount() > 0;
- };
- }, 200));
- String oldFirstItemText = searchField.getTable().getItem(0)
- .getText(1);
- searchField.getFilterText().setText("e");
- int count1 = searchField.getTable().getItemCount();
- assertTrue("expecting matching items", count1 > 0);
- assertNotSame("expecting different item", oldFirstItemText,
- searchField.getTable().getItem(0).getText(1));
- searchField.toggleShowAllMatches();
- int count2 = searchField.getTable().getItemCount();
- assertTrue("still expecting matching items", count2 > 0);
- assertTrue("expecting more matching items", count2 > count1);
- } finally {
- searchField.close();
+ searchField = (SearchField) control.getObject();
+ assertNotNull("Search Field must exist", searchField);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.tests.harness.util.UITestCase#doTearDown()
+ */
+ @Override
+ protected void doTearDown() throws Exception {
+ Text text = searchField.getQuickAccessSearchText();
+ if (text != null){
+ text.setText("");
+ }
+ Shell shell = searchField.getQuickAccessShell();
+ if (shell != null){
+ shell.setVisible(false);
}
}
+ /**
+ * Tests that the shell opens when the command is activated
+ * @throws Exception
+ */
+ public void testOpenByCommand() throws Exception {
+ IHandlerService handlerService = (IHandlerService) getWorkbench().getActiveWorkbenchWindow()
+ .getService(IHandlerService.class);
+ Shell shell = searchField.getQuickAccessShell();
+ assertFalse("Quick access dialog should not be visible yet", shell.isVisible());
+ handlerService
+ .executeCommand("org.eclipse.ui.window.quickAccess", null); //$NON-NLS-1$
+ assertTrue("Quick access dialog should be visible now", shell.isVisible());
+ }
+
+ /**
+ * Tests that typing in the text field opens the shell
+ */
+ public void testOpenByText(){
+ Shell shell = searchField.getQuickAccessShell();
+ assertFalse("Quick access dialog should not be visible yet", shell.isVisible());
+ Text text = searchField.getQuickAccessSearchText();
+ text.setText("Test");
+ assertTrue("Quick access dialog should be visible now", shell.isVisible());
+ }
+
+ /**
+ * Test that changing the filter text works correctly
+ */
+ public void testTextFilter(){
+ final Table table = searchField.getQuickAccessTable();
+ Text text = searchField.getQuickAccessSearchText();
+ assertTrue("Quick access table should say to start typing", table.getItemCount() == 1);
+ assertSame("Quick access table should say to start typing", QuickAccessMessages.QuickAccess_StartTypingToFindMatches, table.getItem(0).getText(1));
+
+ text.setText("T");
+ processEventsUntil(new Condition() {
+ public boolean compute() {
+ return table.getItemCount() > 1;
+ };
+ }, 200);
+ int oldCount = table.getItemCount();
+ assertTrue("Not enough quick access items for simple filter", oldCount > 3);
+ assertTrue("Too many quick access items for size of table", oldCount < 30);
+ final String oldFirstItemText = table.getItem(0).getText(1);
+
+ text.setText("E");
+ processEventsUntil(new Condition() {
+ public boolean compute() {
+ return table.getItemCount() > 1 && !table.getItem(0).getText(1).equals(oldFirstItemText);
+ };
+ }, 200);
+ String newFirstItemText = table.getItem(0).getText(1);
+ assertNotSame("The quick access items should have changed", newFirstItemText, oldFirstItemText);
+ int newCount = table.getItemCount();
+ assertTrue("Not enough quick access items for simple filter", newCount > 3);
+ assertTrue("Too many quick access items for size of table", newCount < 30);
+
+ text.setText("QWERTYUIOPTEST");
+ processEventsUntil(new Condition() {
+ public boolean compute() {
+ return table.getItemCount() == 1;
+ };
+ }, 200);
+ assertTrue("Quick access table should say no results found", table.getItemCount() == 1);
+ assertSame("Quick access table should say no results found", QuickAccessMessages.QuickAccessContents_NoMatchingResults, table.getItem(0).getText());
+
+ text.setText("");
+ processEventsUntil(new Condition() {
+ public boolean compute() {
+ return table.getItemCount() == 1;
+ };
+ }, 200);
+ assertTrue("Quick access table should say to start typing", table.getItemCount() == 1);
+ assertSame("Quick access table should say to start typing", QuickAccessMessages.QuickAccess_StartTypingToFindMatches, table.getItem(0).getText(1));
+ }
+
+ /**
+ * Tests that activating the handler again toggles the show all setting and that the setting changes the results
+ * Also tests that closing and reopening the shell resets show all
+ */
+ public void testShowAll() throws Exception {
+ // Open the shell
+ IHandlerService handlerService = (IHandlerService) getWorkbench().getActiveWorkbenchWindow()
+ .getService(IHandlerService.class);
+ Shell shell = searchField.getQuickAccessShell();
+ assertFalse("Quick access dialog should not be visible yet", shell.isVisible());
+ handlerService
+ .executeCommand("org.eclipse.ui.window.quickAccess", null); //$NON-NLS-1$
+ assertTrue("Quick access dialog should be visible now", shell.isVisible());
+ final Table table = searchField.getQuickAccessTable();
+ Text text = searchField.getQuickAccessSearchText();
+ assertTrue("Quick access table should say to start typing", table.getItemCount() == 1);
+ assertSame("Quick access table should say to start typing", QuickAccessMessages.QuickAccess_StartTypingToFindMatches, table.getItem(0).getText(1));
+
+ // Set a filter to get some items
+ text.setText("T");
+ processEventsUntil(new Condition() {
+ public boolean compute() {
+ return table.getItemCount() > 1;
+ };
+ }, 200);
+ final int oldCount = table.getItemCount();
+ assertTrue("Not enough quick access items for simple filter", oldCount > 3);
+ assertTrue("Too many quick access items for size of table", oldCount < 30);
+ final String oldFirstItemText = table.getItem(0).getText(1);
+
+ // Run the handler to turn on show all
+ handlerService
+ .executeCommand("org.eclipse.ui.window.quickAccess", null); //$NON-NLS-1$
+ processEventsUntil(new Condition() {
+ public boolean compute() {
+ return table.getItemCount() != oldCount;
+ };
+ }, 200);
+ final int newCount = table.getItemCount();
+ assertTrue("Turning on show all should display more items", newCount > oldCount);
+ assertEquals("Turning on show all should not change the top item", oldFirstItemText, table.getItem(0).getText(1));
+
+ // Run the handler to turn off show all
+ handlerService
+ .executeCommand("org.eclipse.ui.window.quickAccess", null); //$NON-NLS-1$
+ processEventsUntil(new Condition() {
+ public boolean compute() {
+ return table.getItemCount() != newCount;
+ };
+ }, 200);
+ // Note: The table count may one off from the old count because of shell resizing (scroll bars being added then removed)
+ assertTrue("Turning off show all should limit items shown", table.getItemCount() < newCount);
+ assertEquals("Turning off show all should not change the top item", oldFirstItemText, table.getItem(0).getText(1));
+
+ // Run the handler to turn on show all
+ handlerService
+ .executeCommand("org.eclipse.ui.window.quickAccess", null); //$NON-NLS-1$
+ processEventsUntil(new Condition() {
+ public boolean compute() {
+ return table.getItemCount() != oldCount;
+ };
+ }, 200);
+ assertEquals("Turning on show all twice shouldn't change the items", newCount, table.getItemCount());
+ assertEquals("Turning on show all twice shouldn't change the top item", oldFirstItemText, table.getItem(0).getText(1));
+
+ // Close and reopen the shell
+ shell.setVisible(false);
+ handlerService
+ .executeCommand("org.eclipse.ui.window.quickAccess", null); //$NON-NLS-1$
+ text.setText("T");
+ processEventsUntil(new Condition() {
+ public boolean compute() {
+ return table.getItemCount() > 1;
+ };
+ }, 200);
+ // Note: The table count may one off from the old count because of shell resizing (scroll bars being added then removed)
+ assertTrue("Show all should be turned off when the shell is closed and reopened", table.getItemCount() < newCount);
+ }
+
}