Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Kennedy2016-02-12 19:16:03 +0000
committerGerrit Code Review @ Eclipse.org2016-02-16 23:07:21 +0000
commit37236c56a7c204d4f34fab2be5b1f307d1af6e4b (patch)
treeb38a7012858f629a7ee2e29fb235b2e1087e0496
parentcc6f1b4b44f00e696f7f5aaecbedab9cd6baa869 (diff)
downloadorg.eclipse.mylyn.tasks-37236c56a7c204d4f34fab2be5b1f307d1af6e4b.tar.gz
org.eclipse.mylyn.tasks-37236c56a7c204d4f34fab2be5b1f307d1af6e4b.tar.xz
org.eclipse.mylyn.tasks-37236c56a7c204d4f34fab2be5b1f307d1af6e4b.zip
487761: Allow credential fields to be toggled
setNeedsRepositoryCredentials() now affects the editability of credentials fields after control creation. Change-Id: I1cc5c8f61f1274dd052c98e0d5ab993504e0dee9 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=487761 Signed-off-by: James Kennedy <james.kennedy@tasktop.com>
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/RepositorySettingsPageTest.java77
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPage.java34
2 files changed, 98 insertions, 13 deletions
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/RepositorySettingsPageTest.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/RepositorySettingsPageTest.java
index 1a595dc87..6e163cccf 100644
--- a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/RepositorySettingsPageTest.java
+++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/RepositorySettingsPageTest.java
@@ -70,6 +70,7 @@ public class RepositorySettingsPageTest {
Combo getServerUrlCombo() {
return serverUrlCombo;
}
+
}
public static class RepositorySettingsPageWithNoCredentials extends TestRepositorySettingsPage {
@@ -206,6 +207,72 @@ public class RepositorySettingsPageTest {
}
@Test
+ public void setNeedsRepositoryCredentialsInitializeFalse() throws Exception {
+ TestRepositorySettingsPage page = new TestRepositorySettingsPage(createTaskRepository());
+ page.setNeedsRepositoryCredentials(false);
+ page.createControl(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+
+ assertFalse(page.needsRepositoryCredentials());
+ assertNull(page.repositoryUserNameEditor);
+ assertNull(page.repositoryPasswordEditor);
+ }
+
+ @Test
+ public void setNeedsRepositoryCredentialsInitializeTrue() throws Exception {
+ TestRepositorySettingsPage page = new TestRepositorySettingsPage(createTaskRepository());
+ page.setNeedsRepositoryCredentials(true);
+ page.createControl(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+
+ assertTrue(page.needsRepositoryCredentials());
+ assertCredentialsEnabled(page);
+ }
+
+ @Test
+ public void setNeedsRepositoryCredentialsFalse() throws Exception {
+ TestRepositorySettingsPage page = new TestRepositorySettingsPage(createTaskRepository());
+ page.setNeedsRepositoryCredentials(true);
+ page.createControl(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ assertCredentialsEnabled(page);
+
+ page.setNeedsRepositoryCredentials(false);
+
+ assertCredentialsDisabled(page);
+ }
+
+ @Test
+ public void setNeedsRepositoryCredentialsTrue() throws Exception {
+ TestRepositorySettingsPage page = new TestRepositorySettingsPage(createTaskRepository());
+ page.setNeedsRepositoryCredentials(true);
+ page.createControl(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ page.setNeedsRepositoryCredentials(false);
+ assertCredentialsDisabled(page);
+
+ page.setNeedsRepositoryCredentials(true);
+ assertCredentialsEnabled(page);
+ }
+
+ @Test
+ public void repositoryCredentialsEnabledOnlyIfNeededAndNotAnonymous() throws Exception {
+ TestRepositorySettingsPage page = new TestRepositorySettingsPage(createTaskRepository());
+ page.setNeedsRepositoryCredentials(true);
+ page.setNeedsAnonymousLogin(true);
+ page.createControl(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+
+ assertTrue(page.needsRepositoryCredentials());
+ assertTrue(page.isAnonymousAccess());
+ assertCredentialsDisabled(page);
+
+ page.setAnonymous(false);
+ page.setNeedsRepositoryCredentials(false);
+
+ assertCredentialsDisabled(page);
+
+ page.setNeedsRepositoryCredentials(true);
+
+ assertCredentialsEnabled(page);
+ }
+
+ @Test
public void isUrlReadOnly() throws Exception {
TestRepositorySettingsPage page = new TestRepositorySettingsPage(createTaskRepository());
assertFalse(page.isUrlReadOnly());
@@ -235,4 +302,14 @@ public class RepositorySettingsPageTest {
repository.setRepositoryLabel("label");
return repository;
}
+
+ private void assertCredentialsEnabled(TestRepositorySettingsPage page) {
+ assertTrue(page.repositoryUserNameEditor.getTextControl(page.compositeContainer).isEnabled());
+ assertTrue(page.repositoryPasswordEditor.getTextControl(page.compositeContainer).isEnabled());
+ }
+
+ private void assertCredentialsDisabled(TestRepositorySettingsPage page) {
+ assertFalse(page.repositoryUserNameEditor.getTextControl(page.compositeContainer).isEnabled());
+ assertFalse(page.repositoryPasswordEditor.getTextControl(page.compositeContainer).isEnabled());
+ }
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPage.java
index 9c51e174e..bc808db4a 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPage.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPage.java
@@ -1244,25 +1244,32 @@ public abstract class AbstractRepositorySettingsPage extends AbstractTaskReposit
}
anonymousButton.setSelection(selected);
+ updateCredentialsEditors();
- if (selected) {
- oldUsername = repositoryUserNameEditor.getStringValue();
- oldPassword = (repositoryPasswordEditor).getStringValue();
- repositoryUserNameEditor.setStringValue(""); //$NON-NLS-1$
- repositoryPasswordEditor.setStringValue(""); //$NON-NLS-1$
- } else {
- repositoryUserNameEditor.setStringValue(oldUsername);
- repositoryPasswordEditor.setStringValue(oldPassword);
- }
-
- repositoryUserNameEditor.setEnabled(!selected, compositeContainer);
- repositoryPasswordEditor.setEnabled(!selected, compositeContainer);
- savePasswordButton.setEnabled(!selected);
if (getWizard() != null) {
getWizard().getContainer().updateButtons();
}
}
+ private void updateCredentialsEditors() {
+ if (repositoryUserNameEditor != null && repositoryPasswordEditor != null) {
+ boolean shouldEnable = needsRepositoryCredentials() && !isAnonymousAccess();
+ if (shouldEnable) {
+ repositoryUserNameEditor.setStringValue(oldUsername);
+ repositoryPasswordEditor.setStringValue(oldPassword);
+ } else {
+ oldUsername = repositoryUserNameEditor.getStringValue();
+ oldPassword = (repositoryPasswordEditor).getStringValue();
+ repositoryUserNameEditor.setStringValue(""); //$NON-NLS-1$
+ repositoryPasswordEditor.setStringValue(""); //$NON-NLS-1$
+ }
+
+ repositoryUserNameEditor.setEnabled(shouldEnable, compositeContainer);
+ repositoryPasswordEditor.setEnabled(shouldEnable, compositeContainer);
+ savePasswordButton.setEnabled(shouldEnable);
+ }
+ }
+
/**
* @since 2.0
*/
@@ -1937,6 +1944,7 @@ public abstract class AbstractRepositorySettingsPage extends AbstractTaskReposit
*/
public void setNeedsRepositoryCredentials(boolean needsRepositoryCredentials) {
this.needsRepositoryCredentials = needsRepositoryCredentials;
+ updateCredentialsEditors();
}
public void setNeedsValidation(boolean needsValidation) {

Back to the top