Java – Eclipse Plug-in – notification when opening the editor in eclipse

I want to be notified when I open the editor in eclipse What is the best way?

Solution

From this thread

(Note: starting from 3.5, ipartlistener 2 can also implement ipagechangedlistener to notify any part about implementing ipagechangeprovider and publishing pagechangeevents.)

Here is how to get the workbench page

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;
        }
    }
}

See also here

Take this class as an example

IPartListener2 partlistener = new IPartListener2(){
        public void partActivated( IWorkbenchPartReference partRef ) {
            if (partRef.getPart(false) == MapEditor.this){
                registerFeatureFlasher();
                ApplicationGIS.getToolManager().setCurrentEditor(editor);
            }
        }
 [...]

Or this general partlistener is used for the general usage of partlistener 2

Or this editortracker

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>