Skip to content

Commit

Permalink
Refactored workspace to delegate fully to project service for all pro…
Browse files Browse the repository at this point in the history
…ject functions. All UI updates now update project in memory immediately.
  • Loading branch information
SergeMerzliakov committed Dec 8, 2019
1 parent 5a48bfe commit b47925d
Show file tree
Hide file tree
Showing 20 changed files with 229 additions and 308 deletions.
37 changes: 12 additions & 25 deletions src/main/kotlin/org/installmation/controller/BinariesController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,25 @@ import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import org.installmation.configuration.Configuration
import org.installmation.configuration.UserHistory
import org.installmation.core.OperatingSystem
import org.installmation.javafx.ComboUtils
import org.installmation.model.*
import org.installmation.model.JDKListUpdatedEvent
import org.installmation.model.ModuleJmodUpdatedEvent
import org.installmation.model.ModuleLibUpdatedEvent
import org.installmation.model.NamedDirectory
import org.installmation.model.binary.JDK
import org.installmation.model.binary.JDKFactory
import org.installmation.core.OperatingSystem
import org.installmation.service.ProjectBeginSaveEvent
import org.installmation.service.ProjectClosedEvent
import org.installmation.service.ProjectLoadedEvent
import org.installmation.service.ProjectService
import org.installmation.service.Workspace
import org.installmation.ui.dialog.BinaryArtefactDialog
import org.installmation.ui.dialog.HelpDialog


class BinariesController(private val configuration: Configuration,
private val userHistory: UserHistory) {
private val userHistory: UserHistory,
private val workspace: Workspace) {

companion object {
val log: Logger = LogManager.getLogger(BinariesController::class.java)
Expand Down Expand Up @@ -82,7 +86,6 @@ class BinariesController(private val configuration: Configuration,
@FXML
fun initialize() {
initializeConfiguredBinaries()
initializeListeners()
}

/**
Expand All @@ -104,27 +107,11 @@ class BinariesController(private val configuration: Configuration,
moduleJmodComboBox.converter = StringConverterFactory.namedItemConverter(moduleJmodComboBox.items)
}

/**
* Selection and other listeners
*/
private fun initializeListeners() {
moduleJmodComboBox.selectionModel.selectedItemProperty()
.addListener { _, old, new ->
if (old != null)
configuration.eventBus.post(ModuleJmodDeselectedEvent(old))
if (new != null)
configuration.eventBus.post(ModuleJmodSelectedEvent(new))
}

moduleLibComboBox.selectionModel.selectedItemProperty()
.addListener { _, old, new ->
if (old != null)
configuration.eventBus.post(ModuleLibDeselectedEvent(old))
if (new != null)
configuration.eventBus.post(ModuleLibSelectedEvent(new))
}
@FXML
fun updateProject() {
workspace.saveProject()
}

@FXML
fun configureModuleLibraries() {
val dialog = moduleLibraryDialog()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,29 @@ import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import org.installmation.configuration.Configuration
import org.installmation.configuration.UserHistory
import org.installmation.model.ModuleJmodDeselectedEvent
import org.installmation.model.ModuleJmodSelectedEvent
import org.installmation.service.ProjectBeginSaveEvent
import org.installmation.service.ProjectClosedEvent
import org.installmation.service.ProjectLoadedEvent
import org.installmation.service.Workspace
import org.installmation.ui.dialog.ChooseDirectoryDialog
import org.installmation.ui.dialog.HelpDialog
import org.installmation.ui.dialog.SimpleListItemDeleter
import java.io.File


class DependenciesController(private val configuration: Configuration,
private val userHistory: UserHistory) {
private val userHistory: UserHistory,
private val workspace: Workspace) {

companion object {
val log: Logger = LogManager.getLogger(DependenciesController::class.java)
const val PROPERTY_HELP_MODULES = "help.modules"
}

@FXML lateinit var classPathListView: ListView<String>
@FXML lateinit var moduleListView: ListView<String>
@FXML lateinit var classpathListContextMenu: ContextMenu
@FXML lateinit var moduleListContextMenu: ContextMenu

// model
private val classpathItems: ObservableList<String> = FXCollections.observableArrayList<String>()
private val moduleItems: ObservableList<String> = FXCollections.observableArrayList<String>()

init {
configuration.eventBus.register(this)
Expand All @@ -63,50 +59,26 @@ class DependenciesController(private val configuration: Configuration,
@FXML
fun initialize() {
classPathListView.items = classpathItems.sorted()
moduleListView.items = moduleItems.sorted()

initializeContextMenus()
}

private fun initializeContextMenus() {
val removeClassPathItem = MenuItem("Remove")
removeClassPathItem.onAction = SimpleListItemDeleter(classPathListView, classpathItems)
classpathListContextMenu.items.add(removeClassPathItem)

val removeModuleItem = MenuItem("Remove")
removeModuleItem.onAction = SimpleListItemDeleter(moduleListView, moduleItems)
moduleListContextMenu.items.add(removeModuleItem)
}

@FXML
fun addClasspathItem() {
val result = ChooseDirectoryDialog.showAndWait(moduleListView.scene.window as Stage, "Add Classpath Item", userHistory)
val result = ChooseDirectoryDialog.showAndWait(classPathListView.scene.window as Stage, "Add Classpath Item", userHistory)
if (result.ok) {
classpathItems.add(result.data!!.path)
// TODO - Here
//workspace.currentProject

workspace.saveProject()
log.debug("Added ${result.data.path} to classpath")
}
}

@FXML
fun addModuleItem() {
val result = ChooseDirectoryDialog.showAndWait(moduleListView.scene.window as Stage, "Add Module Item", userHistory)
if (result.ok) {
moduleItems.add(result.data!!.path)
// TODO - Here
//workspace.currentProject
log.debug("Added ${result.data.path} to modules")
}
private fun initializeContextMenus() {
val removeClassPathItem = MenuItem("Remove")
removeClassPathItem.onAction = SimpleListItemDeleter(classPathListView, classpathItems)
classpathListContextMenu.items.add(removeClassPathItem)
}


@FXML
fun helpModules() {
HelpDialog.showAndWait("Module Paths", configuration.resourceBundle.getString(PROPERTY_HELP_MODULES))
}

//-------------------------------------------------------
// Event Subscribers
//-------------------------------------------------------
Expand All @@ -115,13 +87,9 @@ class DependenciesController(private val configuration: Configuration,
fun handleProjectLoaded(e: ProjectLoadedEvent) {
checkNotNull(e.project)
classpathItems.clear()
moduleItems.clear()

for (cp in e.project.classPath)
classpathItems.add(cp.path)

for (m in e.project.modulePath)
moduleItems.add(m.path)
}

@Subscribe
Expand All @@ -131,30 +99,11 @@ class DependenciesController(private val configuration: Configuration,
// as well
for (path in classPathListView.items)
e.project.classPath.add(File(path))
for (m in moduleItems)
e.project.modulePath.add(File(m))
}

@Subscribe
fun handleProjectClosed(e: ProjectClosedEvent) {
classpathItems.clear()
moduleItems.clear()
}

/**
* Add JFX modules to modules list
*/
@Subscribe
fun handleJFXModuleSelectedEvent(e: ModuleJmodDeselectedEvent) {
moduleItems.remove(e.deselected.path.path)
}

/**
* Add JFX modules to modules list
*/
@Subscribe
fun handleJFXModuleSelectedEvent(e: ModuleJmodSelectedEvent) {
moduleItems.add(e.selected.path.path)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import java.io.File


class ExecutableController(configuration: Configuration,
private val userHistory: UserHistory) {
private val userHistory: UserHistory,
private val workspace: Workspace) {

companion object {
val log: Logger = LogManager.getLogger(ExecutableController::class.java)
Expand All @@ -56,6 +57,11 @@ class ExecutableController(configuration: Configuration,
}
}

@FXML
fun updateProject() {
workspace.saveProject()
}

//-------------------------------------------------------
// Event Subscribers
//-------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ class GeneralInfoController(configuration: Configuration, private val workspace:
installerTypeCombo.items = FXCollections.observableList(OperatingSystem.installerType())
}


@FXML
fun changeInstallerType() {
fun updateProject() {
workspace.saveProject()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ import org.apache.logging.log4j.Logger
import org.installmation.configuration.Configuration
import org.installmation.configuration.UserHistory
import org.installmation.core.*
import org.installmation.model.*
import org.installmation.model.JDKListUpdatedEvent
import org.installmation.model.ModuleJmodUpdatedEvent
import org.installmation.model.NamedDirectory
import org.installmation.service.*
import org.installmation.ui.dialog.*


/**
* Main Application controller, with nested controllers
*/
class InstallmationController(private val configuration: Configuration,
private val userHistory: UserHistory,
private val workspace: Workspace,
Expand All @@ -63,18 +67,17 @@ class InstallmationController(private val configuration: Configuration,
@FXML private lateinit var generateImageTooltip :Tooltip
@FXML private lateinit var generateInstallerTooltip : Tooltip

private var dependenciesController = DependenciesController(configuration, userHistory)
private var dependenciesController = DependenciesController(configuration, userHistory, workspace)

private var locationController = LocationController(configuration,
userHistory,
workspace,
projectService)
workspace)

private var binariesController = BinariesController(configuration, userHistory)
private var binariesController = BinariesController(configuration, userHistory, workspace)

private var generalInfoController = GeneralInfoController(configuration, workspace)

private var executeController = ExecutableController(configuration, userHistory)
private var executeController = ExecutableController(configuration, userHistory, workspace)

// models
private val userMessages: ObservableList<String> = FXCollections.observableArrayList<String>()
Expand Down Expand Up @@ -135,19 +138,20 @@ class InstallmationController(private val configuration: Configuration,
val result = ChooseFileDialog.showAndWait(applicationStage(), "Open Project", userHistory, InstallmationExtensionFilters.projectFilter())

if (result.ok) {
val p = projectService.loadProject(result.data!!.nameWithoutExtension)
val p = projectService.load(result.data!!.nameWithoutExtension)
workspace.setCurrentProject(p)
}
}

@FXML
fun closeProject() {
projectService.closeProject(workspace.currentProject)
projectService.close(workspace.currentProject)
}

@FXML
fun saveProject() {
workspace.saveProject()
workspace.saveProject()
workspace.writeToFile()
}

@FXML
Expand Down Expand Up @@ -263,7 +267,8 @@ class InstallmationController(private val configuration: Configuration,
@FXML
fun jdepsDialog() {
//combined JFX mods with other mods
val d = JdepsDialog(applicationStage(), configuration.jdkEntries.values, workspace.currentProject?.mainJar, workspace.currentProject?.classPath, workspace.currentProject?.modulePath)
val p = workspace.currentProject
val d = JdepsDialog(applicationStage(), configuration.jdkEntries.values, p?.javaFXLib!!.path, p.mainJar, p.classPath)
d.showAndWait()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@ import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import org.installmation.configuration.Configuration
import org.installmation.configuration.UserHistory
import org.installmation.service.Workspace
import org.installmation.service.ProjectBeginSaveEvent
import org.installmation.service.ProjectClosedEvent
import org.installmation.service.ProjectLoadedEvent
import org.installmation.service.ProjectService
import org.installmation.service.Workspace
import org.installmation.ui.dialog.ChooseDirectoryDialog
import org.installmation.ui.dialog.HelpDialog
import java.io.File


class LocationController(private val configuration: Configuration,
private val userHistory: UserHistory,
private val workspace: Workspace,
private val projectService: ProjectService) {
private val workspace: Workspace) {

companion object {
val log: Logger = LogManager.getLogger(LocationController::class.java)
Expand Down Expand Up @@ -114,7 +112,12 @@ class LocationController(private val configuration: Configuration,
fun helpInstallerDirectory() {
HelpDialog.showAndWait("Installer Directory", configuration.resourceBundle.getString(PROPERTY_HELP_INSTALLER_DIR))
}


@FXML
fun updateProject() {
workspace.saveProject()
}

//-------------------------------------------------------
// Event Subscribers
//-------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/org/installmation/model/InstallProject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class InstallProject {
var inputDirectory: File? = null
var imageBuildDirectory: File? = null //output
var installerDirectory: File? = null //output
// not used now - in future for modular applications
var modulePath = mutableSetOf<File>()
var classPath = mutableSetOf<File>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package org.installmation.model.binary

import org.installmation.model.FlagArgument
import org.installmation.model.ValueArgument
import java.io.File

class ModuleDependenciesGenerator(val jdeps: JDepsExecutable, val classPath: String, val modulePath: String, val mainJar: String) {
class ModuleDependenciesGenerator(val jdeps: JDepsExecutable, val classPath: String, val javaFxLibs: File, val mainJar: String) {

var output = mutableListOf<String>()

Expand All @@ -12,7 +13,7 @@ class ModuleDependenciesGenerator(val jdeps: JDepsExecutable, val classPath: Str
*/
fun generate(): List<String> {
jdeps.parameters.addArgument(FlagArgument("-s"))
jdeps.parameters.addArgument(ValueArgument("--module-path", modulePath))
jdeps.parameters.addArgument(ValueArgument("--module-path", javaFxLibs.path))
jdeps.parameters.addArgument(ValueArgument("-classpath", classPath))
jdeps.parameters.addArgument(FlagArgument(mainJar))
val processOutput = jdeps.execute(15)
Expand Down
Loading

0 comments on commit b47925d

Please sign in to comment.