RCP EditorPart 调用doSave的方法

来源:互联网 发布:国际电视直播软件 编辑:程序博客网 时间:2024/05/29 16:46

调用EditorPart的doSaveAs比较容易,调用doSave方法稍微复杂一些,因为需要传入IProgressMonitor参数,如下声明

@Overridepublic void doSave(IProgressMonitor monitor) {// Do the Save operation}@Overridepublic void doSaveAs() {// Do the Save As operation}

可以通过获取IWorkbenchPage,利用IWorkbenchPage作为管理工具进行EditorPart中doSave的调用。

IWorkbenchPage.closeEditor声明如下。

/** * Closes the given editor. The editor must belong to this workbench page. * <p> * If the editor has unsaved content and <code>save</code> is * <code>true</code>, the user will be given the opportunity to save it. * </p> *  * @param editor *            the editor to close * @param save *            <code>true</code> to save the editor contents if required *            (recommended), and <code>false</code> to discard any unsaved *            changes * @return <code>true</code> if the editor was successfully closed, and *         <code>false</code> if the editor is still open */public boolean closeEditor(IEditorPart editor, boolean save);
调用代码如下,关闭时是否保存根据实际需要设置save值即可

IWorkbenchPage page = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();page.closeEditor(page.getActiveEditor(), true);



0 0
原创粉丝点击