Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Dependency Injection
Dependency Injection [message #1080106] Mon, 05 August 2013 13:28 Go to next message
Patrick Sowada is currently offline Patrick SowadaFriend
Messages: 6
Registered: July 2009
Junior Member
Hi,

i want to use my own DI objects but unfortunately it doesn't work.

I use eclipse 4.2.2.

I want to use the variable "table" from the ListView class in the CreateFeatureHandler class. I always get the following error message:
Quote:
org.eclipse.e4.core.di.InjectionException: Unable to process "ListView.table": no actual value was f
ound for the argument "javafx.scene.control.TableView<Feature>".


@SuppressWarnings("restriction")
public class ListView {
 
    @Inject 
    private TableView<Feature> table;
    
    
    @SuppressWarnings("unchecked")
    @Inject
    public ListView(BorderPane parent, final MApplication application, IEclipseContext context) {
    table = new TableView<Feature>();
       
        ... (content of the table)
   
    context.modify("table", table);
    }
    
}


public class CreateFeatureHandler {
 
 
    private Stage stage;
 
    @Execute
    @Inject
    void execute(@Optional final Feature feature, @Named("table") final TableView<Feature> table) {
    GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(0, 10, 0, 10));
    final TextField name = new TextField();
    name.setPromptText("name");
    final TextField number = new TextField();
    number.setPromptText("number");
    Button b = new Button("Create");
    b.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent e) {
        Feature feat = TeamFactory.eINSTANCE.createFeature();
        feat.setName(name.getText());
        feat.setNumber(number.getText());
        LocalFileTest.addFeatureAndSaveIt(feat);
 
        System.out.println("TABLE:\t"+table);
        stage.close();
        }
    });
 
    grid.add(new Label("name:"), 0, 0);
    grid.add(name, 1, 0);
    grid.add(new Label("number:"), 0, 1);
    grid.add(number, 1, 1);
    grid.add(b, 1, 2);
 
    stage = new Stage(StageStyle.DECORATED);
    stage.initModality(Modality.WINDOW_MODAL);
 
    Scene s1 = new Scene(grid);
    stage.setScene(s1);
    stage.show();
 
    }
Re: Dependency Injection [message #1080114 is a reply to message #1080106] Mon, 05 August 2013 13:35 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5470
Registered: July 2009
Senior Member
You need to call IEC.set("table",table) - modify only works if you have
declared this variable at first on the IEC (not needed in your case)

Tom

On 05.08.13 15:29, Patrick Sowada wrote:
> Hi,
>
> i want to use my own DI objects but unfortunately it doesn't work.
>
> I use eclipse 4.2.2.
>
> I want to use the variable "table" from the ListView class in the
> CreateFeatureHandler class. I always get the following error message:
> Quote:
>> org.eclipse.e4.core.di.InjectionException: Unable to process
>> "ListView.table": no actual value was f
>> ound for the argument "javafx.scene.control.TableView<Feature>".
>
>
> @SuppressWarnings("restriction")
> public class ListView {
>
> @Inject private TableView<Feature> table;
> @SuppressWarnings("unchecked")
> @Inject
> public ListView(BorderPane parent, final MApplication application,
> IEclipseContext context) {
> table = new TableView<Feature>();
> ... (content of the table)
> context.modify("table", table);
> }
> }
>
> public class CreateFeatureHandler {
>
>
> private Stage stage;
>
> @Execute
> @Inject
> void execute(@Optional final Feature feature, @Named("table") final
> TableView<Feature> table) {
> GridPane grid = new GridPane();
> grid.setHgap(10);
> grid.setVgap(10);
> grid.setPadding(new Insets(0, 10, 0, 10));
> final TextField name = new TextField();
> name.setPromptText("name");
> final TextField number = new TextField();
> number.setPromptText("number");
> Button b = new Button("Create");
> b.setOnAction(new EventHandler<ActionEvent>() {
> public void handle(ActionEvent e) {
> Feature feat = TeamFactory.eINSTANCE.createFeature();
> feat.setName(name.getText());
> feat.setNumber(number.getText());
> LocalFileTest.addFeatureAndSaveIt(feat);
>
> System.out.println("TABLE:\t"+table);
> stage.close();
> }
> });
>
> grid.add(new Label("name:"), 0, 0);
> grid.add(name, 1, 0);
> grid.add(new Label("number:"), 0, 1);
> grid.add(number, 1, 1);
> grid.add(b, 1, 2);
>
> stage = new Stage(StageStyle.DECORATED);
> stage.initModality(Modality.WINDOW_MODAL);
>
> Scene s1 = new Scene(grid);
> stage.setScene(s1);
> stage.show();
>
> }
Re: Dependency Injection [message #1080115 is a reply to message #1080114] Mon, 05 August 2013 13:38 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5470
Registered: July 2009
Senior Member
.... not unimportant - this naturally only works if the part with the
table is the current active part in your application because handlers
are executed always in the current active context.

Tom

On 05.08.13 15:35, Tom Schindl wrote:
> You need to call IEC.set("table",table) - modify only works if you have
> declared this variable at first on the IEC (not needed in your case)
>
> Tom
>
> On 05.08.13 15:29, Patrick Sowada wrote:
>> Hi,
>>
>> i want to use my own DI objects but unfortunately it doesn't work.
>>
>> I use eclipse 4.2.2.
>>
>> I want to use the variable "table" from the ListView class in the
>> CreateFeatureHandler class. I always get the following error message:
>> Quote:
>>> org.eclipse.e4.core.di.InjectionException: Unable to process
>>> "ListView.table": no actual value was f
>>> ound for the argument "javafx.scene.control.TableView<Feature>".
>>
>>
>> @SuppressWarnings("restriction")
>> public class ListView {
>>
>> @Inject private TableView<Feature> table;
>> @SuppressWarnings("unchecked")
>> @Inject
>> public ListView(BorderPane parent, final MApplication application,
>> IEclipseContext context) {
>> table = new TableView<Feature>();
>> ... (content of the table)
>> context.modify("table", table);
>> }
>> }
>>
>> public class CreateFeatureHandler {
>>
>>
>> private Stage stage;
>>
>> @Execute
>> @Inject
>> void execute(@Optional final Feature feature, @Named("table") final
>> TableView<Feature> table) {
>> GridPane grid = new GridPane();
>> grid.setHgap(10);
>> grid.setVgap(10);
>> grid.setPadding(new Insets(0, 10, 0, 10));
>> final TextField name = new TextField();
>> name.setPromptText("name");
>> final TextField number = new TextField();
>> number.setPromptText("number");
>> Button b = new Button("Create");
>> b.setOnAction(new EventHandler<ActionEvent>() {
>> public void handle(ActionEvent e) {
>> Feature feat = TeamFactory.eINSTANCE.createFeature();
>> feat.setName(name.getText());
>> feat.setNumber(number.getText());
>> LocalFileTest.addFeatureAndSaveIt(feat);
>>
>> System.out.println("TABLE:\t"+table);
>> stage.close();
>> }
>> });
>>
>> grid.add(new Label("name:"), 0, 0);
>> grid.add(name, 1, 0);
>> grid.add(new Label("number:"), 0, 1);
>> grid.add(number, 1, 1);
>> grid.add(b, 1, 2);
>>
>> stage = new Stage(StageStyle.DECORATED);
>> stage.initModality(Modality.WINDOW_MODAL);
>>
>> Scene s1 = new Scene(grid);
>> stage.setScene(s1);
>> stage.show();
>>
>> }
>
Re: Dependency Injection [message #1080846 is a reply to message #1080115] Tue, 06 August 2013 12:54 Go to previous message
Patrick Sowada is currently offline Patrick SowadaFriend
Messages: 6
Registered: July 2009
Junior Member
great it works, thx for your help
Previous Topic:e(fx)clipse 0.9.0 is feature complete
Next Topic:Re: application doesn't start anymore
Goto Forum:
  


Current Time: Sat Nov 29 01:52:37 GMT 2014

Powered by FUDForum. Page generated in 0.02050 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software