use of com.twosigma.beakerx.message.Message in project beakerx by twosigma.
the class InteractiveTest method getCommWidgetByViewName.
private Comm getCommWidgetByViewName(String viewName) {
Message widget = SearchMessages.getListWidgetsByViewName(groovyKernel.getPublishedMessages(), viewName).get(0);
String id = (String) widget.getContent().get(Comm.COMM_ID);
return groovyKernel.getComm(id);
}
use of com.twosigma.beakerx.message.Message in project beakerx by twosigma.
the class Interactive method interact.
@SuppressWarnings("unchecked")
public static synchronized void interact(MethodClosure function, Object... parameters) {
final List<ValueWidget<?>> widgets = widgetsFromAbbreviations(parameters);
for (ValueWidget<?> widget : widgets) {
widget.getComm().addMsgCallbackList(widget.new ValueChangeMsgCallbackHandler() {
private void processCode(Object... params) throws Exception {
Object call = function.call(getWidgetValues());
if (call instanceof String || call instanceof Number) {
label.setValue(call);
}
}
@Override
public void updateValue(Object value, Message message) {
try {
processCode();
} catch (Exception e) {
throw new IllegalStateException("Error occurred during updating interactive widget.", e);
}
}
private Object[] getWidgetValues() {
List<Object> ret = new ArrayList<>(widgets.size());
for (ValueWidget<?> wid : widgets) {
ret.add(wid.getValue());
}
return ret.toArray(new Object[ret.size()]);
}
});
logger.info("interact Widget: " + widget.getClass().getName());
}
widgets.forEach(Widget::display);
Object response = function.call(widgets.stream().map(ValueWidget::getValue).toArray());
if (response instanceof Widget) {
((Widget) response).display();
} else {
label = new Label();
label.setValue(response);
label.display();
}
}
use of com.twosigma.beakerx.message.Message in project beakerx by twosigma.
the class GroovyCompleteHandlerTest method shouldSendCompleteReplyMsgForPrintln.
@Test
public void shouldSendCompleteReplyMsgForPrintln() throws Exception {
// given
Message message = autocompleteMsgFor("//parentheses are optional\n" + "System.out.printl \"hey!\"\n" + "println \"no System.out either!\"", 44);
// when
completeHandler.handle(message);
// then
assertThat(groovyKernel.getSentMessages().size()).isEqualTo(1);
verifyAutocompleteMsg(groovyKernel.getSentMessages().get(0), 38, 44);
}
use of com.twosigma.beakerx.message.Message in project beakerx by twosigma.
the class GroovyCompleteHandlerTest method autocompleteMsgFor.
private Message autocompleteMsgFor(String code, int curPos) {
Message message = new Message();
Map<String, Serializable> content = new HashMap();
content.put(CompleteHandler.CODE, code);
content.put(CompleteHandler.CURSOR_POS, curPos);
message.setContent(content);
return message;
}
use of com.twosigma.beakerx.message.Message in project beakerx by twosigma.
the class JavaKernelInfoHandlerTest method handle_sentMessageHasContent.
@Test
public void handle_sentMessageHasContent() throws Exception {
// when
handler.handle(message);
// then
Message sentMessage = kernel.getSentMessages().get(0);
Assertions.assertThat(sentMessage.getContent()).isNotEmpty();
}
Aggregations