如果按下该编辑器内的按钮,则关闭编辑器? (RCP 日食)

发布于 2024-11-29 05:16:53 字数 1418 浏览 1 评论 0原文

最喜欢的 我有一个用户界面,当我选择一个项目(在树中)然后按“添加”按钮时,我会得到一个新的编辑器。每个项目我都可以得到一个编辑。 (但都有相同的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小糖芽 2024-12-06 05:16:53

如果按钮在您的 IEditorPart 实现中呈现,您可以直接在 EditorPart 中关闭编辑器。

button.addListener(SWT.Selection, new Listener() {

    @Override
    public void handleEvent(Event event) {

        PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                .getActivePage().closeEditor(this, true);

    }

});

if the Button is rendered in your IEditorPart implementation, you can close the editor directly in your EditorPart.

button.addListener(SWT.Selection, new Listener() {

    @Override
    public void handleEvent(Event event) {

        PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                .getActivePage().closeEditor(this, true);

    }

});
╭⌒浅淡时光〆 2024-12-06 05:16:53

可以使用 RCP eclipse 打开选定的编辑器或关闭另一个编辑器。

可以使用 RCP eclipse 打开或关闭选定编辑器时打开的多个编辑器。

    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IWorkbenchPage page = window.getActivePage();
    EmployeeEditorInput input = new EmployeeEditorInput();

    //List out all the editors open
    IEditorReference[] editors = page.getEditorReferences();

    for (int i=0; i<editors.length; i++) {

        //class : EmployeeEditor 
        //public static final String Id="rcp_demo.Editor.emp";  

          if (editors[i].getId().equals(EmployeeEditor.Id)) {
            page.activate(editors[i].getEditor(true));

            //or
            //page.closeEditor(page.getActiveEditor(),true);
            System.out.println("Employee Editor Exist");
            return null;
          } 
          else
          {
             page.closeEditor(page.getActiveEditor(), true);
             System.out.println("Close other Editor");  
          }
    }

Selected editor open or another editor can be close using RCP eclipse.

Multiple Editor open at time selected editor can be open or close using RCP eclipse.

    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IWorkbenchPage page = window.getActivePage();
    EmployeeEditorInput input = new EmployeeEditorInput();

    //List out all the editors open
    IEditorReference[] editors = page.getEditorReferences();

    for (int i=0; i<editors.length; i++) {

        //class : EmployeeEditor 
        //public static final String Id="rcp_demo.Editor.emp";  

          if (editors[i].getId().equals(EmployeeEditor.Id)) {
            page.activate(editors[i].getEditor(true));

            //or
            //page.closeEditor(page.getActiveEditor(),true);
            System.out.println("Employee Editor Exist");
            return null;
          } 
          else
          {
             page.closeEditor(page.getActiveEditor(), true);
             System.out.println("Close other Editor");  
          }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文