Remove or disable the “X” close button shown on a RAP/RCP EditorPart

99封情书 提交于 2019-12-11 04:01:26

问题


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~~



来源:https://stackoverflow.com/questions/11654473/remove-or-disable-the-x-close-button-shown-on-a-rap-rcp-editorpart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!