Search in sources :

Example 1 with IRepositoryTag

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);
    }
}
Also used : IRepositoryTag(org.eclipse.linuxtools.docker.core.IRepositoryTag) TableViewer(org.eclipse.jface.viewers.TableViewer) Activator(org.eclipse.linuxtools.docker.ui.Activator) TableColumn(org.eclipse.swt.widgets.TableColumn) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Table(org.eclipse.swt.widgets.Table) ArrayList(java.util.ArrayList) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) RepositoryTag(org.eclipse.linuxtools.internal.docker.core.RepositoryTag) Composite(org.eclipse.swt.widgets.Composite) DockerException(org.eclipse.linuxtools.docker.core.DockerException) IconColumnLabelProvider(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageSearchPage.IconColumnLabelProvider) WizardPage(org.eclipse.jface.wizard.WizardPage) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) ViewerProperties(org.eclipse.jface.databinding.viewers.ViewerProperties) BlockingQueue(java.util.concurrent.BlockingQueue) IRegistry(org.eclipse.linuxtools.docker.core.IRegistry) Display(org.eclipse.swt.widgets.Display) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Collectors(java.util.stream.Collectors) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) TimeUnit(java.util.concurrent.TimeUnit) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) List(java.util.List) SWTImagesFactory(org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory) BeanProperties(org.eclipse.core.databinding.beans.BeanProperties) SWT(org.eclipse.swt.SWT) RepositoryTagV2(org.eclipse.linuxtools.internal.docker.core.RepositoryTagV2) Collections(java.util.Collections) IRepositoryTag(org.eclipse.linuxtools.docker.core.IRepositoryTag) DockerException(org.eclipse.linuxtools.docker.core.DockerException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) RepositoryTag(org.eclipse.linuxtools.internal.docker.core.RepositoryTag) IRepositoryTag(org.eclipse.linuxtools.docker.core.IRepositoryTag) ArrayList(java.util.ArrayList) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) List(java.util.List)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)1 BeanProperties (org.eclipse.core.databinding.beans.BeanProperties)1 IObservableList (org.eclipse.core.databinding.observable.list.IObservableList)1 ObservableListContentProvider (org.eclipse.jface.databinding.viewers.ObservableListContentProvider)1 ViewerProperties (org.eclipse.jface.databinding.viewers.ViewerProperties)1 GridDataFactory (org.eclipse.jface.layout.GridDataFactory)1 GridLayoutFactory (org.eclipse.jface.layout.GridLayoutFactory)1 CellLabelProvider (org.eclipse.jface.viewers.CellLabelProvider)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)1 WizardPage (org.eclipse.jface.wizard.WizardPage)1