diff options
author | Kevin Sawicki | 2011-06-20 17:38:44 +0000 |
---|---|---|
committer | Kevin Sawicki | 2011-06-20 17:38:44 +0000 |
commit | 86088517ea1a2130f2f2ae5b1ee08b7141bfda01 (patch) | |
tree | 3ff5c4cb4083999cdeda64e58f015eddff82e476 /org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal | |
parent | 428921aac3dfaa973d07fe64d72857e4a898daa9 (diff) | |
download | egit-github-86088517ea1a2130f2f2ae5b1ee08b7141bfda01.tar.gz egit-github-86088517ea1a2130f2f2ae5b1ee08b7141bfda01.tar.xz egit-github-86088517ea1a2130f2f2ae5b1ee08b7141bfda01.zip |
Migrate repository and pull request services to v3.
Searching for repositories still uses the v2 API which is why
the two repository models are now required.
Change-Id: I18700446790337031be2faf9114ff2bb581fdeb3
Signed-off-by: Kevin Sawicki <kevin@github.com>
Diffstat (limited to 'org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal')
6 files changed, 161 insertions, 34 deletions
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/GitHubImages.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/GitHubImages.java index ab5b68f6..1f67d483 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/GitHubImages.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/GitHubImages.java @@ -33,12 +33,14 @@ public class GitHubImages { public static final String GITHUB_ADD_OBJ = NAME_PREFIX + "GITHUB_ADD_OBJ"; //$NON-NLS-1$ public static final String GITHUB_CHECKALL_OBJ = NAME_PREFIX + "GITHUB_CHECKALL_OBJ"; //$NON-NLS-1$ public static final String GITHUB_UNCHECKALL_OBJ = NAME_PREFIX + "GITHUB_UNCHECKALL_OBJ"; //$NON-NLS-1$ + public static final String GITHUB_ORG = NAME_PREFIX + "GITHUB_ORG"; //$NON-NLS-1$ public static final ImageDescriptor DESC_GITHUB_LOGO = create(PATH_OBJ, "github.png"); //$NON-NLS-1$ public static final ImageDescriptor DESC_GITHUB_ISSUE_LABEL = create(PATH_OBJ, "issue_label.png"); //$NON-NLS-1$ public static final ImageDescriptor DESC_GITHUB_ADD = create(PATH_OBJ, "add.png"); //$NON-NLS-1$ public static final ImageDescriptor DESC_GITHUB_CHECKALL = create(PATH_OBJ, "checkall.gif"); //$NON-NLS-1$ public static final ImageDescriptor DESC_GITHUB_UNCHECKALL = create(PATH_OBJ, "uncheckall.gif"); //$NON-NLS-1$ + public static final ImageDescriptor DESC_GITHUB_ORG = create(PATH_OBJ, "org.png"); //$NON-NLS-1$ private static ImageDescriptor create(String prefix, String name) { return ImageDescriptor.createFromURL(makeImageURL(prefix, name)); @@ -57,6 +59,7 @@ public class GitHubImages { manage(GITHUB_ADD_OBJ, DESC_GITHUB_ADD); manage(GITHUB_CHECKALL_OBJ, DESC_GITHUB_CHECKALL); manage(GITHUB_UNCHECKALL_OBJ, DESC_GITHUB_UNCHECKALL); + manage(GITHUB_ORG, DESC_GITHUB_ORG); } private static URL makeImageURL(String prefix, String name) { diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/ImportRepositoriesWizard.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/ImportRepositoriesWizard.java index 5856d2d1..03a2c241 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/ImportRepositoriesWizard.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/ImportRepositoriesWizard.java @@ -84,15 +84,14 @@ public class ImportRepositoriesWizard extends Wizard implements IImportWizard { public boolean performFinish() { String user = credentialsPage.getUserName(); String password = credentialsPage.getPassword(); - for (Object selected : reposPage.getRepositories()) { - Repository repo = (Repository) selected; + for (Repository repo : reposPage.getRepositories()) { AuthenticationCredentials credentials = new AuthenticationCredentials( user, password); TaskRepository repository = new TaskRepository( - GitHub.CONNECTOR_KIND, GitHub.createGitHubUrl( - repo.getOwner(), repo.getName())); + GitHub.CONNECTOR_KIND, GitHub.createGitHubUrl(repo + .getOwner().getLogin(), repo.getName())); repository.setProperty(IRepositoryConstants.PROPERTY_LABEL, - repo.getId()); + repo.generateId()); repository.setCredentials(AuthenticationType.REPOSITORY, credentials, true); repository.setProperty(IRepositoryConstants.PROPERTY_CATEGORY, diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySearchWizardPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySearchWizardPage.java index 6d6e8f12..c20191d7 100755 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySearchWizardPage.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySearchWizardPage.java @@ -12,7 +12,7 @@ package org.eclipse.mylyn.internal.github.ui; import java.io.IOException; -import org.eclipse.egit.github.core.Repository; +import org.eclipse.egit.github.core.SearchRepository; import org.eclipse.egit.github.core.client.GitHubClient; import org.eclipse.egit.github.core.client.IGitHubConstants; import org.eclipse.egit.github.core.service.RepositoryService; @@ -88,7 +88,7 @@ public class RepositorySearchWizardPage extends WizardPage { IGitHubConstants.PROTOCOL_HTTPS); RepositoryService repositoryService = new RepositoryService( client); - java.util.List<Repository> repositories = repositoryService + java.util.List<SearchRepository> repositories = repositoryService .searchRepositories(searchForText.getText()); repoListViewer.setInput(repositories.toArray()); } catch (IOException ioException) { diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySelectionWizardPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySelectionWizardPage.java index 63086552..eb64aa07 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySelectionWizardPage.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySelectionWizardPage.java @@ -15,21 +15,27 @@ import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.egit.github.core.Repository; +import org.eclipse.egit.github.core.User; import org.eclipse.egit.github.core.client.GitHubClient; -import org.eclipse.egit.github.core.client.IGitHubConstants; +import org.eclipse.egit.github.core.service.OrganizationService; import org.eclipse.egit.github.core.service.RepositoryService; import org.eclipse.egit.ui.internal.FilteredCheckboxTree; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTreeViewer; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.mylyn.internal.github.core.GitHub; @@ -37,6 +43,7 @@ import org.eclipse.mylyn.internal.github.core.GitHubException; import org.eclipse.mylyn.internal.github.core.gist.GistConnector; import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.mylyn.tasks.ui.TasksUi; +import org.eclipse.mylyn.tasks.ui.TasksUiImages; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -49,12 +56,82 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.dialogs.PatternFilter; import org.eclipse.ui.model.WorkbenchAdapter; import org.eclipse.ui.model.WorkbenchContentProvider; +import org.eclipse.ui.model.WorkbenchLabelProvider; /** * Repository selection wizard page. */ public class RepositorySelectionWizardPage extends WizardPage { + public static class RepositoryLabelProvider extends + DelegatingStyledCellLabelProvider implements ILabelProvider { + + private final WorkbenchLabelProvider wrapped; + + public RepositoryLabelProvider() { + super(new WorkbenchLabelProvider()); + wrapped = (WorkbenchLabelProvider) getStyledStringProvider(); + } + + public String getText(Object element) { + return wrapped.getText(element); + } + } + + private static class RepositoryAdapter extends WorkbenchAdapter { + + private final Repository repo; + + RepositoryAdapter(Repository repo) { + this.repo = repo; + } + + public String getLabel(Object object) { + String label = this.repo.generateId(); + return label != null ? label : ""; + } + + public ImageDescriptor getImageDescriptor(Object object) { + return TasksUiImages.REPOSITORY; + } + + } + + private static class OrganizationAdapter extends WorkbenchAdapter { + + private final User org; + + private final RepositoryAdapter[] repos; + + OrganizationAdapter(User org, List<Repository> repos) { + this.org = org; + this.repos = new RepositoryAdapter[repos.size()]; + final int length = this.repos.length; + for (int i = 0; i < length; i++) + this.repos[i] = new RepositoryAdapter(repos.get(i)); + } + + public ImageDescriptor getImageDescriptor(Object object) { + return GitHubImages.DESC_GITHUB_ORG; + } + + public Object[] getChildren(Object object) { + return repos; + } + + public StyledString getStyledText(Object object) { + StyledString styled = new StyledString(getLabel(object)); + styled.append(MessageFormat.format(" ({0})", repos.length), + StyledString.COUNTER_STYLER); + return styled; + } + + public String getLabel(Object object) { + return org.getLogin(); + } + + } + private Button addGistRepoButton; private Label selectedLabel; private FilteredCheckboxTree tree; @@ -88,8 +165,13 @@ public class RepositorySelectionWizardPage extends WizardPage { } /** @return array of selected repositories */ - public Object[] getRepositories() { - return this.tree.getCheckboxTreeViewer().getCheckedLeafElements(); + public Repository[] getRepositories() { + Object[] checked = tree.getCheckboxTreeViewer() + .getCheckedLeafElements(); + Repository[] repos = new Repository[checked.length]; + for (int i = 0; i < repos.length; i++) + repos[i] = ((RepositoryAdapter) checked[i]).repo; + return repos; } /** @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) */ @@ -106,8 +188,29 @@ public class RepositorySelectionWizardPage extends WizardPage { | SWT.H_SCROLL | SWT.BORDER, new PatternFilter()); CheckboxTreeViewer viewer = tree.getCheckboxTreeViewer(); viewer.setContentProvider(new WorkbenchContentProvider()); - viewer.setLabelProvider(new LabelProvider()); - viewer.setSorter(new ViewerSorter()); + viewer.setLabelProvider(new RepositoryLabelProvider()); + viewer.setSorter(new ViewerSorter() { + + public int compare(Viewer viewer, Object e1, Object e2) { + if (e1 instanceof OrganizationAdapter) + if (e2 instanceof OrganizationAdapter) + return ((OrganizationAdapter) e1) + .getLabel(e1) + .compareToIgnoreCase( + ((OrganizationAdapter) e2).getLabel(e2)); + else if (e2 instanceof RepositoryAdapter) + return 1; + if (e1 instanceof RepositoryAdapter) + if (e2 instanceof RepositoryAdapter) + return ((RepositoryAdapter) e1).getLabel(e1) + .compareToIgnoreCase( + ((RepositoryAdapter) e2).getLabel(e2)); + else if (e2 instanceof OrganizationAdapter) + return -1; + return super.compare(viewer, e1, e2); + } + + }); viewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { @@ -126,6 +229,9 @@ public class RepositorySelectionWizardPage extends WizardPage { public void widgetSelected(SelectionEvent e) { tree.getCheckboxTreeViewer().setAllChecked(true); + for (Object leaf : tree.getCheckboxTreeViewer() + .getCheckedLeafElements()) + tree.getCheckboxTreeViewer().setChecked(leaf, true); updateSelectionLabel(); } }); @@ -137,7 +243,7 @@ public class RepositorySelectionWizardPage extends WizardPage { uncheckItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - tree.getCheckboxTreeViewer().setAllChecked(false); + tree.getCheckboxTreeViewer().setCheckedElements(new Object[0]); updateSelectionLabel(); } }); @@ -177,7 +283,7 @@ public class RepositorySelectionWizardPage extends WizardPage { setErrorMessage(null); } - private void updateInput(final List<Repository> repos) { + private void updateInput(final List<Object> repos) { PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { @@ -196,6 +302,15 @@ public class RepositorySelectionWizardPage extends WizardPage { }); } + private void removeExisting(List<Repository> repos, List<String> existing) { + Iterator<Repository> iter = repos.iterator(); + while (iter.hasNext()) { + String id = iter.next().generateId(); + if (id == null || existing.contains(id)) + iter.remove(); + } + } + /** @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean) */ public void setVisible(boolean visible) { super.setVisible(visible); @@ -208,28 +323,38 @@ public class RepositorySelectionWizardPage extends WizardPage { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - GitHubClient client = new GitHubClient( - IGitHubConstants.HOST_API_V2, -1, - IGitHubConstants.PROTOCOL_HTTPS); + GitHubClient client = new GitHubClient(); client.setCredentials(user, password); RepositoryService service = new RepositoryService(client); + OrganizationService orgs = new OrganizationService(client); repoCount = 0; - List<Repository> repos = new ArrayList<Repository>(); + List<Object> repos = new ArrayList<Object>(); + List<String> existing = new ArrayList<String>(); + for (TaskRepository repo : TasksUi.getRepositoryManager() + .getRepositories(GitHub.CONNECTOR_KIND)) { + String id = GitHub.getRepository( + repo.getRepositoryUrl()).generateId(); + if (id != null) + existing.add(id); + } try { monitor.beginTask("", 2); //$NON-NLS-1$ monitor.setTaskName(Messages.RepositorySelectionWizardPage_TaskFetchingRepositories); - repos.addAll(service.getRepositories(user)); + List<Repository> userRepos = service + .getRepositories(user); + removeExisting(userRepos, existing); + repoCount += userRepos.size(); + for (Repository repo : service.getRepositories(user)) + repos.add(new RepositoryAdapter(repo)); monitor.worked(1); monitor.setTaskName(Messages.RepositorySelectionWizardPage_TaskFetchingOrganizationRepositories); - repos.addAll(service.getOrganizationRepositories()); - monitor.worked(1); - for (TaskRepository repo : TasksUi - .getRepositoryManager().getRepositories( - GitHub.CONNECTOR_KIND)) { - repos.remove(GitHub.getRepository(repo - .getRepositoryUrl())); + for (User org : orgs.getOrganizations()) { + List<Repository> orgRepos = service + .getOrgRepositories(org.getLogin()); + removeExisting(orgRepos, existing); + repoCount += orgRepos.size(); + repos.add(new OrganizationAdapter(org, orgRepos)); } - repoCount = repos.size(); updateInput(repos); } catch (IOException e) { throw new InvocationTargetException(GitHubException @@ -239,7 +364,7 @@ public class RepositorySelectionWizardPage extends WizardPage { }); setErrorMessage(null); } catch (InvocationTargetException e) { - updateInput(Collections.<Repository> emptyList()); + updateInput(Collections.emptyList()); Throwable cause = e.getCause(); if (cause == null) cause = e; diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueConnectorUi.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueConnectorUi.java index 95abf577..8a346fed 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueConnectorUi.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueConnectorUi.java @@ -17,7 +17,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.eclipse.egit.github.core.Repository; +import org.eclipse.egit.github.core.RepositoryId; import org.eclipse.jface.text.Region; import org.eclipse.jface.text.hyperlink.IHyperlink; import org.eclipse.jface.text.hyperlink.URLHyperlink; @@ -129,7 +129,7 @@ public class IssueConnectorUi extends AbstractRepositoryConnectorUi { if (project == null && user != null) { // same project name, different user String url = repository.getUrl(); - Repository repo = GitHub.getRepository(url); + RepositoryId repo = GitHub.getRepository(url); if (repo != null) project = repo.getName(); } diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueRepositorySettingsPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueRepositorySettingsPage.java index 232ea03b..efc61eab 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueRepositorySettingsPage.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueRepositorySettingsPage.java @@ -20,7 +20,7 @@ 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.egit.github.core.Repository; +import org.eclipse.egit.github.core.RepositoryId; import org.eclipse.egit.github.core.client.GitHubClient; import org.eclipse.egit.github.core.service.IssueService; import org.eclipse.jface.dialogs.IMessageProvider; @@ -84,7 +84,7 @@ public class IssueRepositorySettingsPage extends AbstractRepositorySettingsPage protected void syncRepositoryLabel() { if (syncLabel) { String url = serverUrlCombo.getText(); - Repository repo = GitHub.getRepository(url); + RepositoryId repo = GitHub.getRepository(url); if (repo != null) repositoryLabelEditor.setStringValue(repo.getOwner() + '/' + repo.getName()); @@ -149,7 +149,7 @@ public class IssueRepositorySettingsPage extends AbstractRepositorySettingsPage client.setCredentials(auth.getUserName(), auth.getPassword()); IssueService service = new IssueService(client); - Repository repo = GitHub.getRepository(repository + RepositoryId repo = GitHub.getRepository(repository .getRepositoryUrl()); monitor.worked(50); service.getIssues(repo.getOwner(), repo.getName(), null); |