void () { String query = myTextField.getText(); int length = query.length(); int position = getCaretPosition(); if (position < length) { if (query.charAt(position) != ' ') { handleShowPopupForQuery(); return; } } else if (query.charAt(position - 1) == ' ') { handleShowPopupForQuery(); return; } Ref<Integer> startPosition = new Ref<>(); Pair<String, String> attribute = parseAttributeInQuery(query, position, startPosition); if (attribute.second == null) { showAttributesPopup(attribute.first, startPosition.get()); } else { handleShowAttributeValuesPopup(attribute.first, attribute.second, startPosition.get()); } }