在SWT/JFace中缺少预选事件的任何解决方法?

编程入门 行业动态 更新时间:2024-10-21 04:03:35
本文介绍了在SWT/JFace中缺少预选事件的任何解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的应用程序中,我希望用户在离开选项卡(实现为CTabFolder)之前保存所有更改.

In my application I want the user to save any changes before he leaves a tab (implemented as CTabFolder).

我尝试处理SelectionEvent,但是在更改选项卡后会触发 (因此,为什么它甚至有一个doit字段?在更改其他控件之前会触发吗? )

I tried to handle SelectionEvent, but it fires after the tab has been changed (so why does it even have a doit field? Does it fire before change for some other controls?)

在Bugzilla上,我发现 bugs.eclipse /bugs/show_bug.cgi?id = 193453 和 https ://bugs.eclipse/bugs/show_bug.cgi?id = 193064 ,但两者均未修复.

Looking on Bugzilla, I've found bugs.eclipse/bugs/show_bug.cgi?id=193453 and bugs.eclipse/bugs/show_bug.cgi?id=193064, neither of which is fixed.

由于此要求可能很常见,因此有人有解决方法吗?

Since this requirement is probably common, does anybody have a workaround?

推荐答案

我有一个变通办法,可与由CTabFolder支持的org.eclipse.ui.part.MultiPageEditorPart一起使用.我将其修改为直接的CTabFolder实现.

I have a workaround that works with org.eclipse.ui.part.MultiPageEditorPart which is backed by a CTabFolder. I'll adapt it for a straight CTabFolder implementation.

首先使用选择侦听器:

tabFolder.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { pageChange(tabFolder.indexOf((CTabItem) e.item)); } });

然后我像这样实现pageChange():

Then I implement pageChange() like this:

protected void pageChange(int newPageIndex) { boolean changingPages = this.changingPages; this.changingPages = true; int oldPageIndex = tabFolder.getSelectionIndex(); if (isDirty() && !changingPages) { tabFolder.setSelection(oldPageIndex); if (canChangePages()) { tabFolder.setSelection(newPageIndex); } } this.changingPages = false; }

在canChangePages()中,我弹出一个要保存的对话框,并为用户提供选择是,否或取消的机会.是,保存信息并返回true.否将信息恢复到上一次保存的状态并返回true.取消仅返回false.您可能只想尝试保存并仅在保存失败时才返回false.

In canChangePages() I pop up a do you want to save dialog and give the user an opportunity to select yes, no, or cancel. Yes saves the info and returns true. No reverts the info to the last saved state and returns true. Cancel simply returns false. You may simply want to try saving and return false only if the save fails.

在调用canChangePages()之前切换回旧页面可能看起来很奇怪.该调用快速执行,因此给选项卡从未切换的错觉.除非canChangePages()花费了多长时间,否则用户不会看到制表符更改,除非该选项卡被该方法批准.

It may look weird that I switch back to the old page before calling canChangePages(). This call executes quickly so it gives the illusion the tab never switched. No matter how long canChangePages() takes the user will not see a tab change unless it is approved by that method.

更多推荐

在SWT/JFace中缺少预选事件的任何解决方法?

本文发布于:2023-05-28 12:30:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/320945.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:词库加载错误:Could not find file 'D:\淘小白 高铁采集器win10\Configuration\Dict_Sto

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!