How to run a class anytime the editor page gets focus on Eclipse?

Is there a way to run the class every time the focus on the editor page gets focus, something like a hint when the class source has changed outside of eclipse? Can an editor or plug-in extension do the job?

+3
source share
2 answers

The frequently asked questions “ How do I know which view or editor is selected? ” Can help you call your class when the editor is active (this is when you can check if it has focus as well) usingIPartService :

Two types of listeners can be added to a part service:

, , , .
, :

IWorkbenchPage page = ...;
   //the active part
   IWorkbenchPart active = page.getActivePart();
   //adding a listener
   IPartListener2 pl = new IPartListener2() {
      public void partActivated(IWorkbenchPartReference ref)
         System.out.println("Active: "+ref.getTitle());
      }
      ... other listener methods ...
   };
   page.addPartListener(pl);

: IWorkbenchPage IPartService .
IWorkbenchWindow.getPartService().

+4

" " "", , Eclipse RCP

//class:Current_Workbech  extends AbstractHandler to execute() method

public class Current_Workbech  extends AbstractHandler{

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

        IPartService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService();

        //MessageDialog box open to get title which view or editor focus and current working

        MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindow(
                event).getShell(), "Current Workbench Window", service.getActivePart().getTitle()+"");

        return null;
    }
}
0

Source: https://habr.com/ru/post/1777244/


All Articles