summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-19 19:02:32 (EDT)
committerChris Aniszczyk2011-04-20 10:32:12 (EDT)
commit0237f3c283ab545241e958de3bdc4752d4dbe81f (patch)
treec7867d79ec54edfcc05b0d966d3340d3552ce9d3
parentd00ce7b58e4a2330a8027206a9e772f995376585 (diff)
downloadegit-github-0237f3c283ab545241e958de3bdc4752d4dbe81f.zip
egit-github-0237f3c283ab545241e958de3bdc4752d4dbe81f.tar.gz
egit-github-0237f3c283ab545241e958de3bdc4752d4dbe81f.tar.bz2
Add validation of settings in Gist repository pagerefs/changes/78/3178/3
Change-Id: Iaa284c0c4c9bc391c881f56fed8bb5db7a647aac Signed-off-by: Kevin Sawicki <kevin@github.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java32
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistRepositorySettingsPage.java58
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java15
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties5
4 files changed, 88 insertions, 22 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java
index ef116a3..29498d2 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java
@@ -44,6 +44,22 @@ public class GistConnector extends AbstractRepositoryConnector {
*/
public static final String KIND = "githubGists"; //$NON-NLS-1$
+ /**
+ * Create client for repository
+ *
+ * @param repository
+ * @return client
+ */
+ public static GitHubClient createClient(TaskRepository repository) {
+ GitHubClient client = new GitHubClient();
+ AuthenticationCredentials credentials = repository
+ .getCredentials(AuthenticationType.REPOSITORY);
+ if (credentials != null)
+ client.setCredentials(credentials.getUserName(),
+ credentials.getPassword());
+ return client;
+ }
+
private GistTaskDataHandler dataHandler = new GistTaskDataHandler();
private GistAttachmentHandler attachmentHandler = new GistAttachmentHandler();
@@ -63,22 +79,6 @@ public class GistConnector extends AbstractRepositoryConnector {
}
/**
- * Create client for repository
- *
- * @param repository
- * @return client
- */
- protected GitHubClient createClient(TaskRepository repository) {
- GitHubClient client = new GitHubClient();
- AuthenticationCredentials credentials = repository
- .getCredentials(AuthenticationType.REPOSITORY);
- if (credentials != null)
- client.setCredentials(credentials.getUserName(),
- credentials.getPassword());
- return client;
- }
-
- /**
* @see org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector#canCreateNewTask(org.eclipse.mylyn.tasks.core.TaskRepository)
*/
public boolean canCreateNewTask(TaskRepository repository) {
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistRepositorySettingsPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistRepositorySettingsPage.java
index 418eb67..5f4f0aa 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistRepositorySettingsPage.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistRepositorySettingsPage.java
@@ -12,9 +12,17 @@ package org.eclipse.mylyn.internal.github.ui.gist;
import java.io.IOException;
import java.net.URL;
+import java.text.MessageFormat;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.mylyn.github.internal.GistService;
+import org.eclipse.mylyn.github.internal.GitHub;
+import org.eclipse.mylyn.github.internal.GitHubClient;
+import org.eclipse.mylyn.github.ui.internal.GitHubUi;
import org.eclipse.mylyn.internal.github.core.gist.GistConnector;
import org.eclipse.mylyn.internal.tasks.core.IRepositoryConstants;
import org.eclipse.mylyn.tasks.core.TaskRepository;
@@ -29,6 +37,11 @@ import org.eclipse.swt.widgets.Composite;
public class GistRepositorySettingsPage extends AbstractRepositorySettingsPage {
/**
+ * URL
+ */
+ public static final String URL = "https://gist.github.com"; //$NON-NLS-1$
+
+ /**
* @param taskRepository
*/
public GistRepositorySettingsPage(TaskRepository taskRepository) {
@@ -49,8 +62,9 @@ public class GistRepositorySettingsPage extends AbstractRepositorySettingsPage {
*/
protected void createAdditionalControls(Composite parent) {
if (repository == null) {
- setUrl("https://gist.github.com"); //$NON-NLS-1$
- repositoryLabelEditor.setStringValue("Gists"); //$NON-NLS-1$
+ setUrl(URL);
+ repositoryLabelEditor
+ .setStringValue(Messages.GistRepositorySettingsPage_RepositoryLabelDefault);
}
}
@@ -58,14 +72,13 @@ public class GistRepositorySettingsPage extends AbstractRepositorySettingsPage {
* @see org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage#isValidUrl(java.lang.String)
*/
protected boolean isValidUrl(String url) {
- if (url.startsWith("http://") || url.startsWith("https://")) { //$NON-NLS-1$ //$NON-NLS-2$
+ if (url.startsWith("http://") || url.startsWith("https://")) //$NON-NLS-1$ //$NON-NLS-2$
try {
new URL(url);
return true;
} catch (IOException e) {
return false;
}
- }
return false;
}
@@ -73,11 +86,36 @@ public class GistRepositorySettingsPage extends AbstractRepositorySettingsPage {
/**
* @see org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage#getValidator(org.eclipse.mylyn.tasks.core.TaskRepository)
*/
- protected Validator getValidator(TaskRepository repository) {
+ protected Validator getValidator(final TaskRepository repository) {
return new Validator() {
public void run(IProgressMonitor monitor) throws CoreException {
-
+ monitor.beginTask(
+ Messages.GistRepositorySettingsPage_TaskValidating, 100);
+ try {
+ monitor.subTask(Messages.GistRepositorySettingsPage_TaskContacting);
+ try {
+ GitHubClient client = GistConnector
+ .createClient(repository);
+ GistService service = new GistService(client);
+ String user = GitHub
+ .computeTaskRepositoryUser(repository.getUrl());
+ monitor.worked(20);
+ service.getGists(user);
+ } catch (IOException e) {
+ String message = MessageFormat
+ .format(Messages.GistRepositorySettingsPage_StatusError,
+ e.getLocalizedMessage());
+ setStatus(GitHubUi.createErrorStatus(message));
+ return;
+ } finally {
+ monitor.done();
+ }
+ setStatus(new Status(IStatus.OK, GitHubUi.BUNDLE_ID,
+ Messages.GistRepositorySettingsPage_StatusSuccess));
+ } finally {
+ monitor.done();
+ }
}
};
}
@@ -91,4 +129,12 @@ public class GistRepositorySettingsPage extends AbstractRepositorySettingsPage {
super.applyTo(repository);
}
+ /**
+ * @see org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage#canValidate()
+ */
+ public boolean canValidate() {
+ return isPageComplete()
+ && (getMessage() == null || getMessageType() != IMessageProvider.ERROR);
+ }
+
}
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java
index 5f1e200..84eea02 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/Messages.java
@@ -35,6 +35,21 @@ public class Messages extends NLS {
public static String GistRepositorySettingsPage_Description;
/** */
+ public static String GistRepositorySettingsPage_RepositoryLabelDefault;
+
+ /** */
+ public static String GistRepositorySettingsPage_StatusError;
+
+ /** */
+ public static String GistRepositorySettingsPage_StatusSuccess;
+
+ /** */
+ public static String GistRepositorySettingsPage_TaskContacting;
+
+ /** */
+ public static String GistRepositorySettingsPage_TaskValidating;
+
+ /** */
public static String GistRepositorySettingsPage_Title;
/** */
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties
index 08b7f5d..1c1c02e 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/messages.properties
@@ -3,5 +3,10 @@ GistConnectorUi_LabelTaskKind=Gist
GistRepositoryQueryPage_LabelTitle=Title:
GistRepositoryQueryPage_LabelUser=User:
GistRepositorySettingsPage_Description=Enter repository settings
+GistRepositorySettingsPage_RepositoryLabelDefault=Gists
+GistRepositorySettingsPage_StatusError=Error validating settings: {0}
+GistRepositorySettingsPage_StatusSuccess=Success\!
+GistRepositorySettingsPage_TaskContacting=Contacting server
+GistRepositorySettingsPage_TaskValidating=Validating Settings...
GistRepositorySettingsPage_Title=Gist repository settings
GistTaskEditorPageFactory_PageText=Gist