Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2015-11-12 13:58:22 -0500
committerGerrit Code Review @ Eclipse.org2015-11-25 15:01:21 -0500
commit335845982b92dd656e781e26e7ab1d64cc28d049 (patch)
treebdf729b8141fe90035b0aef7a82c8e896eb872de
parentcc0295a24e13d01c25b764ca6a7c0302f97781aa (diff)
downloadorg.eclipse.mylyn.tasks-335845982b92dd656e781e26e7ab1d64cc28d049.tar.gz
org.eclipse.mylyn.tasks-335845982b92dd656e781e26e7ab1d64cc28d049.tar.xz
org.eclipse.mylyn.tasks-335845982b92dd656e781e26e7ab1d64cc28d049.zip
482633: [api] connectors can suggest query titles
Change-Id: I448d467b1442150bccf984494007d44f3362e67e Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=482633
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositoryQueryPage2Test.java215
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositoryQueryPage2.java41
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/RepositoryQueryWizard.java3
3 files changed, 258 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositoryQueryPage2Test.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositoryQueryPage2Test.java
new file mode 100644
index 000000000..5c6bd0ade
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositoryQueryPage2Test.java
@@ -0,0 +1,215 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.tasks.ui.wizards;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.eclipse.jface.wizard.IWizardContainer;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.mylyn.commons.workbench.WorkbenchUtil;
+import org.eclipse.mylyn.commons.workbench.forms.SectionComposite;
+import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AbstractRepositoryQueryPage2Test {
+
+ private final class TestRepositoryQueryPage extends AbstractRepositoryQueryPage2 {
+ private String suggestedTitle = "";
+
+ private TestRepositoryQueryPage(String pageName, TaskRepository repository, IRepositoryQuery query) {
+ super(pageName, repository, query);
+ }
+
+ @Override
+ protected String suggestQueryTitle() {
+ return suggestedTitle;
+ }
+
+ @Override
+ protected IWizardContainer getContainer() {
+ return super.getContainer();
+ }
+
+ @Override
+ protected void createPageContent(SectionComposite parent) {
+ }
+
+ @Override
+ protected void doRefreshControls() {
+ }
+
+ @Override
+ protected boolean hasRepositoryConfiguration() {
+ return false;
+ }
+
+ @Override
+ protected boolean restoreState(IRepositoryQuery query) {
+ return false;
+ }
+
+ @Override
+ public void applyTo(IRepositoryQuery query) {
+ }
+
+ public void setSuggestedTitle(String suggestedTitle) {
+ this.suggestedTitle = suggestedTitle;
+ }
+ }
+
+ private TestRepositoryQueryPage page;
+
+ private IRepositoryQuery savedQuery;
+
+ @Before
+ public void setUp() {
+ TaskRepository repository = new TaskRepository("mock", "http://mock");
+ savedQuery = mock(IRepositoryQuery.class);
+ page = new TestRepositoryQueryPage("page", repository, savedQuery);
+ RepositoryQueryWizard wizard = new RepositoryQueryWizard(repository);
+ WizardDialog dialog = new WizardDialog(WorkbenchUtil.getShell(), wizard);
+ wizard.setContainer(dialog);
+ wizard.addPage(page);
+ page.createControl(WorkbenchUtil.getShell());
+ dialog.create();
+ // simulate the user making a selection which sets the suggestion:
+ page.setSuggestedTitle("suggested title");
+ }
+
+ @Test
+ public void suggestsTitleWhenTitleEmpty() {
+ assertEquals("", page.getQueryTitle());
+ page.getContainer().updateButtons();
+ assertEquals("suggested title", page.getQueryTitle());
+ }
+
+ @Test
+ public void doesNotSuggestTitleWhenTitleEdited() {
+ page.setQueryTitle("test");
+ assertEquals("test", page.getQueryTitle());
+ page.getContainer().updateButtons();
+ assertEquals("test", page.getQueryTitle());
+
+ page.setQueryTitle("testing");
+ page.getContainer().updateButtons();
+ assertEquals("testing", page.getQueryTitle());
+ }
+
+ @Test
+ public void suggestsTitleWhenTitleCleared() {
+ page.setQueryTitle("test");
+ page.getContainer().updateButtons();
+ assertEquals("test", page.getQueryTitle());
+
+ page.setQueryTitle("");
+ assertEquals("", page.getQueryTitle());
+ page.getContainer().updateButtons();
+ assertEquals("suggested title", page.getQueryTitle());
+ }
+
+ @Test
+ public void suggestsTitleWhenSuggestionChanges() {
+ page.getContainer().updateButtons();
+ assertEquals("suggested title", page.getQueryTitle());
+
+ page.setSuggestedTitle("another suggested title");
+ page.getContainer().updateButtons();
+ assertEquals("another suggested title", page.getQueryTitle());
+ }
+
+ @Test
+ public void suggestsTitleWhenSuggestionEmpty() {
+ page.getContainer().updateButtons();
+ assertEquals("suggested title", page.getQueryTitle());
+
+ page.setSuggestedTitle("");
+ assertEquals("suggested title", page.getQueryTitle());
+ page.getContainer().updateButtons();
+ assertEquals("", page.getQueryTitle());
+ }
+
+ @Test
+ public void doesNotSuggestTitleWhenEditedTitleEqualsSuggestion() {
+ when(savedQuery.getSummary()).thenReturn("saved title");
+ page.setQueryTitle("suggested title");
+ page.getContainer().updateButtons();
+ assertEquals("suggested title", page.getQueryTitle());
+
+ page.setSuggestedTitle("another suggested title");
+ page.getContainer().updateButtons();
+ assertEquals("suggested title", page.getQueryTitle());
+ }
+
+ @Test
+ public void doesNotSuggestTitleWhenSavedTitleEqualsSuggestion() {
+ when(savedQuery.getSummary()).thenReturn("suggested title");
+ page.setQueryTitle("edited title");
+ page.getContainer().updateButtons();
+ assertEquals("edited title", page.getQueryTitle());
+
+ page.setSuggestedTitle("another suggested title");
+ page.getContainer().updateButtons();
+ assertEquals("edited title", page.getQueryTitle());
+ }
+
+ @Test
+ public void doesNotSuggestTitleWhenEditedTitleEqualsSavedTitle() {
+ when(savedQuery.getSummary()).thenReturn("saved title");
+ page.setQueryTitle("saved title");
+ page.getContainer().updateButtons();
+ assertEquals("saved title", page.getQueryTitle());
+
+ page.setSuggestedTitle("another suggested title");
+ page.getContainer().updateButtons();
+ assertEquals("saved title", page.getQueryTitle());
+ }
+
+ @Test
+ public void suggestsTitleWhenEditingQueryWithSuggestedTitle() {
+ when(savedQuery.getSummary()).thenReturn("suggested title");
+ page.setQueryTitle("suggested title");
+ page.getContainer().updateButtons();
+ assertEquals("suggested title", page.getQueryTitle());
+
+ page.setSuggestedTitle("another suggested title");
+ page.getContainer().updateButtons();
+ assertEquals("another suggested title", page.getQueryTitle());
+ }
+
+ @Test
+ public void suggestTitleUpdatesCompletion() {
+ page.getContainer().updateButtons();
+ assertEquals("suggested title", page.getQueryTitle());
+ assertTrue(page.isPageComplete());
+
+ page.setSuggestedTitle("");
+ page.getContainer().updateButtons();
+ assertFalse(page.isPageComplete());
+ assertEquals("", page.getQueryTitle());
+
+ page.getContainer().updateButtons();
+ assertFalse(page.isPageComplete());
+ assertEquals("", page.getQueryTitle());
+
+ page.setSuggestedTitle("another suggested title");
+ page.getContainer().updateButtons();
+ assertTrue(page.isPageComplete());
+ assertEquals("another suggested title", page.getQueryTitle());
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositoryQueryPage2.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositoryQueryPage2.java
index 1271e5cf6..fe74062c0 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositoryQueryPage2.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositoryQueryPage2.java
@@ -50,6 +50,9 @@ import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.IProgressService;
+import com.google.common.base.Objects;
+import com.google.common.base.Strings;
+
/**
* @author Steffen Pingel
* @author Frank Becker
@@ -81,6 +84,10 @@ public abstract class AbstractRepositoryQueryPage2 extends AbstractRepositoryQue
private Text titleText;
+ private boolean titleWasSuggested;
+
+ private boolean editQueryTitleInProgress;
+
public AbstractRepositoryQueryPage2(String pageName, TaskRepository repository, IRepositoryQuery query) {
super(pageName, repository, query);
this.connector = TasksUi.getRepositoryConnector(getTaskRepository().getConnectorKind());
@@ -145,6 +152,33 @@ public abstract class AbstractRepositoryQueryPage2 extends AbstractRepositoryQue
return false;
}
+ /**
+ * Allows connectors to suggest a query title. As long as the title field does not contain edits made by the user,
+ * the field will be updated with the suggestion whenever the button enablement is updated.
+ *
+ * @return a query title suggested based on the query parameters, or the empty string
+ * @since 3.18
+ */
+ @NonNull
+ protected String suggestQueryTitle() {
+ return ""; //$NON-NLS-1$
+ }
+
+ /**
+ * Called by the framework to update the title from the suggestion.
+ */
+ void updateTitleFromSuggestion() {
+ if (editQueryTitleInProgress) {
+ titleWasSuggested = false;
+ } else if (titleWasSuggested
+ || Strings.isNullOrEmpty(getQueryTitle())
+ || (getQuery() != null && Objects.equal(getQuery().getSummary(), getQueryTitle()) && suggestQueryTitle().equals(
+ getQueryTitle()))) {
+ setQueryTitle(suggestQueryTitle());
+ titleWasSuggested = true;
+ }
+ }
+
public boolean needsClear() {
return needsClear;
}
@@ -266,7 +300,12 @@ public abstract class AbstractRepositoryQueryPage2 extends AbstractRepositoryQue
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(titleText);
titleText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
- getContainer().updateButtons();
+ try {
+ editQueryTitleInProgress = true;
+ getContainer().updateButtons();
+ } finally {
+ editQueryTitleInProgress = false;
+ }
}
});
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/RepositoryQueryWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/RepositoryQueryWizard.java
index 740a9e628..e9bee0dea 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/RepositoryQueryWizard.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/RepositoryQueryWizard.java
@@ -51,6 +51,9 @@ public class RepositoryQueryWizard extends Wizard {
@Override
public boolean canFinish() {
IWizardPage currentPage = getContainer().getCurrentPage();
+ if (currentPage instanceof AbstractRepositoryQueryPage2) {
+ ((AbstractRepositoryQueryPage2) currentPage).updateTitleFromSuggestion();
+ }
if (currentPage instanceof AbstractRepositoryQueryPage) {
return currentPage.isPageComplete();
}

Back to the top