|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecteu.webtoolkit.jwt.WObject
eu.webtoolkit.jwt.WAbstractItemDelegate
eu.webtoolkit.jwt.WItemDelegate
public class WItemDelegate
Standard delegate class for rendering a view item.
This class provides the standard implementation for rendering an item (as in
a WAbstractItemView), and renders data provided by the standard data
roles (see ItemDataRole). It also provides default editing support using a
line edit.
You may provide special editing support for an item by specializing the
widget and reimplement
createEditor(),
setModelData(), getEditState(), and
setEditState().
| Constructor Summary | |
|---|---|
WItemDelegate()
Create an item delegate. |
|
WItemDelegate(WObject parent)
Create an item delegate. |
|
| Method Summary | |
|---|---|
protected WWidget |
createEditor(WModelIndex index,
java.util.EnumSet<ViewItemRenderFlag> flags)
Creates an editor for a data item. |
protected WWidget |
createEditor(WModelIndex index,
ViewItemRenderFlag flag,
ViewItemRenderFlag... flags)
Creates an editor for a data item. |
java.lang.Object |
getEditState(WWidget editor)
Returns the current edit state. |
java.lang.String |
getTextFormat()
Returns the text format string. |
void |
setEditState(WWidget editor,
java.lang.Object value)
Sets the editor data from the editor state. |
void |
setModelData(java.lang.Object editState,
WAbstractItemModel model,
WModelIndex index)
Saves the edited data to the model. |
void |
setTextFormat(java.lang.String format)
Sets the text format string. |
WWidget |
update(WWidget widget,
WModelIndex index,
java.util.EnumSet<ViewItemRenderFlag> flags)
Creates or updates a widget that renders an item. |
void |
updateModelIndex(WWidget widget,
WModelIndex index)
Updates the model index of a widget. |
| Methods inherited from class eu.webtoolkit.jwt.WAbstractItemDelegate |
|---|
closeEditor, update, validate |
| Methods inherited from class eu.webtoolkit.jwt.WObject |
|---|
getId, getObjectName, remove, setObjectName, tr |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public WItemDelegate(WObject parent)
public WItemDelegate()
Calls this((WObject)null)
| Method Detail |
|---|
public WWidget update(WWidget widget,
WModelIndex index,
java.util.EnumSet<ViewItemRenderFlag> flags)
The following properties of an item are rendered:
ItemDataRole.DisplayRole data, with the format
specified by setTextFormat()ItemFlag.ItemIsUserCheckable
flag and ItemDataRole.CheckStateRole dataItemDataRole.DecorationRole
ItemDataRole.ToolTipRoleItemDataRole.StyleClassRole
When the flags indicates ViewItemRenderFlag.RenderEditing, then
createEditor() is called to create a suitable editor for editing the
item.
update in class WAbstractItemDelegate
public void updateModelIndex(WWidget widget,
WModelIndex index)
WAbstractItemDelegateThis method is invoked by the view when due to row/column insertions or removals, the index has shifted.
You should reimplement this method only if you are storing the model
index in the widget, to update the stored model index.
The default implementation does nothing.
updateModelIndex in class WAbstractItemDelegatepublic void setTextFormat(java.lang.String format)
The DisplayRole data is converted to a string using
StringUtils.asString(Object), passing the given format. If the
format is an empty string, this corresponds to Object.toString().
The default value is "".
public java.lang.String getTextFormat()
setTextFormat(String format)
public void setModelData(java.lang.Object editState,
WAbstractItemModel model,
WModelIndex index)
The default implementation saves the current edit value to the model. You will need to reimplement this method for a custom editor.
As an example of how to deal with a specialized editor, consider the default implementation:
public void setModelData(Object editState, WAbstractItemModel model,
WModelIndex index) {
model.setData(index, editState, ItemDataRole.EditRole);
}
setModelData in class WAbstractItemDelegatecreateEditor(WModelIndex index, EnumSet flags),
getEditState(WWidget editor)public java.lang.Object getEditState(WWidget editor)
The default implementation returns the current text in the line edit. You will need to reimplement this method for a custom editor.
As an example of how to deal with a specialized editor, consider the default implementation:
public Object getEditState(WWidget editor) {
WContainerWidget w = (WContainerWidget) editor;
WLineEdit lineEdit = (WLineEdit) w.getWidget(0);
return lineEdit.getText();
}
getEditState in class WAbstractItemDelegatecreateEditor(WModelIndex index, EnumSet flags),
setEditState(WWidget editor, Object value),
setModelData(Object editState, WAbstractItemModel
model, WModelIndex index)
public void setEditState(WWidget editor,
java.lang.Object value)
The default implementation resets the text in the line edit. You will need to reimplement this method if for a custom editor.
As an example of how to deal with a specialized editor, consider the default implementation:
public void setEditState(WWidget editor, Object value) {
WContainerWidget w = (WContainerWidget) editor;
WLineEdit lineEdit = (WLineEdit) w.getWidget(0);
lineEdit.setText((String) value);
}
setEditState in class WAbstractItemDelegatecreateEditor(WModelIndex index, EnumSet flags)
protected WWidget createEditor(WModelIndex index,
java.util.EnumSet<ViewItemRenderFlag> flags)
The default implementation returns a WLineEdit which edits the
item's ItemDataRole.EditRole value.
You may reimplement this method to provide a suitable editor, or to
attach a custom validator. In that case, you will probably also want to
reimplement getEditState(),
setEditState(), and
setModelData().
The editor should not keep a reference to the model index (it does not
need to since
setModelData() will provide the proper model index to save the data to
the model). Otherwise, because model indexes may shift because of row or
column insertions, you should reimplement
updateModelIndex().
As an example of how to provide a specialized editor, consider the
default implementation, which returns a WLineEdit:
protected WWidget createEditor(WModelIndex index,
EnumSet<ViewItemRenderFlag> flags) {
final WContainerWidget result = new WContainerWidget();
result.setSelectable(true);
WLineEdit lineEdit = new WLineEdit();
lineEdit.setText(StringUtils.asString(index.getData(ItemDataRole.EditRole),
this.textFormat_).toString());
lineEdit.enterPressed().addListener(this, new Signal.Listener() {
public void trigger() {
WItemDelegate.this.closeEditor().trigger(result, true);
}
});
lineEdit.escapePressed().addListener(this, new Signal.Listener() {
public void trigger() {
WItemDelegate.this.closeEditor().trigger(result, false);
}
});
if (flags.contains(ViewItemRenderFlag.RenderFocused))
lineEdit.setFocus();
result.setLayout(new WHBoxLayout());
result.getLayout().setContentsMargins(1, 1, 1, 1);
result.getLayout().addWidget(lineEdit);
return result;
}
protected final WWidget createEditor(WModelIndex index,
ViewItemRenderFlag flag,
ViewItemRenderFlag... flags)
Returns createEditor(index, EnumSet.of(flag, flags))
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||