为RAP程序添加帮助支持
一、创建RAP程序。
创建一个rap程序。
二、修改代码
首先,在RAP项目中到AppllicationiActionBarAdvisor这个类,按照下面模板修改:
Java代码:
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
// Actions - important to allocate these only in makeActions, and then use them
// in the fill methods. This ensures that the actions aren't recreated // when fillActionBars is called with FILL_PROXY.
private IWorkbenchAction exitAction;
private IAction aboutAction;
private OpenViewAction openViewAction;
private Action messagePopupAction;
private IAction helpContentAction = null; //����,�˴�������
private IAction helpSerchAction = null;
private IAction helpDynamicAction = null;
public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) { super(configurer);
}
protected void makeActions(final IWorkbenchWindow window) {
// Creates the actions and registers them.
// Registering is needed to ensure that key bindings work.
// The corresponding commands keybindings are defined in l file.
/
/ Registering also provides automatic disposal of the actions when
// the window is closed.
exitAction = ate(window);
register(exitAction);
aboutAction = new AboutAction(window);
register(aboutAction);
openViewAction= new OpenViewAction(window, "Open Another Message View", View.ID);
register(openViewAction);
messagePopupAction = new MessagePopupAction("Open Message", window);
register(messagePopupAction);
helpContentAction = ActionFactory.ate(window);
register(helpContentAction);
helpSerchAction = ActionFactory.ate(window);
register(helpSerchAction);
helpDynamicAction = ActionFactory.ate(window);
register(helpDynamicAction);
}
protected void fillMenuBar(IMenuManager menuBar) {
MenuManager fileMenu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE);
MenuManager helpMenu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP);
jsp帮助文档menuBar.add(fileMenu);
// Add a group marker indicating where action set menus will appear.
menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
menuBar.add(helpMenu);
// File
fileMenu.add(messagePopupAction);
fileMenu.add(openViewAction);
fileMenu.add(new Separator());
fileMenu.add(exitAction);
// Help
// Help
helpMenu.add(aboutAction);
helpMenu.add(helpContentAction);
helpMenu.add(helpSerchAction);
helpMenu.add(helpDynamicAction);
}
protected void fillCoolBar(ICoolBarManager coolBar) {
IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
coolBar.add(new ToolBarContributionItem(toolbar, "main"));
toolbar.add(openViewAction);
toolbar.add(messagePopupAction);
}
}
三、添加依赖的插件
打开l,转到"依赖项"的tab页,点击"添加"按钮,需要添加依赖项:
四、核心类RAPHelpUI
这个类继承AbstractHelpUI,在这里类里,实现了帮助内容,动态帮助,帮助搜索等功能。
public class RAPHelpUI extends AbstractHelpUI {
//展示帮助的内容
public void displayHelp() {
openHelpWindow( getBaseUrl( "/index.jsp " ) );
}
private void openHelpWindow( String url ) {
Shell parentShell = getActiveShell();
Shell shell = new Shell( parentShell, SWT.SHELL_TRIM );
GridLayout layout = new GridLayout( 1, false );
layout.marginHeight = 0;
layout.marginWidth = 0;
shell.setLayout( layout );
shell.setSize( 600, 480 );
shell.setLocation( 150, 150 );
Browser browser = new Browser( shell, SWT.NONE );
browser.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); browser.setUrl( url );
shell.open();
}
/
/展示帮助的搜索
public void displaySearch() {
}
private Shell getActiveShell() {
IWorkbench workbench = Workbench();
Shell parentShell = ActiveWorkbenchWindow().getShell();
return parentShell;
}
//展示帮助的资源
public void displayHelpResource( String href ) {
openHelpWindow( getBaseUrl( "/topic" + href ) );
}
public boolean isContextHelpDisplayed() {
return false;
}
//展示动态帮助
public void displayDynamicHelp() {
super.displayDynamicHelp();
displayHelp();
}
public void displayContext( IContext context, int x, int y ) {
String text = Text();
MessageDialog.openInformation( getActiveShell(), "Context Help", text ); }
private static String getBaseUrl( String path ) {
String helpURL = " 127.0.0.1:2262/help " + path;
Object[] param = new Object[]{
String.valueOf( Request().getServerPort() )
};
return MessageFormat.format( helpURL, param );
}
}
五、实现扩展点
实现扩展点lipse.ui.helpsupport扩展点。这个扩展点实现了帮助菜单和帮助内容的关联。
六、测试
启动rap项目,验证帮助系统是否可用。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论