[英]Adding active listener to AbstractDecoratedTextEditor
I have a editor MyEditor
that extends AbstractDecoratedTextEditor
. 我有一个扩展了AbstractDecoratedTextEditor
的编辑器MyEditor
。 In eclipse, I can have a lot of files of MyEditor
opened. 在Eclipse中,我可以打开许多MyEditor
的文件。 Each file is a instance of MyEditor
. 每个文件都是MyEditor
一个实例。 When I click in the tab to change the file, I need to execute same actions of the instance (file) that will open. 当我单击选项卡以更改文件时,我需要执行将要打开的实例(文件)的相同操作。 That is, I need to add a listener in MyEditor
to know when the instance (file) became active. 也就是说,我需要在MyEditor
添加一个侦听器,以了解实例(文件)何时处于活动状态。
You can use an org.eclipse.ui.IPartListener
to listen for changes to parts. 您可以使用org.eclipse.ui.IPartListener
侦听零件的更改。
IPartService partService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService();
partService.addPartListener(listener);
The 该
public void partActivated(IWorkbenchPart part)
method of the listener will be called when a part is activated so you check here for your editor. 激活零件时,将调用侦听器的方法,因此您在此处检查编辑器。
Your editor is an instance of IWorkbenchPart
so you in the `partActivated you can just use 您的编辑器是IWorkbenchPart
的实例,因此您可以在`partActivated中使用
if (part instanceof MyEditor)
{
MyEditor editor = (MyEditor)part;
... check which file this editor is editing
... and do action if it is the required file
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.