summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaloyan Raev2012-10-08 05:14:47 (EDT)
committer Matthias Sohn2012-11-29 19:22:37 (EST)
commit18e3905a98c4dca006f3467bbd4fc1737e9b0cf9 (patch)
tree9d69ba775cccd7b799d6a7529af15ceb35fe4c10
parente95c6e108300cc39e4de77f5f0014e40c5068e9e (diff)
downloadegit-github-18e3905a98c4dca006f3467bbd4fc1737e9b0cf9.zip
egit-github-18e3905a98c4dca006f3467bbd4fc1737e9b0cf9.tar.gz
egit-github-18e3905a98c4dca006f3467bbd4fc1737e9b0cf9.tar.bz2
Show info message that anonymous cannot submit tasksrefs/changes/55/8055/3
When creating or refreshing the editor, it is checked if the github repository is configured with user credentials. In case, it is anonymous an info message is shown. When clicking on the info message, the repository configuration dialog is opened and the user can enter the credentials. If the repository is anonymous and the user insists to submit the issue, then the info message turns into error message. This solution is inspired by the Bugzilla task editor. Bug: 390757 Change-Id: I9f498acdec46a15156939e71bcc9bd40766cd65f Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueTaskEditorPage.java51
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/Messages.java4
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/messages.properties1
3 files changed, 55 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueTaskEditorPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueTaskEditorPage.java
index e200e7f..3c41a7b 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueTaskEditorPage.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueTaskEditorPage.java
@@ -9,18 +9,27 @@
* David Green <david.green@tasktop.com> - initial contribution
* Christian Trutz <christian.trutz@gmail.com> - initial contribution
* Chris Aniszczyk <caniszczyk@gmail.com> - initial contribution
+ * Kaloyan Raev <kaloyan.raev@sap.com> - bug 390757
*******************************************************************************/
package org.eclipse.mylyn.internal.github.ui.issue;
import java.util.Iterator;
import java.util.Set;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
+import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.internal.github.core.GitHub;
import org.eclipse.mylyn.internal.github.core.issue.IssueAttribute;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorPartDescriptor;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.forms.events.HyperlinkAdapter;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
/**
* Editor page for GitHub.
@@ -29,7 +38,7 @@ public class IssueTaskEditorPage extends AbstractTaskEditorPage {
/**
* Constructor for the GitHubTaskEditorPage
- *
+ *
* @param editor
* The task editor to create for GitHub
*/
@@ -67,4 +76,44 @@ public class IssueTaskEditorPage extends AbstractTaskEditorPage {
}.setPath(PATH_ATTRIBUTES));
return partDescriptors;
}
+
+ @Override
+ protected void createParts() {
+ super.createParts();
+ checkCanSubmit(IMessageProvider.INFORMATION);
+ }
+
+ @Override
+ public void refresh() {
+ super.refresh();
+ checkCanSubmit(IMessageProvider.INFORMATION);
+ }
+
+ @Override
+ public void doSubmit() {
+ if (!checkCanSubmit(IMessageProvider.ERROR))
+ return;
+ super.doSubmit();
+ }
+
+ private boolean checkCanSubmit(final int type) {
+ final TaskRepository taskRepository = getModel().getTaskRepository();
+ AuthenticationCredentials cred = taskRepository.getCredentials(AuthenticationType.REPOSITORY);
+ if (cred == null || cred.getUserName() == null || cred.getUserName().equals("")) { //$NON-NLS-1$
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ getTaskEditor().setMessage(Messages.IssueTaskEditorPage_MessageAnonymousCannotSubmit, type,
+ new HyperlinkAdapter() {
+ @Override
+ public void linkActivated(HyperlinkEvent e) {
+ TasksUiUtil.openEditRepositoryWizard(taskRepository);
+ refresh();
+ }
+ });
+ }
+ });
+ return false;
+ }
+ return true;
+ }
}
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/Messages.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/Messages.java
index cec1fce..607e53e 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/Messages.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/Messages.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ * Kaloyan Raev <kaloyan.raev@sap.com> - bug 390757
*******************************************************************************/
package org.eclipse.mylyn.internal.github.ui.issue;
@@ -89,6 +90,9 @@ public class Messages extends NLS {
public static String IssueRepositorySettingsPage_Title;
/** */
+ public static String IssueTaskEditorPage_MessageAnonymousCannotSubmit;
+
+ /** */
public static String IssueTaskEditorPageFactory_PageText;
/** */
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/messages.properties b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/messages.properties
index ff59f48..218c5fa 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/messages.properties
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/messages.properties
@@ -21,6 +21,7 @@ IssueRepositorySettingsPage_StatusSuccess=Success\!
IssueRepositorySettingsPage_TaskContactingServer=Contacting server...
IssueRepositorySettingsPage_TaskValidating=Validating settings
IssueRepositorySettingsPage_Title=GitHub Issue Repository Settings
+IssueTaskEditorPage_MessageAnonymousCannotSubmit=Anonymous cannot submit issues\!
IssueTaskEditorPageFactory_PageText=GitHub
IssueLabelAttributeEditor_ActionNewLabel=New Label...
IssueLabelAttributeEditor_ActionRemoveLabel=Remove Label