diff options
| author | krasimir <krasimir@chalmers.se> | 2011-03-07 21:05:29 +0000 |
|---|---|---|
| committer | krasimir <krasimir@chalmers.se> | 2011-03-07 21:05:29 +0000 |
| commit | 42ad2d5e95f1433d4878bb40d449efaedf841c6f (patch) | |
| tree | 7c0dad4b8dc97ba9c6334e26b6b00c594f375b5a /src/ui | |
| parent | 62c85f1bb6a56ba7236497a4e6dcd8457d9bdcd4 (diff) | |
the user can now upload their own grammars in the editor
Diffstat (limited to 'src/ui')
10 files changed, 123 insertions, 105 deletions
diff --git a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/ContentService.java b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/ContentService.java index e6f0b5509..fd336bf34 100644 --- a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/ContentService.java +++ b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/ContentService.java @@ -6,29 +6,37 @@ import java.util.*; import com.google.gwt.core.client.*; public class ContentService { - String contentBaseURL; // Event listeners private List<SettingsListener> listeners = new LinkedList<SettingsListener>(); private List<GrammarInfo> grammars = null; - public ContentService(String contentBaseURL) { - this.contentBaseURL = contentBaseURL; + public ContentService() { } - - public String getBaseURL() { - return contentBaseURL; + + public static class Init extends JavaScriptObject { + protected Init() { } + + public final native String getUserId() /*-{ return this.userId; }-*/; + public final native String getUserURL() /*-{ return this.userURL; }-*/; + public final native String getUserEMail() /*-{ return this.userEMail; }-*/; + public final native String getContentURL() /*-{ return this.contentURL; }-*/; } - + + public static final native Init getInit() /*-{ + return $wnd.__gfInit; + }-*/; + public void addSettingsListener(SettingsListener listener) { listeners.add(listener); } public void updateAvailableGrammars() { List<Arg> args = new ArrayList<Arg>(); + args.add(new Arg("userId", getInit().getUserId())); args.add(new Arg("command", "grammars")); - JSONRequestBuilder.sendRequest(contentBaseURL, args, new GrammarsCallback() { + JSONRequestBuilder.sendRequest(getInit().getContentURL(), args, new GrammarsCallback() { public void onResult(IterableJsArray<ContentService.GrammarInfo> grammars_) { grammars = new ArrayList<GrammarInfo>(); for (ContentService.GrammarInfo grammar : grammars_.iterable()) { @@ -62,8 +70,9 @@ public class ContentService { public JSONRequest deleteGrammar(String grammarURL, DeleteCallback callback) { List<Arg> args = new ArrayList<Arg>(); args.add(new Arg("url", grammarURL)); + args.add(new Arg("userId", getInit().getUserId())); args.add(new Arg("command", "delete_grammar")); - return JSONRequestBuilder.sendRequest(contentBaseURL, args, callback); + return JSONRequestBuilder.sendRequest(getInit().getContentURL(), args, callback); } public JSONRequest save(Object id, String content, SaveCallback callback) { @@ -71,7 +80,7 @@ public class ContentService { if (id != null) args.add(new Arg("id", id.toString())); args.add(new Arg("command", "save")); - return JSONRequestBuilder.sendDataRequest(contentBaseURL, args, content, callback); + return JSONRequestBuilder.sendDataRequest(getInit().getContentURL(), args, content, callback); } public interface SaveCallback extends JSONCallback<DocumentSignature> {} @@ -80,7 +89,7 @@ public class ContentService { List<Arg> args = new ArrayList<Arg>(); args.add(new Arg("command", "load")); args.add(new Arg("id", id.toString())); - return JSONRequestBuilder.sendRequest(contentBaseURL, args, callback); + return JSONRequestBuilder.sendRequest(getInit().getContentURL(), args, callback); } public interface LoadCallback extends JSONCallback<Document> {} @@ -89,7 +98,7 @@ public class ContentService { List<Arg> args = new ArrayList<Arg>(); args.add(new Arg("command", "search")); args.add(new Arg("query", fullTextQuery)); - return JSONRequestBuilder.sendRequest(contentBaseURL, args, callback); + return JSONRequestBuilder.sendRequest(getInit().getContentURL(), args, callback); } public interface SearchCallback extends JSONCallback<IterableJsArray<DocumentSignature>> {} @@ -115,7 +124,7 @@ public class ContentService { for (Object id : ids) { args.add(new Arg("id", id.toString())); } - return JSONRequestBuilder.sendRequest(contentBaseURL, args, callback); + return JSONRequestBuilder.sendRequest(getInit().getContentURL(), args, callback); } public interface DeleteCallback extends JSONCallback<DeleteResult> {} diff --git a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/EditorApp.java b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/EditorApp.java index dde097b8f..bca76e7bb 100644 --- a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/EditorApp.java +++ b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/EditorApp.java @@ -11,9 +11,6 @@ import com.google.gwt.event.shared.*; public class EditorApp implements EntryPoint { - protected static final String pgfBaseURL = "/grammars"; - protected static final String contentBaseURL = "/grammars.content"; - protected ContentService contentService; protected PGFWrapper pgf; @@ -420,10 +417,10 @@ public class EditorApp implements EntryPoint { protected class MySettingsListener implements SettingsListener { // Will only happen on load public void onAvailableGrammarsChanged() { - if (pgf.getPGFName() == null) { + if (pgf.getGrammarURL() == null) { List<String> grammars = pgf.getGrammars(); if (!grammars.isEmpty()) { - pgf.setPGFName(grammars.get(0)); + pgf.setGrammarURL(grammars.get(0)); } } } @@ -452,8 +449,8 @@ public class EditorApp implements EntryPoint { public void onModuleLoad() { statusPopup = new StatusPopup(); - pgf = new PGFWrapper(pgfBaseURL); - contentService = new ContentService(contentBaseURL); + pgf = new PGFWrapper(); + contentService = new ContentService(); RootPanel.get().add(createUI()); pgf.addSettingsListener(new MySettingsListener()); contentService.updateAvailableGrammars(); diff --git a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/FridgeApp.java b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/FridgeApp.java index acc28977a..4e9963451 100644 --- a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/FridgeApp.java +++ b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/FridgeApp.java @@ -272,16 +272,16 @@ public class FridgeApp implements EntryPoint { protected void updateSettingsFromHistoryToken(String[] tokenParts) { if (tokenParts.length >= 1 && tokenParts[0].length() > 0) { - setPGFName(tokenParts[0]); + setGrammarURL(tokenParts[0]); } if (tokenParts.length >= 2 && tokenParts[1].length() > 0) { setInputLanguage(tokenParts[1]); } } - protected void setPGFName (String pgfName) { - if (pgfName != null && !pgfName.equals(pgf.getPGFName())) { - pgf.setPGFName(pgfName); + protected void setGrammarURL(String url) { + if (url != null && !url.equals(pgf.getGrammarURL())) { + pgf.setGrammarURL(url); } } @@ -298,12 +298,12 @@ public class FridgeApp implements EntryPoint { protected class MySettingsListener implements SettingsListener { // Will only happen on load public void onAvailableGrammarsChanged() { - if (pgf.getPGFName() == null) { + if (pgf.getGrammarURL() == null) { List<String> grammars = pgf.getGrammars(); if (!grammars.isEmpty()) { - pgf.setPGFName(grammars.get(0)); + pgf.setGrammarURL(grammars.get(0)); } - } + } } public void onSelectedGrammarChanged() { if (pgf.getInputLanguage() == null) { @@ -327,7 +327,7 @@ public class FridgeApp implements EntryPoint { public void onModuleLoad() { statusPopup = new StatusPopup(); - pgf = new PGFWrapper(pgfBaseURL); + pgf = new PGFWrapper(); RootPanel.get().add(createUI()); pgf.addSettingsListener(new MySettingsListener()); History.addHistoryListener(new MyHistoryListener()); diff --git a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/GrammarsPanel.java b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/GrammarsPanel.java index 70f761f8b..0857c3c4e 100644 --- a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/GrammarsPanel.java +++ b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/GrammarsPanel.java @@ -112,7 +112,7 @@ public class GrammarsPanel extends Composite { form.setWidth("100%"); form.setEncoding(FormPanel.ENCODING_MULTIPART); form.setMethod(FormPanel.METHOD_POST); - form.setAction(contentService.getBaseURL()); + form.setAction(ContentService.getInit().getContentURL()); form.addSubmitHandler(uploadFormHandler); form.addSubmitCompleteHandler(uploadFormHandler); @@ -120,7 +120,8 @@ public class GrammarsPanel extends Composite { vPanel.setWidth("100%"); form.add(vPanel); - vPanel.add(new HTML("<input type=\"hidden\" name=\"command\" value=\"update_grammar\"/>")); + vPanel.add(new HTML("<input type=\"hidden\" name=\"userId\" value=\""+ContentService.getInit().getUserId()+"\"/>\n"+ + "<input type=\"hidden\" name=\"command\" value=\"update_grammar\"/>")); HorizontalPanel hPanel = new HorizontalPanel(); hPanel.setSpacing(8); diff --git a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/PGFWrapper.java b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/PGFWrapper.java index 9c88da7f6..1e248fa40 100644 --- a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/PGFWrapper.java +++ b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/PGFWrapper.java @@ -11,11 +11,7 @@ import com.google.gwt.core.client.*; public class PGFWrapper { - private String baseURL; - - private String grammarURL; - - private String pgfName = null; + private String grammarURL = null; private PGF pgf; @@ -44,17 +40,11 @@ public class PGFWrapper { public PGFWrapper() { - this.baseURL = null; - this.pgf = new PGF(); - } - - public PGFWrapper(String baseURL) { - this.baseURL = baseURL; this.pgf = new PGF(); } public void updateAvailableGrammars() { - String url = baseURL+"/grammars.xml"; + String url = "/grammars.xml"; RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url)); try { @@ -172,26 +162,12 @@ public class PGFWrapper { // // Settings // - - public String getPGFName() { - return pgfName; - } - - public void setPGFName(String pgfName) { - this.pgfName = pgfName; - this.grammarURL = (pgfName == null) ? null : baseURL + "/" + pgfName; - this.inputLanguage = null; - this.outputLanguage = null; - this.cat = null; - updateSelectedGrammar(); - } public String getGrammarURL() { return grammarURL; } public void setGrammarURL(String grammarURL) { - this.pgfName = null; this.grammarURL = grammarURL; this.inputLanguage = null; this.outputLanguage = null; diff --git a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/SettingsPanel.java b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/SettingsPanel.java index a5c19bc64..b3c22572c 100644 --- a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/SettingsPanel.java +++ b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/SettingsPanel.java @@ -24,7 +24,7 @@ public class SettingsPanel extends Composite { grammarBox = new MyListBox(); grammarBox.addChangeListener(new ChangeListener() { public void onChange(Widget sender) { - SettingsPanel.this.pgf.setPGFName(grammarBox.getSelectedValue()); + SettingsPanel.this.pgf.setGrammarURL(grammarBox.getSelectedValue()); } }); settingsPanel.add(new FormWidget("Grammar:", grammarBox)); @@ -45,6 +45,28 @@ public class SettingsPanel extends Composite { }); settingsPanel.add(new FormWidget("To:", toLangBox)); + if (contentService.getInit().getUserEMail() != null) { + String url = contentService.getInit().getContentURL(); + settingsPanel.add(new FormWidget(contentService.getInit().getUserEMail(), + new HTML("<A href='"+url+"'>Sign Out</A>"))); + } else { + String url = contentService.getInit().getContentURL(); + url = "https://www.google.com/accounts/o8/ud" + + "?openid.ns=http://specs.openid.net/auth/2.0" + + "&openid.ns.max_auth_age=300" + + "&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select" + + "&openid.identity=http://specs.openid.net/auth/2.0/identifier_select" + + "&openid.return_to=http://localhost:8080"+url + + "&openid.realm=http://localhost:8080/" + + "&openid.mode=checkid_setup" + + "&openid.ns.ax=http://openid.net/srv/ax/1.0" + + "&openid.ax.mode=fetch_request" + + "&openid.ax.type.email=http://axschema.org/contact/email" + + "&openid.ax.required=email"; + settingsPanel.add(new FormWidget("", + new HTML("<A href='"+url+"'>Sign In</A>"))); + } + initWidget(settingsPanel); setStylePrimaryName("my-SettingsPanel"); @@ -54,7 +76,7 @@ public class SettingsPanel extends Composite { private static class FormWidget extends HorizontalPanel { public FormWidget(String label, Widget w) { - setStylePrimaryName(".my-FormWidget"); + setStylePrimaryName("form-widget"); setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE); add(new Label(label)); add(w); @@ -65,16 +87,18 @@ public class SettingsPanel extends Composite { public void onAvailableGrammarsChanged() { if (grammarBox != null) { grammarBox.clear(); - + fromLangBox.clear(); + toLangBox.clear(); + for (ContentService.GrammarInfo grammar : contentService.getGrammars()) { grammarBox.addItem(grammar.getName(), grammar.getURL()); } - pgf.setPGFName(grammarBox.getSelectedValue()); + pgf.setGrammarURL(grammarBox.getSelectedValue()); } } public void onSelectedGrammarChanged() { if (grammarBox != null) { - grammarBox.setSelectedValue(pgf.getPGFName()); + grammarBox.setSelectedValue(pgf.getGrammarURL()); } if (fromLangBox != null) { fromLangBox.clear(); diff --git a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/TranslateApp.java b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/TranslateApp.java index 9a6b84a8a..e6c58c1d8 100644 --- a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/TranslateApp.java +++ b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/client/TranslateApp.java @@ -253,16 +253,16 @@ public class TranslateApp implements EntryPoint { protected void updateSettingsFromHistoryToken(String[] tokenParts) { if (tokenParts.length >= 1 && tokenParts[0].length() > 0) { - setPGFName(tokenParts[0]); + setGrammarURL(tokenParts[0]); } if (tokenParts.length >= 2 && tokenParts[1].length() > 0) { setInputLanguage(tokenParts[1]); } } - protected void setPGFName (String pgfName) { - if (pgfName != null && !pgfName.equals(pgf.getPGFName())) { - pgf.setPGFName(pgfName); + protected void setGrammarURL (String url) { + if (url != null && !url.equals(pgf.getGrammarURL())) { + pgf.setGrammarURL(url); } } @@ -279,10 +279,10 @@ public class TranslateApp implements EntryPoint { protected class MySettingsListener implements SettingsListener { // Will only happen on load public void onAvailableGrammarsChanged() { - if (pgf.getPGFName() == null) { + if (pgf.getGrammarURL() == null) { List<String> grammars = pgf.getGrammars(); if (!grammars.isEmpty()) { - pgf.setPGFName(grammars.get(0)); + pgf.setGrammarURL(grammars.get(0)); } } } @@ -310,7 +310,7 @@ public class TranslateApp implements EntryPoint { public void onModuleLoad() { statusPopup = new StatusPopup(); - pgf = new PGFWrapper(pgfBaseURL); + pgf = new PGFWrapper(); RootPanel.get().add(createUI()); pgf.addSettingsListener(new MySettingsListener()); History.addHistoryListener(new MyHistoryListener()); diff --git a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/public/Editor.css b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/public/Editor.css index 0fd99f8a3..f568ab96e 100644 --- a/src/ui/gwt/src/org/grammaticalframework/ui/gwt/public/Editor.css +++ b/src/ui/gwt/src/org/grammaticalframework/ui/gwt/public/Editor.css @@ -152,10 +152,17 @@ font-size: 150%; } -.my-SettingsPanel * { +.my-SettingsPanel { +} + +.my-SettingsPanel .form-widget { margin: 0 0.4em; } +.my-SettingsPanel .form-widget * { + margin: 0 0.1em; +} + .my-LinksPanel * { margin: 0 0.2em; } diff --git a/src/ui/gwt/www/editor/editor.html b/src/ui/gwt/www/editor/editor.html new file mode 100644 index 000000000..114a88ccb --- /dev/null +++ b/src/ui/gwt/www/editor/editor.html @@ -0,0 +1,36 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<!-- The HTML 4.01 Transitional DOCTYPE declaration--> +<!-- above set at the top of the file will set --> +<!-- the browser's rendering engine into --> +<!-- "Quirks Mode". Replacing this declaration --> +<!-- with a "Standards Mode" doctype is supported, --> +<!-- but may lead to some differences in layout. --> + +<html> + <head> + <meta http-equiv="content-type" content="text/html; charset=UTF-8"> + <!-- --> + <!-- Any title is fine --> + <!-- --> + <title>Editor</title> + + <!-- --> + <!-- This script loads your compiled module. --> + <!-- If you add any GWT meta tags, they must --> + <!-- be added before this line. --> + <!-- --> + <script type="text/javascript" language="javascript" src="org.grammaticalframework.ui.gwt.EditorApp/org.grammaticalframework.ui.gwt.EditorApp.nocache.js"></script> + </head> + + <!-- --> + <!-- The body can have arbitrary html, or --> + <!-- you can leave the body empty if you want --> + <!-- to create a completely dynamic UI. --> + <!-- --> + <body> + + <!-- OPTIONAL: include this if you want history support --> + <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe> + + </body> +</html> diff --git a/src/ui/gwt/www/editor/index.html b/src/ui/gwt/www/editor/index.html index 114a88ccb..1af492b4a 100644 --- a/src/ui/gwt/www/editor/index.html +++ b/src/ui/gwt/www/editor/index.html @@ -1,36 +1,4 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> -<!-- The HTML 4.01 Transitional DOCTYPE declaration--> -<!-- above set at the top of the file will set --> -<!-- the browser's rendering engine into --> -<!-- "Quirks Mode". Replacing this declaration --> -<!-- with a "Standards Mode" doctype is supported, --> -<!-- but may lead to some differences in layout. --> - -<html> - <head> - <meta http-equiv="content-type" content="text/html; charset=UTF-8"> - <!-- --> - <!-- Any title is fine --> - <!-- --> - <title>Editor</title> - - <!-- --> - <!-- This script loads your compiled module. --> - <!-- If you add any GWT meta tags, they must --> - <!-- be added before this line. --> - <!-- --> - <script type="text/javascript" language="javascript" src="org.grammaticalframework.ui.gwt.EditorApp/org.grammaticalframework.ui.gwt.EditorApp.nocache.js"></script> - </head> - - <!-- --> - <!-- The body can have arbitrary html, or --> - <!-- you can leave the body empty if you want --> - <!-- to create a completely dynamic UI. --> - <!-- --> - <body> - - <!-- OPTIONAL: include this if you want history support --> - <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe> - - </body> -</html> +<HEAD> +<META HTTP-EQUIV="REFRESH" + content="0; url=https://www.google.com/accounts/o8/ud?openid.ns=http://specs.openid.net/auth/2.0&openid.ns.max_auth_age=300&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&openid.return_to=http://localhost:8080/editor/grammars.content&openid.realm=http://localhost:8080/&openid.mode=checkid_immediate&openid.ns.ax=http://openid.net/srv/ax/1.0&openid.ax.mode=fetch_request&openid.ax.type.email=http://axschema.org/contact/email&openid.ax.required=email"> +</HEAD> |
