![](/img/trans.png)
[英]How to properly set the content of an IFile in Eclipse plugin when the editor is opened
[英]Eclipse Plugin - Notification of when an editor is opened in Eclipse
我想在Eclipse中打開編輯器時得到通知。 最好的方法是什么?
從這個線程
讓您的類實現
org.eclipse.ui.IPartListener2
。
然后,當工作台零件(IEditorPart
等)剛剛打開/關閉時,您會收到通知。 您實際上可以過濾出要關注的部分。
(注意:從3.5開始,IPartListener2還可以實現IPageChangedListener
,以通知有關實現IPageChangeProvider
並發布PageChangedEvents
任何部分。)
棘手的部分(無雙關語)是將偵聽器注冊到工作台。
因此,首先要做的是獲取一個有效的
IWorkbenchPage
以便您可以調用IWorkbenchPage.addPartListener(<your class that implements IPartListener>)
。
這是獲取工作台頁面的方法。
IWorkbenchPage page = null;
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null)
{
page = window.getActivePage();
}
if (page == null)
{
// Look for a window and get the page off it!
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
for (int i = 0; i < windows.length; i++)
{
if (windows[i] != null)
{
window = windows[i];
page = windows[i].getActivePage();
if (page != null)
break;
}
}
}
另請參閱此處 。
以此類為例
IPartListener2 partlistener = new IPartListener2(){
public void partActivated( IWorkbenchPartReference partRef ) {
if (partRef.getPart(false) == MapEditor.this){
registerFeatureFlasher();
ApplicationGIS.getToolManager().setCurrentEditor(editor);
}
}
[...]
或此通用PartListener,用於PartListener2的通用用法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.