summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorDaniel Rolka2013-08-27 05:24:52 (EDT)
committer Gerrit Code Review @ Eclipse.org2013-09-13 06:04:22 (EDT)
commit5cae0230eaf8ba81f941d08ca5c725728396b95b (patch)
treeee754096deaeda0cb7156991e2648c24bda5b2ea
parent0af425db7160e96d988b054781258c2fb0d76e10 (diff)
downloadeclipse.platform.ui-5cae0230eaf8ba81f941d08ca5c725728396b95b.zip
eclipse.platform.ui-5cae0230eaf8ba81f941d08ca5c725728396b95b.tar.gz
eclipse.platform.ui-5cae0230eaf8ba81f941d08ca5c725728396b95b.tar.bz2
Bug 408763 - The ImportExportPage filters allows an empty category torefs/changes/54/14554/8
appear Change-Id: Ic5f23653eb0f14c5a176d418aa4706b7c7f72fb6 Signed-off-by: Daniel Rolka <daniel.rolka@pl.ibm.com>
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardActivityFilter.java32
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardCollectionElement.java62
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardPatternFilter.java22
3 files changed, 100 insertions, 16 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardActivityFilter.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardActivityFilter.java
index 74f21b6..c32ce3d 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardActivityFilter.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardActivityFilter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 IBM Corporation and others.
+ * Copyright (c) 2004, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,8 +10,7 @@
*******************************************************************************/
package org.eclipse.ui.internal.dialogs;
-import org.eclipse.jface.viewers.AbstractTreeViewer;
-import org.eclipse.jface.viewers.ITreeContentProvider;
+import java.util.ArrayList;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.ui.activities.WorkbenchActivityHelper;
@@ -24,17 +23,10 @@ import org.eclipse.ui.model.AdaptableList;
* @since 3.0
*/
public class WizardActivityFilter extends ViewerFilter {
-
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
public boolean select(Viewer viewer, Object parentElement, Object element) {
- Object[] children = ((ITreeContentProvider) ((AbstractTreeViewer) viewer)
- .getContentProvider()).getChildren(element);
- if (children.length > 0) {
- return filter(viewer, element, children).length > 0;
- }
-
if (parentElement.getClass().equals(AdaptableList.class)) {
return true; //top-level ("primary") wizards should always be returned
}
@@ -45,4 +37,24 @@ public class WizardActivityFilter extends ViewerFilter {
return true;
}
+
+ @Override
+ public Object[] filter(Viewer viewer, Object parent, Object[] elements) {
+ int size = elements.length;
+ ArrayList<Object> out = new ArrayList<Object>(size);
+
+ for (int i = 0; i < size; ++i) {
+ Object element = elements[i];
+ if (element instanceof WizardCollectionElement) {
+ Object wizardCollection = WizardCollectionElement.filter(viewer, this,
+ (WizardCollectionElement) element);
+ if (wizardCollection != null) {
+ out.add(wizardCollection);
+ }
+ } else if (select(viewer, parent, element)) {
+ out.add(element);
+ }
+ }
+ return out.toArray();
+ }
}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardCollectionElement.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardCollectionElement.java
index deff78c..74fb3af 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardCollectionElement.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardCollectionElement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,13 +14,14 @@ package org.eclipse.ui.internal.dialogs;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.ui.IPluginContribution;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.activities.WorkbenchActivityHelper;
@@ -36,8 +37,8 @@ import org.eclipse.ui.wizards.IWizardDescriptor;
* thereby facilitating the definition of tree structures composed of these
* elements. Instances also store a list of wizards.
*/
-public class WizardCollectionElement extends AdaptableList implements
- IPluginContribution, IWizardCategory {
+public class WizardCollectionElement extends AdaptableList implements IPluginContribution,
+ IWizardCategory {
private String id;
private String pluginId;
@@ -80,6 +81,17 @@ public class WizardCollectionElement extends AdaptableList implements
this.parent = parent;
}
+ @SuppressWarnings("unchecked")
+ private WizardCollectionElement(WizardCollectionElement input, AdaptableList wizards) {
+ this(input.id, input.pluginId, input.name, input.parent);
+ this.configElement = input.configElement;
+ this.wizards = wizards;
+
+ for (Object child : input.children) {
+ children.add(child);
+ }
+ }
+
/**
* Adds a wizard collection to this collection.
*/
@@ -413,4 +425,46 @@ public class WizardCollectionElement extends AdaptableList implements
public IWizardCategory findCategory(IPath path) {
return findChildCollection(path);
}
+
+ /**
+ * The helper method used to filter <code>WizardCollectionElement</code>
+ * using <code>ViewerFilter</code>.<br>
+ * It returns the result in the following way:<br>
+ * - if some of the wizards from the input collection is skipped by the
+ * viewerFilter then the modified copy of the collection (without skipped
+ * wizards) is returned<br>
+ * - when all wizards are skipped then null will be returned<br>
+ * - if none of the wizards is skipped during filtering then the original
+ * input collection is returned
+ *
+ * @param viewer
+ * the Viewer used by <code>ViewerFilter.select</code> method
+ * @param viewerFilter
+ * the ViewerFilter
+ * @param inputCollection
+ * collection to filter
+ * @return inputCollection, modified copy of inputCollection or null
+ *
+ */
+ public static WizardCollectionElement filter(Viewer viewer, ViewerFilter viewerFilter,
+ WizardCollectionElement inputCollection) {
+ AdaptableList wizards = null;
+
+ for (Object child : inputCollection.getWizardAdaptableList().getChildren()) {
+ if (viewerFilter.select(viewer, inputCollection, child)) {
+ if (wizards == null) {
+ wizards = new AdaptableList();
+ }
+ wizards.add((IAdaptable) child);
+ }
+ }
+
+ if (wizards == null) {
+ return null;
+ }
+ if (inputCollection.getWizardAdaptableList().size() == wizards.size()) {
+ return inputCollection;
+ }
+ return new WizardCollectionElement(inputCollection, wizards);
+ }
}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardPatternFilter.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardPatternFilter.java
index ba94c9d..7f9b33e 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardPatternFilter.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardPatternFilter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2009 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.ui.internal.dialogs;
+import java.util.ArrayList;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.dialogs.PatternFilter;
@@ -21,7 +22,6 @@ import org.eclipse.ui.dialogs.PatternFilter;
*
*/
public class WizardPatternFilter extends PatternFilter {
-
/**
* Create a new instance of a WizardPatternFilter
* @param isMatchItem
@@ -63,4 +63,22 @@ public class WizardPatternFilter extends PatternFilter {
return false;
}
+ @Override
+ public Object[] filter(Viewer viewer, Object parent, Object[] elements) {
+ ArrayList<Object> result = new ArrayList<Object>();
+
+ for (Object elem : super.filter(viewer, parent, elements)) {
+ if (elem instanceof WizardCollectionElement) {
+ Object wizardCollection = WizardCollectionElement.filter(viewer, this,
+ (WizardCollectionElement) elem);
+ if (wizardCollection != null) {
+ result.add(wizardCollection);
+ }
+ } else {
+ result.add(elem);
+ }
+ }
+
+ return result.toArray();
+ }
}