<
extension
point ="org.eclipse.ui.presentationFactories" >
< factory
class ="presentation.PresentationFactory"
id ="resentation.PresentationFactory"
name ="PresentationFactory" />
</ extension >
< extension
id ="product"
point ="org.eclipse.core.runtime.products" >
< product
application ="application"
name ="Name" >
< property
name ="preferenceCustomization"
value ="plugin_customization.ini" />
</ product >
</ extension >
point ="org.eclipse.ui.presentationFactories" >
< factory
class ="presentation.PresentationFactory"
id ="resentation.PresentationFactory"
name ="PresentationFactory" />
</ extension >
< extension
id ="product"
point ="org.eclipse.core.runtime.products" >
< product
application ="application"
name ="Name" >
< property
name ="preferenceCustomization"
value ="plugin_customization.ini" />
</ product >
</ extension >
声明了一个自定义的Presentation. 但是要让这个Presentation生效, 必须是要用Product的声明(因为我是做RCP, 所以Plug-In方式不是太关心, 理论上做Plug-In你也不太应该更改这些个内容).
plugin_customization.ini和plugin.xml在同一个目录下. 内容如下
org.eclipse.ui/presentationFactoryId=presentation.PresentationFactory
org.eclipse.ui/SHOW_TRADITIONAL_STYLE_TABS=false
第一行是说现在使用的是这个表现了, id和xml中的id一致.
第二行比较简单, 就是说现在tab都是圆边的了.
package
presentation;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IWorkbenchPreferenceConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.IPreferenceConstants;
import org.eclipse.ui.internal.WorkbenchMessages;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.preferences.IDynamicPropertyMap;
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.SystemMenuMaximize;
import org.eclipse.ui.internal.presentations.SystemMenuMinimize;
import org.eclipse.ui.internal.presentations.SystemMenuMove;
import org.eclipse.ui.internal.presentations.SystemMenuRestore;
import org.eclipse.ui.internal.presentations.UpdatingActionContributionItem;
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.util.ISystemMenu;
import org.eclipse.ui.internal.presentations.util.PresentablePartFolder;
import org.eclipse.ui.internal.presentations.util.TabbedStackPresentation;
import org.eclipse.ui.presentations.IPresentablePart;
import org.eclipse.ui.presentations.IStackPresentationSite;
import org.eclipse.ui.presentations.StackPresentation;
import org.eclipse.ui.presentations.WorkbenchPresentationFactory;
/**
* Create at 2007-4-24,下午03:59:11<br>
* 表现工厂
*
* @author Brad.Wu
* @version 1.0
*/
public class PresentationFactory extends WorkbenchPresentationFactory {
private static int editorTabPosition = WorkbenchPlugin.getDefault().getPreferenceStore().getInt(
IPreferenceConstants.EDITOR_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));
/*
* 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 EditorSystemMenu(site));
DefaultThemeListener themeListener = new DefaultThemeListener(folder, result.getTheme());
result.getTheme().addListener(themeListener);
IDynamicPropertyMap workbenchPreferences = result.getPluginPreferences(WorkbenchPlugin.getDefault());
new DefaultMultiTabListener(workbenchPreferences, IPreferenceConstants.SHOW_MULTIPLE_EDITOR_TABS, folder);
new DefaultSimpleTabListener(result.getApiPreferences(), IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS, folder);
return result;
}
class EditorSystemMenu implements ISystemMenu {
private MenuManager menuManager = new MenuManager();
private SystemMenuRestore restore;
private SystemMenuMove move;
private SystemMenuMinimize minimize;
private SystemMenuMaximize maximize;
private SystemMenuClose close;
private SystemMenuCloseOthers closeOthers;
private SystemMenuCloseAll closeAll;
/**
* Create the standard view menu
*
* @param site
* the site to associate the view with
*/
public EditorSystemMenu(IStackPresentationSite site) {
restore = new SystemMenuRestore(site);
move = new SystemMenuMove(site, WorkbenchMessages.EditorPane_moveEditor, false);
minimize = new SystemMenuMinimize(site);
maximize = new SystemMenuMaximize(site);
close = new SystemMenuClose(site);
closeOthers = new SystemMenuCloseOthers(site);
closeAll = new SystemMenuCloseAll(site);
{ // Initialize system menu
menuManager.add(new GroupMarker("misc")); //$NON-NLS-1$
menuManager.add(new GroupMarker("restore")); //$NON-NLS-1$
menuManager.add(new UpdatingActionContributionItem(restore));
menuManager.add(move);
menuManager.add(new GroupMarker("size")); //$NON-NLS-1$
menuManager.add(new GroupMarker("state")); //$NON-NLS-1$
menuManager.add(new UpdatingActionContributionItem(minimize));
menuManager.add(new UpdatingActionContributionItem(maximize));
menuManager.add(new Separator("close")); //$NON-NLS-1$
menuManager.add(close);
menuManager.add(closeOthers);
menuManager.add(closeAll);
site.addSystemActions(menuManager);
} // End of system menu initialization
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.internal.presentations.util.ISystemMenu#show(org.eclipse.swt.graphics.Point,
* org.eclipse.ui.presentations.IPresentablePart)
*/
public void show(Control parent, Point displayCoordinates, IPresentablePart currentSelection) {
restore.update();
move.setTarget(currentSelection);
move.update();
minimize.update();
maximize.update();
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);
}
/**
* Dispose resources associated with this menu
*/
public void dispose() {
menuManager.dispose();
menuManager.removeAll();
}
}
}
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IWorkbenchPreferenceConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.IPreferenceConstants;
import org.eclipse.ui.internal.WorkbenchMessages;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.preferences.IDynamicPropertyMap;
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.SystemMenuMaximize;
import org.eclipse.ui.internal.presentations.SystemMenuMinimize;
import org.eclipse.ui.internal.presentations.SystemMenuMove;
import org.eclipse.ui.internal.presentations.SystemMenuRestore;
import org.eclipse.ui.internal.presentations.UpdatingActionContributionItem;
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.util.ISystemMenu;
import org.eclipse.ui.internal.presentations.util.PresentablePartFolder;
import org.eclipse.ui.internal.presentations.util.TabbedStackPresentation;
import org.eclipse.ui.presentations.IPresentablePart;
import org.eclipse.ui.presentations.IStackPresentationSite;
import org.eclipse.ui.presentations.StackPresentation;
import org.eclipse.ui.presentations.WorkbenchPresentationFactory;
/**
* Create at 2007-4-24,下午03:59:11<br>
* 表现工厂
*
* @author Brad.Wu
* @version 1.0
*/
public class PresentationFactory extends WorkbenchPresentationFactory {
private static int editorTabPosition = WorkbenchPlugin.getDefault().getPreferenceStore().getInt(
IPreferenceConstants.EDITOR_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));
/*
* 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 EditorSystemMenu(site));
DefaultThemeListener themeListener = new DefaultThemeListener(folder, result.getTheme());
result.getTheme().addListener(themeListener);
IDynamicPropertyMap workbenchPreferences = result.getPluginPreferences(WorkbenchPlugin.getDefault());
new DefaultMultiTabListener(workbenchPreferences, IPreferenceConstants.SHOW_MULTIPLE_EDITOR_TABS, folder);
new DefaultSimpleTabListener(result.getApiPreferences(), IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS, folder);
return result;
}
class EditorSystemMenu implements ISystemMenu {
private MenuManager menuManager = new MenuManager();
private SystemMenuRestore restore;
private SystemMenuMove move;
private SystemMenuMinimize minimize;
private SystemMenuMaximize maximize;
private SystemMenuClose close;
private SystemMenuCloseOthers closeOthers;
private SystemMenuCloseAll closeAll;
/**
* Create the standard view menu
*
* @param site
* the site to associate the view with
*/
public EditorSystemMenu(IStackPresentationSite site) {
restore = new SystemMenuRestore(site);
move = new SystemMenuMove(site, WorkbenchMessages.EditorPane_moveEditor, false);
minimize = new SystemMenuMinimize(site);
maximize = new SystemMenuMaximize(site);
close = new SystemMenuClose(site);
closeOthers = new SystemMenuCloseOthers(site);
closeAll = new SystemMenuCloseAll(site);
{ // Initialize system menu
menuManager.add(new GroupMarker("misc")); //$NON-NLS-1$
menuManager.add(new GroupMarker("restore")); //$NON-NLS-1$
menuManager.add(new UpdatingActionContributionItem(restore));
menuManager.add(move);
menuManager.add(new GroupMarker("size")); //$NON-NLS-1$
menuManager.add(new GroupMarker("state")); //$NON-NLS-1$
menuManager.add(new UpdatingActionContributionItem(minimize));
menuManager.add(new UpdatingActionContributionItem(maximize));
menuManager.add(new Separator("close")); //$NON-NLS-1$
menuManager.add(close);
menuManager.add(closeOthers);
menuManager.add(closeAll);
site.addSystemActions(menuManager);
} // End of system menu initialization
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.internal.presentations.util.ISystemMenu#show(org.eclipse.swt.graphics.Point,
* org.eclipse.ui.presentations.IPresentablePart)
*/
public void show(Control parent, Point displayCoordinates, IPresentablePart currentSelection) {
restore.update();
move.setTarget(currentSelection);
move.update();
minimize.update();
maximize.update();
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);
}
/**
* Dispose resources associated with this menu
*/
public void dispose() {
menuManager.dispose();
menuManager.removeAll();
}
}
}