mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-20 16:42:51 -06:00
more advanced complete function in the PGFService
This commit is contained in:
@@ -2,9 +2,6 @@
|
||||
|
||||
APPDIR=`dirname $0`;
|
||||
|
||||
GWT_DIR="/home/angelov/gwt-2.0.4"
|
||||
GWT_CLASSPATH="$GWT_DIR/gwt-user.jar:$GWT_DIR/gwt-dev.jar"
|
||||
|
||||
if [ -z "$GWT_CLASSPATH" ]; then
|
||||
echo 'ERROR: $GWT_CLASSPATH is not set'
|
||||
echo 'Set $GWT_CLASSPATH to point to the GWT JAR files. For example:'
|
||||
|
||||
@@ -122,7 +122,15 @@ public class CompletionOracle extends SuggestOracle {
|
||||
jsonRequest = null;
|
||||
List<CompletionSuggestion> suggestions = new ArrayList<CompletionSuggestion>();
|
||||
for (PGF.Completion completion : completions.iterable()) {
|
||||
suggestions.add(new CompletionSuggestion(completion.getText()));
|
||||
String text = completion.getBracketedString().render();
|
||||
for (String tokn : completion.getCompletions()) {
|
||||
StringBuilder sbuilder = new StringBuilder();
|
||||
sbuilder.append(text);
|
||||
if (sbuilder.length() > 0)
|
||||
sbuilder.append(' ');
|
||||
sbuilder.append(tokn);
|
||||
suggestions.add(new CompletionSuggestion(sbuilder.toString()));
|
||||
}
|
||||
}
|
||||
suggestionsReady(request, callback, suggestions);
|
||||
}
|
||||
|
||||
@@ -54,23 +54,16 @@ public class FridgeBagPanel extends Composite {
|
||||
limit, new PGF.CompleteCallback() {
|
||||
public void onResult(PGF.Completions completions) {
|
||||
for (PGF.Completion completion : completions.iterable()) {
|
||||
String newText = completion.getText();
|
||||
if (!newText.equals(text + " ")) {
|
||||
String[] words = newText.split("\\s+");
|
||||
if (words.length > 0) {
|
||||
String word = words[words.length - 1];
|
||||
if (word.length() > 0) {
|
||||
if (updatePrefixes) {
|
||||
addPrefix(text, word.substring(0,1));
|
||||
}
|
||||
if (mainPanel.getWidgetCount() < maxMagnets) {
|
||||
Magnet magnet = magnetFactory.createMagnet(word, completion.getFrom());
|
||||
mainPanel.add(magnet);
|
||||
removeStyleDependentName("empty");
|
||||
} else {
|
||||
prefixPanel.setVisible(true);
|
||||
}
|
||||
}
|
||||
for (String word : completion.getCompletions()) {
|
||||
if (updatePrefixes) {
|
||||
addPrefix(text, word.substring(0,1));
|
||||
}
|
||||
if (mainPanel.getWidgetCount() < maxMagnets) {
|
||||
Magnet magnet = magnetFactory.createMagnet(word, completion.getFrom());
|
||||
mainPanel.add(magnet);
|
||||
removeStyleDependentName("empty");
|
||||
} else {
|
||||
prefixPanel.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +113,8 @@ public class PGF {
|
||||
protected Completion() { }
|
||||
|
||||
public final native String getFrom() /*-{ return this.from; }-*/;
|
||||
public final native BracketedString getBracketedString() /*-{ return this.brackets; }-*/;
|
||||
public final native String[] getCompletions() /*-{ return this.completions; }-*/;
|
||||
public final native String getText() /*-{ return this.text; }-*/;
|
||||
}
|
||||
|
||||
@@ -150,6 +152,20 @@ public class PGF {
|
||||
public final native int getFId() /*-{ return this.fid; }-*/;
|
||||
public final native int getIndex() /*-{ return this.index; }-*/;
|
||||
public final native BracketedString[] getChildren() /*-{ return this.children; }-*/;
|
||||
|
||||
public final String render() {
|
||||
if (getToken() != null)
|
||||
return getToken();
|
||||
else {
|
||||
StringBuilder sbuilder = new StringBuilder();
|
||||
for (BracketedString bs : getChildren()) {
|
||||
if (sbuilder.length() > 0)
|
||||
sbuilder.append(' ');
|
||||
sbuilder.append(bs.render());
|
||||
}
|
||||
return sbuilder.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class TcError extends JavaScriptObject {
|
||||
|
||||
Reference in New Issue
Block a user