fireEvent from Custom class

Inge

I have the following class ProtokollEvent

public class ProtokollEvent extends Event {

//variable holds all devices in given protokoll
private ObservableList<Device> devicesList;

//variable holds SaveResult
private SaveResult result;

//final ProtokollEvents
public static final EventType<ProtokollEvent> PROTOKOLL_SAVE = new EventType(ANY, "PROTOKOLL_SAVE");
public static final EventType<ProtokollEvent> PROTOKOLL_SAVE_DONE = new EventType(ANY, "PROTOKOLL_SAVE_DONE");
public static final EventType<ProtokollEvent> PROTOKOLL_UPDATED = new EventType(ANY, "PROTOKOLL_UPDATED");
public static final EventType<ProtokollEvent> PROTOKOLL_DELETED = new EventType(ANY, "PROTOKOLL_DELETED");

public ProtokollEvent() {
    this(PROTOKOLL_SAVE);
}

public ProtokollEvent(EventType<? extends Event> arg0) {
    super(arg0);
}

public ProtokollEvent(Object arg0, EventTarget arg1, EventType<? extends Event> arg2) {
    super(arg0, arg1, arg2);
}

/**
 * getDevices will return current {@link Device} as ObservableList
 *
 * @return {@link ObservableList} of type {@link Device}
 */
public ObservableList getDev() {
    return devicesList;
}
/**
 * setDevices will set devicesList
 * @param devices ObservableList {@link Device}
 */
public void setDev(ObservableList devices) {
    this.devicesList = devices;
}
/**
 * get the result which is returned from calling saveProtokoll
 * @return result {@link SaveResult}
 */
public SaveResult getResult() {
    return result;
}
/**
 * set the result which is returned after calling saveMessprotokoll in RestCall
 * @param result {@link SaveResult}
 */
public void setResult(SaveResult result) {
    this.result = result;
}

}

in the second class

public class SaveUtils {

private MainWindowController controller;
private ObservableList<RowContainerPruefvorschriftController> rows;
private Protokoll lastSavedProtokoll;
private Protokoll currentSavingProtokoll;

public SaveUtils(MainWindowController control){
    this.controller = control;
}

private void startSaving(){
    currentSavingProtokoll = createProtokoll();
    boolean state = controller.networkOnline.get() ? saveOnline() :saveOffline();
}

public void setRows(ObservableList<RowContainerPruefvorschriftController> rows) {
    this.rows = rows;
    //if rows get set start saveing the data
    startSaving();
}

private boolean saveOffline(){
    return false;
}
private boolean saveOnline() {
    RestCall call = controller.getCall();
    //call saveMessprotokoll and look what SaveResult returns
    SaveResult result = call.saveMessprotokoll(currentSavingProtokoll);
    //create ProtokollEvent to tell all consumers if all was ok
    ProtokollEvent save = new ProtokollEvent(ProtokollEvent.PROTOKOLL_SAVE_DONE);
    save.setResult(result);
    //HOW to fire/dispatch the ProtokollEvent here??????
    //TODO: need to fire this event and listen for it in other classes
    if(result.getResult()>0){
        controller.setLoggerMessage("SavedOnline->Protokoll-Nr.:"+result.getProtokollnr());
    }
    else {
        controller.setLoggerMessage("SavedOnline not successful->Error:"+result.getError_message());
    }        
    return true;
}

}

in the saveOnline function i create a ProtokollEvent and pass it some values. What i now want is to fire or dispatch this event so other code parts could listen to this.

I tried with fireEvent() but as i understood the Oracle-DOCs only NODEs, Windows and Scene are able to do so. But how could i solve it with my custom class?

Additional i ask myself whats is the difference between fireEvent and dispatchEvent?

Inge

Found the solution. All events could be fired through the static method

Event.fireEvent(EventTarget eventTarget,Event event)

where eventTarget specifies the path through which the event will travel (taken from java docs). So for my example i just added the following line

Event.fireEvent(controller.getMainWindowBorderPane(),save);

did it...

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Custom类的fireEvent

来自分类Dev

JavaFX fireEvent StackOverflowError

来自分类Dev

mshtml fireevent onchange不触发

来自分类Dev

selObj.fireEvent不是函数

来自分类Dev

使用Backspace fireEvent从后面删除字符

来自分类Dev

FireEvent中焦点和模糊之间的区别

来自分类Dev

菜单内的fireEvent侦听器错误

来自分类Dev

How to convert a custom list class to json?

来自分类Dev

Custom validation class not loading in Laravel 4

来自分类Dev

Convert xml to custom class using lambda linq

来自分类Dev

How to create a custom login class in cloudmine?

来自分类Dev

Add custom class to wishlist top link

来自分类Dev

C# Action delegate with custom class

来自分类Dev

MapStruct:Object.class到Custom.class的映射

来自分类Dev

Should I wrap my class custom exceptions in my class?

来自分类Dev

Pull Properties from Class

来自分类Dev

populate dropdown from class

来自分类Dev

在TextField中以编程方式触发fireEvent-JavaFX

来自分类Dev

HP QTP / UFT中的fireevent()的功能是什么?

来自分类Dev

如何为“ @ testing-library / react” fireEvent“清除模拟”?

来自分类Dev

fireEvent不会在React组件上单击按钮

来自分类Dev

EXT JS 4.2.4-选择网格行[0]-> FireEvent(“单击”

来自分类Dev

Rails Call Custom Controller Action from Custom Form

来自分类Dev

Access class variable from instance

来自分类Dev

Call a function from an another class

来自分类Dev

Get child class from parent

来自分类Dev

How to import a custom java class to my Antlr Grammar?

来自分类Dev

UITableView is being reset when I use Custom Class

来自分类Dev

Accessing static files from custom template tag