Java Code Examples for com.vaadin.client.UIDL#getStringAttribute()

The following examples show how to use com.vaadin.client.UIDL#getStringAttribute() . 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: CubaUIConnector.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateBrowserHistory(UIDL uidl) {
    String lastHistoryOp = uidl.getStringAttribute(CubaUIConstants.LAST_HISTORY_OP);

    History history = Browser.getWindow().getHistory();
    String pageTitle = getState().pageState.title;

    String replace = uidl.getStringAttribute(UIConstants.ATTRIBUTE_REPLACE_STATE);
    String push = uidl.getStringAttribute(UIConstants.ATTRIBUTE_PUSH_STATE);

    if (CubaUIConstants.HISTORY_PUSH_OP.equals(lastHistoryOp)) {
        if (uidl.hasAttribute(UIConstants.ATTRIBUTE_REPLACE_STATE)) {
            history.replaceState(null, pageTitle, replace);
        }
        if (uidl.hasAttribute(UIConstants.ATTRIBUTE_PUSH_STATE)) {
            history.pushState(null, pageTitle, push);
        }
    } else {
        if (uidl.hasAttribute(UIConstants.ATTRIBUTE_PUSH_STATE)) {
            history.pushState(null, pageTitle, push);
        }
        if (uidl.hasAttribute(UIConstants.ATTRIBUTE_REPLACE_STATE)) {
            history.replaceState(null, pageTitle, replace);
        }
    }
}
 
Example 2
Source File: ItemIdClientCriterion.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
// Exception squid:S1166 - Hide origin exception
// Exception squid:S2221 - This code is trans-coded to JavaScript, hence
// Exception semantics changes
@SuppressWarnings({ "squid:S1166", "squid:S2221" })
protected boolean accept(VDragEvent drag, UIDL configuration) {
    try {

        String component = drag.getTransferable().getDragSource().getWidget().getElement().getId();
        int c = configuration.getIntAttribute(COMPONENT_COUNT);
        String mode = configuration.getStringAttribute(MODE);
        for (int dragSourceIndex = 0; dragSourceIndex < c; dragSourceIndex++) {
            String requiredPid = configuration.getStringAttribute(COMPONENT + dragSourceIndex);
            if ((STRICT_MODE.equals(mode) && component.equals(requiredPid))
                    || (PREFIX_MODE.equals(mode) && component.startsWith(requiredPid))) {
                return true;
            }

        }
    } catch (Exception e) {
        // log and continue
        LOGGER.log(Level.SEVERE, "Error verifying drop target: " + e.getLocalizedMessage());
    }
    return false;
}
 
Example 3
Source File: ViewClientCriterion.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Hides the highlighted drop target hints.
 *
 * @param configuration
 *            for the accept criterion to retrieve the drop target hints.
 */
// Exception squid:S1166 - Hide origin exception
// Exception squid:S2221 - This code is trans-coded to JavaScript, hence
// Exception semantics changes
@SuppressWarnings({ "squid:S1166", "squid:S2221" })
void hideDropTargetHints(final UIDL configuration) {
    final int totalDropTargetHintsCount = configuration.getIntAttribute(DROP_AREA_CONFIG_COUNT);
    for (int dropAreaIndex = 0; dropAreaIndex < totalDropTargetHintsCount; dropAreaIndex++) {
        try {
            final String dropArea = configuration.getStringAttribute(DROP_AREA_CONFIG + dropAreaIndex);
            final Element hideHintFor = Document.get().getElementById(dropArea);
            if (hideHintFor != null) {
                hideHintFor.removeClassName(ViewComponentClientCriterion.HINT_AREA_STYLE);
            }
        } catch (final Exception e) {
            // log and continue
            LOGGER.log(Level.SEVERE, "Error highlighting valid drop targets: " + e.getLocalizedMessage());
        }
    }
}
 
Example 4
Source File: ViewComponentClientCriterion.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Checks if this accept criterion is responsible for the current drag
 * source. Therefore the current drag source id has to start with the drag
 * source id-prefix configured for the criterion.
 *
 * @param drag
 *            the current drag event holding the context.
 * @param configuration
 *            for the accept criterion to retrieve the configured drag
 *            source id-prefix.
 * @return <code>true</code> if the criterion is responsible for the current
 *         drag source, otherwise <code>false</code>.
 */
// Exception squid:S1166 - Hide origin exception
// Exception squid:S2221 - This code is trans-coded to JavaScript, hence
// Exception semantics changes
@SuppressWarnings({ "squid:S1166", "squid:S2221" })
boolean isValidDragSource(final VDragEvent drag, final UIDL configuration) {
    try {
        final String dragSource = drag.getTransferable().getDragSource().getWidget().getElement().getId();
        final String dragSourcePrefix = configuration.getStringAttribute(DRAG_SOURCE);
        if (dragSource.startsWith(dragSourcePrefix)) {
            return true;
        }
    } catch (final Exception e) {
        // log and continue
        LOGGER.log(Level.SEVERE, "Error verifying drag source: " + e.getLocalizedMessage());
    }

    return false;
}
 
Example 5
Source File: ViewComponentClientCriterion.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Highlights the valid drop targets configured for the criterion.
 *
 * @param configuration
 *            for the accept criterion to retrieve the configured drop hint
 *            areas.
 */
// Exception squid:S1166 - Hide origin exception
// Exception squid:S2221 - This code is trans-coded to JavaScript, hence
// Exception semantics changes
// Exception squid:S2629 - not supported by GWT
@SuppressWarnings({ "squid:S1166", "squid:S2221", "squid:S2629" })
void showDropTargetHints(final UIDL configuration) {
    final int dropAreaCount = configuration.getIntAttribute(DROP_AREA_COUNT);
    for (int dropAreaIndex = 0; dropAreaIndex < dropAreaCount; dropAreaIndex++) {
        try {
            final String dropArea = configuration.getStringAttribute(DROP_AREA + dropAreaIndex);
            LOGGER.log(Level.FINE, "Hint Area: " + dropArea);

            final Element showHintFor = Document.get().getElementById(dropArea);
            if (showHintFor != null) {
                showHintFor.addClassName(HINT_AREA_STYLE);
            }
        } catch (final Exception e) {
            // log and continue
            LOGGER.log(Level.SEVERE, "Error highlighting drop targets: " + e.getLocalizedMessage());
        }
    }

}
 
Example 6
Source File: ViewComponentClientCriterion.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Checks if the current drop location is a valid drop target for the
 * criterion. Therefore the current drop location id has to start with one
 * of the drop target id-prefixes configured for the criterion.
 *
 * @param configuration
 *            for the accept criterion to retrieve the configured drop
 *            target id-prefixes.
 * @return <code>true</code> if the current drop location is a valid drop
 *         target for the criterion, otherwise <code>false</code>.
 */
// Exception squid:S1166 - Hide origin exception
// Exception squid:S2221 - This code is trans-coded to JavaScript, hence
// Exception semantics changes
// Exception squid:S2629 - not supported by GWT
@SuppressWarnings({ "squid:S1166", "squid:S2221", "squid:S2629" })
boolean isValidDropTarget(final UIDL configuration) {
    try {
        final String dropTarget = VDragAndDropManager.get().getCurrentDropHandler().getConnector().getWidget()
                .getElement().getId();
        final int dropTargetCount = configuration.getIntAttribute(DROP_TARGET_COUNT);
        for (int dropTargetIndex = 0; dropTargetIndex < dropTargetCount; dropTargetIndex++) {
            final String dropTargetPrefix = configuration.getStringAttribute(DROP_TARGET + dropTargetIndex);
            LOGGER.log(Level.FINE, "Drop Target: " + dropTargetPrefix);
            if (dropTarget.startsWith(dropTargetPrefix)) {
                return true;
            }
        }
    } catch (final Exception e) {
        // log and continue
        LOGGER.log(Level.SEVERE, "Error verifying drop target: " + e.getLocalizedMessage());
    }
    return false;
}
 
Example 7
Source File: TableAggregationRow.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void addCellsFromUIDL(UIDL uidl) {
    int colIndex = 0;
    final Iterator cells = uidl.getChildIterator();
    while (cells.hasNext() && colIndex < tableWidget.getVisibleColOrder().length) {
        String columnId = tableWidget.getVisibleColOrder()[colIndex];

        if (addSpecificCell(columnId, colIndex)) {
            colIndex++;
            continue;
        }

        final Object cell = cells.next();

        String style = "";
        if (uidl.hasAttribute("style-" + columnId)) {
            style = uidl.getStringAttribute("style-" + columnId);
        }

        boolean sorted = tableWidget.getHead().getHeaderCell(colIndex).isSorted();

        if (isAggregationEditable(uidl, colIndex)) {
            addCellWithField((String) cell, aligns[colIndex], colIndex);
        } else if (cell instanceof String) {
            addCell((String) cell, aligns[colIndex], style, sorted);
        }

        final String colKey = tableWidget.getColKeyByIndex(colIndex);
        int colWidth;
        if ((colWidth = tableWidget.getColWidth(colKey)) > -1) {
            tableWidget.setColWidth(colIndex, colWidth, false);
        }

        colIndex++;
    }
}
 
Example 8
Source File: CubaMenuBarConnector.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void assignAdditionalMenuStyles(VMenuBar currentMenu, UIDL item) {
    String icon = item.getStringAttribute("icon");
    if (icon != null) {
        currentMenu.addStyleDependentName("has-icons");
    }
}
 
Example 9
Source File: TableAggregationRow.java    From cuba with Apache License 2.0 4 votes vote down vote up
public void updateFromUIDL(UIDL uidl) {
    if (container.hasChildNodes()) {
        container.removeAllChildren();
    }

    aligns = tableWidget.getHead().getColumnAlignments();

    if (uidl.getChildCount() > 0) {
        final Element table = DOM.createTable();
        table.setAttribute("cellpadding", "0");
        table.setAttribute("cellspacing", "0");

        final Element tBody = DOM.createTBody();
        tr = DOM.createTR();

        tr.setClassName(tableWidget.getStylePrimaryName() + "-arow-row");

        if (inputsList != null && !inputsList.isEmpty()) {
            inputsList.clear();
        }

        addCellsFromUIDL(uidl);

        tBody.appendChild(tr);
        table.appendChild(tBody);

        DivElement tableWrapper = Document.get().createDivElement();
        tableWrapper.appendChild(table);
        container.appendChild(tableWrapper);

        // set focus to input if we pressed `ENTER`
        String focusColumnKey = uidl.getStringAttribute("focusInput");
        if (focusColumnKey != null && inputsList != null) {
            for (AggregationInputFieldInfo info : inputsList) {
                if (info.getColumnKey().equals(focusColumnKey)) {
                    info.getInputElement().focus();
                    break;
                }
            }
        }
    }

    initialized = container.hasChildNodes();
}
 
Example 10
Source File: CubaMenuBarWidget.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public String buildItemHTML(UIDL item) {
    // Construct html from the text and the optional icon
    // Haulmont API : Added support for shortcuts
    StringBuilder itemHTML = new StringBuilder();
    if (item.hasAttribute("separator")) {
        itemHTML.append("<span>---</span><span>---</span>");
    } else {
        itemHTML.append("<span class=\"")
                .append(getStylePrimaryName())
                .append("-menuitem-caption\">");

        Icon icon = client.getIcon(item.getStringAttribute("icon"));
        if (icon != null) {
            itemHTML.append(icon.getElement().getString());
        }

        String itemText = item.getStringAttribute("text");
        if (!htmlContentAllowed) {
            itemText = WidgetUtil.escapeHTML(itemText);
        }
        itemHTML.append(itemText);
        itemHTML.append("</span>");

        // Add submenu indicator
        if (item.getChildCount() > 0) {
            String bgStyle = "";
            itemHTML.append("<span class=\"")
                    .append(getStylePrimaryName())
                    .append("-submenu-indicator\"")
                    .append(bgStyle)
                    .append("><span class=\"")
                    .append(getStylePrimaryName())
                    .append("-submenu-indicator-icon\"")
                    .append("><span class=\"text\">&#x25BA;</span></span></span>");
        } else {
            itemHTML.append("<span class=\"");
            String shortcut = "";
            if (item.hasAttribute("shortcut")) {
                shortcut = item.getStringAttribute("shortcut");
            } else {
                itemHTML.append(getStylePrimaryName())
                        .append("-menuitem-empty-shortcut ");
            }

            itemHTML.append(getStylePrimaryName())
                    .append("-menuitem-shortcut\">")
                    .append(shortcut)
                    .append("</span");
        }
    }
    return itemHTML.toString();
}
 
Example 11
Source File: ViewClientCriterion.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
@Override
// Exception squid:S1604 - GWT 2.7 does not support Java 8
@SuppressWarnings("squid:S1604")
public void accept(final VDragEvent drag, final UIDL configuration, final VAcceptCallback callback) {

    if (isDragStarting(drag)) {
        final NativePreviewHandler nativeEventHandler = new NativePreviewHandler() {
            @Override
            public void onPreviewNativeEvent(final NativePreviewEvent event) {
                if (isEscKey(event) || isMouseUp(event)) {
                    try {
                        hideDropTargetHints(configuration);
                    } finally {
                        nativeEventHandlerRegistration.removeHandler();
                    }
                }
            }
        };

        nativeEventHandlerRegistration = Event.addNativePreviewHandler(nativeEventHandler);
        setMultiRowDragDecoration(drag);
    }

    final int childCount = configuration.getChildCount();
    accepted = false;
    for (int childIndex = 0; childIndex < childCount; childIndex++) {
        final VAcceptCriterion crit = getCriteria(configuration, childIndex);
        crit.accept(drag, configuration.getChildUIDL(childIndex), this);
        if (Boolean.TRUE.equals(accepted)) {
            callback.accepted(drag);
            return;
        }
    }

    // if no VAcceptCriterion accepts and the mouse is release, an error
    // message is shown
    if (Event.ONMOUSEUP == Event.getTypeInt(drag.getCurrentGwtEvent().getType())) {
        showErrorNotification(drag);
    }

    errorMessage = configuration.getStringAttribute(ERROR_MESSAGE);
}