Nettable单元格编辑功能API

Nettable支持以下编辑功能
  1. 通过内联单元格编辑文本框,组合框或复选框
  2. 可以同时编辑多个值通过按F2弹出
  3. 编辑更新基础表数据结构
没有特殊的层需要编辑nattable使。一切都是通过配置。

默认配置设置的单元格编辑defaulteditconfiguration这是用defaultgridlayerconfiguration。默认的配置 告诉nattable不可编辑和设置textcelleditor如 编辑默认编辑器打开特定的单元格。它还增加了验证错误的风格 渲染一个单元格红色的验证错误内容。
在用户交互编辑使几个绑定,需要配置。默认的绑定 配置在defaulteditbindings配置,这也部分的defaultgridlayerconfiguration

这个editablegridexampleediterrorhandlingexample这两个例子可以看到。

使单元格编辑

编辑了下车默认情况下。启用编辑ieditablerule要 注册。你通常会注册一个ieditablerule对一个单元列的标签 如果你只想为特定条件下,如下面的代码所示启用编辑:

configregistry.registerconfigattribute( editconfigattributes.cell_editable_rule, ieditablerule.always_editable, displaymode.edit,”mycelllabel”);

mycelllabel总是编辑标签

你也可以创建你自己的ieditablerule如果你需要决定是否 细胞应可编辑或不。只是确保ieditablerule iseditable()。
创建你自己的ieditablerule很有用,如果你想注册一个ieditablerule在全局内(而不是一个特定的单元格标记), 反应在全局标志(如启用/禁用用户界面中编辑)。

单元格编辑器

这是窗口被激活时,细胞进入编辑模式。一个单元格编辑器需要 实施icelleditor接口。 以下编辑提供的:

  • textcelleditor
  • checkboxcelleditor
  • comboboxcelleditor
  • passwordcelleditor(作为一个特殊的textcelleditor)
请注意,编辑必须注册 对单元格标记如下:

configregistry。registerconfigattribute( editconfigattributes.cell_editor,newcheckboxcelleditor(), displaymode.edit,”mycheckboxlabel”);

使用checkboxcelleditor单元格具有标签mycheckboxlabel

textcelleditorcheckboxcelleditor可以创建没有额外的信息,这comboboxcelleditor需求列表包含在组合框的值。

作为编辑和不同的显示模式渲染分离的任务你应该检查哪些单元格 绘画为你编辑的单元格。有小区的绘画存在的细胞 编辑nattable。

  • textcelleditor -魔兽水彩笔
  • checkboxcelleditor - checkboxpainter
  • comboboxcelleditor - comboboxpainter
  • passwordcelleditor - passwordtextpainter
作为 textcelleditor魔兽水彩笔配置 默认情况下,你只需要检查电池的画家 checkboxcelleditorcomboboxcelleditor如果这是有意。
//注册一个显示模式复选框编辑。编辑 configregistry。registerconfigattribute( editconfigattributes.cell_editor,新checkboxcelleditor(), displaymode.edit,”mycheckboxlabel”); /注册框画家DisplayMode。正常 configregistry。registerconfigattribute( cellconfigattributes.cell_painter,新checkboxpainter(), displaymode.normal,”mycheckboxlabel”); 注册/组合框编辑编辑显示模式。 configregistry。registerconfigattribute( editconfigattributes.cell_editor,新comboboxcelleditor(阵列。asList(新的字符串[ ] {“中”,“定”})), displaymode.edit,”mycomboboxlabel”); / /注册框画家为正常显示模式。 configregistry。registerconfigattribute( editconfigattributes.cell_painter,新comboboxpainter(), displaymode.edit;

确保使用匹配细胞画家一起编辑

数据转换

nattable呈现每个信息应该显示在细胞内的字符串。支持 其他数据类型的转换是必要的。这是通过注册完成idisplayconverter在电池标签。

configregistry。registerconfigattribute( cellconfigattributes.display_converter,新defaultbooleandisplayconverter(),”mycheckboxlabel”);

使用defaultbooleandisplayconverter细胞具有标签mycheckboxlabel

有几个默认转换器使用nattable:

  • defaultdisplayconverter
  • defaultcharacterdisplayconverter
  • defaultbooleandisplayconverter
  • defaultbytedisplayconverter
  • defaultshortdisplayconverter
  • defaultintegerdisplayconverter
  • defaultlongdisplayconverter
  • defaultfloatdisplayconverter
  • defaultdoubledisplayconverter
  • defaultbigintegerdisplayconverter
  • defaultbigdecimaldisplayconverter
  • defaultdatedisplayconverter
  • percentagedisplayconverter

请注意,提供的默认转换器是简单的默认实现。如果你需要一个更 特定的转换,例如将通过双值解析,你会 必须创建自己的。
随时提供任何通用的转换器,适合nattable。

创建你自己的idisplayconverter你应该选择一个现有的 抽象的实现依赖于你的要求:

  • displayconverter
    扩展这个类来支持简单的价值转换。
  • contextualdisplayconverter
    扩展这个类来支持价值转换依赖于额外的上下文信息。
如果你想使用专门的转换失败的消息,你需要 扔 conversionfailedexception将由 配置错误处理策略评估(见下文)。

数据验证

您可以配置的nattable实例的可编辑单元格的数据有效性验证规则。 模型的更新仅适用于基础列表如果他们通过验证。 添加数据验证的nattable你需要注册idatavalidator在电池标签。

configregistry。registerconfigattribute( editconfigattributes.data_validator, getsecurtityidvalidator(), displaymode.edit,”mycelllabel”);

使用数据验证返回的值getsecurtityidvalidator()上犯 细胞具有标签mycelllabel

创建你自己的idatavalidator你应该选择一个现有的 抽象的实现依赖于你的要求:

  • datavalidator
    扩展这个类来支持简单的数据验证。
  • contextualdatavalidator
    扩展这个类支持数据验证依赖于额外的上下文信息。
如果你想使用专门的验证失败的信息,你需要 扔 validationfailedexception将由 配置错误处理策略评估(见下文)。

错误处理

转换和验证错误会导致不更新的基础列表的值。 这些错误处理的用户界面可以配置。目前主要有以下 错误处理策略的支持:

  • loggingerrorhandling
    只会写一个日志项的转换/验证错误消息。 默认如果没有其他错误处理。
  • discardvalueerrorhandling
    只会关闭打开的编辑器,删除输入的值没有更新 基础列表的值。
  • dialogerrorhandling
    将显示一个转换/验证错误消息和选择放弃 或改变输入值对话框。弃将关闭编辑器,无需更新值的变化 基础列表,将离开编辑器打开允许改正。
  • rendererrorhandling
    用于可视化的错误进入到textcelleditor这是默认设置。 使输入的值用红色字体颜色处理转换 和验证。
它也可能把这些处理程序,例如打开一个对话框,写一个日志条目 同时。

下面的代码演示如何添加dialogerrorhandling 转换和验证错误。

configregistry。registerconfigattribute( editconfigattributes.conversion_error_handler,新dialogerrorhandling(), displaymode.edit, editerrorhandlingexample。column_four_label); configregistry。registerconfigattribute( editconfigattributes.validation_error_handler,新dialogerrorhandling(), displaymode.edit, editerrorhandlingexample;

从editerrorhandlingexample片段

如果你想改变错误而编辑在处理textcelleditor你需要设置你的定制iediterrorhandler作为inputconversionerrorhandler 或inputvalidationerrorhandler。

不允许将这些处理程序

文本编辑控件的装饰

如果你想为用户提供一种非侵入性的方式更多的上下文信息,然后您可以使用一个controldecoration 。这允许您显示一个小图标,例如错误或信息/警告图标,对 编辑一边,当鼠标悬停在然后工具提示显示的文本信息。如果你不熟悉的 与controldecorations你几乎肯定已经看到他们在行动在Eclipse作为它的一些内容帮助 信息了!

例如,这里是一个控制装饰集显示在顶部的文本编辑器,编辑器左,用鼠标在图标上显示 因此提示徘徊:

文本编辑控件的装饰

这是非常简单的实现:

textcelleditor textcelleditor =新textcelleditor(); textcelleditor。seterrordecorationenabled(true); textcelleditor。seterrordecorationtext(”安全ID必须是3字符后跟数字”); textcelleditor。setdecorationpositionoverride(swt.left | SWT。顶部); configregistry。registerconfigattribute( editconfigattributes。cell_editor, textcelleditor,显示模式;

从editablegridexample片段

这部作品与细胞icellvalidator串联(和国内的textcelleditors rendererrorhandling实例)。

你可以通过调用获得定制进一步的访问textcelleditor getdecorationprovider()。例如力悬停文本能够立即显示而不是在盘旋。返回的controldecorationprovider也 在您自己的自定义编辑重用。

如何把单元格的值

一个单元格编辑器火灾updatedatacommand犯一个小区的新价值。这个命令是由 数据层通过updatedatacommandhandler。 最终idataprovider将更新底层数据结构。

数据更新命令处理
处理不同的数据更新

如果你想执行一个自定义操作,当用户编辑单元格时你会:

  1. 注销updatedatacommandhandler
  2. 处理updatedatacommand自定义命令处理程序注册

该代码将看起来像这样

bodydatalayer。unregistercommandhandler(updatedatacommand。类); bodydatalayer。registercommandhandler(新myupdatedatacommandhandler();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值