删除或禁用在RAP / RCP的EditorPart所示的“X”关闭按钮(Remove or dis

2019-09-20 05:09发布

进出口工作在RAP的应用程序,同时显示ViewParts和EditorParts。 我试着去找到一种方法来防止“全部”编辑部件从关闭。 有没有一种方法是删除或禁用对编辑部分所示的“X”关闭按钮?

Answer 1:

这是可能通过实施表示层-见http://wiki.eclipse.org/RCP_Custom_Look_and_Feel和http://e-rcp.blogspot.ca/2007/09/prevent-that-rcp-editor-is-closed。 HTML 。



Answer 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,你可以简单地overrid方法

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);   
  }
 } 

然后你可以删除“X”按钮,在的EditorPart。它的工作原理在我的机器~~



文章来源: Remove or disable the “X” close button shown on a RAP/RCP EditorPart