use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.
the class JsonForm method handleModelRequestEvent.
protected void handleModelRequestEvent(FormEvent event, boolean protect) {
IJsonAdapter<?> childAdapter = findChildAdapter(event);
if (childAdapter != null) {
JSONObject json = new JSONObject();
putProperty(json, PROP_FORM_FIELD, childAdapter.getId());
JsonEvent jsonEvent = addActionEvent(getRequestEventName(event.getType()), json);
if (protect) {
jsonEvent.protect();
}
}
}
use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.
the class JsonDesktopTest method testHandleModelDownloadResource.
@Test
public void testHandleModelDownloadResource() throws Exception {
IDesktop desktop = new DesktopWithNonDisplayableOutline();
desktop.initDesktop();
JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
jsonDesktop.handleModelOpenUri(new BinaryResource("foo.txt", null), OpenUriAction.DOWNLOAD);
jsonDesktop.handleModelOpenUri(new BinaryResource("TP6 ARL ; Zulassung (UVV) - Bearbeitung elektr. Fax-Eingang [-8874 , ABC-Prüfbericht] (1).pdf", null), OpenUriAction.DOWNLOAD);
List<JsonEvent> events = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "openUri");
JSONObject[] data = new JSONObject[2];
data[0] = events.get(0).getData();
data[1] = events.get(1).getData();
// counter = 0 first for test run
assertEquals("dynamic/" + m_uiSession.getUiSessionId() + "/2/0/foo.txt", data[0].getString("uri"));
assertEquals("dynamic/" + m_uiSession.getUiSessionId() + "/2/1/TP6%2520ARL%2520%253B%2520Zulassung%2520%2528UVV%2529%2520-%2520Bearbeitung%2520elektr.%2520Fax-Eingang%2520%255B-8874%2520%252C%2520ABC-Pr%25C3%25BCfbericht%255D%2520%25281%2529.pdf", // counter = 1 second for test run
data[1].getString("uri"));
assertEquals("download", data[0].getString("action"));
assertEquals("download", data[1].getString("action"));
// cleanup
Jobs.getJobManager().cancel(Jobs.newFutureFilterBuilder().andMatchExecutionHint(DownloadHandlerStorage.RESOURCE_CLEANUP_JOB_MARKER).toFilter(), true);
}
use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.
the class JsonOutlineTest method testNoEventsFiredOnChildPageCreation.
/**
* Tests that no events are fired during page initialization
*/
@Test
public void testNoEventsFiredOnChildPageCreation() throws JSONException {
final Holder<Integer> initPageCounter = new Holder<>(Integer.class);
initPageCounter.setValue(0);
// Build an outline with two nodes, where the second node has a child node
IPage page1 = new AbstractPageWithNodes() {
};
IPage page2 = new AbstractPageWithNodes() {
@Override
protected void execCreateChildPages(List<IPage<?>> pageList) {
pageList.add(new AbstractPageWithNodes() {
@Override
protected void execInitPage() {
// Change some properties (this would normally fire events, but we are inside execInitPage())
setLeaf(!isLeaf());
getCellForUpdate().setText("Test");
initPageCounter.setValue(initPageCounter.getValue() + 1);
}
});
super.execCreateChildPages(pageList);
}
};
List<IPage<?>> pages = new ArrayList<IPage<?>>();
pages.add(page2);
IOutline outline = new Outline(pages);
outline.selectNode(page1);
// Outline to JsonOutline
JsonOutline<IOutline> jsonOutline = UiSessionTestUtility.newJsonAdapter(m_uiSession, outline, m_uiSession.getRootJsonAdapter());
// simulate "send to client"
jsonOutline.toJson();
Assert.assertEquals(0, initPageCounter.getValue().intValue());
// Simulate "select page2" event
JsonEvent event = createNodeSelectionEvent(jsonOutline, page2);
jsonOutline.handleUiEvent(event);
assertEquals(1, initPageCounter.getValue().intValue());
// Get all events for the outline (ignore table events)
List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), null, jsonOutline.getId());
// Check that we got only two events: page-changed (because the table was created), node insertion
assertEquals(2, responseEvents.size());
assertEquals("pageChanged", responseEvents.get(0).getType());
assertEquals(JsonTree.EVENT_NODES_INSERTED, responseEvents.get(1).getType());
}
use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.
the class JsonOutlineViewButtonTest method testLazyLoadingOutline_onUiSelectionChanged.
@Test
public void testLazyLoadingOutline_onUiSelectionChanged() throws Exception {
OutlineWithOneNode outline = new OutlineWithOneNode();
IDesktop desktop = Mockito.mock(IDesktop.class);
Mockito.when(desktop.getAvailableOutlines()).thenReturn(Collections.<IOutline>singletonList(outline));
IOutlineViewButton button = new OutlineViewButton(desktop, outline.getClass());
JsonOutlineViewButton<IOutlineViewButton> jsonViewButton = UiSessionTestUtility.newJsonAdapter(m_uiSession, button, null);
assertNull(jsonViewButton.getAdapter(outline));
JsonEvent event = createJsonActionEvent(jsonViewButton.getId());
assertEquals("action", event.getType());
jsonViewButton.handleUiEvent(event);
// Outline needs to be created and sent if selection changes to true
IJsonAdapter<?> outlineAdapter = jsonViewButton.getAdapter(outline);
assertNotNull(outlineAdapter);
String outlineId = JsonTestUtility.extractProperty(m_uiSession.currentJsonResponse(), jsonViewButton.getId(), "outline");
assertEquals(outlineAdapter.getId(), outlineId);
}
use of org.eclipse.scout.rt.ui.html.json.JsonEvent in project scout.rt by eclipse.
the class JsonBrowserFieldTest method testPostMessage.
@Test
public void testPostMessage() throws JSONException {
String origin = "https://eclipse.org/scout/";
String data = "42";
Map<String, String> map = new HashMap<>();
map.put("origin", origin);
map.put("data", data);
m_browserField.handleUiEvent(new JsonEvent("xyz", "postMessage", new JSONObject(map)));
Assert.assertNotNull(m_lastPostMessage);
Assert.assertEquals(origin, m_lastPostMessage[0]);
Assert.assertEquals(data, m_lastPostMessage[1]);
}
Aggregations