第一步:新建Editor,并继承自GraphicalEditorWithFlyoutPalette
比如:public class ActivityEditor extends GraphicalEditorWithFlyoutPalette
第二步:定义如下的静态变量
protected static final String PALETTE_DOCK_LOCATION = "Dock location"; //$NON-NLS-1$
protected static final String PALETTE_SIZE = "Palette Size"; //$NON-NLS-1$
protected static final String PALETTE_STATE = "Palette state"; //$NON-NLS-1$
protected static final int DEFAULT_PALETTE_SIZE = 130;
第三步:实现createPalettePage() 和createPaletteViewerProvider() 两个方法
protected CustomPalettePage createPalettePage() {
return new CustomPalettePage(getPaletteViewerProvider()) {
public void init(IPageSite pageSite) {
super.init(pageSite);
IAction copy = getActionRegistry().getAction(ActionFactory.COPY.getId());
pageSite.getActionBars().setGlobalActionHandler(
ActionFactory.COPY.getId(), copy);
}
};
}
protected PaletteViewerProvider createPaletteViewerProvider() {
return new PaletteViewerProvider(getEditDomain()) {
private IMenuListener menuListener;
protected void configurePaletteViewer(PaletteViewer viewer) {
super.configurePaletteViewer(viewer);
viewer.setCustomizer(new MyPaletteCustomizer());
viewer.addDragSourceListener(new TemplateTransferDragSourceListener(viewer));
}
protected void hookPaletteViewer(PaletteViewer viewer) {
super.hookPaletteViewer(viewer);
final CopyTemplateAction copy = (CopyTemplateAction)getActionRegistry()
.getAction(ActionFactory.COPY.getId());
viewer.addSelectionChangedListener(copy);
if (menuListener == null)
menuListener = new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
manager.appendToGroup(GEFActionConstants.GROUP_COPY, copy);
}
};
viewer.getContextMenu().addMenuListener(menuListener);
}
};
}
第四步:在测试插件时的时候,打开Palette视图就可以看到其中自己定义的选项了