Skip to content

Commit

Permalink
Refresh filters after loading all tasks into the database.
Browse files Browse the repository at this point in the history
Update #2514
  • Loading branch information
dbarashev committed Sep 28, 2024
1 parent 7b07d54 commit f9059ec
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import javafx.beans.property.BooleanProperty
import javafx.beans.property.SimpleBooleanProperty
import javafx.beans.property.SimpleIntegerProperty
import net.sourceforge.ganttproject.GPLogger
import net.sourceforge.ganttproject.IGanttProject
import net.sourceforge.ganttproject.storage.ColumnConsumer
import net.sourceforge.ganttproject.storage.ProjectDatabase
import net.sourceforge.ganttproject.task.Task
Expand Down Expand Up @@ -104,7 +105,7 @@ object BuiltInFilters {
/**
* Manages the filters, both built-in and custom.
*/
class TaskFilterManager(val taskManager: TaskManager, val projectDatabase: ProjectDatabase) {
class TaskFilterManager(taskManager: TaskManager, private val projectDatabase: ProjectDatabase) {
private val customFilterResults: MutableSet<Int> = mutableSetOf()
private val customFilterFxn: TaskFilterFxn = { _, child ->
child?.taskID?.let { customFilterResults.contains(it) } != false
Expand Down Expand Up @@ -142,7 +143,7 @@ class TaskFilterManager(val taskManager: TaskManager, val projectDatabase: Proje
if (value != VOID_FILTER) {
recentFilterList.remove(value)
recentFilterList.add(0, value)
while (recentFilterList.size > 5) { recentFilterList.removeLast() }
while (recentFilterList.size > RECENT_FILTER_LIST_SIZE) { recentFilterList.removeLast() }
}
if (!value.isBuiltIn) {
refreshCustomFilterResults()
Expand Down Expand Up @@ -182,10 +183,13 @@ class TaskFilterManager(val taskManager: TaskManager, val projectDatabase: Proje
}
}

fun refresh() = refreshCustomFilterResults()

private fun refreshCustomFilterResults() {
customFilterResults.clear()
if (!activeFilter.isBuiltIn) {
LOGGER.debug(">>> refreshCustomFilterResults()")
LOGGER.debug("... active filter={}", activeFilter)
projectDatabase.mapTasks(
ColumnConsumer(SimpleSelect("uid", "num", whereExpression = activeFilter.expression, CustomPropertyClass.INTEGER.javaClass)) { taskNum, value ->
LOGGER.debug("... adding task={} to the results", taskNum)
Expand Down Expand Up @@ -218,4 +222,5 @@ private fun Task.endsBeforeToday() = this.end.displayValue < today()
private fun Task.runsToday() = today().let { this.end.displayValue >= it && this.start <= it }
val VOID_FILTER_FXN: TaskFilterFxn = { _, _ -> true }
val VOID_FILTER: TaskFilter = TaskFilter("filter.void", "", isBuiltIn = true, filterFxn = VOID_FILTER_FXN)
private const val RECENT_FILTER_LIST_SIZE = 5
private val LOGGER = GPLogger.create("TaskTable.Filters")
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ GPOptionGroup getTaskOptions() {
protected GanttProjectBase(Stage stage) {
TaskDefaultColumn.setLocaleApi(key -> GanttLanguage.getInstance().getText(key));

var databaseProxy = new LazyProjectDatabaseProxy(SqlProjectDatabaseImpl.Factory::createInMemoryDatabase, this::getTaskManager);
var databaseProxy = new LazyProjectDatabaseProxy(SqlProjectDatabaseImpl.Factory::createInMemoryDatabase, this::getTaskManager, this::getTaskFilterManager);

myProjectDatabase = databaseProxy;
myTaskManagerConfig = new TaskManagerConfigImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ open class GanttProjectImpl(
override val projectDatabase: ProjectDatabase = LazyProjectDatabaseProxy(
{error("Not supposed to be called")},
{error("Not supposed to be called")},
{error("Not supposed to be called")},
)) : IGanttProject {

val listeners: MutableList<ProjectEventListener> = mutableListOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package net.sourceforge.ganttproject.storage
import biz.ganttproject.customproperty.CalculatedPropertyUpdater
import biz.ganttproject.customproperty.CustomPropertyListener
import biz.ganttproject.customproperty.CustomPropertyManager
import biz.ganttproject.ganttview.TaskFilterManager
import biz.ganttproject.storage.db.tables.records.TaskRecord
import net.sourceforge.ganttproject.ProjectEventListener
import net.sourceforge.ganttproject.storage.ProjectDatabase.*
Expand All @@ -36,7 +37,11 @@ import net.sourceforge.ganttproject.undo.GPUndoListener
*
* @param databaseFactory - factory for generating a project state database.
*/
class LazyProjectDatabaseProxy(private val databaseFactory: () -> ProjectDatabase, private val taskManager: () -> TaskManager): ProjectDatabase {
class LazyProjectDatabaseProxy(
private val databaseFactory: () -> ProjectDatabase,
private val taskManager: () -> TaskManager,
private val taskFilterManager: () -> TaskFilterManager): ProjectDatabase {

private var lazyProjectDatabase: ProjectDatabase? = null
private val calculatedPropertyUpdater by lazy { CalculatedPropertyUpdater(this,
{ taskManager().customPropertyManager },
Expand All @@ -46,7 +51,7 @@ class LazyProjectDatabaseProxy(private val databaseFactory: () -> ProjectDatabas
}.toMap()
}
) }
private val projectEventListenerImpl by lazy { ProjectEventListenerImpl(this, taskManager, calculatedPropertyUpdater) }
private val projectEventListenerImpl by lazy { ProjectEventListenerImpl(this, taskManager, calculatedPropertyUpdater, taskFilterManager) }

private fun isInitialized(): Boolean = lazyProjectDatabase != null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import biz.ganttproject.app.BarrierEntrance
import biz.ganttproject.customproperty.CalculatedPropertyUpdater
import biz.ganttproject.customproperty.CustomPropertyEvent
import biz.ganttproject.customproperty.CustomPropertyListener
import biz.ganttproject.ganttview.TaskFilterManager
import net.sourceforge.ganttproject.GPLogger
import net.sourceforge.ganttproject.IGanttProject
import net.sourceforge.ganttproject.ProjectEventListener
Expand All @@ -38,8 +39,10 @@ import javax.swing.event.UndoableEditEvent
* @param projectDatabase - database which holds the current project state.
*/
internal class ProjectEventListenerImpl(
private val projectDatabase: ProjectDatabase, private val taskManagerSupplier: ()->TaskManager,
private val calculatedPropertyUpdater: CalculatedPropertyUpdater)
private val projectDatabase: ProjectDatabase,
private val taskManagerSupplier: ()->TaskManager,
private val calculatedPropertyUpdater: CalculatedPropertyUpdater,
private val taskFilterManager: ()->TaskFilterManager)
: TaskListener, ProjectEventListener.Stub(), GPUndoListener, CustomPropertyListener {

private fun withLogger(errorMessage: () -> String, body: () -> Unit) {
Expand All @@ -55,7 +58,8 @@ internal class ProjectEventListenerImpl(
barrier.await {
projectDatabase.onCustomColumnChange(it.taskCustomColumnManager)
it.taskManager.tasks.forEach(projectDatabase::insertTask)
calculatedPropertyUpdater.update();
calculatedPropertyUpdater.update()
taskFilterManager().refresh()
}
}

Expand Down

0 comments on commit f9059ec

Please sign in to comment.