use of edu.stanford.bmir.gwtcodemirror.client.EditorPosition in project webprotege by protegeproject.
the class CommentAutoCompleter method handleAutocomplete.
public void handleAutocomplete(@Nonnull String query, @Nonnull EditorPosition caretPosition, int caretPos, @Nonnull AutoCompletionCallback callback) {
String upToCarent = query.substring(0, caretPos);
MatchResult result = nameRegExp.exec(upToCarent);
if (result == null) {
handleAttemptAtEntityCompletions(upToCarent, caretPosition, callback);
} else {
String matchedPartialName = result.getGroup(NAME_GROUP);
EditorPosition replaceTextFrom = new EditorPosition(caretPosition.getLineNumber(), caretPosition.getColumnNumber() - result.getGroup(0).length());
dispatchServiceManager.execute(new GetUserIdCompletionsAction(matchedPartialName), userIdsResult -> {
List<AutoCompletionChoice> suggestions = new ArrayList<>();
List<UserId> userIds = userIdsResult.getPossibleItemCompletions();
for (UserId userId : userIds) {
String userName = userId.getUserName();
String replacement = getReplacementStringFromUserName(userName);
EditorPosition replaceTextTo = new EditorPosition(caretPosition.getLineNumber(), caretPosition.getColumnNumber());
suggestions.add(new AutoCompletionChoice(replacement, userName, "", replaceTextFrom, replaceTextTo));
}
callback.completionsReady(new AutoCompletionResult(suggestions, replaceTextFrom));
});
}
}
use of edu.stanford.bmir.gwtcodemirror.client.EditorPosition in project webprotege by protegeproject.
the class ManchesterSyntaxFrameEditorImpl method setError.
@Override
public void setError(ManchesterSyntaxFrameParseError error) {
int line = error.getLine() - 1;
int col = error.getCol();
editor.setErrorRange(new EditorPosition(line, col), new EditorPosition(line, col + error.getToken().length()));
errorMessageView.setErrorMessage(error.getMessage());
errorMessageView.setCurrentToken(error.getToken());
errorMessageView.setExpectedEntityTypes(error.getExpectedEntityTypes());
showErrorMessageView();
}
use of edu.stanford.bmir.gwtcodemirror.client.EditorPosition in project webprotege by protegeproject.
the class GetManchesterSyntaxFrameCompletionsActionHandler method execute.
@Nonnull
@Override
public GetManchesterSyntaxFrameCompletionsResult execute(@Nonnull GetManchesterSyntaxFrameCompletionsAction action, @Nonnull ExecutionContext executionContext) {
String syntax = action.getSyntax();
int from = action.getFrom();
String triggerText = syntax.substring(0, from) + "\u0000";
ManchesterSyntaxFrameParser parser = manchesterSyntaxFrameParserProvider.get();
try {
parser.parse(triggerText, action);
} catch (ParserException e) {
// ManchesterOWLSyntaxTokenizer tokenizer = new ManchesterOWLSyntaxTokenizer(syntax);
// List<ManchesterOWLSyntaxTokenizer.Token> tokens = tokenizer.tokenize();
// ManchesterOWLSyntaxTokenizer.Token intersectingToken;
// for(ManchesterOWLSyntaxTokenizer.Token token : tokens) {
// int tokenPos = token.getPos();
// if(tokenPos <= from && from <= tokenPos + token.getToken().length()) {
// intersectingToken = token;
// break;
// }
// }
int lastWordStartIndex = getLastWordIndex(syntax, from);
int lastWordEndIndex = getWordEnd(syntax, from);
int fromLineNumber = action.getFromPos().getLineNumber();
int fromColumnNumber = (action.getFromPos().getColumnNumber() - (from - lastWordStartIndex));
EditorPosition fromPos = new EditorPosition(fromLineNumber, fromColumnNumber);
EditorPosition toPos = new EditorPosition(fromLineNumber, action.getFromPos().getColumnNumber() + (lastWordEndIndex - from));
String lastWordPrefix = syntax.substring(lastWordStartIndex, from).toLowerCase();
List<AutoCompletionChoice> choices = Lists.newArrayList();
List<AutoCompletionChoice> entityChoices = getEntityAutocompletionChoices(action, e, fromPos, toPos, lastWordPrefix);
choices.addAll(entityChoices);
List<AutoCompletionChoice> expectedKeywordChoices = getKeywordAutoCompletionChoices(e, fromPos, toPos, lastWordPrefix);
choices.addAll(expectedKeywordChoices);
List<AutoCompletionChoice> ontologyNameChoices = getNameOntologyAutocompletionChoices(e, fromPos, toPos, lastWordPrefix);
choices.addAll(ontologyNameChoices);
return new GetManchesterSyntaxFrameCompletionsResult(new AutoCompletionResult(choices, fromPos));
}
return new GetManchesterSyntaxFrameCompletionsResult(AutoCompletionResult.emptyResult());
}
use of edu.stanford.bmir.gwtcodemirror.client.EditorPosition in project webprotege by protegeproject.
the class CommentAutoCompleter method handleAttemptAtEntityCompletions.
private void handleAttemptAtEntityCompletions(String queryUpToCaret, EditorPosition caretPos, AutoCompletionCallback callback) {
// Last index of space or 0 if there are not spaces
int wordStart = queryUpToCaret.lastIndexOf(" ") + 1;
int wordFragmentLen = queryUpToCaret.length() - wordStart;
String wordFragment = queryUpToCaret.substring(wordStart);
if (wordFragment.isEmpty()) {
callback.completionsReady(new AutoCompletionResult());
return;
}
dispatchServiceManager.execute(new LookupEntitiesAction(projectId, lookUpEntities(wordFragment)), result -> {
List<AutoCompletionChoice> choices = new ArrayList<>();
EditorPosition pos = new EditorPosition(caretPos.getLineNumber(), caretPos.getColumnNumber() - wordFragmentLen);
for (final EntityLookupResult entity : result.getEntityLookupResults()) {
choices.add(new AutoCompletionChoice(formatReplacementTest(entity), entity.getOWLEntityData().getBrowserText(), "", pos, caretPos));
}
AutoCompletionResult autoCompletionResult = new AutoCompletionResult(choices, pos);
callback.completionsReady(autoCompletionResult);
});
}
Aggregations