Commit c665cd25 authored by George Adrian Stoica's avatar George Adrian Stoica

added basic editing for name and description

parent 7aa2893c
Pipeline #52841 passed with stage
in 2 minutes and 13 seconds
......@@ -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) {
......
......@@ -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);
......
......@@ -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
......
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());
}
}
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
}
}
......@@ -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>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment