Commit cdd597d6 authored by Simon Barner's avatar Simon Barner
Browse files

- Interpret model element / annotation name filter as regex

- Add check box to toggle case sensitive match (default: insensitive match as before)
parent 5d6e73cb
......@@ -17,9 +17,14 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.annotation.view.generic.filter;
import static java.util.regex.Pattern.CASE_INSENSITIVE;
import static java.util.regex.Pattern.DOTALL;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getModelElementAncestor;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getModelElementLevel;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
......@@ -44,11 +49,11 @@ import org.fortiss.tooling.kernel.model.IProjectRootElement;
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 7BBC877B6C57F047267BD298D4598529
* @ConQAT.Rating YELLOW Hash: BD2C5BD0033DADE7796F2E87B127B82F
*/
public class AnnotationFilter extends ViewerFilter {
/** Filter hint text. */
static final String FILTER_HINT_TEXT = "type filter text";
static final String FILTER_HINT_TEXT = "type filter text (regex)";
/** Hierarchy filter option: all model elements from any level. */
static final String HIERARCHY_LEVELS_ALL = "Show all levels";
......@@ -60,7 +65,7 @@ public class AnnotationFilter extends ViewerFilter {
static final String HIERARCHY_LEVELS_SELECTED_SUBMODEL = "Show selected sub-model";
/** Current model element / annotation name filter pattern. */
private String filterPattern;
private Pattern filterPattern;
/** Flag whether columns / annotation names should be filtered. */
private boolean filterColumnName;
......@@ -68,6 +73,9 @@ public class AnnotationFilter extends ViewerFilter {
/** Flag whether rows / model element names should be filtered. */
private boolean filterRowName;
/** Flag whether the row/column filter should be case sensitive. */
private boolean filterNameMatchCase;
/** Currently selected model element (may be {@code null}). */
private IModelElement currentlySelectedModelElement;
......@@ -106,8 +114,9 @@ public class AnnotationFilter extends ViewerFilter {
* by {@code filterString}.
*/
private boolean passesNameFilter(String input) {
// Null-filter accepts every input
if(filterPattern == null || filterPattern.equals(FILTER_HINT_TEXT)) {
// Null-filter accepts every input. This covers also the case when the pattern provided by
// the user is invalid.
if(filterPattern == null) {
return true;
}
......@@ -115,7 +124,8 @@ public class AnnotationFilter extends ViewerFilter {
if(input == null) {
return false;
}
return input.toLowerCase().contains(filterPattern.toLowerCase());
return filterPattern.matcher(input).matches();
}
/**
......@@ -183,7 +193,7 @@ public class AnnotationFilter extends ViewerFilter {
* Returns {@code true} if the column represented by the given column is visible in the
* view.
*/
public boolean passesColumnFilter(ColumnHandle columnHandle) {
public boolean passesColumnFilter(ColumnHandle<?> columnHandle) {
// Whether the annotation is visible (i.e., not principally hidden from any view)
boolean passesHiddenFilter =
!columnHandle.getEntry().isHidden(
......@@ -244,8 +254,17 @@ public class AnnotationFilter extends ViewerFilter {
}
/** Sets the model element / annotation name filter pattern. */
public void setNameFilterPattern(String filterPattern) {
this.filterPattern = filterPattern;
public void setNameFilterPattern(String filterPatternString) {
if(filterPatternString.equals(FILTER_HINT_TEXT)) {
filterPattern = null;
} else {
try {
final int patternFlags = (filterNameMatchCase ? 0 : CASE_INSENSITIVE) | DOTALL;
filterPattern = Pattern.compile(".*" + filterPatternString + ".*", patternFlags);
} catch(PatternSyntaxException e) {
filterPattern = null;
}
}
}
/** Sets the flag whether rows should be filtered by name. */
......@@ -258,6 +277,15 @@ public class AnnotationFilter extends ViewerFilter {
this.filterColumnName = filterColumnName;
}
/** Sets the flag whether the row/column filter should be case sensitive. */
public void setFilterNameMatchCase(boolean filterNameMatchCase) {
this.filterNameMatchCase = filterNameMatchCase;
// Recompile pattern
if(filterPattern != null) {
setNameFilterPattern(filterPattern.pattern());
}
}
/** Sets the flag whether the view should be filtered by the selected model element type. */
public void setRestrictToSelectedModelElementType(boolean restrictToSelectedModelElementType) {
this.restrictToSelectedModelElementType = restrictToSelectedModelElementType;
......
......@@ -47,7 +47,7 @@ import org.fortiss.tooling.base.ui.widget.ExtendedCCombo;
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 79A978E8A3949305BDF86E4A700A7582
* @ConQAT.Rating YELLOW Hash: 0339867B10DB35653CD63704E39A8620
*/
public class AnnotationFilterWidget extends Composite {
......@@ -210,6 +210,19 @@ public class AnnotationFilterWidget extends Composite {
}
});
final Button filterNamesMatchCaseButton = new Button(nameFilterScopeComposite, SWT.CHECK);
filterNamesMatchCaseButton.setText("match case:");
filterNamesMatchCaseButton.setSelection(false);
filterNamesMatchCaseButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
final boolean selection = ((Button)e.getSource()).getSelection();
view.getAnnotationFilter().setFilterNameMatchCase(selection);
updateView(view);
}
});
return nameFilterScopeComposite;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment