Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Eclipse4文本编辑器应用程序的自定义ISaveHandler和IWindowCloseHandler_Eclipse_Rcp_E4 - Fatal编程技术网

Eclipse4文本编辑器应用程序的自定义ISaveHandler和IWindowCloseHandler

Eclipse4文本编辑器应用程序的自定义ISaveHandler和IWindowCloseHandler,eclipse,rcp,e4,Eclipse,Rcp,E4,有关问题 我还有一个EclipseRCP4应用程序,其中有多个编辑器部件实现MDirtyable和@Persist 这些部件是可关闭的。当用户关闭一个部件时,应该有一个自定义弹出窗口,询问用户是否真的想保存该部件 此外,当用户关闭应用程序时,弹出窗口应提示用户关闭/保存脏零件。 基本上,它旨在删除默认的CloseEclipse4对话框 我已经在生命周期类中实现了订阅应用程序启动完成事件UIEvents.UILifeCycle.APP_startup_complete的自定义ISaveHandle

有关问题 我还有一个EclipseRCP4应用程序,其中有多个编辑器部件实现MDirtyable和@Persist

这些部件是可关闭的。当用户关闭一个部件时,应该有一个自定义弹出窗口,询问用户是否真的想保存该部件

此外,当用户关闭应用程序时,弹出窗口应提示用户关闭/保存脏零件。 基本上,它旨在删除默认的CloseEclipse4对话框

我已经在生命周期类中实现了订阅应用程序启动完成事件UIEvents.UILifeCycle.APP_startup_complete的自定义ISaveHandler和IWindowCloseHandler

自定义IWindowCloseHandler在对话框方面运行良好,但自定义ISaveHandler则不然

ISaveHandler.save在定义如下时返回stackoverflow错误:

@凌驾 公共布尔值saveMPart dirtyPart,布尔值确认{ EPartService partService=dirtyPart.getContext.getEPartService.class; //尝试关闭部件并通过将文档保存到光盘 //调用@Persist方法 return partService.savePartdirtyPart,确认; } 我已附上完整的LifeCycleManager类:

公共类生命周期管理器{ @注入IEventBroker事件代理; @加工添加 public void processadditions应用程序,EModelService modelService{ MWindow window=MWindowmodelService.findapplication-trimmedwindow,应用程序; eventBroker.subscribeUIEvents.UILifeCycle.APP\u启动\u完成, 新应用程序StartupCompleteEventHandlerWindow、模型服务、应用程序; } 公共类AppStartupCompleteEventHandler实现EventHandler{ 私人窗户; 私人地图应用程序; 私有ISaveHandler-saveHandler; AppStartupCompleteEventHandlerMWindow窗口、EModelService模型服务、MapApplication应用程序{ 窗口=窗口; app=应用程序; } @凌驾 公共无效HandleEvent事件{ window.getContext.setisaveholder.class,新的isaveholder{ @凌驾 公共布尔值saveMPart dirtyPart,布尔值确认{ System.out.printlparte PARA SALVAR…+dirtyPart.getLabel; EPartService partService=dirtyPart.getContext.getEPartService.class; //hidePartdirtyPart,true; return partService.savePartdirtyPart,确认; //返回true; } @凌驾 公共布尔存储部件集合方向部件,布尔确认{ 返回false; } @凌驾 公共保存Promptosavempart dirtyPart{ 返回PromptoSavedialogDirtypart; } @凌驾 公共存储[]PromptosaveCollection dirtyParts{ 返回null; } }; saveHandler=isavehandler thewindow.getContext.getISaveHandler.class; window.getContext.setIWindowCloseHandler.class,新的IWindowCloseHandler{ @凌驾 公共布尔关闭窗口{ List listHandlers=window.getHandlers; System.out.printlnlistHandlers.size; Shell=Shell window.getWidget; 如果选择MessageDialog.openConfirmshell,请关闭Nastran编辑器,是否确实要关闭整个应用程序{ Collection allPartServices=getAllPartServicesapp; 如果包含irtypartsallpartservices{ 返回iterateOverDirtyParts allPartServices; } 否则{ 返回true; } } 返回false; }}; } 私有集合GetAllPartServicesApplication应用程序{ List partServices=newarraylist; EModelService modelService=application.getContext.getEModelService.class; 列表元素=modelService.findElementsapplication,MWindow.class,EModelService.IN\u ACTIVE\u透视图, 新元素MatcherFull,MWindow.class,列表为空; 对于MWindow:元素{ 如果w.isVisible&&w.istoberended{ EPartService partService=w.getContext.getEPartService.class; 如果partService!=null{ partServices.addpartService; } } } 退货服务; } 私有布尔值包含DirtypartsCollection partServices{ 对于EPartService零件服务:零件服务{ if!partService.getDirtyParts.isEmpty返回true; } 返回false; } 私有布尔迭代器VerDirtypartsCollection allPartServices{ 对于EPartService partService:allPartServices{ Collection dirtyParts=partService.getDirtyParts; 格式部分dirtyPart:dirtyParts{ switchsaveHandler.PromptosaveDirtypart{ 案例 否:中断; 案例是: saveHandler.savedirtyPart,false; 打破 案例取消:返回false; } } } 返回true; } 私人保存Promptosavedialogmpart dirtyPart{ MessageDialog=新建MessageDialog ShelltheWindow.getWidget,保存文件,null, “+dirtyPart.getLabel+”已被修改。是否保存更改?、MessageDialog.QUESTION、新字符串[]{YES,NO,CANCEL},0; 切换对话框。打开{ 案例0:返回Save.YES; 案例1:返回Save.NO; 案例2:返回Save.CANCEL; 默认:返回保存。取消; } } } }///生命周期结束管理器 ISaveHandler的save方法是从EPartService savePart方法中调用的,因此您不能再次调用savePart

相反,您应该只调用零件的@Persist方法。比如:

@凌驾 公共布尔值savefinal MPart dirtyPart,final boolean confirm { 如果确认 { 开关PROMPTOSAVEDIRTypart { 违约: 案件编号: 返回true; 个案取消: 返回false; 案例是: 打破 } } 尝试 { ContextInjectionFactory.invokedirtyPart.getObject、Persist.class、dirtyPart.getContext; } 捕获最终注射异常 { //TODO忽略或记录错误 } 返回true; }