如果按下该编辑器内的按钮,则关闭编辑器? (RCP 日食)
最喜欢的 我有一个用户界面,当我选择一个项目(在树中)然后按“添加”按钮时,我会得到一个新的编辑器。每个项目我都可以得到一个编辑。 (但都有相同的ID) 我的目的是仅关闭 item1 的编辑器,例如,当我按“保存”时。我可以使用以下方法关闭所有编辑器: getSite().getWorkbenchWindow().getActivePage().closeAllEditors(true); 但不仅仅是我需要关闭的那个。以下解决方案帮助了我:
// Creating and opening
MyObject item1 = ... //create item1
// open editor
myInput = new MyEditorInput(item1)
IDE.openEditor(workbenchPage, myInput, MY_EDITOR_ID);
// Closing
tmpInput = new MyEditorInput(item1)
IEditorReference[] editorReferences = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()
.getEditorReferences();
List<IEditorReference> relevantEditors = new ArrayList<IEditorReference>();
for (IEditorReference iEditorReference : editorReferences) {
if (iEditorReference.getEditorInput().equals(tmpInput)) {
relevantEditors.add(iEditorReference);
}
}
PlatformUI
.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
.closeEditors(
(IEditorReference[]) relevantEditors.toArray(new IEditorReference[relevantEditors
.size()]), true);
……但我仍然有一些问题……因为我可以同时打开许多编辑器,并且所有编辑器都有相同的“保存”按钮,所以我碰巧在编辑器1中按了“保存”但关闭editor3...实际上,我保存了最后一个打开的编辑器(感谢它的“项目”)...这就是问题..所以我想知道是否有一种方法可以识别其中的编辑器按钮存在,所以我关闭它.. 非常感谢,我感谢任何帮助或提示(很抱歉,如果我的问题看起来很简单并且不值得被问,但我仍然是初学者......)
favorite
I have a UI in which when I select an item (in a tree) and then press a button "add", I get a new editor. With each item I can get an editor. (but all have the same ID)
My purpose is to close only the editor of item1, for example, when I press "save". I'm able to close all the editors with: getSite().getWorkbenchWindow().getActivePage().closeAllEditors(true);
But not only the one that I need to close. The following solution helped me:
// Creating and opening
MyObject item1 = ... //create item1
// open editor
myInput = new MyEditorInput(item1)
IDE.openEditor(workbenchPage, myInput, MY_EDITOR_ID);
// Closing
tmpInput = new MyEditorInput(item1)
IEditorReference[] editorReferences = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()
.getEditorReferences();
List<IEditorReference> relevantEditors = new ArrayList<IEditorReference>();
for (IEditorReference iEditorReference : editorReferences) {
if (iEditorReference.getEditorInput().equals(tmpInput)) {
relevantEditors.add(iEditorReference);
}
}
PlatformUI
.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
.closeEditors(
(IEditorReference[]) relevantEditors.toArray(new IEditorReference[relevantEditors
.size()]), true);
….but I still have some problems... As I can open many editors in the same time, and all of them have the same button "save", it happens that I press "save" in editor1 but close editor3... Actually, I save the last editor to be open (thanks to its "item")... this is the problem.. So I'm wondering if there is a way to identify the editor in which the button exists, so that I close it..
Thanks a lot I appreciate any help or hint (Sorry if my questions look easy and not worth being asked, but I'm still a beginner...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果按钮在您的 IEditorPart 实现中呈现,您可以直接在 EditorPart 中关闭编辑器。
if the Button is rendered in your IEditorPart implementation, you can close the editor directly in your EditorPart.
可以使用 RCP eclipse 打开或关闭选定编辑器时打开的多个编辑器。
Multiple Editor open at time selected editor can be open or close using RCP eclipse.