[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.rcp] Re: Removing editor area after perspective creation

Hello community,

after finding the function setEditorAreaVisible of window pages I
realized a solution of my problem via a IPartListener counter class,
which counts open and close events of IEditorParts and calls the
setEditorAreaVisible function if the last editor has closed. Does there exist a simpler and more natural solution? (There exist some problems concerning a safe usage of the class, e.g. how to ensure that an
instance of EditorAreaWatcher exists **before** the very first editor
was opened.)


Thanks,

Daniel

public class EditorAreaWatcher implements IPartListener {

    private IWorkbenchPage page;
    private long editorCounter;

    public EditorAreaWatcher(IWorkbenchPage page) {
        this.page = page;
        this.page.addPartListener(this);
    }

    public void partClosed(IWorkbenchPart part) {
        if (part instanceof IEditorPart) {
            --editorCounter;
            if (editorCounter == 0) {
                part.getSite().getPage().setEditorAreaVisible(false);
            }
        }
    }

    public void partOpened(IWorkbenchPart part) {
        if (part instanceof IEditorPart) {
            ++editorCounter;
        }
    }

    ... // other IPartListener functions doeing nothing at all

    public void dispose() {
        page.removePartListener(this);
    }
}