Search in sources :

Example 1 with AbstractHintProvider

use of org.structr.autocomplete.AbstractHintProvider in project structr by structr.

the class AutocompleteCommand method processMessage.

@Override
public void processMessage(final WebSocketMessage webSocketData) {
    final Map<String, Object> data = webSocketData.getNodeData();
    final String id = webSocketData.getId();
    final List<GraphObject> result = new LinkedList<>();
    final String contentType = getOrDefault(data.get("contentType"), "text/plain");
    if (contentType != null) {
        final AbstractHintProvider hintProvider = hintProviders.get(contentType);
        if (hintProvider != null) {
            final String currentToken = getAndTrim(data.get("currentToken"));
            final String previousToken = getAndTrim(data.get("previousToken"));
            final String thirdToken = getAndTrim(data.get("thirdToken"));
            final String type = getAndTrim(data.get("type"));
            final int cursorPosition = getInt(data.get("cursorPosition"));
            final int line = getInt(data.get("line"));
            try {
                final List<GraphObject> hints = hintProvider.getHints(StructrApp.getInstance().get(AbstractNode.class, id), type, currentToken, previousToken, thirdToken, line, cursorPosition);
                result.addAll(hints);
            } catch (FrameworkException fex) {
                logger.warn("", fex);
            }
        } else {
            logger.warn("No HintProvider for content type {}, ignoring.", contentType);
        }
    } else {
        logger.warn("No content type for AutocompleteCommand, ignoring.");
    }
    // set full result list
    webSocketData.setResult(result);
    webSocketData.setRawResultCount(result.size());
    getWebSocket().send(webSocketData, true);
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) GraphObject(org.structr.core.GraphObject) AbstractHintProvider(org.structr.autocomplete.AbstractHintProvider) GraphObject(org.structr.core.GraphObject)

Aggregations

AbstractHintProvider (org.structr.autocomplete.AbstractHintProvider)1 FrameworkException (org.structr.common.error.FrameworkException)1 GraphObject (org.structr.core.GraphObject)1 AbstractNode (org.structr.core.entity.AbstractNode)1