From 261b2b3821a24dd91fb87d4e33c75ed33404dc15 Mon Sep 17 00:00:00 2001 From: Mickael ADAM Date: Fri, 26 Aug 2016 17:12:42 +0200 Subject: Bug 500290 - [Model Explorer] It should be possible to filter element from model https://bugs.eclipse.org/bugs/show_bug.cgi?id=500290 Change-Id: Id15819484b62b69a0f0b686f257d9acfee31e870 Signed-off-by: Mickael ADAM --- .../widgets/editors/StringWithClearEditor.java | 61 +++------------------- .../infra/widgets/messages/messages.properties | 2 +- .../widgets/providers/AbstractTreeFilter.java | 24 ++++++++- .../widgets/providers/PatternViewerFilter.java | 53 ++++++++++++++++--- 4 files changed, 74 insertions(+), 66 deletions(-) (limited to 'plugins/infra/ui') diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/StringWithClearEditor.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/StringWithClearEditor.java index d42f8d1b584..abb3851b81d 100644 --- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/StringWithClearEditor.java +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/StringWithClearEditor.java @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Mickaël ADAM (ALL4TEC) - mickae.adam@all4tec.net - Initial API and implementation + * Mickaël ADAM (ALL4TEC) - mickael.adam@all4tec.net - Initial API and implementation * *****************************************************************************/ @@ -61,10 +61,6 @@ public class StringWithClearEditor extends AbstractValueEditor implements KeyLis private TimerTask changeColorTask; - protected final static int DEFAULT_HEIGHT_HINT = 55; - - protected final static int DEFAULT_WIDTH_HINT = 100; - /** The clear icon when enable. */ private static final String CLEAR_ENABLED_ICON = "/icons/clear_enabled.gif";//$NON-NLS-1$ @@ -88,7 +84,7 @@ public class StringWithClearEditor extends AbstractValueEditor implements KeyLis * The style for this editor's text box */ public StringWithClearEditor(Composite parent, int style) { - this(parent, style, null, DEFAULT_HEIGHT_HINT, DEFAULT_WIDTH_HINT); + this(parent, style, null); } @@ -104,67 +100,22 @@ public class StringWithClearEditor extends AbstractValueEditor implements KeyLis * The label for this editor */ public StringWithClearEditor(Composite parent, int style, String label) { - this(parent, style, label, DEFAULT_HEIGHT_HINT, DEFAULT_WIDTH_HINT); - } - - /** - * - * Constructor. - * - * @param parent - * The composite in which this editor should be displayed - * @param style - * The style for this editor's text box - * @param heighHint - * Height hint of the text area in multiline mode - * @param widthHint - * Width hint of the text area in multiline mode - */ - public StringWithClearEditor(Composite parent, int style, int heighHint, int widthHint) { - this(parent, style, null, heighHint, widthHint); - } - - /** - * - * Constructor. - * - * @param parent - * The composite in which this editor should be displayed - * @param style - * The style for this editor's text box - * @param label - * The label for this editor - * @param heighHint - * Height hint of the text area in multiline mode - * @param widthHint - * Width hint of the text area in multiline mode - */ - public StringWithClearEditor(Composite parent, int style, String label, int heighHint, int widthHint) { super(parent, label); // Create the filter composite - final Composite filterComposite = new Composite(parent, style); + final Composite filterComposite = new Composite(this, style); filterComposite.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); // Initialise the layout of the filter composite to display the widgets on 2 columns final GridLayout filterLayout = new GridLayout(2, false); filterLayout.marginHeight = 0; filterLayout.marginWidth = 0; + filterComposite.setLayout(filterLayout); - { - GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); - filterComposite.setLayoutData(gridData); - } + filterComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); text = new Text(filterComposite, SWT.NONE); - { - GridData data = new GridData(); - data.grabExcessVerticalSpace = false; - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - data.verticalAlignment = GridData.BEGINNING; - text.setLayoutData(data); - } + text.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); text.setFont(parent.getFont()); Label clearButton = new Label(filterComposite, SWT.NONE); diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/messages.properties b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/messages.properties index 492be620e3f..e8aa041f768 100644 --- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/messages.properties +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/messages/messages.properties @@ -67,7 +67,7 @@ StringFileSelector_BrowseWorkspace=Browse workspace IntegerMask_ErrorTooManyValues=The mask-based integer editor cannot be used with more than 32 values ProviderBasedBrowseStrategy_0=The provider has not been initialized - +StringWithClearEditor_ClearFilter=Clear the filter BundleIconExplorerDialog_Bundle=Bundle BundleIconExplorerDialog_CantFindBundleIdMessage=impossible to find bundle with id: StringWithClearEditor_ClearFilter=Clear the filter diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/AbstractTreeFilter.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/AbstractTreeFilter.java index d45574b1d74..0249ab6ca98 100644 --- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/AbstractTreeFilter.java +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/AbstractTreeFilter.java @@ -16,11 +16,13 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.viewers.IContentProvider; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.papyrus.infra.tools.util.PlatformHelper; import org.eclipse.papyrus.infra.widgets.strategy.IStrategyBasedContentProvider; import org.eclipse.papyrus.infra.widgets.strategy.ProviderBasedBrowseStrategy; import org.eclipse.papyrus.infra.widgets.strategy.TreeBrowseStrategy; @@ -126,9 +128,27 @@ public abstract class AbstractTreeFilter extends ViewerFilter { } boolean result = false; - if (!visitedElements.contains(element)) { + boolean visited = false; + + if (visitedElements.contains(element)) { + visited = true; + } else { visitedElements.add(element); + } + + // get the semantic element for facet case + if (!visited) { + EObject eObject = PlatformHelper.getAdapter(element, EObject.class); + if (null != eObject) { + if (visitedElements.contains(eObject)) { + visited = true; + } else { + visitedElements.add(eObject); + } + } + } + if (!visited) { Object[] children = strategy.getChildren(element); if (null != children) { for (Object childElement : children) { @@ -171,7 +191,7 @@ public abstract class AbstractTreeFilter extends ViewerFilter { return result; } - protected void clearCache() { + public void clearCache() { visibleElement.clear(); visibleParent.clear(); visibleChild.clear(); diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/PatternViewerFilter.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/PatternViewerFilter.java index ee7080a20f4..571de9a043c 100644 --- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/PatternViewerFilter.java +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/PatternViewerFilter.java @@ -8,6 +8,7 @@ * * Contributors: * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + * Mickaël ADAM (ALL4TEC) - mickael.adam@all4tec.net - Bug 500290: add ignore case boolean and some refactore *****************************************************************************/ package org.eclipse.papyrus.infra.widgets.providers; @@ -31,12 +32,23 @@ import org.eclipse.ui.internal.misc.StringMatcher; */ public class PatternViewerFilter extends AbstractTreeFilter { - private StringMatcher[] validPatterns = new StringMatcher[] { new StringMatcher("*", true, false) }; + /** the wilcard ? */ + private static final String SEMI_COLON = ";";//$NON-NLS-1$ + /** the wilcard * */ + private static final String ASTERISK = "*";//$NON-NLS-1$ + + private StringMatcher[] validPatterns = new StringMatcher[] { new StringMatcher(ASTERISK, true, false) }; + + /** The current pattern. */ private String currentPattern; + /** True if strict. */ private boolean strict = false; + /** To ignore case. */ + private boolean ignoreCase = true; + /** * If the pattern is not strict, wildcards (*) will be added at the beginning and the end of the pattern * The pattern foo becomes equivalent to *foo* @@ -47,26 +59,51 @@ public class PatternViewerFilter extends AbstractTreeFilter { this.strict = strict; } - public void setPattern(String value) { - if (value.equals(currentPattern)) { - return; + /** + * Set to true to ignore case. + * + * @param ignoreCase + * the ignoreCase to set + */ + public void setIgnoreCase(boolean value) { + if (value != ignoreCase) { + this.ignoreCase = value; + setPatterns(); } + } - currentPattern = value; + /** + * Set the pattern. + */ + public void setPattern(String value) { + if (!value.equals(currentPattern)) { + currentPattern = value; + setPatterns(); + } + } - String[] patterns = value.split(";"); + /** + * Set Patterns. + */ + protected void setPatterns() { + String[] patterns = currentPattern.split(SEMI_COLON); this.validPatterns = new StringMatcher[patterns.length]; int i = 0; for (String pattern : patterns) { if (!strict) { - pattern = "*" + pattern.trim() + "*"; + pattern = ASTERISK + pattern.trim() + ASTERISK; } - validPatterns[i++] = new StringMatcher(pattern, true, false); + validPatterns[i++] = new StringMatcher(pattern, ignoreCase, false); } clearCache(); } + /** + * {@inheritDoc} + * + * @see org.eclipse.papyrus.infra.widgets.providers.AbstractTreeFilter#isVisible(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ @Override public boolean isVisible(Viewer viewer, Object parentElement, Object element) { IBaseLabelProvider labelProvider = ((StructuredViewer) viewer).getLabelProvider(); -- cgit v1.2.3