如何将JavaFX中预先存在的对象传递给控制器​​?

时间:2017-01-13 16:26:58

标签: java eclipse model-view-controller javafx

我正在从我的EMF编辑器中的菜单项启动一个Javafx应用程序,到目前为止工作正常:

public class ComponentModelDerivationHandler extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    if (HandlerUtil.getCurrentSelection(event) instanceof TreeSelection) {
        TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
        if (selection.getFirstElement() instanceof ProductConfiguration) {
            ProductConfiguration pc = (ProductConfiguration) selection.getFirstElement();
            App.main(null);
        }
    }
    return null;
}


public class App extends Application {

public static void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("ui.fxml"));

    stage.setScene(new Scene(root));
    stage.show();
}

public class Controller{
@FXML
private TextField modelName;
@FXML
private Button modelLoad;
@FXML
private ComboBox<String> targetFormatcb;
private VariableComponentModel vacomo;
private ProductConfiguration pc;

//.....methods for some calculations

但是,在启动应用程序之前,存在类型为ProductConfiguration的现有对象,我希望将其传递给控制器​​以进行其他计算。但我既不知道如何获得控制器实例,也不知道如何使对象可用。对此有何建议?

0 个答案:

没有答案