RCP开发小结
1 RCP是一种插件式开发系统,其运行流程是这样的:
2 增加菜单和命令
<!--[if !supportLists]-->(1)<!--[endif]-->在plugin.xml文件里增加一个扩menu扩展点,然后再新建一个menu;
<!--[if !supportLists]-->(2)<!--[endif]-->然后在menu里新建一个command;
<!--[if !supportLists]-->(3)<!--[endif]-->在plugin.xml文件里增加一个command扩展点;
3 创建和打开对话框
Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
//创建一个文件对话框
FileDialog fileDialog=new FileDialog(shell);
fileDialog.setText("select file");
fileDialog.setFilterExtensions(new String[]{"*.txt"});
fileDialog.setFilterNames(new String[]{"textFiles(*.txt)"});
String selected= fileDialog.open();
System.out.println(selected);
//创建一个格式对话框
FontDialog fontDialog=new FontDialog(shell);
fontDialog.setText("select the your favorite font");
FontData fontData=fontDialog.open();
System.out.println(fontData);
//创建一个颜色对话框
ColorDialog colorDialog=new ColorDialog(shell);
colorDialog.setText("select your favorite color");
RGB rgb=colorDialog.open();
System.out.println(rgb);
MessageDialog.openConfirm(shell, "confirm", "please confirm");
MessageDialog.openError(shell, "error", "Error accured");
MessageDialog.openInformation(shell, "info", "info for you");
MessageDialog.openQuestion(shell, "question", "Really,really?");
MessageDialog.openWarning(shell, "warning", "I warn you");
4 创建列表选择对话框
Shell shell=HandlerUtil.getActiveWorkbenchWindow(event).getShell();
ElementListSelectionDialog dialog=new ElementListSelectionDialog(shell, new LabelProvider());
dialog.setElements(new String[]{"linux","mac","windows"});
dialog.setTitle("which os dou you select");
int retcode=dialog.open();
Object[] result=dialog.getResult();
for(Object s:result){
System.out.println(s.toString());
}