Java Code Examples for elemental.json.JsonObject#getBoolean()

The following examples show how to use elemental.json.JsonObject#getBoolean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElementListenerMap.java    From flow with Apache License 2.0 5 votes vote down vote up
boolean matchesFilter(JsonObject eventData) {
    if (filter == null) {
        // No filter: always matches
        return true;
    }

    if (eventData == null) {
        // No event data: cannot match the filter
        return false;
    }

    return eventData.getBoolean(filter);
}
 
Example 2
Source File: SimpleElementBindingStrategy.java    From flow with Apache License 2.0 5 votes vote down vote up
private static boolean resolveFilters(Node element, String eventType,
        JsonObject expressionSettings, JsonObject eventData,
        Consumer<String> sendCommand) {

    boolean noFilters = true;
    boolean atLeastOneFilterMatched = false;

    for (String expression : expressionSettings.keys()) {
        JsonValue settings = expressionSettings.get(expression);

        boolean hasDebounce = settings.getType() == JsonType.ARRAY;

        if (!hasDebounce && !settings.asBoolean()) {
            continue;
        }
        noFilters = false;

        boolean filterMatched = eventData != null
                && eventData.getBoolean(expression);
        if (hasDebounce && filterMatched) {
            String debouncerId = "on-" + eventType + ":" + expression;

            // Count as a match only if at least one debounce is eager
            filterMatched = resolveDebounces(element, debouncerId,
                    (JsonArray) settings, sendCommand);
        }

        atLeastOneFilterMatched |= filterMatched;
    }

    return noFilters || atLeastOneFilterMatched;
}
 
Example 3
Source File: CubaSideMenuWidget.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected void addItems(JsonArray items, HasWidgets container) {
    for (int i = 0; i < items.length(); i++) {
        JsonObject itemJson = items.getObject(i);

        Icon icon = null;
        String iconId = itemJson.getString("icon");
        if (menuItemIconSupplier != null && iconId != null) {
            icon = menuItemIconSupplier.apply(iconId);
        }

        boolean captionAsHtml = false;
        if (itemJson.hasKey("captionAsHtml")) {
            captionAsHtml = itemJson.getBoolean("captionAsHtml");
        }

        MenuItemWidget menuItemWidget = new MenuItemWidget(this,
                itemJson.getString("id"),
                icon,
                itemJson.getString("styleName"),
                itemJson.getString("caption"),
                captionAsHtml);

        menuItemWidget.setDescription(itemJson.getString("description"));
        menuItemWidget.setCubaId(itemJson.getString("cubaId"));
        menuItemWidget.setBadgeText(itemJson.getString("badgeText"));

        container.add(menuItemWidget);

        JsonArray childrenItemsJson = itemJson.getArray("children");
        if (childrenItemsJson != null) {
            MenuContainerWidget menuContainerWidget = new MenuContainerWidget(this, menuItemWidget);
            addItems(childrenItemsJson, menuContainerWidget);

            container.add(menuContainerWidget);

            menuItemWidget.setSubMenu(menuContainerWidget);

            if (itemJson.hasKey("expanded")
                    && itemJson.getBoolean("expanded")) {
                menuContainerWidget.setExpanded(true);
            }
        }
    }
}
 
Example 4
Source File: DomEventTest.java    From flow with Apache License 2.0 4 votes vote down vote up
private <T extends ComponentEvent<Component>> void assertSettings(
        Class<T> eventType, String expectedFilter, int expectedTimeout,
        DebouncePhase... expectedPhases) {
    JsonObject settings = getEventSettings(eventType);

    if (expectedFilter == null) {
        Assert.assertArrayEquals(new String[0], settings.keys());
        return;
    }

    Assert.assertArrayEquals(new String[] { expectedFilter },
            settings.keys());

    if (expectedTimeout == 0 && expectedPhases.length == 0) {
        Assert.assertEquals(
                "There should be a boolean instead of empty phase list",
                JsonType.BOOLEAN, settings.get(expectedFilter).getType());
        boolean isFilter = settings.getBoolean(expectedFilter);
        Assert.assertTrue("Expression should be used as a filter",
                isFilter);
        return;
    }

    JsonArray filterSettings = settings.getArray(expectedFilter);

    Assert.assertEquals(1, filterSettings.length());

    JsonArray filterSetting = filterSettings.getArray(0);

    Assert.assertEquals("Debunce timeout should be as expected",
            expectedTimeout, (int) filterSetting.getNumber(0));

    Assert.assertEquals("Number of phases should be as expected",
            expectedPhases.length, filterSetting.length() - 1);

    for (int i = 0; i < expectedPhases.length; i++) {
        String expectedIdentifier = expectedPhases[i].getIdentifier();
        Assert.assertEquals(expectedIdentifier,
                filterSetting.getString(i + 1));
    }
}