I have the following ProtokollEvent class
public class ProtokollEvent extends Event {
private ObservableList<Device> devicesList;
private SaveResult result;
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);
}
public ObservableList getDev() {
return devicesList;
}
public void setDev(ObservableList devices) {
this.devicesList = devices;
}
public SaveResult getResult() {
return result;
}
public void setResult(SaveResult result) {
this.result = result;
}
}
in second grade
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;
startSaving();
}
private boolean saveOffline(){
return false;
}
private boolean saveOnline() {
RestCall call = controller.getCall();
SaveResult result = call.saveMessprotokoll(currentSavingProtokoll);
ProtokollEvent save = new ProtokollEvent(ProtokollEvent.PROTOKOLL_SAVE_DONE);
save.setResult(result);
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. Now I want to fire or send this event so that other parts of the code can listen to this.
I tried with fireEvent (), but as I understand it, Oracle-DOCs only NODE, Windows and Scene can do this. But how can I solve this with my custom class?
Additionally I ask myself, what is the difference between fireEvent and dispatchEvent?
source
share