use of org.eclipse.linuxtools.docker.core.IRepositoryTag in project linuxtools by eclipse.
the class ImageTagSelectionPage method searchTags.
private void searchTags() {
try {
final BlockingQueue<List<DockerImageTagSearchResult>> searchResultQueue = new ArrayBlockingQueue<>(1);
ImageTagSelectionPage.this.getContainer().run(true, true, monitor -> {
monitor.beginTask(WizardMessages.getString(// $NON-NLS-1$
"ImageTagSelectionPage.searchTask"), 2);
final String selectedImageName = ImageTagSelectionPage.this.model.getSelectedImage().getName();
try {
final List<IRepositoryTag> repositoryTags = registry.getTags(selectedImageName);
// we have to convert to list of RepositoryTag which
// can be sorted
final List<RepositoryTag> tags = repositoryTags.stream().map(c -> (RepositoryTag) c).collect(Collectors.toList());
Collections.sort(tags);
monitor.worked(1);
final IDockerConnection connection = model.getSelectedConnection();
final List<DockerImageTagSearchResult> searchResults = repositoryTags.stream().map(t -> new DockerImageTagSearchResult(selectedImageName, t, connection.hasImage(selectedImageName, t.getName()))).collect(Collectors.toList());
monitor.worked(1);
searchResultQueue.offer(searchResults);
} catch (DockerException e) {
} finally {
monitor.done();
}
});
List<DockerImageTagSearchResult> res = searchResultQueue.poll(10, TimeUnit.SECONDS);
final List<DockerImageTagSearchResult> searchResult = (res == null) ? new ArrayList<>() : res;
Display.getCurrent().asyncExec(() -> {
ImageTagSelectionPage.this.model.setImageTagSearchResult(searchResult);
// refresh the wizard buttons
getWizard().getContainer().updateButtons();
});
// display a warning in the title area if the search result is empty
if (searchResult.isEmpty()) {
this.setMessage(WizardMessages.getString(// $NON-NLS-1$
"ImageTagSelectionPage.noTagWarning"), WARNING);
} else if (searchResult.size() == 1) {
this.setMessage(WizardMessages.getString(// $NON-NLS-1$
"ImageTagSelectionPage.oneTagMatched"), INFORMATION);
} else {
this.setMessage(WizardMessages.getFormattedString(// $NON-NLS-1$
"ImageTagSelectionPage.tagsMatched", Integer.toString(searchResult.size())), INFORMATION);
}
} catch (InvocationTargetException | InterruptedException e) {
Activator.log(e);
}
}
Aggregations