use of org.eclipse.scout.rt.ui.html.json.JsonResponse in project scout.rt by eclipse.
the class JsonDesktopTest method testFormAddedAndRemoved.
@Test
public void testFormAddedAndRemoved() throws Exception {
DesktopWithOneOutline desktop = new DesktopWithOneOutline();
desktop.initDesktop();
JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
FormWithOneField form = new FormWithOneField();
form.setDisplayParent(desktop);
form.setShowOnStart(false);
JsonForm formAdapter = (JsonForm) jsonDesktop.getAdapter(form);
assertNull(formAdapter);
desktop.showForm(form);
formAdapter = (JsonForm) jsonDesktop.getAdapter(form);
assertNotNull(formAdapter);
JsonResponse jsonResp = m_uiSession.currentJsonResponse();
List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(jsonResp, "formShow");
assertTrue(responseEvents.size() == 1);
JsonEvent event = responseEvents.get(0);
String formId = event.getData().getString("form");
// Add event must contain reference (by ID) to form.
assertEquals(jsonDesktop.getId(), event.getTarget());
assertEquals(formAdapter.getId(), formId);
// adapter-data for form must exist in 'adapterData' property of response
JSONObject json = jsonResp.toJson();
JSONObject adapterData = JsonTestUtility.getAdapterData(json, formId);
assertEquals(formAdapter.getId(), adapterData.getString("id"));
assertEquals("Form", adapterData.getString("objectType"));
String rootGroupBoxId = adapterData.getString("rootGroupBox");
adapterData = JsonTestUtility.getAdapterData(json, rootGroupBoxId);
assertEquals("GroupBox", adapterData.getString("objectType"));
// we could continue to test the reference structure in the JSON response,
// but for the moment this should be enough...
JsonTestUtility.endRequest(m_uiSession);
desktop.hideForm(form);
responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formHide");
assertTrue(responseEvents.size() == 1);
event = responseEvents.get(0);
formId = event.getData().getString("form");
// Remove event must only contain the id, no other properties
assertEquals(jsonDesktop.getId(), event.getTarget());
assertEquals(formAdapter.getId(), formId);
}
use of org.eclipse.scout.rt.ui.html.json.JsonResponse in project scout.rt by eclipse.
the class JsonTableTest method testColumnStructureChangedEvent.
/**
* If column structure changes, we need to resend every row including its new cells.
*/
@Test
public void testColumnStructureChangedEvent() throws JSONException {
TableWith3Cols table = new TableWith3Cols();
table.fill(2);
table.initTable();
table.resetColumns();
table.getColumnSet().getColumn(0).setVisible(false);
IJsonAdapter<? super TableWith3Cols> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
jsonTable.toJson();
// ----
table.getColumnSet().getColumn(0).setVisible(true);
JsonResponse response = m_uiSession.currentJsonResponse();
response.fireProcessBufferedEvents();
List<JsonEvent> events = response.getEventList();
assertEquals(4, events.size());
assertEquals(JsonTable.EVENT_COLUMN_STRUCTURE_CHANGED, events.get(0).getType());
assertEquals(JsonEventType.PROPERTY.getEventType(), events.get(1).getType());
assertEquals(JsonTable.EVENT_ALL_ROWS_DELETED, events.get(2).getType());
assertEquals(JsonTable.EVENT_ROWS_INSERTED, events.get(3).getType());
}
use of org.eclipse.scout.rt.ui.html.json.JsonResponse in project scout.rt by eclipse.
the class JsonTableTest method testColumnStructureChangedEvent_dispose.
/**
* If column structure changes, old columns are disposed and the new ones attached
*/
@Test
public void testColumnStructureChangedEvent_dispose() throws JSONException {
TableWith3Cols table = new TableWith3Cols();
table.fill(2);
table.initTable();
table.resetColumns();
IColumn column0 = table.getColumnSet().getColumn(0);
IColumn column1 = table.getColumnSet().getColumn(1);
IColumn column2 = table.getColumnSet().getColumn(2);
column0.setVisible(false);
JsonTable<ITable> jsonTable = UiSessionTestUtility.newJsonAdapter(m_uiSession, table, null);
jsonTable.toJson();
String column0Id = jsonTable.getColumnId(column0);
String column1Id = jsonTable.getColumnId(column1);
String column2Id = jsonTable.getColumnId(column2);
assertNull(column0Id);
assertNotNull(column1Id);
assertNotNull(column2Id);
column0.setVisible(true);
column2.setVisible(false);
JsonResponse response = m_uiSession.currentJsonResponse();
response.fireProcessBufferedEvents();
String newColumn0Id = jsonTable.getColumnId(column0);
String newColumn1Id = jsonTable.getColumnId(column1);
String newColumn2Id = jsonTable.getColumnId(column2);
assertNotNull(newColumn0Id);
assertNotNull(newColumn1Id);
Assert.assertNotEquals(column1Id, newColumn1Id);
assertNull(newColumn2Id);
}
use of org.eclipse.scout.rt.ui.html.json.JsonResponse in project scout.rt by eclipse.
the class UiSession method createJsonStartupResponse.
protected JsonResponse createJsonStartupResponse() {
JsonResponse response = new JsonResponse();
response.markAsStartupResponse();
return response;
}
use of org.eclipse.scout.rt.ui.html.json.JsonResponse in project scout.rt by eclipse.
the class JsonAction method handleModelPropertyChange.
@Override
protected void handleModelPropertyChange(PropertyChangeEvent event) {
// [Similar code exist in JsonFormField]
if (IAction.PROP_VISIBLE.equals(event.getPropertyName()) && !getModel().isVisibleGranted()) {
JsonResponse response = getUiSession().currentJsonResponse();
if (response.containsAdapter(this) && response.isWritable()) {
dispose();
return;
}
LOG.warn("Setting visibleGranted=false has no effect, because JsonAdapter {} ({}) is already sent to the UI.", getId(), getModel());
}
super.handleModelPropertyChange(event);
}
Aggregations