Eclipse RCP编辑器关闭按钮的屏蔽方法

首先,在ApplicationWorkbenchWindowAdvisor类的preWindowOpen()方法中注册我们自己定制的PresentationFactory。
configurer.setPresentationFactory(new UnCloseableEditorPresentationFactory()); 
UnCloseableEditorPresentationFactory类继承WorkbenchPresentationFactory类,为了不影响别的GUI功能,我们只需要重写public StackPresentation createEditorPresentation(Composite parent, IStackPresentationSite site)方法中的关于设置TableFolder的部分,具体如下:
package AdminLoader;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPreferenceConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.Workbench;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.presentations.defaultpresentation.DefaultMultiTabListener;
import org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder;
import org.eclipse.ui.internal.presentations.defaultpresentation.DefaultThemeListener;
import org.eclipse.ui.internal.presentations.defaultpresentation.EmptyTabFolder;
import org.eclipse.ui.internal.presentations.util.PresentablePartFolder;
import org.eclipse.ui.internal.presentations.util.StandardEditorSystemMenu;
import org.eclipse.ui.internal.presentations.util.StandardViewSystemMenu;
import org.eclipse.ui.internal.presentations.util.TabbedStackPresentation;
import org.eclipse.ui.presentations.IStackPresentationSite;
import org.eclipse.ui.presentations.StackPresentation;
import org.eclipse.ui.presentations.WorkbenchPresentationFactory;


public class UnCloseableEditorPresentationFactory extends
WorkbenchPresentationFactory {


// don't reset these dynamically, so just keep the information static.
// see bug:
// 75422 [Presentations] Switching presentation to R21 switches immediately,
// but only partially
private static int editorTabPosition = WorkbenchPlugin.getDefault()
.getPreferenceStore()
.getInt(IWorkbenchPreferenceConstants.EDITOR_TAB_POSITION);
private static int viewTabPosition = WorkbenchPlugin.getDefault()
.getPreferenceStore()
.getInt(IWorkbenchPreferenceConstants.VIEW_TAB_POSITION);
/*
* (non-Javadoc)
* 
* @see org.eclipse.ui.presentations.AbstractPresentationFactory#
* createEditorPresentation(org.eclipse.swt.widgets.Composite,
* org.eclipse.ui.presentations.IStackPresentationSite)
*/
public StackPresentation createEditorPresentation(Composite parent,
IStackPresentationSite site) {
// DefaultTabFolder folder = new DefaultTabFolder(parent,
// editorTabPosition | SWT.BORDER,
// site.supportsState(IStackPresentationSite.STATE_MINIMIZED),
// site.supportsState(IStackPresentationSite.STATE_MAXIMIZED));


DefaultTabFolder folder = new UnCloseableEditorFolder(parent,editorTabPosition | SWT.BORDER,
site.supportsState(IStackPresentationSite.STATE_MINIMIZED),


site.supportsState(IStackPresentationSite.STATE_MAXIMIZED));


/*
* Set the minimum characters to display, if the preference is something
* other than the default. This is mainly intended for RCP applications
* or for expert users (i.e., via the plug-in customization file).
* 
* Bug 32789.
*/
final IPreferenceStore store = PlatformUI.getPreferenceStore();
if (store
.contains(IWorkbenchPreferenceConstants.EDITOR_MINIMUM_CHARACTERS)) {
final int minimumCharacters = store
.getInt(IWorkbenchPreferenceConstants.EDITOR_MINIMUM_CHARACTERS);
if (minimumCharacters >= 0) {
folder.setMinimumCharacters(minimumCharacters);
}
}


PresentablePartFolder partFolder = new PresentablePartFolder(folder);


TabbedStackPresentation result = new TabbedStackPresentation(site,
partFolder, new StandardEditorSystemMenu(site));


DefaultThemeListener themeListener = new DefaultThemeListener(folder,
result.getTheme());
result.getTheme().addListener(themeListener);


// RAP [bm]:
if (!Workbench.getInstance().isClosing()) {
final DefaultMultiTabListener defaultMultiTabListener = new DefaultMultiTabListener(
result.getApiPreferences(),
IWorkbenchPreferenceConstants.SHOW_MULTIPLE_EDITOR_TABS,
folder);
result.getControl().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
defaultMultiTabListener
.attach(null,
IWorkbenchPreferenceConstants.SHOW_MULTIPLE_EDITOR_TABS,
true);
}
});
}
// RAPEND: [bm]


// RAP [bm]: tab style cannot change
// new DefaultSimpleTabListener(result.getApiPreferences(),
// IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
// folder);
// TODO: needs SessionStoreListener too when activated
// RAPEND: [bm]
return result;
}
/*
* (non-Javadoc)
* 
* @see org.eclipse.ui.presentations.AbstractPresentationFactory#
* createViewPresentation(org.eclipse.swt.widgets.Composite,
* org.eclipse.ui.presentations.IStackPresentationSite)
*/
public StackPresentation createViewPresentation(Composite parent,
IStackPresentationSite site) {
DefaultTabFolder folder = new DefaultTabFolder(parent, viewTabPosition
| SWT.BORDER,
site.supportsState(IStackPresentationSite.STATE_MINIMIZED),
site.supportsState(IStackPresentationSite.STATE_MAXIMIZED));
final IPreferenceStore store = PlatformUI.getPreferenceStore();
final int minimumCharacters = store
.getInt(IWorkbenchPreferenceConstants.VIEW_MINIMUM_CHARACTERS);
if (minimumCharacters >= 0) {
folder.setMinimumCharacters(minimumCharacters);
}
PresentablePartFolder partFolder = new PresentablePartFolder(folder);


folder.setUnselectedCloseVisible(false);
folder.setUnselectedImageVisible(true);
TabbedStackPresentation result = new TabbedStackPresentation(site,
partFolder, new StandardViewSystemMenu(site));
DefaultThemeListener themeListener = new DefaultThemeListener(folder,
result.getTheme());
result.getTheme().addListener(themeListener);


// RAP [bm]: not needed as tab style does not change
// new DefaultSimpleTabListener(result.getApiPreferences(),
// IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
// folder);
// RAPEND: [bm]
return result;
}
/*
* (non-Javadoc)
* 
* @see org.eclipse.ui.presentations.AbstractPresentationFactory#
* createStandaloneViewPresentation(org.eclipse.swt.widgets.Composite,
* org.eclipse.ui.presentations.IStackPresentationSite, boolean)
*/
public StackPresentation createStandaloneViewPresentation(Composite parent,
IStackPresentationSite site, boolean showTitle) {
if (showTitle) {
return createViewPresentation(parent, site);
}
EmptyTabFolder folder = new EmptyTabFolder(parent, true);
TabbedStackPresentation presentation = new TabbedStackPresentation(
site, folder, new StandardViewSystemMenu(site));
return presentation;
}
}
最后就是定义我们自己的UnCloseableEditorFolder了
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);  }
}




 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值