I have a use case, where I need to the close the eclipse
empty editor area, so that editor area can be used by something else.
This can be achieved by implementing IPartListerner2 interface which is provided org.eclipse.ui.*
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPartReference;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.editors.text.TextEditor;
public class AbstractMyEditor extends TextEditor implements IPartListener2 {
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
site.getPage().addPartListener(this);
super.init(site, input);
}
@Override
public void partActivated(IWorkbenchPartReference partRef) {
}
@Override
public void partBroughtToTop(IWorkbenchPartReference partRef) {
}
@Override
public void partClosed(IWorkbenchPartReference partRef) {
IWorkbenchPage page = partRef.getPage();
if (page.isEditorAreaVisible()) {
IEditorReference[] editores = page.getEditorReferences();
if (editores.length <= 0) {
page.setEditorAreaVisible(false);
}
}
}
@Override
public void partDeactivated(IWorkbenchPartReference partRef) {
}
@Override
public void partOpened(IWorkbenchPartReference partRef) {
}
@Override
public void partHidden(IWorkbenchPartReference partRef) {
}
@Override
public void partVisible(IWorkbenchPartReference partRef) {
}
@Override
public void partInputChanged(IWorkbenchPartReference partRef) { }
}
No comments:
Post a Comment