NatTable and context/dependency injection [message #1767926] |
Wed, 12 July 2017 04:28  |
Eclipse User |
|
|
|
Hi everyone,
I'm currently working as an intern in a lab and I have to use contexts, dependency injections, and NatTable elements in my project. Problem is, I've never used any of those before and I have a bit of trouble getting the gist of it. In my project, I need to export the NatTable object created in a specific class through another class. The export should be associated to a handler linked to a button. The button was created in the application model (I think? it's called fragment.e4xmi).
For the export, I'm using native NatTable commands that work well when I use them within the same class as the one where the NatTable object is. However, I can't do that if I want to associate the export to the button I should link it to; I need to put the NatTable in the context, then inject it to the class I need to use it in. But then again, I'm not sure this is how it should be done...
Here is what I do (I only show you the snippets of code I added to the project):
In the class "UiHazopTable.java":
@Inject
public NatTable init(IEclipseContext context) {
//it initiliazes the nattable object before I put it in the context (not shown)
context.set("UiHazopTable.nat", natTable);
}
In the class "ExportHazopTable.java" (handler for the export button):
@Inject
private NatTable natTable;
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell s , @Named("fr.laas.hazopuml.ui.commandparameter.0") Object o) {
// TO RETRIEVE OBJECT
ExportCommand cmd = new ExportCommand(natTable.getConfigRegistry(), natTable.getShell());
natTable.doCommand(cmd);
I tried to follow Vogella's tutorials but I still can't proper grasp how things should be done. I hope I'm clear enough.
Thank you for reading through!
|
|
|
|
|
|
|
|
|
|
Re: NatTable and context/dependency injection [message #1768325 is a reply to message #1768322] |
Mon, 17 July 2017 09:38  |
Eclipse User |
|
|
|
I was convinced the "fr.laas.hazopuml.ui.command.clicksum" was supposed to be the ID of the command called by the class, but I just deleted it altogether and now it works! Both my test and the exportation of the table. I guess once I point the handler in the fragment to the corresponding class, the handler's ID doesn't need to be added to the class's execute.
Thank you so much for your help! :)
|
|
|
Powered by
FUDForum. Page generated in 0.06473 seconds