Skip to content

Commit

Permalink
'#2163 Implements restoreDefinedFilters for filterers declared in App
Browse files Browse the repository at this point in the history
class and corrects this method name.
  • Loading branch information
patrickdalla committed May 29, 2024
1 parent 8eef37f commit fbc1804
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 24 deletions.
98 changes: 84 additions & 14 deletions iped-app/src/main/java/iped/app/ui/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ public void actionPerformed(ActionEvent event) {
filterManager.addQueryFilterer(TableHeaderFilterManager.get());
filterManager.addResultSetFilterer(bookmarksListener);
filterManager.addResultSetFilterer(FilterSelectedEdges.getInstance());
filterManager.addResultSetFilterer(duplicatesFilterer, false);
filterManager.addResultSetFilterer(duplicatesFilterer);
filterManager.addResultSetFilterer(similarImagesFilterer);
filterManager.addResultSetFilterer(similarFacesSearchFilterer);
filterManager.addResultSetFilterer(timelineListener);
Expand Down Expand Up @@ -1768,6 +1768,16 @@ public void setItem(IItemId itemId, IItem similarImagesFilterer) {
item = similarImagesFilterer;
imageFilter = new SimilarImageFilter(itemId, item);
}

@Override
public void restoreDefinedFilters(List<IFilter> filtersToRestore) {
for (IFilter filter : filtersToRestore) {
if (filter instanceof SimilarImageFilter) {
imageFilter = (SimilarImageFilter) filter;
break;
}
}
}
};

class DuplicateFilter implements IResultSetFilter, IMutableFilter {
Expand All @@ -1787,6 +1797,9 @@ public IMultiSearchResult filterResult(IMultiSearchResult src) throws ParseExcep
IResultSetFilter duplicateFilter = new DuplicateFilter();

class DuplicatesFilterer implements IResultSetFilterer {

IResultSetFilter cduplicateFilter = duplicateFilter;

@Override
public List getDefinedFilters() {
ArrayList<IFilter> result = new ArrayList<IFilter>();
Expand All @@ -1807,7 +1820,7 @@ public IFilter getFilter() {

@Override
public boolean hasFilters() {
return true;
return cduplicateFilter != null;
}

@Override
Expand All @@ -1818,9 +1831,18 @@ public boolean hasFiltersApplied() {
@Override
public void clearFilter() {
appletListener.clearAllFilters = true;
cduplicateFilter = null;
if (filterDuplicates.isSelected())
filterDuplicates.doClick();
appletListener.clearAllFilters = false;
this.fireActionListener(new ActionEvent(this, IFilterer.DISABLE_FILTER_EVENT, "DESELECTED"));
}

@Override
public void restoreDefinedFilters(List<IFilter> filtersToRestore) {
cduplicateFilter = duplicateFilter;
filterDuplicates.setSelected(true);
this.fireActionListener(new ActionEvent(this, IFilterer.ENABLE_FILTER_EVENT, "SELECTED"));
}
}

Expand Down Expand Up @@ -1958,6 +1980,34 @@ public void clearFilter() {
SimilarFacesFilterActions.clear(false);
}

@Override
public void restoreDefinedFilters(List<IFilter> filtersToRestore) {
for (IFilter filter : filtersToRestore) {
if (filter instanceof SimilarFacesSearchFilter) {
filter = (SimilarFacesSearchFilter) filter;
break;
}
}
}

}

class SearchFilter implements IQueryFilter {
String filterText;

public SearchFilter(String filterText) {
this.filterText = filterText;
}

@Override
public Query getQuery() {
return query;
}

public String toString() {
return filterText;
}

}

class SearchFilterer implements IQueryFilterer {
Expand All @@ -1969,18 +2019,7 @@ public List<IFilter> getDefinedFilters() {
Query query;
try {
query = new QueryBuilder(appCase).getQuery(filterText);
result.add(new IQueryFilter() {
String title = filterText;

@Override
public Query getQuery() {
return query;
}

public String toString() {
return title;
}
});
result.add(new SearchFilter(filterText));
} catch (ParseException | QueryNodeException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -2031,6 +2070,17 @@ public void clearFilter() {
appletListener.clearAllFilters = false;
}

@Override
public void restoreDefinedFilters(List<IFilter> filtersToRestore) {
for (IFilter filter : filtersToRestore) {
if (filter instanceof SearchFilter) {
filter = (SearchFilter) filter;
queryComboBox.setSelectedItem(((SearchFilter) filter).filterText);
break;
}
}
}

}

public IItem getSimilarImagesQueryRefItem() {
Expand Down Expand Up @@ -2173,9 +2223,29 @@ public void setPercent(int percent) {
this.percent = percent;
filter = null;
}

@Override
public void restoreDefinedFilters(List<IFilter> filtersToRestore) {
for (IFilter filter : filtersToRestore) {
if (filter instanceof SimilarDocumentFilter) {
filter = (SimilarDocumentFilter) filter;
break;
}
}
}
}

public AppListener getAppletListener() {
return appletListener;
}

public void selectFilterDuplicates(boolean selected) {
if (selected) {
duplicatesFilterer.cduplicateFilter = duplicateFilter;
duplicatesFilterer.fireActionListener(new ActionEvent(this, IFilterer.ENABLE_FILTER_EVENT, "SELECTED"));
} else {
duplicatesFilterer.cduplicateFilter = null;
duplicatesFilterer.fireActionListener(new ActionEvent(this, IFilterer.DISABLE_FILTER_EVENT, "DESELECTED"));
}
}
}
8 changes: 2 additions & 6 deletions iped-app/src/main/java/iped/app/ui/AppListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,8 @@ public void actionPerformed(ActionEvent evt) {
}

if (evt.getSource() == App.get().filterDuplicates) {
if (!App.get().filterDuplicates.isSelected()) {
App.get().filterManager.setFilterEnabled(App.get().duplicatesFilterer, false);
} else {
App.get().filterManager.setFilterEnabled(App.get().duplicatesFilterer, true);
}

App.get().selectFilterDuplicates(App.get().filterDuplicates.isSelected());
updateFileListing();
App.get().filtersPanel.updateUI();
updateFileList = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public Category getCategory() {
}

@Override
public void restoreDefineFilters(List<IFilter> filtersToRestore) {
public void restoreDefinedFilters(List<IFilter> filtersToRestore) {
if (filtersToRestore == null) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion iped-app/src/main/java/iped/app/ui/FiltersPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void actionPerformed(ActionEvent e) {
} else {
List<IFilter> clastFilters = lastFilters.get(filterer);
if (clastFilters != null) {
filterer.restoreDefineFilters(clastFilters);
filterer.restoreDefinedFilters(clastFilters);
App.get().getAppListener().updateFileListing();
App.get().filtersPanel.updateUI();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public interface IFilterer extends ClearFilterListener, ActionListenerControl {
*
* @return
*/
default public void restoreDefineFilters(List<IFilter> filtersToRestore) {
return;
default public void restoreDefinedFilters(List<IFilter> filtersToRestore){

}

default public String getFilterName() {
Expand Down

0 comments on commit fbc1804

Please sign in to comment.