【问题标题】:Remove or disable the "X" close button shown on a RAP/RCP EditorPart删除或禁用 RAP/RCP EditorPart 上显示的“X”关闭按钮
【发布时间】:2012-07-24 03:57:00
【问题描述】:

我正在开发一个同时显示 ViewParts 和 EditorParts 的 RAP 应用程序。 我试图找到一种方法来防止“所有”编辑器部分关闭。有没有办法删除或禁用 编辑器部件上显示的“X”关闭按钮?

【问题讨论】:

    标签: java eclipse-rcp workbench eclipse-rap


    【解决方案1】:

    你可以这样做(我写的大致相同: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”按钮。它在我的机器上工作~~

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 2014-02-24
      • 1970-01-01
      • 1970-01-01
      • 2019-05-14
      • 1970-01-01
      • 1970-01-01
      • 2018-09-03
      • 1970-01-01
      • 2019-04-15
      相关资源
      最近更新 更多