javafx treeTableView删除项
我有一个JavaFXTreeTableView组件。其中一列中有一个用于删除该行数据的按钮。当单击每一行时,页面的其他位置会显示一些数据。现在,我想删除一行,自动选择另一行。最后,我为糟糕的英语写作道歉 controller.java:javafx treeTableView删除项,java,javafx-2,Java,Javafx 2,我有一个JavaFXTreeTableView组件。其中一列中有一个用于删除该行数据的按钮。当单击每一行时,页面的其他位置会显示一些数据。现在,我想删除一行,自动选择另一行。最后,我为糟糕的英语写作道歉 controller.java: @FXML public TreeTableView<ClientDispatcherConnectionFactory> treeTableView; @FXML TreeTableColumn<ClientDispatcherConnect
@FXML
public TreeTableView<ClientDispatcherConnectionFactory> treeTableView;
@FXML
TreeTableColumn<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory> columnName;
@FXML
TreeTableColumn<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory> refreshColumn;
@FXML
TreeTableColumn<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory> deleteColumn;
private HBox hb = new HBox();
private GridPane downPane = new GridPane();
private Node updateimage = new ImageView(new Image(getClass()
.getResourceAsStream(Utils.getMessage("update"))));
private Node deleteimage = new ImageView(new Image(getClass()
.getResourceAsStream(Utils.getMessage("delete"))));
TreeItem<ClientDispatcherConnectionFactory> container = new TreeItem<ClientDispatcherConnectionFactory>();
TreeItem<ClientDispatcherConnectionFactory> selectedTree;
Stage dialog = null;
void initialize() {
columnName
.setCellValueFactory(new Callback<CellDataFeatures<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory>, ObservableValue<ClientDispatcherConnectionFactory>>() {
@SuppressWarnings({ "rawtypes", "unchecked" })
public ObservableValue<ClientDispatcherConnectionFactory> call(
CellDataFeatures<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory> features) {
return new ReadOnlyObjectWrapper(features.getValue()
.getValue());
}
});
refreshColumn
.setCellValueFactory(new Callback<CellDataFeatures<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory>, ObservableValue<ClientDispatcherConnectionFactory>>() {
@SuppressWarnings({ "rawtypes", "unchecked" })
public ObservableValue<ClientDispatcherConnectionFactory> call(
CellDataFeatures<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory> features) {
return new ReadOnlyObjectWrapper(features.getValue()
.getValue());
}
});
deleteColumn
.setCellValueFactory(new Callback<CellDataFeatures<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory>, ObservableValue<ClientDispatcherConnectionFactory>>() {
@SuppressWarnings({ "rawtypes", "unchecked" })
public ObservableValue<ClientDispatcherConnectionFactory> call(
CellDataFeatures<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory> features) {
return new ReadOnlyObjectWrapper(features.getValue()
.getValue());
}
});
createTreeList();
treeTableView.setRoot(container);
treeTableView.setShowRoot(false);
selectNodeEvent();
treeGenerate();
}
private TreeItem<ClientDispatcherConnectionFactory> createTreeList() {
for (ClientDispatcherConnectionFactory iter : clientDispatchersList) {
TreeItem<ClientDispatcherConnectionFactory> item = new TreeItem<ClientDispatcherConnectionFactory>(
iter);
container.getChildren().add(item);
}
return container;
}
private void treeGenerate() {
refreshColumn
.setCellFactory(new Callback<TreeTableColumn<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory>, TreeTableCell<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory>>() {
public TreeTableCell<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory> call(
TreeTableColumn<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory> btnCol) {
return new TreeTableCell<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory>() {
@SuppressWarnings("static-access")
public void updateItem(
final ClientDispatcherConnectionFactory item,
boolean empty) {
hb = new HBox();
updateimage = new ImageView(new Image(
getClass().getResourceAsStream(
Utils.getMessage("update"))));
Node deleteimage = new ImageView(new Image(
getClass().getResourceAsStream(
Utils.getMessage("delete"))));
updateimage
.setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(
MouseEvent mouseEvent) {
TreeItem<ClientDispatcherConnectionFactory> dispatcher = treeTableView
.getSelectionModel()
.getSelectedItem();
dispatcher
.getValue()
.creatClientDispatcherMBean();
if (dispatcher.getValue()
.safeCheck()) {
RowEnum.clientDispatcher = dispatcher
.getValue()
.getClientDispatcher();
APane.getChildren().clear();
APane.getChildren().add(
scrollVB);
rebindChoiseBoxs();
hb.getChildren().clear();
setGraphic(null);
LOG.info("service is up");
} else {
RowEnum.clientDispatcher = null;
APane.getChildren().clear();
APane.getChildren().add(
pagenotfound);
LOG.info("service is down yet");
}
createTable();
}
});
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
if (item != null) {
if (!(item.safeCheck())) {
selectedTree.setGraphic(serveroffline);
hb.getChildren().clear();
hb.getChildren()
.addAll(updateimage);
hb.setMargin(deleteimage,
new Insets(0, 0, 0, 9));
hb.setMargin(updateimage,
new Insets(0, 0, 0, 9));
setGraphic(hb);
} else {
selectedTree.setGraphic(server);
hb.getChildren().clear();
setGraphic(null);
}
}
}
}
};
}
});
deleteColumn
.setCellFactory(new Callback<TreeTableColumn<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory>, TreeTableCell<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory>>() {
public TreeTableCell<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory> call(
TreeTableColumn<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory> btnCol) {
return new TreeTableCell<ClientDispatcherConnectionFactory, ClientDispatcherConnectionFactory>() {
@SuppressWarnings("static-access")
public void updateItem(
final ClientDispatcherConnectionFactory item,
boolean empty) {
hb = new HBox();
Node deleteimage = new ImageView(new Image(
getClass().getResourceAsStream(
Utils.getMessage("delete"))));
deleteimage
.setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(
MouseEvent mouseEvent) {
String message = "do you want to delete";
Stage stage = (Stage) treeTableView
.getScene().getWindow();
dialog = new MyDialog(stage,
message);
dialog.sizeToScene();
dialog.show();
}
});
noBtn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
dialog.close();
LOG.info("service cleaning canceled");
}
});
yesBtn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
dialog.close();
TreeItem<ClientDispatcherConnectionFactory> deleteItem = treeTableView.getSelectionModel()
.getSelectedItem();
propertiesremove(deleteItem.getValue()
.getConnectionName());
clientDispatchersList.remove(deleteItem
.getValue());
if (clientDispatchersList
.size() == 0) {
treeTableView.getRoot().getChildren()
.clear();
RowEnum.clientDispatcher = null;
createTable();
APane.getChildren().clear();
APane.getChildren().add(
pagenotfound);
selectedClientIndex = 0;
} else{
treeTableView.getSelectionModel().clearSelection();
container.getChildren().clear();
container = createTreeList();
System.out.println(container.getChildren().get(0).getValue());
treeTableView = new TreeTableView<>(container);
// treeTableView.setRoot(container);
System.out.println("deleted"
+ "");
}
}
});
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
if (item != null) {
hb.getChildren().clear();
hb.getChildren().addAll(deleteimage);
hb.setMargin(deleteimage, new Insets(0,
0, 0, 11));
setGraphic(hb);
}
}
}
};
}
});
}
private boolean selectNodeEvent() {
treeTableView
.getSelectionModel()
.selectedItemProperty()
.addListener(
new ChangeListener<TreeItem<ClientDispatcherConnectionFactory>>() {
@Override
public void changed(
ObservableValue<? extends TreeItem<ClientDispatcherConnectionFactory>> observable,
TreeItem<ClientDispatcherConnectionFactory> oldValue,
TreeItem<ClientDispatcherConnectionFactory> newValue) {
treeGenerate();
selectedClientIndex = treeTableView
.getSelectionModel().getSelectedIndex();
if (selectedTree != null) {
selectedTree = newValue;
selectedClient = selectedTree.getValue();
// System.out.println(selectedTree);
if (selectedTree.getValue() != null) {
return;
}
if (selectedTree.getValue().safeCheck()) {
RowEnum.clientDispatcher = selectedTree
.getValue()
.getClientDispatcher();
loadLeftPage(true);
createRoutes(selectedTree.getValue()
.getMbsc());
changeMBeanBtn.setDisable(false);
LOG.info(selectedTree.getValue()
+ " was loaded");
} else {
loadLeftPage(false);
RowEnum.clientDispatcher = null;
}
createTable();
rebindChoiseBoxs();
// factory.updateItem(selectedTree, false);
}
// System.out.println(selectedTree);
// factory.updateItem(selectedTree, true);
}
});
return true;
}
@FXML
公共树视图树视图;
@FXML
TreeTableColumnName;
@FXML
TreeTableColumn刷新列;
@FXML
TreeTableColumn删除column;
专用HBox hb=新HBox();
private GridPane downPane=新建GridPane();
私有节点updateimage=newImageView(新图像(getClass())
.getResourceAsStream(Utils.getMessage(“更新”));
私有节点deleteimage=新图像视图(新图像(getClass)()
.getResourceAsStream(Utils.getMessage(“删除”));
TreeItem容器=新的TreeItem();
TreeItem-selectedTree;
阶段对话框=空;
void initialize(){
列名
.setCellValueFactory(新回调(){
@SuppressWarnings({“rawtypes”,“unchecked”})
公共价值呼叫(
CellDataFeatures){
返回新的ReadOnlyObjectWrapper(features.getValue()
.getValue());
}
});
刷新列
.setCellValueFactory(新回调(){
@SuppressWarnings({“rawtypes”,“unchecked”})
公共价值呼叫(
CellDataFeatures){
返回新的ReadOnlyObjectWrapper(features.getValue()
.getValue());
}
});
删除列
.setCellValueFactory(新回调(){
@SuppressWarnings({“rawtypes”,“unchecked”})
公共价值呼叫(
CellDataFeatures){
返回新的ReadOnlyObjectWrapper(features.getValue()
.getValue());
}
});
createTreeList();
treeTableView.setRoot(容器);
treeTableView.setShowRoot(false);
选择nodeEvent();
treeGenerate();
}
私有树Item createTreeList(){
对于(客户端DispatcherConnectionFactory iter:ClientDispatcherList){
TreeItem=新的TreeItem(
iter);
container.getChildren().add(项);
}
返回容器;
}
私有无效树生成(){
刷新列
.setCellFactory(新回调函数(){
公用树电话(
三级柱(btnCol){
返回新的TreeTableCell(){
@抑制警告(“静态访问”)
公共无效更新项(
最终客户DispatcherConnectionFactory项目,
布尔值(空){
hb=新的HBox();
updateimage=新图像视图(新图像(
getClass().getResourceAsStream(
Utils.getMessage(“更新”);
节点deleteimage=新图像视图(新图像(
getClass().getResourceAsStream(
Utils.getMessage(“删除”);
更新图像
.setOnMouseClicked(新的EventHandler(){
公共无效句柄(
MouseEvent(MouseEvent){
TreeItem dispatcher=treeTableView
.getSelectionModel()
.getSelectedItem();
调度员
.getValue()
.creatClientDispatcherMBean();
if(dispatcher.getValue()
.safeCheck()){
RowEnum.clientDispatcher=调度程序
.getValue()
.getClientDispatcher();
APane.getChildren().clear();
APane.getChildren().add(
(vb);
Rebindchioseboxs();
hb.getChildren().clear();
设置图形(空);
LOG.info(“服务启动”);
}否则{
RowEnum.clientDispatcher=null;
APane.getChildren().clear();
APane.getChildren().add(
pagenotfound);
LOG.info(“服务已关闭”);
}
createTable();
}
});
super.updateItem(项,空);
if(空){
setText(空);
设置图形(空);
}否则{
如果(项!=null){
如果(!(item.safeCheck()){
选择Tree.setGraphic(服务器脱机);
hb.getChildren().clear();
hb.getChildren()