From d4fe9f96360b4112e4ce358b35f2b01da94a6623 Mon Sep 17 00:00:00 2001 From: Phillipus Date: Sat, 18 Jan 2025 14:26:32 +0000 Subject: [PATCH] Search Filter - match regex, match case, property values - Match Regex - Match Case - Match on Property Value - Remember some settings - Also search model "Purpose" field for Documentation - Refactored --- .../views/tree/search/SearchFilter.java | 171 ++++++++++++------ .../views/tree/search/SearchWidget.java | 27 ++- 2 files changed, 134 insertions(+), 64 deletions(-) diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchFilter.java b/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchFilter.java index c23b8b831..5fdeb324a 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchFilter.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchFilter.java @@ -40,9 +40,10 @@ public class SearchFilter extends ViewerFilter { private boolean fFilterName = true; // default to true private boolean fFilterDocumentation; + private boolean fFilterPropertyValues; private Set fConceptsFilter = new HashSet<>(); - private Set fPropertiesFilter = new HashSet<>(); + private Set fPropertyKeyFilter = new HashSet<>(); private Set fSpecializationsFilter = new HashSet<>(); private boolean fFilterViews; @@ -63,9 +64,10 @@ void setSearchText(String text) { void reset() { setFilterOnName(true); setFilterOnDocumentation(false); + setFilterOnPropertyValues(false); resetConceptsFilter(); - resetPropertiesFilter(); + resetPropertyKeyFilter(); resetSpecializationsFilter(); setFilterViews(false); } @@ -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; @@ -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; } } } @@ -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 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); } @@ -297,21 +332,11 @@ void resetConceptsFilter() { fConceptsFilter.clear(); } - void addPropertiesFilter(String key) { - fPropertiesFilter.add(key); - } - - void removePropertiesFilter(String key) { - fPropertiesFilter.remove(key); - } - - Set getPropertiesFilter() { - return fPropertiesFilter; + boolean isFilteringConcepts() { + return !fConceptsFilter.isEmpty(); } - void resetPropertiesFilter() { - fPropertiesFilter.clear(); - } + // ===== Specializations void addSpecializationsFilter(IProfile profile) { fSpecializationsFilter.add(profile); @@ -325,6 +350,12 @@ void resetSpecializationsFilter() { fSpecializationsFilter.clear(); } + boolean isFilteringSpecializations() { + return !fSpecializationsFilter.isEmpty(); + } + + // ===== All Folders + void setShowAllFolders(boolean set) { fShowAllFolders = set; } @@ -333,6 +364,8 @@ boolean isShowAllFolders() { return fShowAllFolders; } + // ===== Views + void setFilterViews(boolean set) { fFilterViews = set; } @@ -340,4 +373,26 @@ void setFilterViews(boolean 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; + } } \ No newline at end of file diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchWidget.java b/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchWidget.java index 7c0123a3d..c2607f2aa 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchWidget.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/views/tree/search/SearchWidget.java @@ -74,6 +74,7 @@ public class SearchWidget extends Composite { private IAction fActionFilterName; private IAction fActionFilterDocumentation; + private IAction fActionFilterPropertyValues; private IAction fActionFilterViews; private List fConceptActions = new ArrayList<>(); @@ -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(); } @@ -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(); @@ -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();