diff --git a/simpleexample2/fxui/src/main/java/simpleex/ui/AbstractFxAppController.java b/simpleexample2/fxui/src/main/java/simpleex/ui/AbstractFxAppController.java index b8f6e976722159a0ee52ca2adc909cafc45f46da..bbdd4dfa1164473b979acbde0e2b2e74dd13aed0 100644 --- a/simpleexample2/fxui/src/main/java/simpleex/ui/AbstractFxAppController.java +++ b/simpleexample2/fxui/src/main/java/simpleex/ui/AbstractFxAppController.java @@ -9,6 +9,7 @@ import fxmapcontrol.MapItemsControl; import fxmapcontrol.MapNode; import fxmapcontrol.MapProjection; import javafx.collections.FXCollections; +import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.geometry.Insets; import javafx.geometry.Point2D; @@ -98,6 +99,14 @@ public abstract class AbstractFxAppController { .addListener((prop, oldValue, newValue) -> updateMapMarker(true)); //connect the cell renderer to the list locationListView.setCellFactory(listView -> new LatLongCell()); + locationListView.addEventHandler(MetaDataEditorController.METADATA_SAVED, new EventHandler<MetaDataEvent>() { + + @Override + public void handle(MetaDataEvent event) { + System.out.println("saved at list level"); + + } + }); } private void handleMapDragged(final Node node, final double dx, final double dy) { diff --git a/simpleexample2/fxui/src/main/java/simpleex/ui/LatLongCell.java b/simpleexample2/fxui/src/main/java/simpleex/ui/LatLongCell.java index 16594d13720a710d0e100b05cbaa1efb86ca39a5..567ed680d22440cb17923c95f18d0edf7cf1512a 100644 --- a/simpleexample2/fxui/src/main/java/simpleex/ui/LatLongCell.java +++ b/simpleexample2/fxui/src/main/java/simpleex/ui/LatLongCell.java @@ -19,7 +19,7 @@ public class LatLongCell extends ListCell<LatLong> { setGraphic(null); setPrefHeight(30.0); } else { - LatLongCellController latLongCellController = new LatLongCellController(); + LatLongCellController latLongCellController = new LatLongCellController(this); latLongCellController.setLatLong(location); setGraphic(latLongCellController.getCellView(this.isSelected())); setPrefHeight(Region.USE_COMPUTED_SIZE); diff --git a/simpleexample2/fxui/src/main/java/simpleex/ui/LatLongCellController.java b/simpleexample2/fxui/src/main/java/simpleex/ui/LatLongCellController.java index 92054f7294cdeaf6712589ca346431dc8cdeb4bb..c450b28df6911b691e8b47103cb9d968d785e80d 100644 --- a/simpleexample2/fxui/src/main/java/simpleex/ui/LatLongCellController.java +++ b/simpleexample2/fxui/src/main/java/simpleex/ui/LatLongCellController.java @@ -3,12 +3,21 @@ package simpleex.ui; import java.util.Iterator; +import javafx.event.ActionEvent; +import javafx.event.Event; +import javafx.event.EventHandler; +import javafx.fxml.FXMLLoader; import javafx.geometry.Insets; +import javafx.scene.Parent; +import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.HBox; import javafx.scene.layout.Region; import javafx.scene.layout.VBox; +import javafx.stage.Modality; +import javafx.stage.Stage; +import javafx.stage.StageStyle; import simpleex.core.LatLong; import simpleex.core.MetaData; @@ -61,12 +70,15 @@ public class LatLongCellController { * the current LatLong object that needs to be displayed */ private LatLong latLong; +private LatLongCell latLongCell; /** * create a new controller for managing a LatLong list cell + * @param latLongCell */ - public LatLongCellController() { + public LatLongCellController(LatLongCell latLongCell) { super(); + this.latLongCell = latLongCell; } /** @@ -89,6 +101,33 @@ public class LatLongCellController { if(selected) { this.editMetadataButton = new Button("..."); this.hBox.getChildren().add(editMetadataButton); + editMetadataButton.setOnAction(event -> { + try { + FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MetaDataEditor.fxml")); + Parent root1 = fxmlLoader.load(); + MetaDataEditorController metaDataEditorController = fxmlLoader.getController(); + metaDataEditorController.setLatLong(this.latLong); + Stage stage = new Stage(); + stage.initModality(Modality.APPLICATION_MODAL); + stage.initStyle(StageStyle.DECORATED); + stage.setTitle("Loction MetaData Editor"); + Scene scene = new Scene(root1); + stage.setScene(scene); + stage.show(); + stage.addEventHandler(MetaDataEditorController.METADATA_SAVED, new EventHandler<MetaDataEvent>() { + + @Override + public void handle(MetaDataEvent event) { + if ( event.getEventType() == MetaDataEditorController.METADATA_SAVED) { + System.out.println("metadata saved click"); + LatLongCellController.this.latLongCell.updateItem(latLong, false); + } + } + } ); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); } if(this.latLong.hasMetaData()) { @@ -131,6 +170,9 @@ public class LatLongCellController { } } + + + /** * get the UI for the cell based on selection and * the available info in the latLong object diff --git a/simpleexample2/fxui/src/main/java/simpleex/ui/MetaDataEditorController.java b/simpleexample2/fxui/src/main/java/simpleex/ui/MetaDataEditorController.java index 67f7f6e2a3ce0b1f19f5a26081aa2a2ccbcef3cd..6d4e8ecf710de293d68601c59434b90af71afc4b 100644 --- a/simpleexample2/fxui/src/main/java/simpleex/ui/MetaDataEditorController.java +++ b/simpleexample2/fxui/src/main/java/simpleex/ui/MetaDataEditorController.java @@ -1,20 +1,38 @@ package simpleex.ui; import javafx.event.ActionEvent; +import javafx.event.Event; +import javafx.event.EventType; import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.TextArea; import javafx.scene.control.TextField; +import javafx.scene.layout.BorderPane; import javafx.scene.layout.VBox; +import javafx.stage.Modality; +import javafx.stage.Stage; +import javafx.stage.StageStyle; import simpleex.core.LatLong; +import simpleex.core.MetaData; import simpleex.ui.tags.TagsBar; + public class MetaDataEditorController { + + public static EventType<MetaDataEvent> OPTIONS_ALL = new EventType<>("OPTIONS_ALL"); + public static EventType<MetaDataEvent> METADATA_SAVED = new EventType<>(OPTIONS_ALL, "METADATA_SAVED"); private LatLong latlong; + @FXML + private BorderPane rootContainer; + @FXML private Button saveButton; @@ -42,9 +60,12 @@ public class MetaDataEditorController { @FXML private TagsBar tagsBar; + @FXML + private Label coordinatesLabel; + @FXML void onCancel(ActionEvent event) { - + closeDialog(event); } @FXML @@ -52,9 +73,19 @@ public class MetaDataEditorController { } + void closeDialog(ActionEvent event) { + Stage stage = (Stage) ((Button) event.getSource()).getScene().getWindow(); + stage.close(); + } + @FXML void onSave(ActionEvent event) { - + latlong.getMetaData().setProperty(MetaData.NAME_PROPERTY, nameInput.getText()); + latlong.getMetaData().setProperty(MetaData.DESCRIPTION_PROPERTY, descriptionInput.getText()); + Event.fireEvent(((Button) event.getSource()).getScene().getWindow(), + new MetaDataEvent(METADATA_SAVED)); + closeDialog(event); + } void setLatLong(LatLong latLong) { @@ -63,8 +94,10 @@ public class MetaDataEditorController { } private void updateUi() { - // TODO Auto-generated method stub - + nameInput.setText(latlong.getMetaData().getProperty(MetaData.NAME_PROPERTY)); + descriptionInput.setText(latlong.getMetaData().getProperty(MetaData.DESCRIPTION_PROPERTY)); + coordinatesLabel.setText(latlong.toString()); } + } diff --git a/simpleexample2/fxui/src/main/java/simpleex/ui/MetaDataEvent.java b/simpleexample2/fxui/src/main/java/simpleex/ui/MetaDataEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..672c6d4d477b6dfad9efcf422d202c471bb5a6b5 --- /dev/null +++ b/simpleexample2/fxui/src/main/java/simpleex/ui/MetaDataEvent.java @@ -0,0 +1,24 @@ +package simpleex.ui; + +import javafx.event.Event; +import javafx.event.EventTarget; +import javafx.event.EventType; + +public class MetaDataEvent extends Event { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public MetaDataEvent(Object source, EventTarget target, EventType<? extends Event> eventType) { + super(source, target, eventType); + // TODO Auto-generated constructor stub + } + + public MetaDataEvent(EventType<? extends Event> eventType) { + super(eventType); + // TODO Auto-generated constructor stub + } + +} diff --git a/simpleexample2/fxui/src/main/resources/simpleex/ui/MetaDataEditor.fxml b/simpleexample2/fxui/src/main/resources/simpleex/ui/MetaDataEditor.fxml index 88be1e25d9997ce11bbcf26ecbada665a03f9bf0..adaae662aa305bc22842555f72d57a897edc4863 100644 --- a/simpleexample2/fxui/src/main/resources/simpleex/ui/MetaDataEditor.fxml +++ b/simpleexample2/fxui/src/main/resources/simpleex/ui/MetaDataEditor.fxml @@ -12,7 +12,7 @@ <?import javafx.scene.layout.VBox?> <?import simpleex.ui.tags.TagsBar?> -<fx:root prefHeight="500.0" prefWidth="600.0" type="BorderPane" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="simpleex.ui.MetaDataEditorController"> +<BorderPane prefHeight="500.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="simpleex.ui.MetaDataEditorController" fx:id="rootContainer"> <bottom> <HBox alignment="CENTER_RIGHT" prefHeight="40.0" prefWidth="600.0" spacing="10.0" BorderPane.alignment="CENTER_RIGHT"> <children> @@ -32,7 +32,7 @@ <HBox prefHeight="23.0" prefWidth="580.0" spacing="10.0"> <children> <Label text="Coordinates:" /> - <Label layoutX="10.0" layoutY="10.0" text="Label" /> + <Label layoutX="10.0" layoutY="10.0" text="Label" fx:id="coordinatesLabel"/> </children> </HBox> <Label text="Description:" /> @@ -52,4 +52,4 @@ </BorderPane.margin> </VBox> </center> -</fx:root> +</BorderPane>