Skip to content

Commit

Permalink
Search Filter - match regex, match case, property values
Browse files Browse the repository at this point in the history
- Match Regex
- Match Case
- Match on Property Value
- Remember some settings
- Also search model "Purpose" field for Documentation
- Refactored
  • Loading branch information
Phillipus committed Jan 18, 2025
1 parent c732efc commit d4fe9f9
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ public class SearchFilter extends ViewerFilter {

private boolean fFilterName = true; // default to true
private boolean fFilterDocumentation;
private boolean fFilterPropertyValues;

private Set<EClass> fConceptsFilter = new HashSet<>();
private Set<String> fPropertiesFilter = new HashSet<>();
private Set<String> fPropertyKeyFilter = new HashSet<>();
private Set<IProfile> fSpecializationsFilter = new HashSet<>();

private boolean fFilterViews;
Expand All @@ -63,9 +64,10 @@ void setSearchText(String text) {
void reset() {
setFilterOnName(true);
setFilterOnDocumentation(false);
setFilterOnPropertyValues(false);

resetConceptsFilter();
resetPropertiesFilter();
resetPropertyKeyFilter();
resetSpecializationsFilter();
setFilterViews(false);
}
Expand Down Expand Up @@ -124,10 +126,11 @@ public boolean matchesFilter(Object element) {
}

// Name, Documentation or Property
if(isFilteringName() || isFilteringDocumentation() || isFilteringPropertyKeys()) {
if(isFilteringName() || isFilteringDocumentation() || isFilteringPropertyKeys() || isFilteringPropertyValues()) {
show &= (isFilteringName() && shouldShowObjectWithName(element))
|| (isFilteringDocumentation() && shouldShowObjectWithDocumentation(element))
|| (isFilteringPropertyKeys() && shouldShowProperty(element));
|| (isFilteringPropertyValues() && shouldShowPropertyValue(element))
|| (isFilteringPropertyKeys() && shouldShowPropertyKey(element));
}

return show;
Expand Down Expand Up @@ -176,11 +179,29 @@ private boolean shouldShowSpecialization(Object element) {
return false;
}

private boolean shouldShowProperty(Object element) {
private boolean shouldShowPropertyKey(Object element) {
if(element instanceof IProperties properties) {
for(IProperty property : properties.getProperties()) {
if(fPropertiesFilter.contains(property.getKey())) {
return hasSearchText() ? matchesString(property.getValue()) : true;
if(fPropertyKeyFilter.contains(property.getKey())) {
// If there is search text filter on that, otherwise show the element if the property key is selected
return hasSearchText() && isFilteringPropertyValues() ? matchesString(property.getValue()) : true;
}
}
}

return false;
}

private boolean shouldShowPropertyValue(Object element) {
if(element instanceof IProperties properties) {
for(IProperty property : properties.getProperties()) {
// If we are filtering on property keys match on property key and value
if(isFilteringPropertyKeys()) {
return fPropertyKeyFilter.contains(property.getKey()) && matchesString(property.getValue());
}
// If we are not filtering on property keys match on value (equivalent to all property kesy selected)
if(matchesString(property.getValue())) {
return true;
}
}
}
Expand Down Expand Up @@ -223,68 +244,82 @@ private void createRegexMatcher() {
}

public boolean isFiltering() {
return isFilteringName() || isFilteringDocumentation() || isFilteringConcepts() || isFilteringPropertyKeys() || isFilteringSpecializations() || isFilteringViews();
return isFilteringName()
|| isFilteringDocumentation()
|| isFilteringConcepts()
|| isFilteringPropertyKeys()
|| isFilteringPropertyValues()
|| isFilteringSpecializations()
|| isFilteringViews();
}

private boolean isFilteringName() {
return fFilterName && hasSearchText();
}

private boolean isFilteringDocumentation() {
return fFilterDocumentation && hasSearchText();
private boolean hasSearchText() {
return fSearchText.length() > 0;
}

private boolean isFilteringConcepts() {
return !fConceptsFilter.isEmpty();
boolean isValidSearchString() {
// If we are using regex and we have a matcher then it's valid
if(isUseRegex() && hasSearchText()) {
return fRegexMatcher != null;
}

return true;
}

private boolean isFilteringPropertyKeys() {
return !fPropertiesFilter.isEmpty();

// ===== Name

void setFilterOnName(boolean set) {
fFilterName = set;
}

private boolean isFilteringSpecializations() {
return !fSpecializationsFilter.isEmpty();
boolean isFilteringName() {
return fFilterName && hasSearchText();
}

// ===== Documentation

private boolean hasSearchText() {
return fSearchText.length() > 0;
void setFilterOnDocumentation(boolean set) {
fFilterDocumentation = set;
}

void setMatchCase(boolean set) {
fMatchCase = set;
createRegexMatcher();
boolean isFilteringDocumentation() {
return fFilterDocumentation && hasSearchText();
}

boolean isMatchCase() {
return fMatchCase;
// ===== Property Values

void setFilterOnPropertyValues(boolean set) {
fFilterPropertyValues = set;
}

void setUseRegex(boolean set) {
fUseRegex = set;
createRegexMatcher();
boolean isFilteringPropertyValues() {
return fFilterPropertyValues && hasSearchText();
}

boolean isUseRegex() {
return fUseRegex;
// ===== Property Keys

void addPropertyKeyFilter(String key) {
fPropertyKeyFilter.add(key);
}

void removePropertyKeyFilter(String key) {
fPropertyKeyFilter.remove(key);
}

boolean isValidSearchString() {
// If we are using regex and we have a matcher then it's valid
if(isUseRegex() && hasSearchText()) {
return fRegexMatcher != null;
}

return true;
Set<String> getPropertyKeyFilter() {
return fPropertyKeyFilter;
}

void setFilterOnName(boolean set) {
fFilterName = set;
void resetPropertyKeyFilter() {
fPropertyKeyFilter.clear();
}

void setFilterOnDocumentation(boolean set) {
fFilterDocumentation = set;
boolean isFilteringPropertyKeys() {
return !fPropertyKeyFilter.isEmpty();
}

// ===== Concepts

void addConceptFilter(EClass eClass) {
fConceptsFilter.add(eClass);
}
Expand All @@ -297,21 +332,11 @@ void resetConceptsFilter() {
fConceptsFilter.clear();
}

void addPropertiesFilter(String key) {
fPropertiesFilter.add(key);
}

void removePropertiesFilter(String key) {
fPropertiesFilter.remove(key);
}

Set<String> getPropertiesFilter() {
return fPropertiesFilter;
boolean isFilteringConcepts() {
return !fConceptsFilter.isEmpty();
}

void resetPropertiesFilter() {
fPropertiesFilter.clear();
}
// ===== Specializations

void addSpecializationsFilter(IProfile profile) {
fSpecializationsFilter.add(profile);
Expand All @@ -325,6 +350,12 @@ void resetSpecializationsFilter() {
fSpecializationsFilter.clear();
}

boolean isFilteringSpecializations() {
return !fSpecializationsFilter.isEmpty();
}

// ===== All Folders

void setShowAllFolders(boolean set) {
fShowAllFolders = set;
}
Expand All @@ -333,11 +364,35 @@ boolean isShowAllFolders() {
return fShowAllFolders;
}

// ===== Views

void setFilterViews(boolean set) {
fFilterViews = set;
}

boolean isFilteringViews() {
return fFilterViews;
}

// ===== Match Case

void setMatchCase(boolean set) {
fMatchCase = set;
createRegexMatcher();
}

boolean isMatchCase() {
return fMatchCase;
}

// ===== Regex

void setUseRegex(boolean set) {
fUseRegex = set;
createRegexMatcher();
}

boolean isUseRegex() {
return fUseRegex;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class SearchWidget extends Composite {

private IAction fActionFilterName;
private IAction fActionFilterDocumentation;
private IAction fActionFilterPropertyValues;
private IAction fActionFilterViews;

private List<IAction> fConceptActions = new ArrayList<>();
Expand Down Expand Up @@ -248,16 +249,27 @@ public void run() {
fActionFilterDocumentation.setToolTipText(Messages.SearchWidget_3);
dropDownAction.add(fActionFilterDocumentation);

// Properties
// Property Values
fActionFilterPropertyValues = new Action("Property Value", IAction.AS_CHECK_BOX) {
@Override
public void run() {
fSearchFilter.setFilterOnPropertyValues(isChecked());
refreshTree();
};
};
fActionFilterPropertyValues.setToolTipText("Search in Property Values");
dropDownAction.add(fActionFilterPropertyValues);

// Property Keys
IAction actionProperties = new Action(Messages.SearchWidget_5, IAction.AS_PUSH_BUTTON) {
@Override
public void run() {
UserPropertiesKeySelectionDialog dialog = new UserPropertiesKeySelectionDialog(getShell(), getAllUniquePropertyKeys(),
new ArrayList<>(fSearchFilter.getPropertiesFilter()));
new ArrayList<>(fSearchFilter.getPropertyKeyFilter()));
if(dialog.open() != Window.CANCEL) {
fSearchFilter.resetPropertiesFilter();
fSearchFilter.resetPropertyKeyFilter();
for(String key : dialog.getSelectedKeys()) {
fSearchFilter.addPropertiesFilter(key);
fSearchFilter.addPropertyKeyFilter(key);
}
refreshTree();
}
Expand Down Expand Up @@ -406,6 +418,9 @@ private void reset() {

// Don't filter on Documentation menu item
fActionFilterDocumentation.setChecked(false);

// Don't filter on Property Values menu item
fActionFilterPropertyValues.setChecked(false);

// Clear & uncheck Specializations menu items
populateSpecializationsMenu();
Expand All @@ -429,8 +444,8 @@ private void reset() {
* Currently called when a model is opened or closed to update Properties and Specializations
*/
public void softReset() {
// Clear & Reset Properties
fSearchFilter.resetPropertiesFilter();
// Clear & Reset Property keys
fSearchFilter.resetPropertyKeyFilter();

// Clear & Reset Specializations
populateSpecializationsMenu();
Expand Down

0 comments on commit d4fe9f9

Please sign in to comment.