Eclipse Plugin - Notification of when an editor opens in Eclipse

I want to be notified when an editor opens in Eclipse. What is the best way to do this?

+3
source share
1 answer

From this stream

Ask your class to complete . Then you get a notification when a part of the workplace ( etc.) has just been opened / closed. In fact, you can filter out which parts you want to pay attention to. org.eclipse.ui.IPartListener2
IEditorPart

(Note: Starting with version 3.5, IPartListener2 can also implement IPageChangedListenerto notify of all parts that implement IPageChangeProviderpost 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.

EditorTracker

+7

Source: https://habr.com/ru/post/1711052/


All Articles