Skip to content

Commit

Permalink
Hide default columns unless they are explicitly marked as shown in th…
Browse files Browse the repository at this point in the history
…e xml view

Fixes issue #2306
  • Loading branch information
dbarashev committed Jul 10, 2023
1 parent 2e74e4a commit 051cc09
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copyright 2023 BarD Software s.r.o, Dmitry Barashev
This file is part of GanttProject, an open-source project management tool.
GanttProject is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
GanttProject is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GanttProject. If not, see <http://www.gnu.org/licenses/>.
*/
package net.sourceforge.ganttproject.parser

import biz.ganttproject.core.io.XmlView
import biz.ganttproject.core.model.task.TaskDefaultColumn
import biz.ganttproject.core.table.ColumnList
import biz.ganttproject.core.time.impl.GPTimeUnitStack
import biz.ganttproject.lib.fx.BuiltinColumns
import biz.ganttproject.lib.fx.ColumnListImpl
import biz.ganttproject.lib.fx.copyOf
import net.sourceforge.ganttproject.gui.zoom.ZoomManager
import net.sourceforge.ganttproject.task.CustomColumnsManager
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test

class TestViewSerializer {
private val builtinColumns = BuiltinColumns(
isZeroWidth = {
when (TaskDefaultColumn.find(it)) {
TaskDefaultColumn.COLOR, TaskDefaultColumn.INFO -> true
else -> false
}
},
allColumns = {
ColumnList.Immutable.fromList(TaskDefaultColumn.getColumnStubs()).copyOf()
}
)
@Test
fun `default columns remain hidden - issue 2306`() {
val storage = mutableListOf<ColumnList.Column>()
val columnList = ColumnListImpl(columnList = storage, customPropertyManager = CustomColumnsManager(), tableColumns = { emptyList() }, builtinColumns = builtinColumns)
val xmlView = XmlView(fields = listOf(
XmlView.XmlField(id = TaskDefaultColumn.NAME.stub.id, name = "Name", width = 50, order = 0),
XmlView.XmlField(id = TaskDefaultColumn.BEGIN_DATE.stub.id, name = "Begin date", width = 70, order = 1)
))
loadView(xmlView, ZoomManager(GPTimeUnitStack()), columnList)
columnList.columns().first { it.id == TaskDefaultColumn.BEGIN_DATE.stub.id }.also {
assertTrue(it.isVisible)
assertEquals(70, it.width)
assertEquals(1, it.order)
}
columnList.columns().first { it.id == TaskDefaultColumn.NAME.stub.id }.also {
assertTrue(it.isVisible)
assertEquals(50, it.width)
assertEquals(0, it.order)
}
columnList.columns().first { it.id == TaskDefaultColumn.END_DATE.stub.id }.also {
assertFalse(it.isVisible)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ fun loadView(xmlView: XmlView, zoomManager: ZoomManager, columnList: ColumnList)
// Set orders for the columns which had no orders defined
val countPositiveOrders = stubs.count { it.order >= 0 }
stubs.filter { it.order == -1 }.forEachIndexed { idx, stub -> stub.order = idx + countPositiveOrders }
columnList.importData(ColumnList.Immutable.fromList(stubs + TaskDefaultColumn.getColumnStubs().filter { defaultColumn ->
stubs.firstOrNull { it.id == defaultColumn.id } == null
}), false)
val defaultColumns = TaskDefaultColumn.getColumnStubs().filter { defaultColumn ->
stubs.firstOrNull { it.id == defaultColumn.id } == null
}.onEach { it.isVisible = false }
columnList.importData(ColumnList.Immutable.fromList(stubs + defaultColumns), false)
}
}

0 comments on commit 051cc09

Please sign in to comment.