-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Travel Planner to use MVVM instead of MVC
- Loading branch information
Showing
5 changed files
with
94 additions
and
57 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...irst Access Control/Example/src/main/scala/lofi_acl/example/monotonic_acl/MainScene.scala
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,40 @@ | ||
package lofi_acl.example.monotonic_acl | ||
|
||
import scalafx.geometry.Pos | ||
import scalafx.scene.Scene | ||
import scalafx.scene.control.{Button, TextField} | ||
import scalafx.scene.layout.{BorderPane, HBox, VBox} | ||
|
||
class MainScene extends Scene { | ||
private val viewModel = new MainSceneViewModel() | ||
private val rootPane = new BorderPane() | ||
|
||
private val createNewDocumentButton: Button = new Button("Create new Travel Plan Document") | ||
createNewDocumentButton.alignment = Pos.Center | ||
createNewDocumentButton.onAction = _ => viewModel.createNewDocumentButtonPressed() | ||
createNewDocumentButton.disable <== viewModel.documentIsOpen | ||
|
||
private val joinDocumentButton: Button = new Button("Join") | ||
joinDocumentButton.alignment = Pos.Center | ||
joinDocumentButton.onAction = _ => viewModel.joinDocumentButtonPressed() | ||
joinDocumentButton.disable <== viewModel.documentIsOpen | ||
|
||
private val remoteDocumentUriTextField = new TextField { | ||
promptText = "user@host:port" | ||
// hgrow = Priority.Always | ||
} | ||
remoteDocumentUriTextField.disable <== viewModel.documentIsOpen | ||
remoteDocumentUriTextField.text <==> viewModel.joinDocumentUri | ||
|
||
rootPane.center = VBox( | ||
createNewDocumentButton, | ||
HBox( | ||
remoteDocumentUriTextField, | ||
joinDocumentButton | ||
) | ||
) | ||
|
||
content = rootPane | ||
|
||
// TODO: Hook in the document view on document open | ||
} |
38 changes: 38 additions & 0 deletions
38
...ss Control/Example/src/main/scala/lofi_acl/example/monotonic_acl/MainSceneViewModel.scala
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,38 @@ | ||
package lofi_acl.example.monotonic_acl | ||
|
||
import scalafx.beans.property.{BooleanProperty, StringProperty} | ||
import scalafx.scene.layout.StackPane | ||
|
||
import scala.concurrent.ExecutionContext.global | ||
|
||
class MainSceneViewModel { | ||
private var model: Option[TravelPlanModel] = None | ||
|
||
val bucketListViewContainer: StackPane = new StackPane() | ||
bucketListViewContainer.minWidth = 400 | ||
bucketListViewContainer.minHeight = 800 | ||
|
||
val expenseViewContainer: StackPane = new StackPane() | ||
expenseViewContainer.minWidth = 400 | ||
expenseViewContainer.minHeight = 800 | ||
|
||
val documentIsOpen: BooleanProperty = new BooleanProperty() | ||
documentIsOpen.value = false | ||
|
||
val joinDocumentUri: StringProperty = new StringProperty() | ||
|
||
def createNewDocumentButtonPressed(): Unit = { | ||
require(model.isEmpty) | ||
documentIsOpen.value = true | ||
global.execute { () => | ||
model = Some(TravelPlanModel(None)) | ||
} | ||
} | ||
|
||
def joinDocumentButtonPressed(): Unit = { | ||
documentIsOpen.value = true | ||
global.execute { () => | ||
model = Some(TravelPlanModel(Some(joinDocumentUri.value))) | ||
} | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
...Access Control/Example/src/main/scala/lofi_acl/example/monotonic_acl/TravelPlanView.scala
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,5 @@ | ||
package lofi_acl.example.monotonic_acl | ||
|
||
class TravelPlanView { | ||
|
||
} |
45 changes: 5 additions & 40 deletions
45
...cess Control/Example/src/main/scala/lofi_acl/example/monotonic_acl/TravelPlannerApp.scala
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 |
---|---|---|
@@ -1,50 +1,15 @@ | ||
package lofi_acl.example.monotonic_acl | ||
|
||
import scalafx.application.JFXApp3 | ||
import scalafx.scene.Scene | ||
import scalafx.scene.control.{Button, TextField} | ||
import scalafx.scene.layout.VBox | ||
|
||
object TravelPlannerAppMonotonic extends TravelPlannerApp | ||
|
||
class TravelPlannerApp extends JFXApp3 { | ||
var controller: Option[TravelPlannerController] = None | ||
|
||
object TravelPlannerApp extends JFXApp3 { | ||
override def start(): Unit = { | ||
val createNewDocumentButton = new Button { | ||
text = "Create new travel plan" | ||
onAction = ev => { | ||
controller = Some(TravelPlannerController.forNewDocument) | ||
} | ||
} | ||
|
||
val remoteDocumentUriTextField = new TextField { | ||
promptText = "user@host:port" | ||
// hgrow = Priority.Always | ||
} | ||
|
||
val joinDocumentButton = new Button { | ||
text = "Join travel document" | ||
onAction = ev => { | ||
controller = Some(TravelPlannerController.forExistingDocument(remoteDocumentUriTextField.getText)) | ||
} | ||
} | ||
|
||
stage = new JFXApp3.PrimaryStage { | ||
title.value = s"App with replicaId: ???" | ||
scene = new Scene { | ||
content = new VBox { | ||
children = Seq( | ||
createNewDocumentButton, | ||
remoteDocumentUriTextField, | ||
joinDocumentButton | ||
) | ||
} | ||
} | ||
title = s"Travel Planner" | ||
scene = new MainScene() | ||
resizable = true | ||
} | ||
} | ||
|
||
override def stopApp(): Unit = { | ||
controller.foreach(_.shutdown()) | ||
} | ||
override def stopApp(): Unit = {} | ||
} |