Im working on a RAP application that shows both ViewParts and EditorParts. Im trying to find a way to prevent "All" Editor parts from closing. Is there a way to either remove or disable the "X" close button shown on a Editor part?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
This is possible through implementing a presentation layer - see http://wiki.eclipse.org/RCP_Custom_Look_and_Feel and http://e-rcp.blogspot.ca/2007/09/prevent-that-rcp-editor-is-closed.html.
回答2:
you can do like this(what I have written is about the same like :http://wiki.eclipse.org/RCP_Custom_Look_and_Feel): In your ApplicationWorkbenchWindowAdvisor class ,you can register your own PresentationFacory like:
public void preWindowOpen() {
WorkbenchAdapterBuilder.registerAdapters();
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setPresentationFactory(new UnCloseableEditorPresentationFactory());
}
the class UnCloseableEditorPresentationFactory extends WorkbenchPresentationFactory,you can simply overrid the method
public StackPresentation creatEditorPresentation(Composite parent,IStackPresentationSite site)
as followings :
DefaultTabFolder folder = new UnCloseableEditorFolder(parent,
editorTabPosition | SWT.BORDER,
site.supportsState(IStackPresentationSite.STATE_MINIMIZED),
site.supportsState(IStackPresentationSite.STATE_MAXIMIZED));
// other code int this method is the same as the parent class
then is the class UnCloseableFolder
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder;
import org.eclipse.ui.internal.presentations.util.AbstractTabItem;
public class UnCloseableEditorFolder extends DefaultTabFolder {
public UnCloseableEditorFolder(Composite parent, int flags,
boolean allowMin, boolean allowMax) {
super(parent, flags, allowMin, allowMax);
}
@SuppressWarnings("restriction")
public AbstractTabItem add(int index, int flags) {
return super.add(index, flags ^ SWT.CLOSE);
}
}
then you can remove the "X" button in the EditorPart .It works in my machine~~