more advanced complete function in the PGFService

This commit is contained in:
krasimir
2010-08-24 15:58:22 +00:00
parent 4df7b04935
commit d3a6866277
6 changed files with 66 additions and 65 deletions

View File

@@ -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:'

View File

@@ -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);
}

View File

@@ -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);
}
}
}

View File

@@ -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 {