use of org.eclipse.che.plugin.github.ide.load.ProjectData in project che by eclipse.
the class GithubImporterPageViewImpl method createRepositoriesTable.
/**
* Creates table what contains list of available repositories.
*
* @param resources
*/
private void createRepositoriesTable(final Resources resources, GitHubLocalizationConstant locale) {
repositories = new CellTable<>(15, resources);
Column<ProjectData, ImageResource> iconColumn = new Column<ProjectData, ImageResource>(new ImageResourceCell()) {
@Override
public ImageResource getValue(ProjectData item) {
return null;
}
};
Column<ProjectData, SafeHtml> repositoryColumn = new Column<ProjectData, SafeHtml>(new SafeHtmlCell()) {
@Override
public SafeHtml getValue(final ProjectData item) {
return SafeHtmlUtils.fromString(item.getName());
}
};
Column<ProjectData, SafeHtml> descriptionColumn = new Column<ProjectData, SafeHtml>(new SafeHtmlCell()) {
@Override
public SafeHtml getValue(final ProjectData item) {
return new SafeHtmlBuilder().appendHtmlConstant("<span>").appendEscaped(item.getDescription() == null ? "" : item.getDescription()).appendHtmlConstant("</span>").toSafeHtml();
}
};
repositories.addColumn(iconColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
repositories.setColumnWidth(iconColumn, 28, Style.Unit.PX);
repositories.addColumn(repositoryColumn, locale.samplesListRepositoryColumn());
repositories.addColumn(descriptionColumn, locale.samplesListDescriptionColumn());
// don't show loading indicator
repositories.setLoadingIndicator(null);
final SingleSelectionModel<ProjectData> selectionModel = new SingleSelectionModel<>();
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
@Override
public void onSelectionChange(SelectionChangeEvent event) {
ProjectData selectedObject = selectionModel.getSelectedObject();
delegate.onRepositorySelected(selectedObject);
}
});
repositories.setSelectionModel(selectionModel);
}
use of org.eclipse.che.plugin.github.ide.load.ProjectData in project che by eclipse.
the class GithubImporterPagePresenterTest method onLoadRepoClickedWhenGetUserReposIsSuccessful.
@Test
public void onLoadRepoClickedWhenGetUserReposIsSuccessful() throws Exception {
doAnswer(new Answer() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
presenter.onSuccessRequest(jsArrayMixed);
return null;
}
}).when(presenter).doRequest(any(Promise.class), any(Promise.class), any(Promise.class));
when(view.getAccountName()).thenReturn("AccountName");
presenter.onLoadRepoClicked();
verify(gitHubClientService).getRepositoriesList();
verify(gitHubClientService).getUserInfo();
verify(gitHubClientService).getOrganizations();
verify(view).setLoaderVisibility(eq(true));
verify(view).setInputsEnableState(eq(false));
verify(view).setLoaderVisibility(eq(false));
verify(view).setInputsEnableState(eq(true));
verify(view).setAccountNames(Matchers.<Set>anyObject());
verify(view, times(2)).showGithubPanel();
verify(view).setRepositories(Matchers.<List<ProjectData>>anyObject());
verify(view).reset();
}
use of org.eclipse.che.plugin.github.ide.load.ProjectData in project che by eclipse.
the class GithubImporterPagePresenterTest method onLoadRepoClickedWhenGetUserReposIsFailed.
@Test
public void onLoadRepoClickedWhenGetUserReposIsFailed() throws Exception {
doAnswer(new Answer() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
presenter.onFailRequest(promiseError);
return null;
}
}).when(presenter).doRequest(any(Promise.class), any(Promise.class), any(Promise.class));
presenter.onLoadRepoClicked();
verify(gitHubClientService).getRepositoriesList();
verify(gitHubClientService).getUserInfo();
verify(gitHubClientService).getOrganizations();
verify(view).setLoaderVisibility(eq(true));
verify(view).setInputsEnableState(eq(false));
verify(view).setLoaderVisibility(eq(false));
verify(view).setInputsEnableState(eq(true));
verify(view, never()).setAccountNames((Set<String>) anyObject());
verify(view, never()).showGithubPanel();
verify(view, never()).setRepositories(Matchers.<List<ProjectData>>anyObject());
}
use of org.eclipse.che.plugin.github.ide.load.ProjectData in project che by eclipse.
the class GithubImporterPagePresenterTest method onLoadRepoClickedWhenAuthorizeIsFailed.
@Test
public void onLoadRepoClickedWhenAuthorizeIsFailed() throws Exception {
String userId = "userId";
CurrentUser user = mock(CurrentUser.class);
ProfileDto profile = mock(ProfileDto.class);
when(appContext.getCurrentUser()).thenReturn(user);
when(user.getProfile()).thenReturn(profile);
when(profile.getUserId()).thenReturn(userId);
final Throwable exception = mock(UnauthorizedException.class);
doAnswer(new Answer() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
presenter.onFailRequest(promiseError);
return null;
}
}).when(presenter).doRequest(any(Promise.class), any(Promise.class), any(Promise.class));
doReturn(exception).when(promiseError).getCause();
presenter.onLoadRepoClicked();
verify(gitHubClientService).getRepositoriesList();
verify(gitHubClientService).getUserInfo();
verify(gitHubClientService).getOrganizations();
verify(gitHubAuthenticator).authenticate(anyString(), asyncCallbackCaptor.capture());
AsyncCallback<OAuthStatus> asyncCallback = asyncCallbackCaptor.getValue();
asyncCallback.onFailure(exception);
verify(view, times(2)).setLoaderVisibility(eq(true));
verify(view, times(2)).setInputsEnableState(eq(false));
verify(view, times(2)).setInputsEnableState(eq(true));
verify(view, never()).setAccountNames((Set<String>) anyObject());
verify(view, never()).showGithubPanel();
verify(view, never()).setRepositories(Matchers.<List<ProjectData>>anyObject());
}
use of org.eclipse.che.plugin.github.ide.load.ProjectData in project che by eclipse.
the class GithubImporterPagePresenter method refreshProjectList.
/**
* Refresh project list on view.
*/
private void refreshProjectList() {
List<ProjectData> projectsData = new ArrayList<>();
String accountName = view.getAccountName();
if (repositories.containsKey(accountName)) {
List<GitHubRepository> repo = repositories.get(accountName);
for (GitHubRepository repository : repo) {
ProjectData projectData = new ProjectData(repository.getName(), repository.getDescription(), null, null, repository.getSshUrl(), repository.getGitUrl());
projectsData.add(projectData);
}
Collections.sort(projectsData, new Comparator<ProjectData>() {
@Override
public int compare(ProjectData o1, ProjectData o2) {
return o1.getName().compareTo(o2.getName());
}
});
view.setRepositories(projectsData);
view.reset();
view.showGithubPanel();
}
}
Aggregations