开发者

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

Is there a way to run a class everytime editor page receive focus, something like prompt message when a class source has changed outside eclips开发者_开发技巧e? Can a plug-in editor or extension do this work?


The FAQ "How do I find out what view or editor is selected?" can help you call your class when the Editor is active (which is when you can test if it has focus as well), by using a IPartService:

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

  • IPartListener
  • and the poorly named IPartListener2.

You should always use this second one as it can handle part-change events on parts that have not yet been created because they are hidden in a stack behind another part.
This listener will also tell you when a part is made visible or hidden or when an editor's input is changed:

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);

Note: IWorkbenchPage implements IPartService directly.
You can also access an activation service by using IWorkbenchWindow.getPartService().


I am click Toolbar or Button to get focus which view or editor current working on RCP eclipse

//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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜