- Fix scroll to selected item
- Fix reset field on change station
This commit is contained in:
@@ -3,7 +3,6 @@ package ru.trader.controllers;
|
|||||||
import javafx.beans.property.DoubleProperty;
|
import javafx.beans.property.DoubleProperty;
|
||||||
import javafx.beans.property.ReadOnlyStringProperty;
|
import javafx.beans.property.ReadOnlyStringProperty;
|
||||||
import javafx.beans.property.SimpleDoubleProperty;
|
import javafx.beans.property.SimpleDoubleProperty;
|
||||||
import javafx.collections.ListChangeListener;
|
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
@@ -20,6 +19,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import ru.trader.core.OFFER_TYPE;
|
import ru.trader.core.OFFER_TYPE;
|
||||||
import ru.trader.model.*;
|
import ru.trader.model.*;
|
||||||
import ru.trader.model.support.BindingsHelper;
|
import ru.trader.model.support.BindingsHelper;
|
||||||
|
import ru.trader.view.support.ViewUtils;
|
||||||
import ru.trader.view.support.cells.TextFieldCell;
|
import ru.trader.view.support.cells.TextFieldCell;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -63,12 +63,10 @@ public class VendorEditorController {
|
|||||||
|
|
||||||
public Action showDialog(Parent parent, Parent content, VendorModel vendor){
|
public Action showDialog(Parent parent, Parent content, VendorModel vendor){
|
||||||
this.vendor = vendor;
|
this.vendor = vendor;
|
||||||
|
reset();
|
||||||
if (vendor != null) {
|
if (vendor != null) {
|
||||||
fill();
|
fill();
|
||||||
} else {
|
|
||||||
reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog dlg = new Dialog(parent, vendor == null ? "Добавление станции" : "Редактирование станции");
|
Dialog dlg = new Dialog(parent, vendor == null ? "Добавление станции" : "Редактирование станции");
|
||||||
dlg.setContent(content);
|
dlg.setContent(content);
|
||||||
dlg.getActions().addAll(actSave, Dialog.Actions.CANCEL);
|
dlg.getActions().addAll(actSave, Dialog.Actions.CANCEL);
|
||||||
@@ -114,7 +112,7 @@ public class VendorEditorController {
|
|||||||
if (index>0){
|
if (index>0){
|
||||||
FakeOffer offer = items.getItems().remove(index);
|
FakeOffer offer = items.getItems().remove(index);
|
||||||
items.getItems().add(index-1, offer);
|
items.getItems().add(index-1, offer);
|
||||||
items.getSelectionModel().select(index - 1, items.getColumns().get(0));
|
selectRow(index - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,17 +121,27 @@ public class VendorEditorController {
|
|||||||
if (index>=0 && index<items.getItems().size()-1){
|
if (index>=0 && index<items.getItems().size()-1){
|
||||||
FakeOffer offer = items.getItems().remove(index);
|
FakeOffer offer = items.getItems().remove(index);
|
||||||
items.getItems().add(index+1, offer);
|
items.getItems().add(index+1, offer);
|
||||||
items.getSelectionModel().select(index + 1, items.getColumns().get(0));
|
selectRow(index + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add() {
|
public void add() {
|
||||||
Optional<ItemModel> item = Screeners.showAddItem();
|
Optional<ItemModel> item = Screeners.showAddItem();
|
||||||
if (item.isPresent()){
|
if (item.isPresent()){
|
||||||
items.getItems().add(new FakeOffer(item.get()));
|
int index = items.getSelectionModel().getSelectedIndex();
|
||||||
|
if (index<0) index = items.getItems().size()-1;
|
||||||
|
items.getItems().add(index, new FakeOffer(item.get()));
|
||||||
|
selectRow(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void selectRow(int index){
|
||||||
|
items.requestFocus();
|
||||||
|
items.getSelectionModel().select(index, items.getColumns().get(0));
|
||||||
|
ViewUtils.show(items, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void saveChanges(){
|
public void saveChanges(){
|
||||||
LOG.info("Save vendor changes");
|
LOG.info("Save vendor changes");
|
||||||
|
|||||||
34
client/src/main/java/ru/trader/view/support/ViewUtils.java
Normal file
34
client/src/main/java/ru/trader/view/support/ViewUtils.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package ru.trader.view.support;
|
||||||
|
|
||||||
|
import com.sun.javafx.scene.control.skin.TableViewSkin;
|
||||||
|
import com.sun.javafx.scene.control.skin.VirtualFlow;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.scene.control.TablePosition;
|
||||||
|
import javafx.scene.control.TableView;
|
||||||
|
|
||||||
|
public class ViewUtils {
|
||||||
|
|
||||||
|
//Scroll to row if invisible
|
||||||
|
public static void show(TableView tableView, int index){
|
||||||
|
ObservableList kids = ((TableViewSkin) tableView.getSkin()).getChildren();
|
||||||
|
if (kids == null || kids.isEmpty()) { return; }
|
||||||
|
VirtualFlow flow = (VirtualFlow)kids.get(1);
|
||||||
|
flow.show(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edit next cell
|
||||||
|
public static <S> void editNext(TableView<S> tableView){
|
||||||
|
TableView.TableViewSelectionModel<S> sm = tableView.getSelectionModel();
|
||||||
|
sm.selectNext();
|
||||||
|
ObservableList<TablePosition> pos = sm.getSelectedCells();
|
||||||
|
for (TablePosition p : pos) {
|
||||||
|
if (p.getTableColumn().isEditable()) {
|
||||||
|
show(tableView, p.getRow() > 0 ? p.getRow() : 0);
|
||||||
|
//noinspection unchecked
|
||||||
|
tableView.edit(p.getRow(), p.getTableColumn());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
editNext(tableView);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package ru.trader.view.support.cells;
|
package ru.trader.view.support.cells;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.collections.ObservableList;
|
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.MouseButton;
|
import javafx.scene.input.MouseButton;
|
||||||
@@ -9,6 +8,7 @@ import javafx.util.Callback;
|
|||||||
import javafx.util.StringConverter;
|
import javafx.util.StringConverter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import ru.trader.view.support.ViewUtils;
|
||||||
|
|
||||||
|
|
||||||
public class TextFieldCell<S,T> extends TableCell<S,T> {
|
public class TextFieldCell<S,T> extends TableCell<S,T> {
|
||||||
@@ -94,7 +94,7 @@ public class TextFieldCell<S,T> extends TableCell<S,T> {
|
|||||||
textField.prefWidthProperty().bind(this.getTableColumn().widthProperty());
|
textField.prefWidthProperty().bind(this.getTableColumn().widthProperty());
|
||||||
textField.setOnKeyPressed(t -> {
|
textField.setOnKeyPressed(t -> {
|
||||||
if (t.getCode() == KeyCode.ENTER) {
|
if (t.getCode() == KeyCode.ENTER) {
|
||||||
if (commit(true)) editNext();
|
if (commit(true)) ViewUtils.editNext(getTableView());
|
||||||
} else if (t.getCode() == KeyCode.ESCAPE) {
|
} else if (t.getCode() == KeyCode.ESCAPE) {
|
||||||
textField = null;
|
textField = null;
|
||||||
cancelEdit();
|
cancelEdit();
|
||||||
@@ -132,17 +132,4 @@ public class TextFieldCell<S,T> extends TableCell<S,T> {
|
|||||||
return textField == null;
|
return textField == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void editNext(){
|
|
||||||
TableView.TableViewSelectionModel sm = getTableView().getSelectionModel();
|
|
||||||
sm.selectNext();
|
|
||||||
ObservableList<TablePosition<S,T>> pos = sm.getSelectedCells();
|
|
||||||
for (TablePosition<S,T> p : pos) {
|
|
||||||
if (p.getTableColumn().isEditable()) {
|
|
||||||
getTableView().scrollTo(p.getRow()>0? p.getRow()-1 : 0);
|
|
||||||
getTableView().edit(p.getRow(), p.getTableColumn());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
editNext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user