Search in sources :

Example 1 with UiException

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;
}
Also used : NlsLocale(org.eclipse.scout.rt.platform.nls.NlsLocale) Locale(java.util.Locale) JSONObject(org.json.JSONObject) DefaultExceptionTranslator(org.eclipse.scout.rt.platform.exception.DefaultExceptionTranslator) Method(java.lang.reflect.Method) UiException(org.eclipse.scout.rt.ui.html.UiException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with UiException

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);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UiException(org.eclipse.scout.rt.ui.html.UiException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 3 with UiException

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
    }
}
Also used : ITableRowFilter(org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter) TableWith3Cols(org.eclipse.scout.rt.ui.html.json.table.fixtures.TableWith3Cols) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable) ITableRow(org.eclipse.scout.rt.client.ui.basic.table.ITableRow) UiException(org.eclipse.scout.rt.ui.html.UiException) Test(org.junit.Test)

Example 4 with UiException

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);
    }
}
Also used : JSONObject(org.json.JSONObject) Reader(java.io.Reader) IOException(java.io.IOException) UiException(org.eclipse.scout.rt.ui.html.UiException)

Example 5 with UiException

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.");
    }
}
Also used : TreeEvent(org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent) IPage(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TablePage(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.TablePage) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) Outline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.Outline) JsonOutline(org.eclipse.scout.rt.ui.html.json.desktop.JsonOutline) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) UiException(org.eclipse.scout.rt.ui.html.UiException) Test(org.junit.Test)

Aggregations

UiException (org.eclipse.scout.rt.ui.html.UiException)6 Test (org.junit.Test)3 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)2 JSONObject (org.json.JSONObject)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Method (java.lang.reflect.Method)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)1 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)1 ITableRowFilter (org.eclipse.scout.rt.client.ui.basic.table.ITableRowFilter)1 ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)1 TreeEvent (org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent)1 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)1 IPage (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage)1 DefaultExceptionTranslator (org.eclipse.scout.rt.platform.exception.DefaultExceptionTranslator)1