mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-10-30 02:26:58 +00:00
Added context menu for sheet editor to insert, clone, and delete rows.
This commit is contained in:
parent
d7e4c85e10
commit
31fd48eefd
@ -25,7 +25,6 @@ import javafx.scene.image.WritableImage;
|
|||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Font;
|
||||||
import javafx.scene.text.FontWeight;
|
import javafx.scene.text.FontWeight;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import org.badvision.outlaweditor.Application;
|
|
||||||
import org.badvision.outlaweditor.MapEditor;
|
import org.badvision.outlaweditor.MapEditor;
|
||||||
import org.badvision.outlaweditor.TransferHelper;
|
import org.badvision.outlaweditor.TransferHelper;
|
||||||
import org.badvision.outlaweditor.api.ApplicationState;
|
import org.badvision.outlaweditor.api.ApplicationState;
|
||||||
|
@ -19,7 +19,10 @@ import java.io.File;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.beans.property.SimpleObjectProperty;
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
@ -28,17 +31,23 @@ import javafx.event.ActionEvent;
|
|||||||
import javafx.scene.control.ContextMenu;
|
import javafx.scene.control.ContextMenu;
|
||||||
import javafx.scene.control.MenuItem;
|
import javafx.scene.control.MenuItem;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.TableColumn;
|
||||||
|
import javafx.scene.control.TableRow;
|
||||||
|
import javafx.scene.control.TableView;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.control.cell.TextFieldTableCell;
|
import javafx.scene.control.cell.TextFieldTableCell;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
|
import javafx.util.Callback;
|
||||||
import javafx.util.converter.DefaultStringConverter;
|
import javafx.util.converter.DefaultStringConverter;
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
import org.badvision.outlaweditor.SheetEditor;
|
import org.badvision.outlaweditor.SheetEditor;
|
||||||
|
import org.badvision.outlaweditor.TransferHelper;
|
||||||
import org.badvision.outlaweditor.data.DataUtilities;
|
import org.badvision.outlaweditor.data.DataUtilities;
|
||||||
import static org.badvision.outlaweditor.data.DataUtilities.getValue;
|
import static org.badvision.outlaweditor.data.DataUtilities.getValue;
|
||||||
import static org.badvision.outlaweditor.data.DataUtilities.setValue;
|
import static org.badvision.outlaweditor.data.DataUtilities.setValue;
|
||||||
import org.badvision.outlaweditor.data.xml.Columns;
|
import org.badvision.outlaweditor.data.xml.Columns;
|
||||||
import org.badvision.outlaweditor.data.xml.Rows;
|
import org.badvision.outlaweditor.data.xml.Rows;
|
||||||
import org.badvision.outlaweditor.data.xml.Rows.Row;
|
import org.badvision.outlaweditor.data.xml.Rows.Row;
|
||||||
|
import org.badvision.outlaweditor.data.xml.Script;
|
||||||
import org.badvision.outlaweditor.data.xml.UserType;
|
import org.badvision.outlaweditor.data.xml.UserType;
|
||||||
import org.badvision.outlaweditor.ui.ApplicationUIController;
|
import org.badvision.outlaweditor.ui.ApplicationUIController;
|
||||||
import org.badvision.outlaweditor.ui.SheetEditorController;
|
import org.badvision.outlaweditor.ui.SheetEditorController;
|
||||||
@ -59,6 +68,21 @@ public class SheetEditorControllerImpl extends SheetEditorController {
|
|||||||
tableData = FXCollections.observableArrayList();
|
tableData = FXCollections.observableArrayList();
|
||||||
table.setItems(tableData);
|
table.setItems(tableData);
|
||||||
table.setEditable(true);
|
table.setEditable(true);
|
||||||
|
table.setRowFactory(tableView -> {
|
||||||
|
final TableRow<Row> row = new TableRow<>();
|
||||||
|
|
||||||
|
final ContextMenu contextMenu = new ContextMenu(
|
||||||
|
createMenuItem("Insert Row", () -> tableData.add(row.getIndex(), new Row())),
|
||||||
|
createMenuItem("Clone Row", () -> cloneRow(row.getItem())),
|
||||||
|
createMenuItem("Delete Row", () -> deleteRowWithConfirmation(row.getItem()))
|
||||||
|
);
|
||||||
|
row.contextMenuProperty().bind(
|
||||||
|
Bindings.when(row.emptyProperty())
|
||||||
|
.then((ContextMenu) null)
|
||||||
|
.otherwise(contextMenu)
|
||||||
|
);
|
||||||
|
return row;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -231,6 +255,19 @@ public class SheetEditorControllerImpl extends SheetEditorController {
|
|||||||
return colNumber;
|
return colNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deleteRowWithConfirmation(Row row) {
|
||||||
|
UIAction.confirm("Delete row, are you sure?", ()->tableData.remove(row), ()->{});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cloneRow(Row row) {
|
||||||
|
try {
|
||||||
|
Row newRow = TransferHelper.cloneObject(row, Row.class, "row");
|
||||||
|
tableData.add(tableData.lastIndexOf(row), newRow);
|
||||||
|
} catch (JAXBException ex) {
|
||||||
|
Logger.getLogger(SheetEditorControllerImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void syncData() {
|
private void syncData() {
|
||||||
if (editor.getSheet().getRows() == null) {
|
if (editor.getSheet().getRows() == null) {
|
||||||
editor.getSheet().setRows(new Rows());
|
editor.getSheet().setRows(new Rows());
|
||||||
|
Loading…
Reference in New Issue
Block a user