RCP的EditorPart保存后焦点控制

from:http://blog.csdn.net/bee2518/archive/2007/09/21/1795390.aspx
今天为了实现在EditorPart中保存后,提示“是否继续增加”后,能够初始化数据并实现焦点移到指定TEXT中,必须扩展org.eclipse.ui.internal.SaveAction。

仅仅在doSave事件中做txLdlpNo.setFocus();是无效到的,查看源代码可以看到执行保存的代码如下:
IRunnableWithProgress progressOp = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
IProgressMonitor monitorWrap = new EventLoopProgressMonitor(monitor);
saveable.doSave(monitorWrap); // 此处调用EditorPart.doSave();
}
};



IRunnableWithProgress中无法对EditorPart的控件焦点进行控制,浏览了一下SaveAction保存事件代码,发现在EditorPart没有提供保存后控制焦点的函数,决定在扩展org.eclipse.ui.internal.SaveAction,实现保存后对焦点的控制。实现代码如下:
public class CustomSaveAction extends SaveAction {

public CustomSaveAction(IWorkbenchWindow window) {
super(window);
}

public void run() {
super.run();

//在此处扩展保存后设置默认焦点,其他不变
IEditorPart part = getActiveEditor();
part.setFocus();
}

// 不破坏原来创建,模仿 ActionFactory 创建这个CustomSaveAction

public static final ActionFactory SAVE = new ActionFactory("save") {//$NON-NLS-1$

/*
* (non-Javadoc)
*
* @see org.eclipse.ui.actions.ActionFactory#create(org.eclipse.ui.IWorkbenchWindow)
*/
public IWorkbenchAction create(IWorkbenchWindow window) {
if (window == null) {
throw new IllegalArgumentException();
}
IWorkbenchAction action = new CustomSaveAction(window);// 这个地方改为CustomSaveAction
action.setId(getId());
return action;
}
};

}


这样,在ApplicationActionBarAdvisor中创建保存action代码如下:
saveAction = CustomSaveAction.SAVE.create(window);
register(saveAction);



通过以上改造,实现了焦点控制
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值