Skip to content

Commit

Permalink
3
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillipus committed Jan 18, 2025
1 parent d4fe9f9 commit 21fde92
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ public interface IPreferenceConstants {
String PROPERTIES_SINGLE_COLUMN = "propertiesSingleColumn";

// Search Filter
String SEARCHFILTER_NAME = "searchFilterName";
String SEARCHFILTER_DOCUMENTATION = "searchFilterDocumentation";
String SEARCHFILTER_PROPETY_VALUES = "searchFilterPropertyValues";
String SEARCHFILTER_VIEWS = "searchFilterViews";
String SEARCHFILTER_SHOW_ALL_FOLDERS = "searchFilterShowAllFolders";
String SEARCHFILTER_MATCH_CASE = "searchFilterMatchCase";
String SEARCHFILTER_USE_REGEX = "searchFilterUseRegex";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,7 @@ public void initializeDefaultPreferences() {
store.setDefault(UPDATE_URL, "https://www.archimatetool.com/archi-version.txt");

store.setDefault(PROPERTIES_SINGLE_COLUMN, false);

store.setDefault(SEARCHFILTER_NAME, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@
public class SearchFilter extends ViewerFilter {
private String fSearchText = "";

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

private boolean filterName;
private boolean filterDocumentation;
private boolean filterPropertyValues;

private boolean filterViews;
private boolean showAllFolders;
private boolean matchCase;
private boolean useRegex;

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

private boolean fFilterViews;
private boolean fShowAllFolders;
private boolean fMatchCase;
private boolean fUseRegex;

private Matcher fRegexMatcher;

SearchFilter() {
Expand Down Expand Up @@ -102,7 +102,7 @@ private boolean isElementVisible(Object element) {
}
}

if(isShowAllFolders()) {
if(getShowAllFolders()) {
return true;
}
}
Expand Down Expand Up @@ -214,11 +214,11 @@ private boolean matchesString(String str) {
return false;
}

if(isUseRegex()) {
if(getUseRegex()) {
return matchesRegexString(str);
}

if(isMatchCase()) {
if(getMatchCase()) {
return str.contains(fSearchText);
}

Expand All @@ -232,10 +232,10 @@ private boolean matchesRegexString(String searchString) {
private void createRegexMatcher() {
fRegexMatcher = null;

if(isUseRegex() && hasSearchText()) {
if(getUseRegex() && hasSearchText()) {
try {
// Create a Matcher from the search text Pattern that can be re-used
Pattern pattern = Pattern.compile(fSearchText, isMatchCase() ? 0 : Pattern.CASE_INSENSITIVE);
Pattern pattern = Pattern.compile(fSearchText, getMatchCase() ? 0 : Pattern.CASE_INSENSITIVE);
fRegexMatcher = pattern.matcher("");
}
catch(Exception ex) {
Expand All @@ -259,7 +259,7 @@ private boolean hasSearchText() {

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

Expand All @@ -269,31 +269,43 @@ boolean isValidSearchString() {
// ===== Name

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

boolean isFilteringName() {
return fFilterName && hasSearchText();
boolean getFilterOnName() {
return filterName;
}

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

// ===== Documentation

void setFilterOnDocumentation(boolean set) {
fFilterDocumentation = set;
filterDocumentation = set;
}

boolean isFilteringDocumentation() {
return fFilterDocumentation && hasSearchText();
boolean getFilterOnDocumentation() {
return filterDocumentation;
}

private boolean isFilteringDocumentation() {
return getFilterOnDocumentation() && hasSearchText();
}

// ===== Property Values

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

boolean isFilteringPropertyValues() {
return fFilterPropertyValues && hasSearchText();
boolean getFilterOnPropertyValues() {
return filterPropertyValues;
}

private boolean isFilteringPropertyValues() {
return getFilterOnPropertyValues() && hasSearchText();
}

// ===== Property Keys
Expand Down Expand Up @@ -357,42 +369,42 @@ boolean isFilteringSpecializations() {
// ===== All Folders

void setShowAllFolders(boolean set) {
fShowAllFolders = set;
showAllFolders = set;
}

boolean isShowAllFolders() {
return fShowAllFolders;
boolean getShowAllFolders() {
return showAllFolders;
}

// ===== Views

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

boolean isFilteringViews() {
return fFilterViews;
return filterViews;
}

// ===== Match Case

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

boolean isMatchCase() {
return fMatchCase;
boolean getMatchCase() {
return matchCase;
}

// ===== Regex

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

boolean isUseRegex() {
return fUseRegex;
boolean getUseRegex() {
return useRegex;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public class SearchWidget extends Composite {
private IAction fActionFilterDocumentation;
private IAction fActionFilterPropertyValues;
private IAction fActionFilterViews;
private IAction fActionShowAllFolders;
private IAction fActionMatchCase;
private IAction fActionUseRegex;

private List<IAction> fConceptActions = new ArrayList<>();

Expand Down Expand Up @@ -226,7 +229,7 @@ public ImageDescriptor getImageDescriptor() {
};
toolBarmanager.add(dropDownAction);

// Filter on Name
// Name
fActionFilterName = new Action(Messages.SearchWidget_0, IAction.AS_CHECK_BOX) {
@Override
public void run() {
Expand All @@ -235,10 +238,9 @@ public void run() {
};
};
fActionFilterName.setToolTipText(Messages.SearchWidget_1);
fActionFilterName.setChecked(true); // default is true for name
dropDownAction.add(fActionFilterName);

// Filter on Documentation
// Documentation
fActionFilterDocumentation = new Action(Messages.SearchWidget_2, IAction.AS_CHECK_BOX) {
@Override
public void run() {
Expand Down Expand Up @@ -275,6 +277,7 @@ public void run() {
}
}
};
actionProperties.setToolTipText("Search in Property Keys");
dropDownAction.add(actionProperties);

dropDownAction.add(new Separator());
Expand Down Expand Up @@ -349,50 +352,44 @@ public void run() {
refreshTree();
}
};
fActionFilterViews.setChecked(fSearchFilter.isFilteringViews());
fActionFilterViews.setToolTipText("Filter on Views");
dropDownAction.add(fActionFilterViews);

dropDownAction.add(new Separator());

// Show All Folders
IAction actionFolders = new Action(Messages.SearchWidget_12, IAction.AS_CHECK_BOX) {
fActionShowAllFolders = new Action(Messages.SearchWidget_12, IAction.AS_CHECK_BOX) {
@Override
public void run() {
ArchiPlugin.PREFERENCES.setValue(IPreferenceConstants.SEARCHFILTER_SHOW_ALL_FOLDERS, isChecked());
fSearchFilter.setShowAllFolders(isChecked());
refreshTree();
}
};
actionFolders.setChecked(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SEARCHFILTER_SHOW_ALL_FOLDERS));
fSearchFilter.setShowAllFolders(actionFolders.isChecked());
dropDownAction.add(actionFolders);
fActionShowAllFolders.setToolTipText("Show all folders");
dropDownAction.add(fActionShowAllFolders);

// Match Case
IAction actionMatchCase = new Action(Messages.SearchWidget_18, IAction.AS_CHECK_BOX) {
fActionMatchCase = new Action(Messages.SearchWidget_18, IAction.AS_CHECK_BOX) {
@Override
public void run() {
ArchiPlugin.PREFERENCES.setValue(IPreferenceConstants.SEARCHFILTER_MATCH_CASE, isChecked());
fSearchFilter.setMatchCase(isChecked());
refreshTree();
}
};
actionMatchCase.setChecked(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SEARCHFILTER_MATCH_CASE));
fSearchFilter.setMatchCase(actionMatchCase.isChecked());
dropDownAction.add(actionMatchCase);
fActionMatchCase.setToolTipText("Match case");
dropDownAction.add(fActionMatchCase);

// Regex
IAction actionUseRegex = new Action(Messages.SearchWidget_19, IAction.AS_CHECK_BOX) {
fActionUseRegex = new Action(Messages.SearchWidget_19, IAction.AS_CHECK_BOX) {
@Override
public void run() {
ArchiPlugin.PREFERENCES.setValue(IPreferenceConstants.SEARCHFILTER_USE_REGEX, isChecked());
fSearchFilter.setUseRegex(isChecked());
setValidSearchTextHint();
refreshTree();
}
};
actionUseRegex.setChecked(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SEARCHFILTER_USE_REGEX));
fSearchFilter.setUseRegex(actionUseRegex.isChecked());
dropDownAction.add(actionUseRegex);
fActionUseRegex.setToolTipText("Match based on regular expression");
dropDownAction.add(fActionUseRegex);

dropDownAction.add(new Separator());

Expand All @@ -405,10 +402,45 @@ public void run() {
};
dropDownAction.add(actionReset);

loadPreferences();

// Need to update toolbar manager now
toolBarmanager.update(true);
}

private void loadPreferences() {
fActionFilterName.setChecked(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SEARCHFILTER_NAME));
fSearchFilter.setFilterOnName(fActionFilterName.isChecked());

fActionFilterDocumentation.setChecked(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SEARCHFILTER_DOCUMENTATION));
fSearchFilter.setFilterOnDocumentation(fActionFilterDocumentation.isChecked());

fActionFilterPropertyValues.setChecked(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SEARCHFILTER_PROPETY_VALUES));
fSearchFilter.setFilterOnPropertyValues(fActionFilterPropertyValues.isChecked());

fActionFilterViews.setChecked(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SEARCHFILTER_VIEWS));
fSearchFilter.setFilterViews(fActionFilterViews.isChecked());

fActionShowAllFolders.setChecked(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SEARCHFILTER_SHOW_ALL_FOLDERS));
fSearchFilter.setShowAllFolders(fActionShowAllFolders.isChecked());

fActionMatchCase.setChecked(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SEARCHFILTER_MATCH_CASE));
fSearchFilter.setMatchCase(fActionMatchCase.isChecked());

fActionUseRegex.setChecked(ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.SEARCHFILTER_USE_REGEX));
fSearchFilter.setUseRegex(fActionUseRegex.isChecked());
}

private void savePreferences() {
ArchiPlugin.PREFERENCES.setValue(IPreferenceConstants.SEARCHFILTER_NAME, fSearchFilter.getFilterOnName());
ArchiPlugin.PREFERENCES.setValue(IPreferenceConstants.SEARCHFILTER_DOCUMENTATION, fSearchFilter.getFilterOnDocumentation());
ArchiPlugin.PREFERENCES.setValue(IPreferenceConstants.SEARCHFILTER_PROPETY_VALUES, fSearchFilter.getFilterOnPropertyValues());
ArchiPlugin.PREFERENCES.setValue(IPreferenceConstants.SEARCHFILTER_VIEWS, fSearchFilter.isFilteringViews());
ArchiPlugin.PREFERENCES.setValue(IPreferenceConstants.SEARCHFILTER_SHOW_ALL_FOLDERS, fSearchFilter.getShowAllFolders());
ArchiPlugin.PREFERENCES.setValue(IPreferenceConstants.SEARCHFILTER_MATCH_CASE, fSearchFilter.getMatchCase());
ArchiPlugin.PREFERENCES.setValue(IPreferenceConstants.SEARCHFILTER_USE_REGEX, fSearchFilter.getUseRegex());
}

/**
* Reset all filters, properties, specializations
*/
Expand Down Expand Up @@ -614,6 +646,8 @@ private void restoreTreeState() {
public void dispose() {
super.dispose();

savePreferences();

fViewer.removeTreeListener(treeExpansionListener);

if(fSearchFilter.isFiltering()) {
Expand Down

0 comments on commit 21fde92

Please sign in to comment.