use of org.eclipse.scout.rt.ui.html.UiException in project scout.rt by eclipse.
the class JsonDateColumn method toJson.
@Override
public JSONObject toJson() {
JSONObject json = super.toJson();
json.put("hasDate", getColumn().isHasDate());
json.put("hasTime", getColumn().isHasTime());
json.put(IDateColumn.PROP_GROUP_FORMAT, getColumn().getGroupFormat());
// TODO [7.0] CGU: update IDateColumnInterface
// getDateFormat uses NlsLocale. IMHO getDateFormat should not perform any logic because it just a getter-> refactor. same on AbstractDateField
// Alternative would be to use a clientJob or set localethreadlocal in ui thread as well, as done in rap
Locale oldLocale = NlsLocale.getOrElse(null);
try {
NlsLocale.set(getUiSession().getClientSession().getLocale());
Method method = AbstractDateColumn.class.getDeclaredMethod("getDateFormat");
method.setAccessible(true);
SimpleDateFormat dateFormat = (SimpleDateFormat) method.invoke(getColumn());
// Don't use toLocalizedPattern, it translates the chars ('d' to 't' for german).
json.put("format", dateFormat.toPattern());
} catch (ReflectiveOperationException e) {
throw new UiException("Failed to create JSON from 'date column'", BEANS.get(DefaultExceptionTranslator.class).unwrap(e));
} finally {
NlsLocale.set(oldLocale);
}
return json;
}
use of org.eclipse.scout.rt.ui.html.UiException in project scout.rt by eclipse.
the class JsonSvgField method svgToString.
protected String svgToString(SVGDocument svg) {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
SVGUtility.writeSVGDocument(svg, out, SVG_ENCODING);
return new String(out.toByteArray(), SVG_ENCODING);
} catch (UnsupportedEncodingException | ProcessingException e) {
throw new UiException("Failed to write SVG document", e);
}
}
use of org.eclipse.scout.rt.ui.html.UiException in project scout.rt by eclipse.
the class JsonTableTest method testRowFilter.
@Test
public void testRowFilter() throws JSONException {
TableWith3Cols table = new TableWith3Cols();
table.fill(3);
table.initTable();
JsonTable<ITable> jsonTable = m_uiSession.createJsonAdapter(table, null);
ITableRow row0 = table.getRow(0);
ITableRow row1 = table.getRow(1);
ITableRow row2 = table.getRow(2);
jsonTable.toJson();
assertNotNull(jsonTable.tableRowIdsMap().get(row0));
assertNotNull(jsonTable.tableRowIdsMap().get(row1));
assertNotNull(jsonTable.tableRowIdsMap().get(row2));
String row0Id = jsonTable.getOrCreateRowId(row0);
String row1Id = jsonTable.getOrCreateRowId(row1);
assertNotNull(row0Id);
assertNotNull(jsonTable.getTableRow(row0Id));
assertNotNull(row1Id);
assertNotNull(jsonTable.getTableRow(row1Id));
table.addRowFilter(new ITableRowFilter() {
@Override
public boolean accept(ITableRow r) {
// hide first row
return r.getRowIndex() > 0;
}
});
// After flushing the event buffers and applying the model changes
// to the JsonTable, the row should not exist anymore on the JsonTable
JsonTestUtility.processBufferedEvents(m_uiSession);
assertEquals(3, table.getRowCount());
assertEquals(2, table.getFilteredRowCount());
assertNull(jsonTable.tableRowIdsMap().get(row0));
assertNotNull(jsonTable.tableRowIdsMap().get(row1));
assertNotNull(jsonTable.tableRowIdsMap().get(row2));
// should still exist -> should NOT throw an exception
jsonTable.getTableRow(row1Id);
try {
// throws exception
jsonTable.getTableRow(row0Id);
fail("Expected an exception, but no exception was thrown");
} catch (UiException e) {
// ok
}
}
use of org.eclipse.scout.rt.ui.html.UiException in project scout.rt by eclipse.
the class JsonRequestHelper method readJsonRequest.
/**
* Reads the content of {@link ServletRequest} into a {@link JSONObject}.
*/
public JSONObject readJsonRequest(final ServletRequest servletRequest) {
try (Reader in = servletRequest.getReader()) {
final String jsonData = IOUtility.readString(in);
LOG.debug("Received: {}", formatJsonForLogging(jsonData));
return (jsonData == null ? new JSONObject() : new JSONObject(jsonData));
} catch (RuntimeException | IOException e) {
throw new UiException(e.getMessage(), e);
}
}
use of org.eclipse.scout.rt.ui.html.UiException in project scout.rt by eclipse.
the class JsonTreeTest method testDeletionOfAllChildrenOfUnknownNode.
@Test
public void testDeletionOfAllChildrenOfUnknownNode() throws Exception {
IOutline outline = new Outline(new ArrayList<IPage<?>>());
ITreeNode parent = new TablePage(0);
ITreeNode node1 = new TablePage(0);
node1.setParentNodeInternal(parent);
ITreeNode node2 = new TablePage(0);
node2.setParentNodeInternal(parent);
ITreeNode node3 = new TablePage(0);
node3.setParentNodeInternal(parent);
outline.addChildNode(outline.getRootNode(), parent);
outline.addChildNode(parent, node1);
outline.addChildNode(parent, node2);
outline.addChildNode(parent, node3);
JsonOutline<IOutline> jsonOutline = m_uiSession.createJsonAdapter(outline, null);
List<ITreeNode> allChildren = CollectionUtility.arrayList(node1, node2, node3);
jsonOutline.bufferModelEvent(new TreeEvent(outline, TreeEvent.TYPE_ALL_CHILD_NODES_DELETED, parent, allChildren));
try {
jsonOutline.processBufferedEvents();
} catch (UiException e) {
fail("Regression of ticket 210096: Tree does not contain node whose children are to be deleted.");
}
}
Aggregations