Skip to content
Snippets Groups Projects
Commit 3d030784 authored by George Adrian Stoica's avatar George Adrian Stoica
Browse files

completed editor for both properties and tags

parent 92ce3d21
Branches
No related tags found
1 merge request!6Issue 11 allow user to enter and update metadata about the latlong points
Pipeline #53023 passed
......@@ -5,31 +5,40 @@ import java.util.Collection;
import java.util.Iterator;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventType;
import javafx.fxml.FXML;
import javafx.scene.Node;
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.control.TableColumn.CellDataFeatures;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
import javafx.util.Pair;
import simpleex.core.LatLong;
import simpleex.core.MetaData;
import simpleex.ui.tags.TagsBar;
/*
* Controller class for the location metadata editor
*/
public class MetaDataEditorController {
/*
* Generic metadata event
*/
public static EventType<MetaDataEvent> OPTIONS_ALL = new EventType<>("OPTIONS_ALL");
/*
* Specific metadata event dispatched when the metadata is saved
*/
public static EventType<MetaDataEvent> METADATA_SAVED = new EventType<>(OPTIONS_ALL, "METADATA_SAVED");
private LatLong latlong;
......@@ -38,13 +47,13 @@ public class MetaDataEditorController {
private BorderPane rootContainer;
@FXML
private Button saveButton;
private VBox centerVBox;
@FXML
private Button cancelButton;
private Button saveButton;
@FXML
private VBox centerVBox;
private Button cancelButton;
@FXML
private TextField nameInput;
......@@ -61,6 +70,18 @@ public class MetaDataEditorController {
@FXML
private TableColumn<Pair<String, String>, String> propertyValuesColumn;
@FXML
private TextField newValueInput;
@FXML
private TextField newKeyInput;
@FXML
private Button buttonAddUpdate;
@FXML
private Button buttonDelete;
@FXML
private TagsBar tagsBar;
......@@ -78,8 +99,22 @@ public class MetaDataEditorController {
cellData -> new SimpleStringProperty(
((Pair<String, String>) (cellData.getValue())).getValue()
));
}
propertiesTableView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Pair<String, String>>() {
@Override
public void changed(ObservableValue<? extends Pair<String, String>> observable, Pair<String, String> oldValue, Pair<String, String> newValue) {
if(newValue == null) {
buttonAddUpdate.setDisable(false);
buttonDelete.setDisable(true);
} else {
buttonAddUpdate.setDisable(false);
buttonDelete.setDisable(false);
newKeyInput.setText(newValue.getKey());
newValueInput.setText(newValue.getValue());
}
}
});
}
@FXML
void onCancel(ActionEvent event) {
......@@ -100,10 +135,32 @@ public class MetaDataEditorController {
void onSave(ActionEvent event) {
latlong.getMetaData().setProperty(MetaData.NAME_PROPERTY, nameInput.getText());
latlong.getMetaData().setProperty(MetaData.DESCRIPTION_PROPERTY, descriptionInput.getText());
ObservableList<Pair<String, String>> props = propertiesTableView.getItems();
final Iterator<String> propertyNames = latlong.getMetaData().propertyNames();
if (propertyNames.hasNext()) {
while(propertyNames.hasNext()) {
final String propName = propertyNames.next();
if((propName==MetaData.NAME_PROPERTY)||(propName==MetaData.DESCRIPTION_PROPERTY)) {
continue;
} else {
latlong.getMetaData().removeProperty(propName);
}
}
}
for (Pair<String, String> pair : props) {
latlong.getMetaData().setProperty(pair.getKey(), pair.getValue());
}
final ObservableList<Node> tags = tagsBar.getTags();
latlong.getMetaData().setTags();
for (Node node : tags) {
latlong.getMetaData().addTags(((TagsBar.Tag)node).getTag());
}
Event.fireEvent(((Button) event.getSource()).getScene().getWindow(),
new MetaDataEvent(METADATA_SAVED));
closeDialog(event);
}
void setLatLong(LatLong latLong) {
......@@ -116,6 +173,22 @@ public class MetaDataEditorController {
descriptionInput.setText(latlong.getMetaData().getProperty(MetaData.DESCRIPTION_PROPERTY));
coordinatesLabel.setText(latlong.toString());
updatePropertiesTable();
updateTags();
}
@FXML
public void onAddUpdateProperty(ActionEvent event) {
final String newKey = newKeyInput.getText();
final String newValue = newValueInput.getText();
if(!newKey.isBlank() && (newKey != MetaData.NAME_PROPERTY)
&& (newKey != MetaData.DESCRIPTION_PROPERTY)) {
latlong.getMetaData().setProperty(newKey, newValue);
updatePropertiesTable();
}
}
private void updatePropertiesTable() {
MetaData metaData = latlong.getMetaData();
final Iterator<String> propertyNames = metaData.propertyNames();
Collection<Pair<String, String>> locationProperties = new ArrayList<Pair<String,String>>();
......@@ -130,9 +203,14 @@ public class MetaDataEditorController {
locationProperties.add(p);
}
}
propertiesTableView.getItems().clear();
propertiesTableView.getItems().addAll(locationProperties);
}
}
private void updateTags() {
tagsBar.clearAllTags();
MetaData metaData = latlong.getMetaData();
final Iterator<String> tags = metaData.tags();
if(tags.hasNext()) {
while(tags.hasNext()) {
......@@ -140,8 +218,11 @@ public class MetaDataEditorController {
tagsBar.addTag(tag);
}
}
}
@FXML
public void onDeleteProperty(ActionEvent event) {
int selectedIndex = propertiesTableView.getSelectionModel().getSelectedIndex();
propertiesTableView.getItems().remove(selectedIndex);
}
}
......@@ -36,7 +36,8 @@
</children>
</HBox>
<Label text="Description:" />
<TextArea fx:id="descriptionInput" prefHeight="68.0" prefWidth="580.0" promptText="enter a description for this location" />
<TextArea fx:id="descriptionInput" prefHeight="68.0" prefWidth="580.0"
promptText="enter a description for this location" wrapText="true"/>
<Label text="Custom properties:" />
<TableView fx:id="propertiesTableView" prefHeight="120.0" prefWidth="580.0">
<columns>
......@@ -44,6 +45,14 @@
<TableColumn fx:id="propertyValuesColumn" prefWidth="400.0" text="Value" />
</columns>
</TableView>
<HBox prefWidth="580" spacing="3.0">
<children>
<TextField fx:id="newKeyInput" promptText="Property name"/>
<TextField fx:id="newValueInput" promptText="Property value"/>
<Button fx:id="buttonAddUpdate" onAction="#onAddUpdateProperty" text="Add / Update"/>
<Button fx:id="buttonDelete" onAction="#onDeleteProperty" text="Delete" disable="true"/>
</children>
</HBox>
<Label text="Tags:" />
<TagsBar fx:id="tagsBar" />
</children>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment