4

I'm having a bit of an issue with an eclipse plugin that I am working on. In this plugin, a special type of plugin-specific editor is often opened programmatically; this is triggered by various actions in various views/editors, but the code to open the editor is the same. The plugin-specific editors open fine; however, I've recently noticed that every time one of these editors is opened, a strange focus glitch happens:

When the editor is opened, it appears to receive focus, but if the previously active view/editor is clicked immediately after this, it does not take back focus. As soon as anything other than the previously active view/editor is clicked, the problem is instantly solved, and focus resumes normally.

As an example, say you choose a context menu option from the Package Explorer view, which causes an editor to open. The editor opens properly and appears to have focus. After this, you first click again on the Package Explorer, but it doesn't get focus (the editor still appears to have focus). You right-click on Package Explorer, but Package Explorer-specific context menu items do not appear. After this, you click on some other view and then on Package Explorer again. Now Package Explorer gets focus, as normal.

This is the code I'm using to open the editor:

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final GraphEditorPart gp = (GraphEditorPart) page.openEditor(new NullEditorInput(), "editor.id");

After this, the editor is populated with some visuals, via the albireo SWT-AWT bridge (Not sure if this is relevant to the problem -- the class used for main editor elements is org.eclipse.albireo.core.SwingControl).

I thought perhaps the problem was that the editor wasn't "really" getting focus, or the previously active view wasn't "really" losing focus, so I tried adding the following line:

page.activate(gp);

However this didn't seem to change anything. Why this might happen?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Reyan
  • 584
  • 1
  • 5
  • 16
  • 1
    Does your editor part implement a setFocus() method? – Paul Webster Oct 01 '12 at 14:32
  • Yes, it does. Its setFocus() actually just sets the focus to the SwingControl instance – Reyan Oct 04 '12 at 14:41
  • I'm still having this problem, and I actually noticed it is occurring in more situations than I originally thought. Almost every time one of my plugin's editors or views are opened, some sort of focus problem happens. The one thing they have in common is this albireo SWT-AWT SwingControl thing, so I'm suspecting even more strongly that this is the cause. – Reyan Apr 24 '13 at 14:50
  • Also, all of these problems behave even worse on Mac - sometimes my editors gain focus for no reason, for example (ie pop up from the bottom of the stack of editors) – Reyan Apr 24 '13 at 14:51

1 Answers1

-1

package name:rcp_demo.Editor

class name: EmpCommand.java, EmployeeEditor.java and EmployeeEditorInput.java


package rcp_demo.Editor;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;

public class EmpCommand extends AbstractHandler {
    public static final String Id = "rcp_demo.Editor.EmpCommand";

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {

         IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
            IWorkbenchPage page = window.getActivePage();
            IEditorReference[] editors = page.getEditorReferences();
            EmployeeEditorInput input = new EmployeeEditorInput();

            //All Comments are easily understand
            //public class EmployeeEditorInput implements IEditorInput{}

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

            //List out all Exist editor
            //compare with EmployeeEditor.Id="rcp_demo.Editor.emp";

              if (editors[i].getId().equals(EmployeeEditor.Id)) {

                //public class EmployeeEditor extends EditorPart
                //{
                //  public static final String Id="rcp_demo.Editor.emp";
                //      public void createPartControl(Composite parent) {.....}
                //}

                    page.activate(editors[i].getEditor(true));
                    System.out.println("set focus an existing editor(Employee)");
                    return null;
              } 
            }
            try {
                //open new Editor like EmployeeEditor.Id="rcp_demo.Editor.emp";
                page.openEditor(input,EmployeeEditor.Id);
                System.out.println("open Editor(Employee) ");
            } catch (PartInitException e) {
                e.printStackTrace();
            }
        return null;
    }
}

Full describe this question and answer visit : Eclipse RCP : have the same editor open in editor window

Community
  • 1
  • 1
Chetan Bhagat
  • 610
  • 6
  • 21
  • Please provide some explanation for your answer so it will be easy to be understood by others. – afxentios Jan 13 '17 at 09:40
  • Full describe this question and answer please visit : http://stackoverflow.com/questions/41606181/eclipse-rcp-have-the-same-editor-open-in-editor-window thanks. – Chetan Bhagat Jan 13 '17 at 09:59
  • @ChetanBhagat the link is dead. Could you either provide a new one or explain your answer? – Sadık Mar 22 '19 at 08:10