Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2015-05-29 12:48:55 -0400
committerJeff Johnston2015-05-29 19:26:29 -0400
commit23d12633327bc46cfbd9f3a97e3c8db50b93e451 (patch)
tree93857745d49b7d23c76a1e80586205695f8148fc
parent4b84372141009311ad4f6acf85634a1cb91640be (diff)
downloadorg.eclipse.linuxtools-23d12633327bc46cfbd9f3a97e3c8db50b93e451.tar.gz
org.eclipse.linuxtools-23d12633327bc46cfbd9f3a97e3c8db50b93e451.tar.xz
org.eclipse.linuxtools-23d12633327bc46cfbd9f3a97e3c8db50b93e451.zip
Bug 468754 - Images view shows all elements at startup even if the "Show all Images" filter is unselected
Problem appeared on both Containers and Images view - enforced the filters at the end of part creation - changed to form title to include the number of items displayed (and the total number of items when filters are enabled) - changed a method signature to simplify the refresh in CommandUtils - Used constants to refer to the DockerExplorerView ID - reset the toggle commands and apply the filters when the view is created Change-Id: I3bdc99e15b80e0e2cea5f9492a61b800c9eb712e Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/48985 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> Tested-by: Jeff Johnston <jjohnstn@redhat.com> Reviewed-on: https://git.eclipse.org/r/49010
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtils.java19
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties5
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersView.java76
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImagesView.java76
4 files changed, 145 insertions, 31 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtils.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtils.java
index 2353baa842..2af584e4d2 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtils.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtils.java
@@ -20,8 +20,8 @@ import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
@@ -44,20 +44,17 @@ import org.eclipse.ui.IWorkbenchPart;
public class CommandUtils {
/**
- * Refreshes (async) the {@link TableViewer} or {@link TreeViewer} in the
- * given {@link IWorkbenchPart}.
+ * Refreshes (async) the {@link Viewer}.
*
- * @param activePart
- * - active Workbench part
+ * @param viewer
+ * - the {@link Viewer} to refresh
*/
- public static void refresh(final IWorkbenchPart activePart) {
+ public static void refresh(final Viewer viewer) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- if (activePart instanceof DockerContainersView) {
- ((DockerContainersView) activePart).getViewer().refresh();
- } else if (activePart instanceof DockerImagesView) {
- ((DockerImagesView) activePart).getViewer().refresh();
+ if (viewer != null && !viewer.getControl().isDisposed()) {
+ viewer.refresh();
}
}
});
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties
index 289075fac9..14f5fbd520 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DVMessages.properties
@@ -176,5 +176,8 @@ ImagePull.title=Pulling Image <{0}>
ImagePush.msg=Pushing Image
ImagePush.title=Pushing Image <{0}>
+ContainersViewTitle.all.msg={0} ({1} Containers)
+ContainersViewTitle.filtered.msg={0} ({1}/{2} Containers)
-
+ImagesViewTitle.all.msg={0} ({1} Images)
+ImagesViewTitle.filtered.msg={0} ({1}/{2} Images)
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersView.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersView.java
index 1d65fc8e71..8b6ba79db8 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersView.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerContainersView.java
@@ -11,6 +11,8 @@
package org.eclipse.linuxtools.internal.docker.ui.views;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
@@ -48,6 +50,7 @@ import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.part.ViewPart;
@@ -63,9 +66,15 @@ public class DockerContainersView extends ViewPart implements
IDockerContainerListener, ISelectionListener,
IDockerConnectionManagerListener, ITabbedPropertySheetPageContributor {
+ private static final String TOGGLE_STATE = "org.eclipse.ui.commands.toggleState"; //$NON-NLS-1$
+
+ private static final String SHOW_ALL_CONTAINERS_COMMAND_ID = "org.eclipse.linuxtools.docker.ui.commands.showAllContainers"; //$NON-NLS-1$
+
public static final String VIEW_ID = "org.eclipse.linuxtools.docker.ui.dockerContainersView";
private final static String DaemonMissing = "ViewerDaemonMissing.msg"; //$NON-NLS-1$
+ private final static String ViewAllTitle = "ContainersViewTitle.all.msg"; //$NON-NLS-1$
+ private final static String ViewFilteredTitle = "ContainersViewTitle.filtered.msg"; //$NON-NLS-1$
private Form form;
private Text search;
@@ -80,7 +89,8 @@ public class DockerContainersView extends ViewPart implements
@Override
public void dispose() {
// stop tracking selection changes in the Docker Explorer view (only)
- getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener("org.eclipse.linuxtools.docker.ui.dockerExplorerView", this);
+ getSite().getWorkbenchWindow().getSelectionService()
+ .removeSelectionListener(DockerExplorerView.VIEW_ID, this);
DockerConnectionManager.getInstance().removeConnectionManagerListener(
this);
super.dispose();
@@ -88,7 +98,7 @@ public class DockerContainersView extends ViewPart implements
@Override
public String getContributorId() {
- return "org.eclipse.linuxtools.docker.ui.dockerExplorerView"; //$NON-NLS-1$
+ return DockerExplorerView.VIEW_ID;
}
@Override
@@ -100,13 +110,8 @@ public class DockerContainersView extends ViewPart implements
}
private void hookContextMenu() {
- MenuManager menuMgr = new MenuManager("#PopupMenu");
+ MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
menuMgr.setRemoveAllWhenShown(true);
- // menuMgr.addMenuListener(new IMenuListener() {
- // public void menuAboutToShow(IMenuManager manager) {
- // DockerContainersView.this.fillContextMenu(manager);
- // }
- // });
Menu menu = menuMgr.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuMgr, viewer);
@@ -123,10 +128,18 @@ public class DockerContainersView extends ViewPart implements
createTableViewer(container);
getSite().registerContextMenu(new MenuManager(), null);
// track selection changes in the Docker Explorer view (only)
- getSite().getWorkbenchWindow().getSelectionService().addSelectionListener("org.eclipse.linuxtools.docker.ui.dockerExplorerView", this);
+ getSite().getWorkbenchWindow().getSelectionService()
+ .addSelectionListener(DockerExplorerView.VIEW_ID, this);
DockerConnectionManager.getInstance()
.addConnectionManagerListener(this);
hookContextMenu();
+ // by default, only show running containers
+ showAllContainers(false);
+ final ICommandService service = getViewSite().getWorkbenchWindow()
+ .getService(ICommandService.class);
+ service.getCommand(SHOW_ALL_CONTAINERS_COMMAND_ID)
+ .getState(TOGGLE_STATE).setValue(false);
+ service.refreshElements(SHOW_ALL_CONTAINERS_COMMAND_ID, null);
}
private void createTableViewer(final Composite container) {
@@ -330,9 +343,10 @@ public class DockerContainersView extends ViewPart implements
// remember the current selection before the viewer is
// refreshed
final ISelection currentSelection = DockerContainersView.this.viewer.getSelection();
- CommandUtils.refresh(DockerContainersView.this);
+ CommandUtils.refresh(DockerContainersView.this.getViewer());
// restore the selection
DockerContainersView.this.viewer.setSelection(currentSelection);
+ refreshViewTitle();
}
});
}
@@ -380,8 +394,48 @@ public class DockerContainersView extends ViewPart implements
public void showAllContainers(boolean enabled) {
if(!enabled) {
this.viewer.addFilter(hideStoppedContainersViewerFilter);
+
+ } else {
+ final List<ViewerFilter> filters = new ArrayList<>(
+ Arrays.asList(this.viewer.getFilters()));
+
+ // remove filters and make sure there is no duplicate in the list of
+ // filters
+ for (Iterator<ViewerFilter> iterator = filters.iterator(); iterator
+ .hasNext();) {
+ ViewerFilter viewerFilter = iterator.next();
+ if (viewerFilter.equals(hideStoppedContainersViewerFilter)) {
+ iterator.remove();
+ }
+ }
+ this.viewer.setFilters(filters.toArray(new ViewerFilter[0]));
+ }
+ refreshViewTitle();
+ }
+
+ private void refreshViewTitle() {
+ if (this.viewer == null || this.viewer.getControl().isDisposed()
+ || this.form == null
+ || this.connection == null) {
+ return;
+ } else if (!this.connection.isContainersLoaded()) {
+ form.setText(connection.getName());
} else {
- this.viewer.removeFilter(hideStoppedContainersViewerFilter);
+ final List<ViewerFilter> filters = Arrays
+ .asList(this.viewer.getFilters());
+ if (filters.contains(hideStoppedContainersViewerFilter)) {
+ this.form.setText(
+ DVMessages.getFormattedString(ViewFilteredTitle,
+ new String[] { connection.getName(),
+ Integer.toString(viewer.getTable()
+ .getItemCount()),
+ Integer.toString(
+ connection.getContainers().size()), }));
+ } else {
+ this.form.setText(DVMessages.getFormattedString(ViewAllTitle,
+ new String[] { connection.getName(), Integer.toString(
+ connection.getContainers().size()) }));
+ }
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImagesView.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImagesView.java
index 71161e3ad6..2db18d9055 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImagesView.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerImagesView.java
@@ -13,6 +13,7 @@ package org.eclipse.linuxtools.internal.docker.ui.views;
import java.text.DecimalFormat;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -50,6 +51,7 @@ import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.part.ViewPart;
@@ -67,7 +69,14 @@ public class DockerImagesView extends ViewPart implements IDockerImageListener,
public static final String VIEW_ID = "org.eclipse.linuxtools.docker.ui.dockerImagesView";
+ private static final String TOGGLE_STATE = "org.eclipse.ui.commands.toggleState"; //$NON-NLS-1$
+
+ private static final String SHOW_ALL_IMAGES_COMMAND_ID = "org.eclipse.linuxtools.docker.ui.commands.showAllImages"; //$NON-NLS-1$
+
private final static String DaemonMissing = "ViewerDaemonMissing.msg"; //$NON-NLS-1$
+ private final static String ViewAllTitle = "ImagesViewTitle.all.msg"; //$NON-NLS-1$
+ private final static String ViewFilteredTitle = "ImagesViewTitle.filtered.msg"; //$NON-NLS-1$
+
private Form form;
private Text search;
private TableViewer viewer;
@@ -82,7 +91,8 @@ public class DockerImagesView extends ViewPart implements IDockerImageListener,
@Override
public void dispose() {
// stop tracking selection changes in the Docker Explorer view (only)
- getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener("org.eclipse.linuxtools.docker.ui.dockerExplorerView", this);
+ getSite().getWorkbenchWindow().getSelectionService()
+ .removeSelectionListener(DockerExplorerView.VIEW_ID, this);
DockerConnectionManager.getInstance().removeConnectionManagerListener(
this);
super.dispose();
@@ -90,7 +100,7 @@ public class DockerImagesView extends ViewPart implements IDockerImageListener,
@Override
public String getContributorId() {
- return "org.eclipse.linuxtools.docker.ui.dockerExplorerView"; //$NON-NLS-1$
+ return DockerExplorerView.VIEW_ID;
}
@Override
@@ -102,7 +112,7 @@ public class DockerImagesView extends ViewPart implements IDockerImageListener,
}
private void hookContextMenu() {
- MenuManager menuMgr = new MenuManager("#PopupMenu");
+ MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
menuMgr.setRemoveAllWhenShown(true);
// menuMgr.addMenuListener(new IMenuListener() {
// public void menuAboutToShow(IMenuManager manager) {
@@ -124,10 +134,19 @@ public class DockerImagesView extends ViewPart implements IDockerImageListener,
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(container);
createTableViewer(container);
// track selection changes in the Docker Explorer view (only)
- getSite().getWorkbenchWindow().getSelectionService().addSelectionListener("org.eclipse.linuxtools.docker.ui.dockerExplorerView", this);
+ getSite().getWorkbenchWindow().getSelectionService()
+ .addSelectionListener(DockerExplorerView.VIEW_ID, this);
DockerConnectionManager.getInstance()
.addConnectionManagerListener(this);
hookContextMenu();
+ // by default, hide dangling and intermediate images
+ showAllImages(false);
+ final ICommandService service = getViewSite().getWorkbenchWindow()
+ .getService(ICommandService.class);
+ service.getCommand(SHOW_ALL_IMAGES_COMMAND_ID).getState(TOGGLE_STATE)
+ .setValue(false);
+ service.refreshElements(SHOW_ALL_IMAGES_COMMAND_ID, null);
+
}
private void createTableViewer(final Composite container) {
@@ -173,7 +192,7 @@ public class DockerImagesView extends ViewPart implements IDockerImageListener,
public String getText(final Object element) {
if (element instanceof IDockerImage) {
final StringBuilder tags = new StringBuilder();
- List<String> repoTags = new ArrayList<String>();
+ List<String> repoTags = new ArrayList<>();
repoTags.addAll(((IDockerImage) element).repoTags());
Collections.sort(repoTags);
for (Iterator<String> iterator = repoTags.iterator(); iterator
@@ -343,14 +362,43 @@ public class DockerImagesView extends ViewPart implements IDockerImageListener,
// remember the current selection before the viewer is
// refreshed
final ISelection currentSelection = DockerImagesView.this.viewer.getSelection();
- CommandUtils.refresh(DockerImagesView.this);
+ CommandUtils.refresh(DockerImagesView.this.getViewer());
// restore the selection
DockerImagesView.this.viewer.setSelection(currentSelection);
+ refreshViewTitle();
}
});
}
}
+ private void refreshViewTitle() {
+ if (this.viewer == null || this.viewer.getControl().isDisposed()
+ || this.form == null
+ || this.connection == null) {
+ return;
+ } else if (!this.connection.isImagesLoaded()) {
+ form.setText(connection.getName());
+ } else {
+ final List<ViewerFilter> filters = Arrays
+ .asList(this.viewer.getFilters());
+ if (filters.contains(hideDanglingImagesFilter)
+ || filters.contains(hideIntermediateImagesFilter)) {
+ this.form.setText(
+ DVMessages.getFormattedString(ViewFilteredTitle,
+ new String[] { connection.getName(),
+ Integer.toString(viewer.getTable()
+ .getItemCount()),
+ Integer.toString(
+ connection.getImages().size()), }));
+ } else {
+ this.form.setText(DVMessages.getFormattedString(ViewAllTitle,
+ new String[] { connection.getName(), Integer
+ .toString(connection.getImages().size()) }));
+
+ }
+ }
+ }
+
/**
* @return the {@link IDockerConnection} used to display the current {@link IDockerContainer}
*/
@@ -399,9 +447,21 @@ public class DockerImagesView extends ViewPart implements IDockerImageListener,
this.viewer.addFilter(hideDanglingImagesFilter);
this.viewer.addFilter(hideIntermediateImagesFilter);
} else {
- this.viewer.removeFilter(hideDanglingImagesFilter);
- this.viewer.removeFilter(hideIntermediateImagesFilter);
+ final List<ViewerFilter> filters = new ArrayList<>(
+ Arrays.asList(this.viewer.getFilters()));
+ // remove filters and make sure there is no duplicate in the list of
+ // filters
+ for (Iterator<ViewerFilter> iterator = filters.iterator(); iterator
+ .hasNext();) {
+ ViewerFilter viewerFilter = iterator.next();
+ if (viewerFilter.equals(hideDanglingImagesFilter)
+ || viewerFilter.equals(hideIntermediateImagesFilter)) {
+ iterator.remove();
+ }
+ }
+ this.viewer.setFilters(filters.toArray(new ViewerFilter[0]));
}
+ refreshViewTitle();
}
@Override

Back to the top