step 1: register with Workbench ProgressService
An EclipseJob
can belong to a family, where a family can be any java Object
. The ProgressService
maintains a table of icons associated with each family. So step one is to register your icon and family in your Activator's start()
method.@Override
public void start(final BundleContext context) throws Exception {
super.start(context);
getWorkbench().getProgressService().
registerIconForFamily(
getImageDescriptor(ICONPATH),
MyTools.PLUGIN_ID);
[...]
Rebuilder rebuilder = new Rebuilder("Initializing My Tools");
rebuilder.schedule(20L);
}
step 2: override belongsTo()
in your Job subclass
Next you override the method belongsTo()
in your subclass with some simpel logic, calling super.belongsTo()
when not equal top allow for Job class hierarchies.public class Rebuilder extends Job {
[...]
@Override
public boolean belongsTo(final Object family) {
if (family.equals(MyTools.PLUGIN_ID)) {
return true;
}
return super.belongsTo(family);
}
[...]
}
Conclusion
As always in Eclipse programming this solution took a long time to find, but can be implemented in a few lines of code once you know how.Caveat
What remains is that you can only do this for Jobs that you launch yourself, and not for other background tasks like the Auto Build jobs that call your Builders.They all share the same icon :-(
I have created a bug for this, please support and vote here.
Do you think that this is something you might consider contributing to the Eclipse FAQ?
BeantwoordenVerwijderenhttp://wiki.eclipse.org/The_Official_Eclipse_FAQs#Runtime_Facilities
Thanks for pointing this out Maarten. The next EA release of Tasktop will be using job families so that all Tasktop Jobs have an appropriate icon.
BeantwoordenVerwijderenI know, I'm late to the party :-)
BeantwoordenVerwijderenThank you for this post. You will see it implemented in the upcoming release of nWire. Once small comment: I noticed that the getImageDescriptor(ICONPATH) will not always work, as the Bundle might not be found at this point. To overcome this, you can get the bundle yourself from the BundleContext argument and use bundle.getResource followed by ImageDescriptor.createFromURL. This should work just fine.