Is there a way for Eclipse to launch its taskbar icon when a lot of time is up?

I often minimize Eclipse to read or work on something else for several minutes while I wait for it to do something (for example, run a large set of JUnit tests, synchronize a huge number of files with a repo, run long Ant build, etc. .d.). I have to check every 30 seconds or so to find out if this is still over. I would like Eclipse to warn me, preferably by flashing its taskbar icon after it completes a time-consuming operation. Are there any settings or plugins that can do this?

+4
source share
2 answers

I believe that you have Mylyn installed, this should be enabled by default for Windows 7. See here and here . Regarding post-build actions, I don't know any existing Eclipse plugins that do this. However, I did not exhaustively search the market . However, this can be achieved using the existing Eclipse APIs, but this requires someone to create a new Eclipse plugin.

The Eclipse Platform framework has an API called IJobManager . The developer could write a new Eclipse plugin that could use this API to listen for job changes and do the following:

  • Create an eclipse plugin, register a listener before IJobManager at startup.
  • Once an interesting task is completed, it can disable an external task / script using the regular Java process API in the JDK

All this can be done in a single Java file, possibly less than 500 lines. You can use this template to customize the basic Eclipse plug-in project, including the build system , and it was built-in and ready to be installed in existing Eclipse.

Update . I just found the maven archetype for creating eclipse plugins with tycho here . This would be my recommendation for someone new to create an eclipse / updatesite function.

+4
source

You can create a new plug-in project and create such functionality for yourself. The IJobchangeListener of the Eclipse Jobs API is probably very interesting for you.

IJobChangeListener is an interface in which you can receive notifications for different types of job states.

I created a class called JobListener that adds an IJobChangeListener to the JobManager . With the SampleAction action SampleAction you can register or unregister the listener. this means that if the listener is registered and your application is minimized, you will be notified using MessageDialog (without a blinking taskbar).

I found a link where someone started their swing application. This function must be included in the public void done(final IJobChangeEvent event) method. I did not do this in my test class.

You can also get more information about Job with

 event.getJob(); 

Here you can check the job name:

 String jobName = event.getJob().getName(); 

The name of the task is read by a person, for example, “Garbage collection”, “Update for decoration”, “Construction workspace”, etc.

Class JobListener .

 /** * A job listener which may be added to a job manager */ public class JobListener { private MyJobListener listener = null; private IWorkbenchWindow window = null; private boolean active = false; public JobListener(IWorkbenchWindow window) { this.window = window; } /** * register the job listener */ public void register() { listener = new MyJobListener(window); IJobManager jobMan = Job.getJobManager(); jobMan.addJobChangeListener(listener); active = true; } /** * unregister the job listener */ public void unregister() { IJobManager jobMan = Job.getJobManager(); jobMan.removeJobChangeListener(listener); active = false; } public boolean isActive() { return active; } class MyJobListener implements IJobChangeListener { private IWorkbenchWindow window; public MyJobListener(IWorkbenchWindow window) { this.window = window; } @Override public void sleeping(IJobChangeEvent event) { } @Override public void scheduled(IJobChangeEvent event) { } @Override public void running(IJobChangeEvent event) { } @Override public void done(final IJobChangeEvent event) { window.getShell().getDisplay().asyncExec(new Runnable() { @Override public void run() { if(window.getShell().getMinimized()) { MessageDialog.openInformation( window.getShell(), "Test", "Job " + event.getJob().getName() + " done."); } } }); } @Override public void awake(IJobChangeEvent event) { } @Override public void aboutToRun(IJobChangeEvent event) { System.out.println("About to run: " + event.getJob().getName()); } } } 

I called this class from the SampleAction.java class

 public class SampleAction implements IWorkbenchWindowActionDelegate { private IWorkbenchWindow window; private JobListener listener; /** * The constructor. */ public SampleAction() { } public void run(IAction action) { if(listener.isActive()) { listener.unregister(); MessageDialog.openInformation( window.getShell(), "Lrt", "Unregistered"); } else { listener.register(); MessageDialog.openInformation( window.getShell(), "Lrt", "Registered"); } } public void selectionChanged(IAction action, ISelection selection) { } public void dispose() { } public void init(IWorkbenchWindow window) { this.window = window; this.listener = new JobListener(window); } 

You can start by developing the eclipse plugin by creating a new plugin project:

 File > New > Project > Plugin Project 

I used the Hello World project template to verify the code above.

+1
source

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


All Articles