Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Aniszczyk2011-03-23 19:04:34 -0400
committerChris Aniszczyk2011-03-23 19:04:34 -0400
commit8758fb2dd13ed6031ead593e4fc092c9c2e7f1eb (patch)
treec20c312bdf7da473e6fe3e435c0670cd8dc0b82a /org.eclipse.mylyn.github.ui
downloadegit-github-8758fb2dd13ed6031ead593e4fc092c9c2e7f1eb.tar.gz
egit-github-8758fb2dd13ed6031ead593e4fc092c9c2e7f1eb.tar.xz
egit-github-8758fb2dd13ed6031ead593e4fc092c9c2e7f1eb.zip
Initial commit of Mylyn GitHub Integration
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.mylyn.github.ui')
-rw-r--r--org.eclipse.mylyn.github.ui/.classpath7
-rw-r--r--org.eclipse.mylyn.github.ui/.gitignore2
-rw-r--r--org.eclipse.mylyn.github.ui/.project28
-rw-r--r--org.eclipse.mylyn.github.ui/.settings/org.eclipse.core.resources.prefs3
-rw-r--r--org.eclipse.mylyn.github.ui/.settings/org.eclipse.core.runtime.prefs3
-rw-r--r--org.eclipse.mylyn.github.ui/.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF17
-rw-r--r--org.eclipse.mylyn.github.ui/build.properties7
-rw-r--r--org.eclipse.mylyn.github.ui/images/git-logo.pngbin0 -> 202 bytes
-rw-r--r--org.eclipse.mylyn.github.ui/plugin.properties2
-rw-r--r--org.eclipse.mylyn.github.ui/plugin.xml27
-rw-r--r--org.eclipse.mylyn.github.ui/pom.xml23
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryConnectorUI.java147
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryQueryPage.java119
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositorySettingsPage.java147
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java73
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPageFactory.java82
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubUi.java54
18 files changed, 753 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.github.ui/.classpath b/org.eclipse.mylyn.github.ui/.classpath
new file mode 100644
index 00000000..64c5e31b
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.mylyn.github.ui/.gitignore b/org.eclipse.mylyn.github.ui/.gitignore
new file mode 100644
index 00000000..d567ba01
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/.gitignore
@@ -0,0 +1,2 @@
+bin
+target
diff --git a/org.eclipse.mylyn.github.ui/.project b/org.eclipse.mylyn.github.ui/.project
new file mode 100644
index 00000000..6b7553c4
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.mylyn.github.ui</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.mylyn.github.ui/.settings/org.eclipse.core.resources.prefs b/org.eclipse.mylyn.github.ui/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 00000000..84f3fcc6
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,3 @@
+#Tue Jun 09 20:22:15 CEST 2009
+eclipse.preferences.version=1
+encoding/<project>=UTF-8
diff --git a/org.eclipse.mylyn.github.ui/.settings/org.eclipse.core.runtime.prefs b/org.eclipse.mylyn.github.ui/.settings/org.eclipse.core.runtime.prefs
new file mode 100644
index 00000000..f96d6778
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/.settings/org.eclipse.core.runtime.prefs
@@ -0,0 +1,3 @@
+#Tue Jun 09 20:22:15 CEST 2009
+eclipse.preferences.version=1
+line.separator=\n
diff --git a/org.eclipse.mylyn.github.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.mylyn.github.ui/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000..094b3472
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Sun Aug 23 18:34:16 EDT 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..356db6d0
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/META-INF/MANIFEST.MF
@@ -0,0 +1,17 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Eclipse EGit Mylyn GitHub UI Plug-in (Incubation)
+Bundle-SymbolicName: org.eclipse.mylyn.github.ui;singleton:=true
+Bundle-Version: 0.1.0.qualifier
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-Vendor: Eclipse EGit
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0",
+ org.eclipse.ui;bundle-version="3.5.0",
+ org.eclipse.ui.forms;bundle-version="3.4.0",
+ org.eclipse.mylyn.tasks.ui;bundle-version="3.2.0",
+ org.eclipse.mylyn.github.core;bundle-version="0.1.0",
+ org.eclipse.jface.text;bundle-version="3.5.0",
+ org.eclipse.mylyn.commons.net;bundle-version="3.2.0",
+ org.eclipse.mylyn.tasks.core
+Export-Package: org.eclipse.mylyn.github.ui.internal;x-internal:=true
diff --git a/org.eclipse.mylyn.github.ui/build.properties b/org.eclipse.mylyn.github.ui/build.properties
new file mode 100644
index 00000000..3a0c53af
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/build.properties
@@ -0,0 +1,7 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ plugin.properties,\
+ images/
diff --git a/org.eclipse.mylyn.github.ui/images/git-logo.png b/org.eclipse.mylyn.github.ui/images/git-logo.png
new file mode 100644
index 00000000..dd98d355
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/images/git-logo.png
Binary files differ
diff --git a/org.eclipse.mylyn.github.ui/plugin.properties b/org.eclipse.mylyn.github.ui/plugin.properties
new file mode 100644
index 00000000..da940291
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/plugin.properties
@@ -0,0 +1,2 @@
+org.eclipse.mylyn.github.ui.internal.GitHubRepositoryConnector=GitHub repository connector
+org.eclipse.mylyn.github.ui.internal.GitHubRepositoryConnectorUI=GitHub repository connector UI \ No newline at end of file
diff --git a/org.eclipse.mylyn.github.ui/plugin.xml b/org.eclipse.mylyn.github.ui/plugin.xml
new file mode 100644
index 00000000..57da2a54
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/plugin.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.mylyn.tasks.ui.repositories">
+ <connectorCore
+ class="org.eclipse.mylyn.github.internal.GitHubRepositoryConnector"
+ id="org.eclipse.mylyn.github.ui.internal.GitHubRepositoryConnector"
+ name="%org.eclipse.mylyn.github.ui.internal.GitHubRepositoryConnector">
+ </connectorCore>
+ <connectorUi
+ brandingIcon="images/git-logo.png"
+ class="org.eclipse.mylyn.github.ui.internal.GitHubRepositoryConnectorUI"
+ id="org.eclipse.mylyn.github.ui.internal.GitHubRepositoryConnectorUI"
+ name="%org.eclipse.mylyn.github.ui.internal.GitHubRepositoryConnectorUI"
+ overlayIcon="images/git-logo.png">
+ </connectorUi>
+ </extension>
+ <extension
+ point="org.eclipse.mylyn.tasks.ui.editors">
+ <pageFactory
+ class="org.eclipse.mylyn.github.ui.internal.GitHubTaskEditorPageFactory"
+ id="org.eclipse.mylyn.github.ui.internal.GitHubTaskEditorPageFactory">
+ </pageFactory>
+ </extension>
+
+</plugin>
diff --git a/org.eclipse.mylyn.github.ui/pom.xml b/org.eclipse.mylyn.github.ui/pom.xml
new file mode 100644
index 00000000..1accffc8
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/pom.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (C) 2011, Chris Aniszczyk <caniszczyk@gmail.com>
+
+ 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
+-->
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>github-parent</artifactId>
+ <groupId>org.eclipse.mylyn.github</groupId>
+ <version>0.1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>ui</artifactId>
+ <packaging>eclipse-plugin</packaging>
+ <name>Eclipse EGit Mylyn GitHub UI (Incubation)</name>
+</project>
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryConnectorUI.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryConnectorUI.java
new file mode 100644
index 00000000..eda7565f
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryConnectorUI.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat 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:
+ * David Green <david.green@tasktop.com> - initial contribution
+ * Christian Trutz <christian.trutz@gmail.com> - initial contribution
+ * Chris Aniszczyk <caniszczyk@gmail.com> - initial contribution
+ *******************************************************************************/
+package org.eclipse.mylyn.github.ui.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.jface.text.hyperlink.URLHyperlink;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.mylyn.github.internal.GitHub;
+import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
+import org.eclipse.mylyn.tasks.core.ITaskMapping;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi;
+import org.eclipse.mylyn.tasks.ui.TaskHyperlink;
+import org.eclipse.mylyn.tasks.ui.TasksUi;
+import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage;
+import org.eclipse.mylyn.tasks.ui.wizards.ITaskRepositoryPage;
+import org.eclipse.mylyn.tasks.ui.wizards.NewTaskWizard;
+import org.eclipse.mylyn.tasks.ui.wizards.RepositoryQueryWizard;
+
+/**
+ * GitHub connector specific UI extensions.
+ */
+public class GitHubRepositoryConnectorUI extends AbstractRepositoryConnectorUi {
+
+ private final Pattern issuePattern = Pattern.compile("(?:([a-zA-Z0-9_\\.-]+)(?:/([a-zA-Z0-9_\\.-]+))?)?\\#(\\d+)");
+
+ /**
+ *
+ *
+ * @return the unique type of the repository: "github"
+ */
+ @Override
+ public String getConnectorKind() {
+ return GitHub.CONNECTOR_KIND;
+ }
+
+ /**
+ *
+ *
+ * @return {@link AbstractRepositorySettingsPage} with GitHub specific
+ * parameter like user name, password, ...
+ */
+ @Override
+ public ITaskRepositoryPage getSettingsPage(
+ final TaskRepository taskRepository) {
+ return new GitHubRepositorySettingsPage(taskRepository);
+ }
+
+ /**
+ *
+ *
+ * @return {@link NewTaskWizard} with GitHub specific tab
+ */
+ @Override
+ public IWizard getNewTaskWizard(final TaskRepository taskRepository,
+ final ITaskMapping taskSelection) {
+ return new NewTaskWizard(taskRepository, taskSelection);
+ }
+
+ /**
+ * This {@link AbstractRepositoryConnectorUi} has search page.
+ *
+ * @return {@code true}
+ */
+ @Override
+ public boolean hasSearchPage() {
+ return true;
+ }
+
+ /**
+ * Returns {@link IWizard} used in Mylyn for creating new queries. This
+ * {@link IWizard} has a wizard page for creating GitHub specific task
+ * queries.
+ *
+ * @return {@link RepositoryQueryWizard} with GitHub specific query page
+ */
+ @Override
+ public IWizard getQueryWizard(final TaskRepository taskRepository,
+ final IRepositoryQuery queryToEdit) {
+ RepositoryQueryWizard wizard = new RepositoryQueryWizard(taskRepository);
+ GitHubRepositoryQueryPage queryPage = new GitHubRepositoryQueryPage(
+ taskRepository, queryToEdit);
+ wizard.addPage(queryPage);
+ return wizard;
+ }
+
+
+ public IHyperlink[] findHyperlinks(TaskRepository repository, String text, int index, int textOffset) {
+ List<IHyperlink> hyperlinks = new ArrayList<IHyperlink>();
+
+ Matcher matcher = issuePattern.matcher(text);
+ while (matcher.find()) {
+ if (index == -1 || (index >= matcher.start() && index <= matcher.end())) {
+ String user = matcher.group(1);
+ String project = matcher.group(2);
+ String taskId = matcher.group(3);
+
+ if (project == null && user != null) {
+ // same project name, different user
+ String url = repository.getUrl();
+ project = GitHub.computeTaskRepositoryProject(url);
+ }
+
+ TaskRepository taskRepository = null;
+ if (user == null && project == null) {
+ taskRepository = repository;
+ } else if (user != null && project != null) {
+ String repositoryUrl = GitHub.createGitHubUrl(user,project);
+ taskRepository = TasksUi.getRepositoryManager().getRepository(GitHub.CONNECTOR_KIND, repositoryUrl);
+ if (taskRepository == null) {
+ repositoryUrl = GitHub.createGitHubUrlAlternate(user,project);
+ taskRepository = TasksUi.getRepositoryManager().getRepository(GitHub.CONNECTOR_KIND, repositoryUrl);
+ }
+ }
+ if (taskRepository != null) {
+ Region region = createRegion(textOffset, matcher);
+ hyperlinks.add(new TaskHyperlink(region, repository, taskId));
+ } else if (user != null && project != null) {
+ Region region = createRegion(textOffset, matcher);
+ String url = GitHub.createGitHubUrl(user, project)+"/issues/issue/"+taskId;
+ hyperlinks.add(new URLHyperlink(region, url));
+ }
+ }
+ }
+ return hyperlinks.toArray(new IHyperlink[hyperlinks.size()]);
+ }
+
+ private Region createRegion(int textOffset, Matcher matcher) {
+ return new Region(matcher.start()+textOffset,matcher.end()-matcher.start());
+ }
+}
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryQueryPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryQueryPage.java
new file mode 100644
index 00000000..b55e72a5
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositoryQueryPage.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat 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:
+ * David Green <david.green@tasktop.com> - initial contribution
+ * Christian Trutz <christian.trutz@gmail.com> - initial contribution
+ * Chris Aniszczyk <caniszczyk@gmail.com> - initial contribution
+ *******************************************************************************/
+package org.eclipse.mylyn.github.ui.internal;
+
+import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositoryQueryPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * GitHub connector specific extensions.
+ */
+public class GitHubRepositoryQueryPage extends AbstractRepositoryQueryPage {
+
+ private static final String ATTR_QUERY_TEXT = "queryText";
+
+ private static final String ATTR_STATUS = "status";
+
+ private Text queryText = null;
+
+ private Combo status = null;
+
+ /**
+ * @param taskRepository
+ * @param query
+ */
+ public GitHubRepositoryQueryPage(final TaskRepository taskRepository,
+ final IRepositoryQuery query) {
+ super("GitHub", taskRepository, query);
+ setTitle("GitHub search query parameters");
+ setDescription("Valid search query parameters entered.");
+ setPageComplete(false);
+ }
+
+ @Override
+ public String getQueryTitle() {
+ return "GitHub Query";
+ }
+
+ @Override
+ public void applyTo(IRepositoryQuery query) {
+ String statusString = status.getText();
+ String queryString = queryText.getText();
+
+ String summary = statusString;
+ summary += " issues";
+ if (queryString!=null && queryString.trim().length() > 0) {
+ summary += " matching "+queryString;
+ }
+ query.setSummary(summary);
+ query.setAttribute(ATTR_STATUS, statusString);
+ query.setAttribute(ATTR_QUERY_TEXT, queryString);
+ }
+
+ /**
+ *
+ *
+ */
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout gridLayout = new GridLayout(2, false);
+ gridLayout.marginTop = 20;
+ gridLayout.marginLeft = 25;
+ gridLayout.verticalSpacing = 8;
+ gridLayout.horizontalSpacing = 8;
+ composite.setLayout(gridLayout);
+
+
+ // create the status option combo box
+ new Label(composite, SWT.NONE).setText("Status:");
+ status = new Combo(composite, SWT.READ_ONLY);
+ String[] queryValues = new String[] { "all", "open", "closed" };
+ status.setItems(queryValues);
+ status.select(0);
+ String queryModelStatus = getQuery()==null?null:getQuery().getAttribute(ATTR_STATUS);
+ if (queryModelStatus != null) {
+ for (int x = 0;x<queryValues.length;++x) {
+ if (queryValues[x].equals(queryModelStatus)) {
+ status.select(x);
+ break;
+ }
+ }
+ }
+
+ // create the query entry box
+ new Label(composite, SWT.NONE).setText("Query text:");
+ queryText = new Text(composite, SWT.BORDER);
+ GridData gridData = new GridData();
+ gridData.widthHint = 250;
+ queryText.setLayoutData(gridData);
+ String queryModelText = getQuery()==null?null:getQuery().getAttribute(ATTR_QUERY_TEXT);
+ queryText.setText(queryModelText==null?"":queryModelText);
+
+ setControl(composite);
+ }
+
+ @Override
+ public boolean isPageComplete() {
+ setErrorMessage(null);
+ return true;
+ }
+
+}
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositorySettingsPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositorySettingsPage.java
new file mode 100644
index 00000000..28cd3a55
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubRepositorySettingsPage.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat 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:
+ * David Green <david.green@tasktop.com> - initial contribution
+ * Christian Trutz <christian.trutz@gmail.com> - initial contribution
+ * Chris Aniszczyk <caniszczyk@gmail.com> - initial contribution
+ *******************************************************************************/
+package org.eclipse.mylyn.github.ui.internal;
+
+import java.util.regex.Matcher;
+
+
+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.mylyn.commons.net.AuthenticationCredentials;
+import org.eclipse.mylyn.commons.net.AuthenticationType;
+import org.eclipse.mylyn.github.internal.GitHub;
+import org.eclipse.mylyn.github.internal.GitHubCredentials;
+import org.eclipse.mylyn.github.internal.GitHubService;
+import org.eclipse.mylyn.github.internal.GitHubServiceException;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * GitHub connector specific extensions.
+ */
+public class GitHubRepositorySettingsPage extends
+ AbstractRepositorySettingsPage {
+
+ static final String URL = "http://github.com";
+
+ private static final String PASS_LABEL_TEXT = "GitHub API Token:";
+
+ /**
+ * Populate taskRepository with repository settings.
+ *
+ * @param taskRepository
+ * - Object to populate
+ */
+ public GitHubRepositorySettingsPage(final TaskRepository taskRepository) {
+ super("GitHub Repository Settings", "", taskRepository);
+ this.setHttpAuth(false);
+ this.setNeedsAdvanced(false);
+ this.setNeedsAnonymousLogin(false);
+ this.setNeedsTimeZone(false);
+ this.setNeedsHttpAuth(false);
+ }
+
+ @Override
+ public String getConnectorKind() {
+ return GitHub.CONNECTOR_KIND;
+ }
+
+ @Override
+ protected void createAdditionalControls(Composite parent) {
+ // Set the URL now, because serverURL is definitely instantiated .
+ if (serverUrlCombo != null && (serverUrlCombo.getText() == null || serverUrlCombo.getText().trim().length() == 0)) {
+ String fullUrlText = URL+"/user/project";
+ serverUrlCombo.setText(fullUrlText);
+ // select the user/project part of the URL so that the user can just start
+ // typing to replace the text.
+ serverUrlCombo.setSelection(new Point(URL.length()+1,fullUrlText.length()));
+ }
+
+ // Specify that you need the GitHub User Name
+ if (repositoryUserNameEditor != null) {
+ String text = repositoryUserNameEditor.getLabelText();
+ repositoryUserNameEditor.setLabelText("GitHub " + text);
+ }
+
+ // Use the password field for the API Token Key
+ if (repositoryPasswordEditor != null) {
+ repositoryPasswordEditor.setLabelText(PASS_LABEL_TEXT);
+ }
+ }
+
+ @Override
+ protected Validator getValidator(final TaskRepository repository) {
+ Validator validator = new Validator() {
+ @Override
+ public void run(IProgressMonitor monitor) throws CoreException {
+ int totalWork = 1000;
+ monitor.beginTask("Validating settings", totalWork);
+ try {
+
+ String urlText = repository.getUrl();
+ Matcher urlMatcher = GitHub.URL_PATTERN.matcher(urlText==null?"":urlText);
+ if (!urlMatcher.matches()) {
+ setStatus(GitHubUi.createErrorStatus("Server URL must be in the form http://github.com/user/project or\nhttp://www.github.org/user/project"));
+ return;
+ }
+ monitor.worked(100);
+
+ String user = urlMatcher.group(1);
+ String repo = urlMatcher.group(2);
+ AuthenticationCredentials auth = repository.getCredentials(AuthenticationType.REPOSITORY);
+
+ GitHubService service = new GitHubService();
+
+ monitor.subTask("Contacting server...");
+ try {
+ // verify the repo
+ service.searchIssues(user, repo, new String("open"),"");
+ monitor.worked(400);
+
+ // verify the credentials
+ if (auth == null) {
+ setStatus(GitHubUi.createErrorStatus("Credentials are required. Please specify username and API Token."));
+ return;
+ }
+ GitHubCredentials credentials = new GitHubCredentials(auth.getUserName(), auth.getPassword());
+ if (!service.verifyCredentials(credentials)) {
+ setStatus(GitHubUi.createErrorStatus("Invalid credentials. Please check your GitHub User ID and API Token.\nYou can find your API Token on your GitHub account settings page."));
+ return;
+ }
+ } catch (GitHubServiceException e) {
+ setStatus(GitHubUi.createErrorStatus("Repository Test failed:"+ e.getMessage()));
+ return;
+ }
+
+ setStatus(new Status(IStatus.OK,GitHubUi.BUNDLE_ID, "Success!"));
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+ return validator;
+ }
+
+ @Override
+ protected boolean isValidUrl(final String url) {
+ if (url.contains("github")) {
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java
new file mode 100644
index 00000000..a24d8cb1
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPage.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat 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:
+ * David Green <david.green@tasktop.com> - initial contribution
+ * Christian Trutz <christian.trutz@gmail.com> - initial contribution
+ * Chris Aniszczyk <caniszczyk@gmail.com> - initial contribution
+ *******************************************************************************/
+package org.eclipse.mylyn.github.ui.internal;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.mylyn.github.internal.GitHub;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
+import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
+import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory;
+import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
+import org.eclipse.mylyn.tasks.ui.editors.TaskEditorPartDescriptor;
+
+/**
+ * Editor page for GitHub.
+ */
+public class GitHubTaskEditorPage extends AbstractTaskEditorPage {
+
+ /**
+ * Constructor for the GitHubTaskEditorPage
+ *
+ * @param editor
+ * The task editor to create for GitHub
+ */
+ public GitHubTaskEditorPage(final TaskEditor editor) {
+ super(editor, GitHub.CONNECTOR_KIND);
+ setNeedsPrivateSection(true);
+ setNeedsSubmitButton(true);
+ }
+
+ @Override
+ protected Set<TaskEditorPartDescriptor> createPartDescriptors() {
+ Set<TaskEditorPartDescriptor> partDescriptors = super.createPartDescriptors();
+ Iterator<TaskEditorPartDescriptor> descriptorIt = partDescriptors.iterator();
+ while (descriptorIt.hasNext()) {
+ TaskEditorPartDescriptor partDescriptor = descriptorIt.next();
+ if (partDescriptor.getId().equals(ID_PART_ATTRIBUTES)) {
+ descriptorIt.remove();
+ } else if (partDescriptor.getId().equals(ID_PART_COMMENTS)) {
+ // currently the API doesn't support reading existing comments,
+ // though it does allow for creating them. Silly really.
+ // see http://support.github.com/discussions/feature-requests/696-issues-api-improvement
+ descriptorIt.remove();
+ }
+ }
+ return partDescriptors;
+ }
+
+
+ @Override
+ protected AttributeEditorFactory createAttributeEditorFactory() {
+ return new AttributeEditorFactory(getModel(), getTaskRepository(), getEditorSite()) {
+ @Override
+ public AbstractAttributeEditor createEditor(String type,
+ TaskAttribute taskAttribute) {
+ // TODO Auto-generated method stub
+ return super.createEditor(type, taskAttribute);
+ }
+ };
+ }
+}
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPageFactory.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPageFactory.java
new file mode 100644
index 00000000..b442b494
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubTaskEditorPageFactory.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat 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:
+ * David Green <david.green@tasktop.com> - initial contribution
+ * Christian Trutz <christian.trutz@gmail.com> - initial contribution
+ * Chris Aniszczyk <caniszczyk@gmail.com> - initial contribution
+ *******************************************************************************/
+package org.eclipse.mylyn.github.ui.internal;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.mylyn.github.internal.GitHub;
+import org.eclipse.mylyn.tasks.ui.ITasksUiConstants;
+import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
+import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPageFactory;
+import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
+import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.forms.editor.IFormPage;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+/**
+ * Editor page factory for GitHub.
+ */
+public class GitHubTaskEditorPageFactory extends AbstractTaskEditorPageFactory {
+
+ private Image gitLogoImage = null;
+
+ @Override
+ public boolean canCreatePageFor(TaskEditorInput input) {
+ if (GitHub.CONNECTOR_KIND.equals(
+ input.getTask().getConnectorKind())) {
+ return true;
+ }
+ if (TasksUiUtil.isOutgoingNewTask(input.getTask(),
+ GitHub.CONNECTOR_KIND)) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public Image getPageImage() {
+ if (gitLogoImage != null)
+ return gitLogoImage;
+ ImageDescriptor imageDescriptor = AbstractUIPlugin
+ .imageDescriptorFromPlugin("org.eclipse.mylyn.github.ui",
+ "images/git-logo.png");
+ if (imageDescriptor == null) {
+ return null;
+ }
+
+ return gitLogoImage = new Image(Display.getCurrent(), imageDescriptor
+ .getImageData());
+ }
+
+ @Override
+ public String getPageText() {
+ return "GitHub";
+ }
+
+ @Override
+ public int getPriority() {
+ return PRIORITY_TASK;
+ }
+
+ @Override
+ public IFormPage createPage(TaskEditor parentEditor) {
+ return new GitHubTaskEditorPage(parentEditor);
+ }
+
+ @Override
+ public String[] getConflictingIds(TaskEditorInput input) {
+ return new String[] { ITasksUiConstants.ID_PAGE_PLANNING };
+ }
+
+}
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubUi.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubUi.java
new file mode 100644
index 00000000..6b2bdb60
--- /dev/null
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/github/ui/internal/GitHubUi.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat 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:
+ * David Green <david.green@tasktop.com> - initial contribution
+ * Christian Trutz <christian.trutz@gmail.com> - initial contribution
+ * Chris Aniszczyk <caniszczyk@gmail.com> - initial contribution
+ *******************************************************************************/
+package org.eclipse.mylyn.github.ui.internal;
+
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+
+class GitHubUi {
+ public static final String BUNDLE_ID = "org.eclipse.mylyn.github.ui";
+
+ public static IStatus createStatus(int severity,String message) {
+ return new Status(severity,BUNDLE_ID,message);
+ }
+
+ public static IStatus createStatus(int severity,String message,Throwable e) {
+ return new Status(severity,BUNDLE_ID,message,e);
+ }
+
+ public static IStatus createErrorStatus(String message) {
+ return createStatus(IStatus.ERROR, message);
+ }
+
+ public static IStatus createErrorStatus(String message,Throwable t) {
+ return createStatus(IStatus.ERROR, message,t);
+ }
+
+ public static IStatus createErrorStatus(Throwable e) {
+ return createStatus(IStatus.ERROR, "Unexpected error: "+e.getMessage(),e);
+ }
+
+ public static ILog getLog() {
+ return Platform.getLog(Platform.getBundle(BUNDLE_ID));
+ }
+
+ public static void logError(String message,Throwable t) {
+ getLog().log(createErrorStatus(message, t));
+ }
+
+ public static void logError(Throwable t) {
+ getLog().log(createErrorStatus(t.getMessage(), t));
+ }
+}

Back to the top