Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten2006-07-06 15:08:16 +0000
committermkersten2006-07-06 15:08:16 +0000
commitfc4fbb4b481b91eb60fb0a629bbf40fd329136b3 (patch)
treea0f16542ce1ae6bd88e36d8fb65c25ce75c4381e
parent6f349472f453609a630d48f7596ea92999810019 (diff)
downloadorg.eclipse.mylyn.tasks-fc4fbb4b481b91eb60fb0a629bbf40fd329136b3.tar.gz
org.eclipse.mylyn.tasks-fc4fbb4b481b91eb60fb0a629bbf40fd329136b3.tar.xz
org.eclipse.mylyn.tasks-fc4fbb4b481b91eb60fb0a629bbf40fd329136b3.zip
Completed: 148378: refactor AbstractRepositorySettingsPage for more flexibility
https://bugs.eclipse.org/bugs/show_bug.cgi?id=148378
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/AllTaskListTests.java1
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/RepositorySettingsPageTest.java174
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AbstractRepositorySettingsPage.java29
3 files changed, 192 insertions, 12 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/AllTaskListTests.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/AllTaskListTests.java
index 2f7baa038..b3a9b2fea 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/AllTaskListTests.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/AllTaskListTests.java
@@ -46,6 +46,7 @@ public class AllTaskListTests {
suite.addTestSuite(TaskActivityTimingTest.class);
suite.addTestSuite(TaskActivityViewTest.class);
suite.addTestSuite(TaskAttachmentActionsTest.class);
+ suite.addTestSuite(RepositorySettingsPageTest.class);
// suite.addTestSuite(RetrieveTitleFromUrlTest.class);
// $JUnit-END$
return suite;
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/RepositorySettingsPageTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/RepositorySettingsPageTest.java
new file mode 100644
index 000000000..e92ebda00
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasklist/tests/RepositorySettingsPageTest.java
@@ -0,0 +1,174 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers 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
+ *******************************************************************************/
+
+package org.eclipse.mylar.tasklist.tests;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.mylar.internal.tasklist.ui.wizards.AbstractRepositorySettingsPage;
+import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryConnector;
+import org.eclipse.mylar.provisional.tasklist.TaskRepository;
+import org.eclipse.mylar.tasklist.tests.mockconnector.MockRepositoryConnector;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * @author Steffen Pingel
+ */
+public class RepositorySettingsPageTest extends TestCase {
+
+ public void testNeedsEncoding() {
+ TaskRepository repository = new TaskRepository("kind", "http://localhost/");
+ repository.setCharacterEncoding("UTF-8");
+
+ MockRepositoryConnector connector = new MockRepositoryConnector();
+ MockRepositorySettingsPage page = new MockRepositorySettingsPage(connector);
+ page.setNeedsEncoding(true);
+
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ page.createControl(shell);
+ page.setVisible(true);
+
+ TaskRepository repository2 = page.createTaskRepository();
+ assertEquals("UTF-8", repository2.getCharacterEncoding());
+ }
+
+ public void testNeedsEncodingFalse() {
+ MockRepositoryConnector connector = new MockRepositoryConnector();
+ MockRepositorySettingsPage page = new MockRepositorySettingsPage(connector);
+ page.setNeedsEncoding(false);
+
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ page.createControl(shell);
+ page.setVisible(true);
+
+ page.createTaskRepository();
+ }
+
+ public void testNeedsAnonyoumousLoginFalse() {
+ MockRepositoryConnector connector = new MockRepositoryConnector();
+ MockRepositorySettingsPage page = new MockRepositorySettingsPage(connector);
+ page.setNeedsAnonymousLogin(false);
+
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ page.createControl(shell);
+ page.setVisible(true);
+
+ assertNull(page.getAnonymousButton());
+ }
+
+ public void testNeedsAnonyoumousLoginNoRepository() {
+ MockRepositoryConnector connector = new MockRepositoryConnector();
+ MockRepositorySettingsPage page = new MockRepositorySettingsPage(connector);
+ page.setNeedsAnonymousLogin(true);
+
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ page.createControl(shell);
+ page.setVisible(true);
+
+ assertNotNull(page.getAnonymousButton());
+
+ assertFalse(page.getAnonymousButton().getSelection());
+ assertTrue(page.getUserNameEditor().getTextControl(page.getParent()).isEnabled());
+ assertTrue(page.getPasswordEditor().getTextControl(page.getParent()).isEnabled());
+ assertEquals("", page.getUserName());
+ assertEquals("", page.getPassword());
+ }
+
+ public void testNeedsAnonyoumousLogin() {
+ TaskRepository repository = new TaskRepository("kind", "http://localhost/");
+ MockRepositoryConnector connector = new MockRepositoryConnector();
+ MockRepositorySettingsPage page = new MockRepositorySettingsPage(connector);
+ page.setNeedsAnonymousLogin(true);
+ page.setRepository(repository);
+
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ page.createControl(shell);
+ page.setVisible(true);
+
+ assertNotNull(page.getAnonymousButton());
+
+ assertTrue(page.getAnonymousButton().getSelection());
+ assertFalse(page.getUserNameEditor().getTextControl(page.getParent()).isEnabled());
+ assertFalse(page.getPasswordEditor().getTextControl(page.getParent()).isEnabled());
+ assertEquals("", page.getUserName());
+ assertEquals("", page.getPassword());
+
+ page.getAnonymousButton().setSelection(false);
+ page.getAnonymousButton().notifyListeners(SWT.Selection, new Event());
+ assertTrue(page.getUserNameEditor().getTextControl(page.getParent()).isEnabled());
+ assertTrue(page.getPasswordEditor().getTextControl(page.getParent()).isEnabled());
+ page.getUserNameEditor().setStringValue("user");
+ page.getPasswordEditor().setStringValue("password");
+ assertEquals("user", page.getUserName());
+ assertEquals("password", page.getPassword());
+
+ page.getAnonymousButton().setSelection(true);
+ page.getAnonymousButton().notifyListeners(SWT.Selection, new Event());
+ assertFalse(page.getUserNameEditor().getTextControl(page.getParent()).isEnabled());
+ assertFalse(page.getPasswordEditor().getTextControl(page.getParent()).isEnabled());
+ assertEquals("", page.getUserName());
+ assertEquals("", page.getPassword());
+
+ page.getAnonymousButton().setSelection(false);
+ page.getAnonymousButton().notifyListeners(SWT.Selection, new Event());
+ assertTrue(page.getUserNameEditor().getTextControl(page.getParent()).isEnabled());
+ assertTrue(page.getPasswordEditor().getTextControl(page.getParent()).isEnabled());
+ assertEquals("user", page.getUserNameEditor().getStringValue());
+ assertEquals("password", page.getPasswordEditor().getStringValue());
+ assertEquals("user", page.getUserName());
+ assertEquals("password", page.getPassword());
+ }
+
+ private class MockRepositorySettingsPage extends AbstractRepositorySettingsPage {
+
+ private Composite parent;
+
+ public MockRepositorySettingsPage(AbstractRepositoryConnector connector) {
+ super("title", "description", connector);
+ }
+
+ @Override
+ protected void createAdditionalControls(Composite parent) {
+ this.parent = parent;
+ }
+
+ @Override
+ protected boolean isValidUrl(String name) {
+ // ignore
+ return false;
+ }
+
+ @Override
+ protected void validateSettings() {
+ // ignore
+ }
+
+ Button getAnonymousButton() {
+ return anonymousButton;
+ }
+
+ StringFieldEditor getUserNameEditor() {
+ return userNameEditor;
+ }
+
+ StringFieldEditor getPasswordEditor() {
+ return passwordEditor;
+ }
+
+ Composite getParent() {
+ return parent;
+ }
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AbstractRepositorySettingsPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AbstractRepositorySettingsPage.java
index 4d4c8125a..c4c14c67c 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AbstractRepositorySettingsPage.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasklist/ui/wizards/AbstractRepositorySettingsPage.java
@@ -70,7 +70,7 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
// private Combo timeZonesCombo;
- private Button anonymousButton;
+ protected Button anonymousButton;
private String oldUsername;
@@ -93,8 +93,8 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
setNeedsTimeZone(true);
}
- public void createControl(final Composite parent) {
- Composite container = new Composite(parent, SWT.NULL);
+ public void createControl(Composite parent) {
+ final Composite container = new Composite(parent, SWT.NULL);
FillLayout layout = new FillLayout();
container.setLayout(layout);
@@ -114,24 +114,21 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
serverUrlEditor.setErrorMessage("Server path must be a valid http(s):// url");
if (needsAnonymousLogin()) {
- Label anonymousLabel = new Label(parent, SWT.NONE);
- anonymousLabel.setText("");
- anonymousButton = new Button(parent, SWT.CHECK);
+ anonymousButton = new Button(container, SWT.CHECK);
anonymousButton.setText("Anonymous Access");
- if (repository != null) {
- anonymousButton.setSelection(isAnonymousAccess());
- }
anonymousButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
boolean selected = anonymousButton.getSelection();
- updateAnonymousButton(selected, parent);
+ updateAnonymousButton(selected, container);
}
public void widgetDefaultSelected(SelectionEvent e) {
// ignore
}
});
- updateAnonymousButton(anonymousButton.getSelection(), parent);
+
+ Label anonymousLabel = new Label(container, SWT.NONE);
+ anonymousLabel.setText("");
}
userNameEditor = new StringFieldEditor("", LABEL_USER, StringFieldEditor.UNLIMITED, container);
@@ -153,6 +150,14 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
// bug 131656: must set echo char after setting value on Mac
((RepositoryStringFieldEditor) passwordEditor).getTextControl().setEchoChar('*');
+ if (needsAnonymousLogin()) {
+ // do this after username and password widgets have been intialized
+ if (repository != null) {
+ anonymousButton.setSelection(isAnonymousAccess());
+ }
+ updateAnonymousButton(anonymousButton.getSelection(), container);
+ }
+
// TODO: put this back if we can't get the info from all connectors
// if (needsTimeZone()) {
// Label timeZoneLabel = new Label(container, SWT.NONE);
@@ -423,4 +428,4 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
passwordEditor.setStringValue(pass);
}
-}
+} \ No newline at end of file

Back to the top