Reputation: 1821
following situation in a Eclipse RCP 4.X Software.
I have a part class with a button inside, on click I need to execute some tasks like SQL Import...
Question: Where is the right place for SQL Import code? It feels like it is wrong just to put it into a button listener (within a Part class).
Should I create a SQLImport class, and use an object of this? Maybe Eclipse RCP offers some solutions for this kind of problem? Maybe I need to put it into a Handler or something like this?
Thank you all
Upvotes: 0
Views: 120
Reputation: 111142
There is no fixed way of doing this.
If you are going to have several SQL related operations you could create a SQL Service class with the methods you need. You can then inject it to the parts that need to use it.
There are several ways to create services but the simplest for e4 is to just declare the class using:
@Creatable
@Singleton
public class SQLService
{
.... your code
}
You can just inject this:
@Inject
SQLService sqlService;
Using @Creatable
means the injection system will create the class when it is needed. @Singleton
means there will only ever be one instance of the service.
Upvotes: 2