gpt4 book ai didi

java - Vaadin - 使添加的项目可选择(和可编辑)

转载 作者:行者123 更新时间:2023-12-01 09:00:54 27 4
gpt4 key购买 nike

我希望在通过单击添加按钮添加新添加的表项(又称行)后立即可以选择它。我的主要目的是使其既可选择又可编辑(但仅限该行,现在是整个表格)。

这是表格代码:

            public Table createTable(BeanContainer<Long, PS_SECTION> beans) {       
table.setImmediate(true);
table.setContainerDataSource(beans);
table.setColumnHeader("PS_SECTION", "ID");
table.setColumnHeader("NAME", "SECTION");
table.setColumnHeader("VORDER","ORDER");

table.addGeneratedColumn("ACTIVE", new Table.ColumnGenerator() {

@Override
public Object generateCell(final Table source, final Object itemId,
Object columnId) {

table.setTableFieldFactory(new DefaultFieldFactory() {

@Override
public Field<?> createField(Container container, final Object itemId, Object propertyId, Component uiContext) {

if (!itemId.equals(table.getValue())) {
return null;
}
Field<?> field = super.createField(container, itemId, propertyId, uiContext);
field.setBuffered(true);

return field;
}
});


table.addValueChangeListener(new Property.ValueChangeListener() {
@Override
public void valueChange(Property.ValueChangeEvent event) {
if (table.getValue() != null) {
editButton.setVisible(true);
}
else {
editButton.setVisible(false);
}
}
});

table.addItemClickListener(new ItemClickEvent.ItemClickListener() {
@Override
public void itemClick(ItemClickEvent itemClickEvent) {
if (itemClickEvent.isDoubleClick() && !table.isEditable()) {
table.setValue(itemClickEvent.getItemId());
configureEditable(true);
// THE FUNCTION THAT MAKES THE SELECTED ROW EDITABLE
editButton.setVisible(false);
addButton.setVisible(false);
}
}
});


// ....SOME MORE TABLE ATTRIBUTES HERE....

return table;
}

上面的代码对于选定的行可以正常工作,但是如何使新添加的行直接被选中并可编辑?

addButton.addClickListener(new ClickListener() {            
@Override
public void buttonClick(ClickEvent event) {
addList(); //HERE THE ROW (AND THE BEAN) IS ADDED

/**
* What to put here?
*
*/
configureEditable(true);

}
});

最佳答案

Object itemId = createNewBean();//创建一个新的bean,返回一个可以设置为新项目id的唯一id。

table.addItem(itemId); //add this newly created item to the table
//set the column values here for this particular item
table.getItem(itemId).getProperty("column_name").setValue("column_value");
//similarly set values of other columns for this particular item

table.setValue(itemId); //this selects the just added row

希望对您有所帮助。

关于java - Vaadin - 使添加的项目可选择(和可编辑),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41677962/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com