2

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?

4

2 回答 2

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”按钮。它在我的机器上工作~~

于 2013-10-11T02:58:42.817 回答
1

这可以通过实现表示层来实现 - 请参阅http://wiki.eclipse.org/RCP_Custom_Look_and_Feelhttp://e-rcp.blogspot.ca/2007/09/prevent-that-rcp-editor-is-closed。 .html _

于 2012-08-24T23:40:18.643 回答