
org.dwcj.controls.button.sinks.ButtonClickEventSink Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dwcj Show documentation
Show all versions of dwcj Show documentation
Program that allows implementation of an API layer
enabling the developer to build application software for the BBj
ecosystem by using Java or other JVM languages like Kotlin instead
of the BBj Business Basic syntax built into the BBj product.
The newest version!
package org.dwcj.controls.button.sinks;
import com.basis.bbj.proxies.event.BBjButtonPushEvent;
import com.basis.bbj.proxies.sysgui.BBjControl;
import org.dwcj.Environment;
import org.dwcj.bridge.ControlAccessor;
import org.dwcj.controls.button.Button;
import org.dwcj.controls.button.events.ButtonClickEvent;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.function.Consumer;
public final class ButtonClickEventSink {
private ArrayList> targets;
private final Button button;
@SuppressWarnings({"static-access"})
public ButtonClickEventSink(Button btn) {
this.targets = new ArrayList<>();
this.button = btn;
BBjControl bbjctrl = null;
try {
bbjctrl = ControlAccessor.getDefault().getBBjControl(btn);
bbjctrl.setCallback(Environment.getInstance().getBBjAPI().ON_BUTTON_PUSH, //NOSONAR
Environment.getInstance().getDwcjHelper().getEventProxy(this, "pushEvent"),
"onEvent");
} catch (Exception e) {
Environment.logError(e);
}
}
public ButtonClickEventSink(Button btn, Consumer callback) {
this.targets = new ArrayList<>();
this.targets.add(callback);
this.button = btn;
BBjControl bbjctrl = null;
try {
bbjctrl = ControlAccessor.getDefault().getBBjControl(btn);
bbjctrl.setCallback(Environment.getInstance().getBBjAPI().ON_BUTTON_PUSH, //NOSONAR
Environment.getInstance().getDwcjHelper().getEventProxy(this, "pushEvent"),
"onEvent");
} catch (Exception e) {
Environment.logError(e);
}
}
public void pushEvent(BBjButtonPushEvent ev) { // NOSONAR
ButtonClickEvent dwcEv = new ButtonClickEvent(this.button);
Iterator> it = targets.iterator();
while (it.hasNext())
it.next().accept(dwcEv);
}
/**
* Clicks the button, for testing purposes
*/
public void doClick() {
ButtonClickEvent dwcEv = new ButtonClickEvent(button);
Iterator> it = targets.iterator();
while (it.hasNext())
it.next().accept(dwcEv);
}
public void addCallback(Consumer callback) {
targets.add(callback);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy