Remove or disable the “X” close button shown on a

2019-07-21 04:47发布

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?

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-07-21 05:15

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

查看更多
登录 后发表回答