-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ChildModelFilter to implement index windows
Issue: #162
- Loading branch information
Showing
7 changed files
with
150 additions
and
143 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
filters/src/main/java/name/mlopatkin/andlogview/filters/ChildModelFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2024 the Andlogview authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package name.mlopatkin.andlogview.filters; | ||
|
||
/** | ||
* A Filter that has a submodel. | ||
*/ | ||
public interface ChildModelFilter extends Filter { | ||
// TODO {@link FilterModel} should know about these filters and may provide a "parent" model for it. | ||
|
||
/** | ||
* Returns the child model of this filter. | ||
* | ||
* @return the model of this filter | ||
*/ | ||
FilterModel getFilters(); | ||
// TODO(mlopatkin) FilterModel can subscribe to child model upon adding a filter and unsubscribe afterwards. | ||
// This way, the notifications can still be sent from the main model, so clients do not have to care about watching | ||
// for children and subscribing themselves. | ||
// TODO(mlopatkin) The returned model doesn't have to be mutable, but some filters may implement it as such. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/name/mlopatkin/andlogview/ui/filterdialog/IndexWindowFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2024 the Andlogview authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package name.mlopatkin.andlogview.ui.filterdialog; | ||
|
||
import name.mlopatkin.andlogview.filters.AbstractFilter; | ||
import name.mlopatkin.andlogview.filters.ChildModelFilter; | ||
import name.mlopatkin.andlogview.filters.FilterModel; | ||
import name.mlopatkin.andlogview.filters.FilteringMode; | ||
import name.mlopatkin.andlogview.filters.PredicateFilter; | ||
import name.mlopatkin.andlogview.logmodel.LogRecord; | ||
import name.mlopatkin.andlogview.search.RequestCompilationException; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
|
||
import java.util.Objects; | ||
import java.util.function.Predicate; | ||
|
||
public class IndexWindowFilter extends AbstractFilter<IndexWindowFilter> implements FilterFromDialog, ChildModelFilter { | ||
private final FilterFromDialogData filterData; | ||
private final FilterModel model; | ||
|
||
public IndexWindowFilter(boolean enabled, FilterFromDialogData filterData) throws RequestCompilationException { | ||
super(FilteringMode.WINDOW, enabled); | ||
this.model = FilterModel.create(ImmutableSet.of(predicateToHideFilter(filterData.compilePredicate()))); | ||
this.filterData = filterData; | ||
} | ||
|
||
private IndexWindowFilter(boolean enabled, IndexWindowFilter orig) { | ||
super(FilteringMode.WINDOW, enabled); | ||
this.model = orig.model; | ||
this.filterData = orig.filterData; | ||
} | ||
|
||
private static PredicateFilter predicateToHideFilter(Predicate<? super LogRecord> filterPredicate) { | ||
class HideFilter extends AbstractFilter<HideFilter> implements PredicateFilter { | ||
protected HideFilter() { | ||
super(FilteringMode.HIDE, true); | ||
} | ||
|
||
@Override | ||
protected HideFilter copy(boolean enabled) { | ||
throw new UnsupportedOperationException("Cannot disable!"); | ||
} | ||
|
||
@Override | ||
public boolean test(LogRecord logRecord) { | ||
return filterPredicate.test(logRecord); | ||
} | ||
} | ||
|
||
return new HideFilter(); | ||
} | ||
|
||
@Override | ||
protected IndexWindowFilter copy(boolean enabled) { | ||
return new IndexWindowFilter(enabled, this); | ||
} | ||
|
||
@Override | ||
public FilterFromDialogData getData() { | ||
// TODO(mlopatkin) defensive copy? | ||
return filterData; | ||
} | ||
|
||
@Override | ||
public FilterModel getFilters() { | ||
return model; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(isEnabled(), filterData); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == this) { | ||
return true; | ||
} | ||
if (obj instanceof IndexWindowFilter that) { | ||
return that.isEnabled() == isEnabled() && Objects.equals(that.filterData, filterData); | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 0 additions & 73 deletions
73
src/name/mlopatkin/andlogview/ui/indexfilter/IndexFilterModel.java
This file was deleted.
Oops, something went wrong.
58 changes: 0 additions & 58 deletions
58
test/name/mlopatkin/andlogview/ui/indexfilter/IndexFilterModelTest.java
This file was deleted.
Oops, something went wrong.