ECLIPSE RCP 应用程序:工具栏实现
我有一个带有自定义工具栏的视图,其中包含第一个记录、下一个记录、上一个记录等按钮。 我想实现这个功能。我有工具栏按钮的命令对象。如何传递表查看器中当前行是哪一行的信息?如果我选择工具栏上的下一条记录按钮,焦点如何移动到下一条记录?
I have a view with custom toolbar with buttons such as first record, next record, previous record,etc.
I want to implement this functionality. I have command object for the toolbar buttons. How can I pass the info about which row is the current row on the table viewer? How the focus be moved to the next record if I select next record button on the tool bar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
访问当前行:
设置下一行的选择
Access current row:
Set selection on next row
首先,您必须确保
TableViewer
是您的视图的选择提供程序:每次表中选定的行发生更改时,它都会通知工作台窗口的选择服务。该选择包含与所选行对应的模型对象。
在命令处理程序中,您可以通过调用获取当前选择。
要在按下下一个按钮时移动
TableViewer
中的焦点,您必须在视图中实现一个公共方法,该方法会增加基础Table
减一。要使命令处理程序能够调用此方法,您需要获取视图的实例。一个快速而肮脏的解决方案是通过调用返回的
IWorkbenchPart
来获取当前部件并将其转换为您的视图类。First you have to make sure that the
TableViewer
is the selection provider for your view:This notifies the selection service of your workbench window every time the selected row in your table changes. The selection contains the model object that corresponds to the selected row.
In your command handler, you can get the current selection by calling
To move the focus in your
TableViewer
when the next button is pressed, you have to implement a public method in your view that increases the selection index of the underlyingTable
by one. To enable your command handler to call this method, you need to get the instance of the view. A quick-and-dirty solution would be to get the current part by callingand cast the returned
IWorkbenchPart
to your view class.