我正在开发一个显示ViewParts和EditorParts的RAP应用程序。 我试图找到一种方法来阻止“所有”编辑器部件关闭。有没有办法删除或禁用 编辑器部分显示“X”关闭按钮?
答案 0 :(得分:2)
你可以这样做(我写的内容大致相同:http://wiki.eclipse.org/RCP_Custom_Look_and_Feel): 在ApplicationWorkbenchWindowAdvisor类中,您可以注册自己的PresentationFacory,如:
public void preWindowOpen() {
WorkbenchAdapterBuilder.registerAdapters();
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setPresentationFactory(new UnCloseableEditorPresentationFactory());
}
类UnCloseableEditorPresentationFactory扩展了WorkbenchPresentationFactory,你可以简单地覆盖方法
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);
}
}
然后你可以删除EditorPart中的“X”按钮。它可以在我的机器上运行~~
答案 1 :(得分:1)