一:新建2个文件:
(1)MyTab.java
package com.rcp.tab;
import org.eclipse.core.runtime.ILog;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.internal.WorkbenchMessages;
import org.eclipse.ui.internal.presentations.SystemMenuClose;
import org.eclipse.ui.internal.presentations.SystemMenuCloseAll;
import org.eclipse.ui.internal.presentations.SystemMenuCloseOthers;
import org.eclipse.ui.internal.presentations.util.ISystemMenu;
import org.eclipse.ui.presentations.IPresentablePart;
import org.eclipse.ui.presentations.IStackPresentationSite;
public class MyTab implements ISystemMenu {
MenuManager menuManager = new MenuManager();
private SystemMenuClose close;
private SystemMenuCloseOthers closeOthers;
private SystemMenuCloseAll closeAll;
public MyTab(IStackPresentationSite site) {
close = new SystemMenuClose(site);
closeOthers = new SystemMenuCloseOthers(site);
closeAll = new SystemMenuCloseAll(site);
{ // Initialize system menu
menuManager.add(close);
menuManager.add(closeOthers);
menuManager.add(closeAll);
// site.addSystemActions(menuManager); 这一行一定要注释掉,否则会添加系统的菜单项
} // End of system menu initialization
}
String getMoveMenuText() {
return WorkbenchMessages.ViewPane_moveView;
}
public void show(Control parent, Point displayCoordinates, IPresentablePart currentSelection) {
close.setTarget(currentSelection);
closeOthers.setTarget(currentSelection);
closeAll.update();
Menu aMenu = menuManager.createContextMenu(parent);
menuManager.update(true);
aMenu.setLocation(displayCoordinates.x, displayCoordinates.y);
aMenu.setVisible(true);
}
public void dispose() {
menuManager.dispose();
menuManager.removeAll();
}
}
(2)MyWorkbenchPresentationFactory.java
package com.rcp.tab;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPreferenceConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.presentations.defaultpresentation.DefaultMultiTabListener;
import org.eclipse.ui.internal.presentations.defaultpresentation.DefaultSimpleTabListener;
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.TabbedStackPresentation;
import org.eclipse.ui.presentations.AbstractPresentationFactory;
import org.eclipse.ui.presentations.IStackPresentationSite;
import org.eclipse.ui.presentations.StackPresentation;
public class MyWorkbenchPresentationFactory extends AbstractPresentationFactory {
// 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 = PlatformUI.getPreferenceStore()
.getInt(IWorkbenchPreferenceConstants.EDITOR_TAB_POSITION);
private static int viewTabPosition = PlatformUI.getPreferenceStore()
.getInt(IWorkbenchPreferenceConstants.VIEW_TAB_POSITION);
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));
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 MyTab(site));
DefaultThemeListener themeListener = new DefaultThemeListener(folder,
result.getTheme());
result.getTheme().addListener(themeListener);
new DefaultMultiTabListener(result.getApiPreferences(),
IWorkbenchPreferenceConstants.SHOW_MULTIPLE_EDITOR_TABS, folder);
new DefaultSimpleTabListener(result.getApiPreferences(),
IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
folder);
return result;
}
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 MyTab(site));
DefaultThemeListener themeListener = new DefaultThemeListener(folder,
result.getTheme());
result.getTheme().addListener(themeListener);
new DefaultSimpleTabListener(result.getApiPreferences(),
IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
folder);
return result;
}
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 MyTab(site));
return presentation;
}
}
二:修改自动生成的ApplicationWorkbenchWindowAdvisor.java的preWindowOpen()
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(700, 600));
configurer.setShowCoolBar(false);
configurer.setShowStatusLine(false);
configurer.setTitle("webservice测试程序(wangbq)");
configurer.setPresentationFactory(new MyWorkbenchPresentationFactory());
}
这样就可以了