Skip to content

Commit 139f24c

Browse files
committed
Importer chooser page rewritten in JavaFX
1 parent 01daae9 commit 139f24c

File tree

5 files changed

+69
-117
lines changed

5 files changed

+69
-117
lines changed

ganttproject/src/main/java/net/sourceforge/ganttproject/export/ExportFileChooserPage.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ import javax.swing.filechooser.FileFilter
4343
internal class ExportFileChooserPage(
4444
private val myState: ExportFileWizardImpl.State,
4545
private val myProject: IGanttProject,
46-
prefs: Preferences,
46+
override val preferences: Preferences,
4747
uiFacade: UIFacade?
4848
) : FileChooserPageBase(
49-
prefs, myProject.document, uiFacade,
49+
myProject.document, uiFacade,
5050
fileChooserTitle = i18n.formatText("selectFileToExport"),
5151
fileChooserSelectionMode = JFileChooser.FILES_AND_DIRECTORIES,
5252
pageTitle = i18n.formatText("selectFileToExport")

ganttproject/src/main/java/net/sourceforge/ganttproject/export/ExporterChooserPageFx.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
1+
/*
2+
* Copyright (c) 2026 Dmitry Barashev, BarD Software s.r.o.
3+
*
4+
* This file is part of GanttProject, an open-source project management tool.
5+
*
6+
* GanttProject is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* GanttProject is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with GanttProject. If not, see <http://www.gnu.org/licenses/>.
18+
*/
219
package net.sourceforge.ganttproject.export
320

421
import biz.ganttproject.app.*
@@ -7,6 +24,9 @@ import net.sourceforge.ganttproject.export.ExportFileWizardImpl.State
724
import net.sourceforge.ganttproject.gui.projectwizard.WizardPage
825
import java.awt.Component
926

27+
/**
28+
* This is the first page of the export wizard that allows the user to choose an exporter.
29+
*/
1030
class ExporterChooserPageFx(exporters: List<Exporter>, private val model: State) : WizardPage {
1131
override val title: String = i18n.formatText("option.exporter.title")
1232
override val component: Component? = null

ganttproject/src/main/java/net/sourceforge/ganttproject/gui/FileChooserPageBase.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import javax.swing.filechooser.FileFilter
4040
* Base class for the file chooser pages in the Import and Export wizards.
4141
*/
4242
abstract class FileChooserPageBase protected constructor(
43-
protected val preferences: Preferences,
4443
private val myDocument: Document?,
4544
uiFacade: UIFacade?,
4645
val fileChooserTitle: String?,
@@ -52,6 +51,9 @@ abstract class FileChooserPageBase protected constructor(
5251
tryChosenFile(file)
5352
}
5453
}
54+
55+
abstract val preferences: Preferences
56+
5557
private val myOptionsBuilder: OptionsPageBuilder = OptionsPageBuilder().also {
5658
it.i18N = object : OptionsPageBuilder.I18N() {
5759
protected override fun hasValue(key: String): Boolean {

ganttproject/src/main/java/net/sourceforge/ganttproject/importer/ImportFileWizard.kt

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,22 @@
1818
*/
1919
package net.sourceforge.ganttproject.importer
2020

21-
import biz.ganttproject.app.RootLocalizer
21+
import biz.ganttproject.app.*
2222
import biz.ganttproject.core.option.GPOptionGroup
2323
import com.github.michaelbull.result.Err
2424
import com.github.michaelbull.result.Ok
2525
import com.github.michaelbull.result.Result
2626
import com.github.michaelbull.result.andThen
2727
import javafx.beans.property.SimpleObjectProperty
2828
import javafx.scene.Node
29-
import javafx.scene.control.Label
3029
import net.sourceforge.ganttproject.IGanttProject
3130
import net.sourceforge.ganttproject.filter.ExtensionBasedFileFilter
3231
import net.sourceforge.ganttproject.gui.FileChooserPageBase
3332
import net.sourceforge.ganttproject.gui.UIFacade
3433
import net.sourceforge.ganttproject.gui.projectwizard.WizardModel
3534
import net.sourceforge.ganttproject.gui.projectwizard.WizardPage
3635
import net.sourceforge.ganttproject.gui.projectwizard.showWizard
37-
import net.sourceforge.ganttproject.plugins.PluginManager.*
36+
import net.sourceforge.ganttproject.plugins.PluginManager.getExtensions
3837
import org.osgi.service.prefs.Preferences
3938
import java.awt.Component
4039
import java.io.File
@@ -52,7 +51,7 @@ class ImportFileWizard(uiFacade: UIFacade, project: IGanttProject, pluginPrefere
5251
filePage.selectedFileProperty.addListener { _, _, _ ->
5352
wizardModel.needsRefresh.set(true, this)
5453
}
55-
wizardModel.addPage(ImporterChooserPage(importers, uiFacade, pluginPreferences, wizardModel))
54+
wizardModel.addPage(ImporterChooserPageFx(importers, wizardModel))
5655
wizardModel.addPage(filePage)
5756
wizardModel.customPageProperty.addListener { _, oldValue, newValue ->
5857
if (oldValue == null && newValue != null) {
@@ -68,6 +67,9 @@ class ImportFileWizard(uiFacade: UIFacade, project: IGanttProject, pluginPrefere
6867
}
6968
}
7069

70+
// --------------------------------------------------------------------------------------------------------------------
71+
// --------------------------------------------------------------------------------------------------------------------
72+
7173
/**
7274
* Model for the import wizard, managing importer and file selection.
7375
*/
@@ -78,6 +80,7 @@ class ImporterWizardModel: WizardModel() {
7880
field = value
7981
customPageProperty.set(null)
8082
value?.customPage?.let { customPageProperty.set(it) }
83+
needsRefresh.set(true, this)
8184
}
8285

8386
// Selected file.
@@ -105,36 +108,57 @@ private fun getImporters(): MutableList<Importer> {
105108
return getExtensions(Importer.EXTENSION_POINT_ID, Importer::class.java)
106109
}
107110

108-
private class ImporterChooserPageFx(
109-
importers: List<Importer>,
110-
uiFacade: UIFacade,
111-
pluginPreferences: Preferences,
112-
wizardModel: ImporterWizardModel
113-
) : WizardPage {
114-
override val title: String = i18n.formatText("importerChooserPageTitle")
115-
override val component: Component?
116-
get() = null
111+
// --------------------------------------------------------------------------------------------------------------------
112+
// --------------------------------------------------------------------------------------------------------------------
117113

118-
override fun setActive(b: Boolean) {
114+
/**
115+
* The first page in the import wizard that allows the user to choose an importer.
116+
*/
117+
private class ImporterChooserPageFx(importers: List<Importer>, model: ImporterWizardModel) : WizardPage {
118+
override val title: String = RootLocalizer.formatText("importerChooserPageTitle")
119+
120+
private val titles = importers.flatMapIndexed { index, importer -> listOf(
121+
"title.$index" to { LocalizedString(importer.fileTypeDescription, DummyLocalizer)},
122+
"title.$index.help" to { LocalizedString("", DummyLocalizer)}
123+
)}.toMap()
124+
125+
override val fxComponent: Node? by lazy {
126+
val optionPaneBuilder = OptionPaneBuilder<Importer>().apply {
127+
this.i18n = MappingLocalizer(titles, DummyLocalizer::create)
128+
this.styleClass = "exporter-chooser-page"
129+
elements = importers.mapIndexed { index, importer ->
130+
OptionElementData("title.${index}", importer, isSelected = (index == 0),
131+
customContent = null)
132+
}
133+
onSelect = { model.importer = it }
134+
}
135+
optionPaneBuilder.buildPane()
119136
}
120137

121-
override val fxComponent: Node by lazy {
122-
Label("foo")
138+
override val component: Component? = null
139+
140+
override fun setActive(b: Boolean) {
123141
}
124142
}
143+
144+
// --------------------------------------------------------------------------------------------------------------------
145+
// --------------------------------------------------------------------------------------------------------------------
146+
125147
/**
126148
* Wizard page for choosing a file to import from.
127149
*/
128150
private class ImportFileChooserPage(
129-
private val state: ImporterWizardModel, project: IGanttProject, prefs: Preferences, uiFacade: UIFacade)
130-
: FileChooserPageBase(prefs, project.document, uiFacade, fileChooserTitle = "",
151+
private val state: ImporterWizardModel, project: IGanttProject, private val prefs: Preferences, uiFacade: UIFacade)
152+
: FileChooserPageBase(project.document, uiFacade, fileChooserTitle = "",
131153
pageTitle = i18n.formatText("importerFileChooserPageTitle")) {
132154

133155
val importer get() = state.importer
134156

157+
override val preferences: Preferences get() = prefs.node(state.importer?.id ?: "")
158+
135159
init {
136160
hasOverwriteOption = false
137-
selectedFileProperty.addListener { value, file, newValue ->
161+
selectedFileProperty.addListener { _, _, newValue ->
138162
state.file = newValue
139163
}
140164
}
@@ -144,7 +168,6 @@ private class ImportFileChooserPage(
144168
return ExtensionBasedFileFilter(it.getFileNamePattern(), it.getFileTypeDescription())
145169
}
146170

147-
148171
override val optionGroups: List<GPOptionGroup> = emptyList()
149172

150173
override fun validateFile(file: File?): Result<File?, String?> {

ganttproject/src/main/java/net/sourceforge/ganttproject/importer/ImporterChooserPage.java

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)