mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
The GF editor now lets the user to upload his/her own grammars
This commit is contained in:
@@ -50,15 +50,21 @@ cgiMain' cache path =
|
|||||||
do c <- liftIO $ readCache cache path
|
do c <- liftIO $ readCache cache path
|
||||||
mb_command <- liftM (liftM (urlDecodeUnicode . UTF8.decodeString)) (getInput "command")
|
mb_command <- liftM (liftM (urlDecodeUnicode . UTF8.decodeString)) (getInput "command")
|
||||||
case mb_command of
|
case mb_command of
|
||||||
|
Just "update_grammar"
|
||||||
|
-> do mb_pgf <- getFile
|
||||||
|
id <- getGrammarId
|
||||||
|
name <- getFileName
|
||||||
|
descr <- getDescription
|
||||||
|
doUpdateGrammar c mb_pgf id name descr
|
||||||
|
Just "delete_grammar"
|
||||||
|
-> do id <- getGrammarId
|
||||||
|
doDeleteGrammar c id
|
||||||
|
Just "grammars"
|
||||||
|
-> doGrammars c
|
||||||
Just "save" -> doSave c =<< getId
|
Just "save" -> doSave c =<< getId
|
||||||
Just "load" -> doLoad c =<< getId
|
Just "load" -> doLoad c =<< getId
|
||||||
Just "search" -> doSearch c =<< getQuery
|
Just "search" -> doSearch c =<< getQuery
|
||||||
Just "delete" -> doDelete c =<< getIds
|
Just "delete" -> doDelete c =<< getIds
|
||||||
Just "update_grammar"
|
|
||||||
-> do mb_pgf <- getFile
|
|
||||||
name <- getFileName
|
|
||||||
descr <- getDescription
|
|
||||||
doUpdateGrammar c mb_pgf name descr
|
|
||||||
Just cmd -> throwCGIError 400 "Unknown command" ["Unknown command: " ++ show cmd]
|
Just cmd -> throwCGIError 400 "Unknown command" ["Unknown command: " ++ show cmd]
|
||||||
Nothing -> throwCGIError 400 "No command given" ["No command given"]
|
Nothing -> throwCGIError 400 "No command given" ["No command given"]
|
||||||
where
|
where
|
||||||
@@ -70,19 +76,71 @@ cgiMain' cache path =
|
|||||||
|
|
||||||
getQuery :: CGI String
|
getQuery :: CGI String
|
||||||
getQuery = fmap (fromMaybe "") (getInput "query")
|
getQuery = fmap (fromMaybe "") (getInput "query")
|
||||||
|
|
||||||
|
getGrammarId :: CGI String
|
||||||
|
getGrammarId = do
|
||||||
|
mb_url <- getInput "url"
|
||||||
|
return (maybe "null" (reverse . drop 4 . reverse) mb_url)
|
||||||
|
|
||||||
getFile :: CGI (Maybe BS.ByteString)
|
getFile :: CGI (Maybe BS.ByteString)
|
||||||
getFile = getInputFPS "file"
|
getFile = do
|
||||||
|
getInputFPS "file"
|
||||||
|
|
||||||
getFileName :: CGI String
|
getFileName :: CGI String
|
||||||
getFileName = do
|
getFileName = do
|
||||||
mb_name <- getInput "name"
|
mb_name0 <- getInput "name"
|
||||||
|
let mb_name | mb_name0 == Just "" = Nothing
|
||||||
|
| otherwise = mb_name0
|
||||||
mb_file <- getInputFilename "file"
|
mb_file <- getInputFilename "file"
|
||||||
return (fromMaybe "" (mb_name `mplus` mb_file))
|
return (fromMaybe "" (mb_name `mplus` mb_file))
|
||||||
|
|
||||||
getDescription :: CGI String
|
getDescription :: CGI String
|
||||||
getDescription = fmap (fromMaybe "") (getInput "description")
|
getDescription = fmap (fromMaybe "") (getInput "description")
|
||||||
|
|
||||||
|
doGrammars c = do
|
||||||
|
r <- liftIO $ handleSql (return . Left) $ do
|
||||||
|
s <- query c "call getGrammars()"
|
||||||
|
rows <- collectRows getGrammar s
|
||||||
|
return (Right rows)
|
||||||
|
case r of
|
||||||
|
Right rows -> outputJSONP rows
|
||||||
|
Left e -> throwCGIError 400 "Loading failed" (lines (show e))
|
||||||
|
where
|
||||||
|
getGrammar s = do
|
||||||
|
id <- getFieldValue s "id"
|
||||||
|
name <- getFieldValue s "name"
|
||||||
|
description <- getFieldValue s "description"
|
||||||
|
return $ toJSObject [ ("url", showJSON (addExtension (show (id :: Int)) "pgf"))
|
||||||
|
, ("name", showJSON (name :: String))
|
||||||
|
, ("description", showJSON (description :: String))
|
||||||
|
]
|
||||||
|
|
||||||
|
doUpdateGrammar c mb_pgf id name descr = do
|
||||||
|
r <- liftIO $ handleSql (return . Left) $ do
|
||||||
|
s <- query c ("call updateGrammar("++id++","++toSqlValue name++","++toSqlValue descr++")")
|
||||||
|
[id] <- collectRows (\s -> getFieldValue s "id") s
|
||||||
|
return (Right id)
|
||||||
|
nid <- case r of
|
||||||
|
Right id -> return (id :: Int)
|
||||||
|
Left e -> throwCGIError 400 "Saving failed" (lines (show e))
|
||||||
|
path <- pathTranslated
|
||||||
|
case mb_pgf of
|
||||||
|
Just pgf -> if pgf /= BS.empty
|
||||||
|
then liftIO (BS.writeFile (dropExtension path </> addExtension (show nid) "pgf") pgf)
|
||||||
|
else if id == "null"
|
||||||
|
then throwCGIError 400 "Grammar update failed" []
|
||||||
|
else return ()
|
||||||
|
Nothing -> return ()
|
||||||
|
outputHTML ""
|
||||||
|
|
||||||
|
doDeleteGrammar c id = do
|
||||||
|
r <- liftIO $ handleSql (return . Left) $ do
|
||||||
|
execute c ("call deleteGrammar("++id++")")
|
||||||
|
return (Right "")
|
||||||
|
case r of
|
||||||
|
Right x -> outputJSONP ([] :: [(String,String)])
|
||||||
|
Left e -> throwCGIError 400 "Saving failed" (lines (show e))
|
||||||
|
|
||||||
doSave c mb_id = do
|
doSave c mb_id = do
|
||||||
body <- getBody
|
body <- getBody
|
||||||
r <- liftIO $ handleSql (return . Left) $ do
|
r <- liftIO $ handleSql (return . Left) $ do
|
||||||
@@ -151,20 +209,6 @@ doDelete c ids = do
|
|||||||
mapM_ (\id -> execute c ("DELETE FROM Documents WHERE id = "++toSqlValue id)) ids
|
mapM_ (\id -> execute c ("DELETE FROM Documents WHERE id = "++toSqlValue id)) ids
|
||||||
outputJSONP (toJSObject ([] :: [(String,String)]))
|
outputJSONP (toJSObject ([] :: [(String,String)]))
|
||||||
|
|
||||||
doUpdateGrammar c mb_pgf name descr = do
|
|
||||||
r <- liftIO $ handleSql (return . Left) $ do
|
|
||||||
s <- query c ("call updateGrammar(null,"++toSqlValue name++","++toSqlValue descr++")")
|
|
||||||
[id] <- collectRows (\s -> getFieldValue s "id") s
|
|
||||||
return (Right id)
|
|
||||||
id <- case r of
|
|
||||||
Right id -> return (id :: Int)
|
|
||||||
Left e -> throwCGIError 400 "Saving failed" (lines (show e))
|
|
||||||
path <- pathTranslated
|
|
||||||
case mb_pgf of
|
|
||||||
Just pgf -> liftIO (BS.writeFile (path </> ".." </> "grammars" </> addExtension (show id) "pgf") pgf)
|
|
||||||
Nothing -> return ()
|
|
||||||
outputHTML "<H1>Done.</H1>"
|
|
||||||
|
|
||||||
dbConnect fpath = do
|
dbConnect fpath = do
|
||||||
[host,db,user,pwd] <- fmap words $ readFile fpath
|
[host,db,user,pwd] <- fmap words $ readFile fpath
|
||||||
connect host db user pwd
|
connect host db user pwd
|
||||||
@@ -207,3 +251,13 @@ dbInit c =
|
|||||||
" select id;\n"++
|
" select id;\n"++
|
||||||
" END IF;\n"++
|
" END IF;\n"++
|
||||||
"END")
|
"END")
|
||||||
|
execute c "DROP PROCEDURE IF EXISTS deleteGrammar"
|
||||||
|
execute c ("CREATE PROCEDURE deleteGrammar(IN grammarId INTEGER)\n"++
|
||||||
|
"BEGIN\n"++
|
||||||
|
" DELETE FROM Grammars WHERE id = grammarId;\n"++
|
||||||
|
"END")
|
||||||
|
execute c "DROP PROCEDURE IF EXISTS getGrammars"
|
||||||
|
execute c ("CREATE PROCEDURE getGrammars()\n"++
|
||||||
|
"BEGIN\n"++
|
||||||
|
" SELECT id,name,description FROM Grammars ORDER BY name;\n"++
|
||||||
|
"END")
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ public class BrowsePanel extends Composite {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class MySettingsListener implements PGFWrapper.SettingsListener {
|
protected class MySettingsListener implements SettingsListener {
|
||||||
|
|
||||||
private PGFWrapper pgf;
|
private PGFWrapper pgf;
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class CompletionOracle extends SuggestOracle {
|
|||||||
public CompletionOracle (PGFWrapper pgf, ErrorHandler errorHandler) {
|
public CompletionOracle (PGFWrapper pgf, ErrorHandler errorHandler) {
|
||||||
this.pgf = pgf;
|
this.pgf = pgf;
|
||||||
this.errorHandler = errorHandler;
|
this.errorHandler = errorHandler;
|
||||||
pgf.addSettingsListener(new PGFWrapper.SettingsListener() {
|
pgf.addSettingsListener(new SettingsListener() {
|
||||||
public void onAvailableGrammarsChanged() { clearState(); }
|
public void onAvailableGrammarsChanged() { clearState(); }
|
||||||
public void onSelectedGrammarChanged() { clearState(); }
|
public void onSelectedGrammarChanged() { clearState(); }
|
||||||
public void onInputLanguageChanged() { clearState(); }
|
public void onInputLanguageChanged() { clearState(); }
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ import com.google.gwt.core.client.*;
|
|||||||
public class ContentService {
|
public class ContentService {
|
||||||
String contentBaseURL;
|
String contentBaseURL;
|
||||||
|
|
||||||
|
// Event listeners
|
||||||
|
private List<SettingsListener> listeners = new LinkedList<SettingsListener>();
|
||||||
|
private List<GrammarInfo> grammars = null;
|
||||||
|
|
||||||
|
|
||||||
public ContentService(String contentBaseURL) {
|
public ContentService(String contentBaseURL) {
|
||||||
this.contentBaseURL = contentBaseURL;
|
this.contentBaseURL = contentBaseURL;
|
||||||
}
|
}
|
||||||
@@ -15,6 +20,51 @@ public class ContentService {
|
|||||||
public String getBaseURL() {
|
public String getBaseURL() {
|
||||||
return contentBaseURL;
|
return contentBaseURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addSettingsListener(SettingsListener listener) {
|
||||||
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateAvailableGrammars() {
|
||||||
|
List<Arg> args = new ArrayList<Arg>();
|
||||||
|
args.add(new Arg("command", "grammars"));
|
||||||
|
JSONRequestBuilder.sendRequest(contentBaseURL, args, new GrammarsCallback() {
|
||||||
|
public void onResult(IterableJsArray<ContentService.GrammarInfo> grammars_) {
|
||||||
|
grammars = new ArrayList<GrammarInfo>();
|
||||||
|
for (ContentService.GrammarInfo grammar : grammars_.iterable()) {
|
||||||
|
grammars.add(grammar);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (SettingsListener listener : listeners) {
|
||||||
|
listener.onAvailableGrammarsChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GrammarInfo> getGrammars() {
|
||||||
|
return grammars;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface GrammarsCallback extends JSONCallback<IterableJsArray<GrammarInfo>> {}
|
||||||
|
|
||||||
|
public static class GrammarInfo extends JavaScriptObject {
|
||||||
|
protected GrammarInfo() { }
|
||||||
|
|
||||||
|
public final native String getURL() /*-{ return this.url; }-*/;
|
||||||
|
public final native String getName() /*-{ return this.name; }-*/;
|
||||||
|
public final native String getDescription() /*-{ return this.description; }-*/;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONRequest deleteGrammar(String grammarURL, DeleteCallback callback) {
|
||||||
|
List<Arg> args = new ArrayList<Arg>();
|
||||||
|
args.add(new Arg("url", grammarURL));
|
||||||
|
args.add(new Arg("command", "delete_grammar"));
|
||||||
|
return JSONRequestBuilder.sendRequest(contentBaseURL, args, callback);
|
||||||
|
}
|
||||||
|
|
||||||
public JSONRequest save(Object id, String content, SaveCallback callback) {
|
public JSONRequest save(Object id, String content, SaveCallback callback) {
|
||||||
List<Arg> args = new ArrayList<Arg>();
|
List<Arg> args = new ArrayList<Arg>();
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class DocumentsPanel extends Composite implements HasSelectionHandlers<Ob
|
|||||||
});
|
});
|
||||||
|
|
||||||
FlexTable header = new FlexTable();
|
FlexTable header = new FlexTable();
|
||||||
header.setStylePrimaryName("my-DocumentsHeader");
|
header.setStylePrimaryName("my-TableHeader");
|
||||||
header.setText(0,0,"Documents");
|
header.setText(0,0,"Documents");
|
||||||
header.setWidget(0,1,deleteButton);
|
header.setWidget(0,1,deleteButton);
|
||||||
header.getColumnFormatter().setWidth(1,"20px");
|
header.getColumnFormatter().setWidth(1,"20px");
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public class EditorApp implements EntryPoint {
|
|||||||
protected ContentService contentService;
|
protected ContentService contentService;
|
||||||
protected PGFWrapper pgf;
|
protected PGFWrapper pgf;
|
||||||
|
|
||||||
|
protected SettingsPanel settingsPanel;
|
||||||
protected VerticalPanel outputPanel;
|
protected VerticalPanel outputPanel;
|
||||||
protected Widget editorPanel;
|
protected Widget editorPanel;
|
||||||
protected BrowsePanel browsePanel;
|
protected BrowsePanel browsePanel;
|
||||||
@@ -221,7 +222,7 @@ public class EditorApp implements EntryPoint {
|
|||||||
hPanel.setCellHorizontalAlignment(linksPanel,HorizontalPanel.ALIGN_LEFT);
|
hPanel.setCellHorizontalAlignment(linksPanel,HorizontalPanel.ALIGN_LEFT);
|
||||||
linksPanel.selectTab(1);
|
linksPanel.selectTab(1);
|
||||||
|
|
||||||
Widget settingsPanel = createSettingsPanel();
|
settingsPanel = createSettingsPanel();
|
||||||
hPanel.add(settingsPanel);
|
hPanel.add(settingsPanel);
|
||||||
hPanel.setCellHorizontalAlignment(settingsPanel,HorizontalPanel.ALIGN_RIGHT);
|
hPanel.setCellHorizontalAlignment(settingsPanel,HorizontalPanel.ALIGN_RIGHT);
|
||||||
|
|
||||||
@@ -231,8 +232,8 @@ public class EditorApp implements EntryPoint {
|
|||||||
return vPanel;
|
return vPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Widget createSettingsPanel () {
|
protected SettingsPanel createSettingsPanel () {
|
||||||
return new SettingsPanel(pgf);
|
return new SettingsPanel(pgf, contentService, statusPopup);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Widget createEditorPanel() {
|
protected Widget createEditorPanel() {
|
||||||
@@ -412,23 +413,11 @@ public class EditorApp implements EntryPoint {
|
|||||||
return msgHTML;
|
return msgHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setPGFName (String pgfName) {
|
|
||||||
if (pgfName != null && !pgfName.equals(pgf.getPGFName())) {
|
|
||||||
pgf.setPGFName(pgfName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setInputLanguage (String inputLanguage) {
|
|
||||||
if (inputLanguage != null && !inputLanguage.equals(pgf.getInputLanguage())) {
|
|
||||||
pgf.setInputLanguage(inputLanguage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Initialization
|
// Initialization
|
||||||
//
|
//
|
||||||
|
|
||||||
protected class MySettingsListener implements PGFWrapper.SettingsListener {
|
protected class MySettingsListener implements SettingsListener {
|
||||||
// Will only happen on load
|
// Will only happen on load
|
||||||
public void onAvailableGrammarsChanged() {
|
public void onAvailableGrammarsChanged() {
|
||||||
if (pgf.getPGFName() == null) {
|
if (pgf.getPGFName() == null) {
|
||||||
@@ -459,7 +448,7 @@ public class EditorApp implements EntryPoint {
|
|||||||
statusPopup.showError(msg,e);
|
statusPopup.showError(msg,e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onModuleLoad() {
|
public void onModuleLoad() {
|
||||||
statusPopup = new StatusPopup();
|
statusPopup = new StatusPopup();
|
||||||
|
|
||||||
@@ -467,7 +456,7 @@ public class EditorApp implements EntryPoint {
|
|||||||
contentService = new ContentService(contentBaseURL);
|
contentService = new ContentService(contentBaseURL);
|
||||||
RootPanel.get().add(createUI());
|
RootPanel.get().add(createUI());
|
||||||
pgf.addSettingsListener(new MySettingsListener());
|
pgf.addSettingsListener(new MySettingsListener());
|
||||||
pgf.updateAvailableGrammars();
|
contentService.updateAvailableGrammars();
|
||||||
|
|
||||||
textPanel.setFocus(true);
|
textPanel.setFocus(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,11 +202,11 @@ public class FridgeApp implements EntryPoint {
|
|||||||
prefixPanel.setStylePrimaryName("my-PrefixPanel");
|
prefixPanel.setStylePrimaryName("my-PrefixPanel");
|
||||||
bagPanel = new FridgeBagPanel();
|
bagPanel = new FridgeBagPanel();
|
||||||
outputPanel = new TranslationsPanel();
|
outputPanel = new TranslationsPanel();
|
||||||
SettingsPanel settingsPanel = new SettingsPanel(pgf, true, false);
|
SettingsPanel settingsPanel = new SettingsPanel(pgf, null, statusPopup);
|
||||||
|
|
||||||
VerticalPanel vPanel = new VerticalPanel();
|
VerticalPanel vPanel = new VerticalPanel();
|
||||||
vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
|
vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
|
||||||
vPanel.setWidth("100%");
|
vPanel.setWidth("100%");
|
||||||
vPanel.add(prefixPanel);
|
vPanel.add(prefixPanel);
|
||||||
vPanel.add(bagPanel);
|
vPanel.add(bagPanel);
|
||||||
|
|
||||||
@@ -295,7 +295,7 @@ public class FridgeApp implements EntryPoint {
|
|||||||
// Initialization
|
// Initialization
|
||||||
//
|
//
|
||||||
|
|
||||||
protected class MySettingsListener implements PGFWrapper.SettingsListener {
|
protected class MySettingsListener implements SettingsListener {
|
||||||
// Will only happen on load
|
// Will only happen on load
|
||||||
public void onAvailableGrammarsChanged() {
|
public void onAvailableGrammarsChanged() {
|
||||||
if (pgf.getPGFName() == null) {
|
if (pgf.getPGFName() == null) {
|
||||||
|
|||||||
@@ -14,79 +14,187 @@ public class GrammarsPanel extends Composite {
|
|||||||
private PGFWrapper pgf;
|
private PGFWrapper pgf;
|
||||||
private ContentService contentService;
|
private ContentService contentService;
|
||||||
private StatusPopup statusPopup;
|
private StatusPopup statusPopup;
|
||||||
private FlexTable table;
|
|
||||||
private ArrayList documentIds = new ArrayList();
|
private VerticalPanel grammarsPanel;
|
||||||
|
private FormPanel form = null;
|
||||||
|
|
||||||
public GrammarsPanel(PGFWrapper pgf, ContentService contentService, StatusPopup statusPopup) {
|
public GrammarsPanel(PGFWrapper pgf, ContentService contentService, StatusPopup statusPopup) {
|
||||||
this.pgf = pgf;
|
this.pgf = pgf;
|
||||||
this.contentService = contentService;
|
this.contentService = contentService;
|
||||||
this.statusPopup = statusPopup;
|
this.statusPopup = statusPopup;
|
||||||
|
|
||||||
HorizontalPanel grammarsPanel = new HorizontalPanel();
|
VerticalPanel vpanel = new VerticalPanel();
|
||||||
|
|
||||||
UploadFormHandler uploadFormHandler = new UploadFormHandler();
|
|
||||||
|
|
||||||
final FormPanel form = new FormPanel();
|
Button btnNew = new Button("New Grammar");
|
||||||
form.setEncoding(FormPanel.ENCODING_MULTIPART);
|
btnNew.addClickListener(new ClickListener() {
|
||||||
form.setMethod(FormPanel.METHOD_POST);
|
|
||||||
form.setAction(contentService.getBaseURL());
|
|
||||||
form.addSubmitHandler(uploadFormHandler);
|
|
||||||
form.addSubmitCompleteHandler(uploadFormHandler);
|
|
||||||
grammarsPanel.add(form);
|
|
||||||
|
|
||||||
HorizontalPanel hPanel = new HorizontalPanel();
|
|
||||||
hPanel.setSpacing(8);
|
|
||||||
form.add(hPanel);
|
|
||||||
|
|
||||||
VerticalPanel vPanel = new VerticalPanel();
|
|
||||||
hPanel.add(vPanel);
|
|
||||||
|
|
||||||
vPanel.add(new HTML("<input type=\"hidden\" name=\"command\" value=\"update_grammar\"/>"));
|
|
||||||
|
|
||||||
FileUpload fileUpload = new FileUpload();
|
|
||||||
fileUpload.setName("file");
|
|
||||||
vPanel.add(fileUpload);
|
|
||||||
|
|
||||||
vPanel.add(new HTML("<BR/>"));
|
|
||||||
|
|
||||||
vPanel.add(new Label("Name:"));
|
|
||||||
TextBox grammarName = new TextBox();
|
|
||||||
grammarName.setName("name");
|
|
||||||
grammarName.setWidth("100%");
|
|
||||||
vPanel.add(grammarName);
|
|
||||||
|
|
||||||
vPanel.add(new HTML("<BR/>"));
|
|
||||||
|
|
||||||
vPanel.add(new Label("Description:"));
|
|
||||||
TextArea grammarDescr = new TextArea();
|
|
||||||
grammarDescr.setName("description");
|
|
||||||
grammarDescr.setWidth("100%");
|
|
||||||
grammarDescr.setHeight("150px");
|
|
||||||
vPanel.add(grammarDescr);
|
|
||||||
|
|
||||||
VerticalPanel btnPanel = new VerticalPanel();
|
|
||||||
btnPanel.setSpacing(3);
|
|
||||||
hPanel.add(btnPanel);
|
|
||||||
|
|
||||||
btnPanel.add(new Button("Upload", new ClickListener() {
|
|
||||||
public void onClick(Widget sender) {
|
public void onClick(Widget sender) {
|
||||||
form.submit();
|
if (form == null) {
|
||||||
|
grammarsPanel.insert(new GrammarInfoPanel(null),0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
btnPanel.add(new Button("Cancel", new ClickListener() {
|
vpanel.add(btnNew);
|
||||||
public void onClick(Widget sender) {
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
initWidget(grammarsPanel);
|
grammarsPanel = new VerticalPanel();
|
||||||
|
grammarsPanel.setWidth("100%");
|
||||||
|
vpanel.add(grammarsPanel);
|
||||||
|
|
||||||
|
initWidget(vpanel);
|
||||||
setStylePrimaryName("my-GrammarsPanel");
|
setStylePrimaryName("my-GrammarsPanel");
|
||||||
|
|
||||||
|
contentService.addSettingsListener(new MySettingsListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
private class UploadFormHandler implements FormPanel.SubmitHandler, FormPanel.SubmitCompleteHandler {
|
private class GrammarInfoPanel extends Composite {
|
||||||
public void onSubmit(FormPanel.SubmitEvent event) {
|
public GrammarInfoPanel(final ContentService.GrammarInfo grammar) {
|
||||||
|
final VerticalPanel vpanel = new VerticalPanel();
|
||||||
|
|
||||||
|
if (grammar != null) {
|
||||||
|
FlexTable header = new FlexTable();
|
||||||
|
header.setStylePrimaryName("my-TableHeader");
|
||||||
|
header.setText(0,0,grammar.getName());
|
||||||
|
vpanel.add(header);
|
||||||
|
|
||||||
|
final Image updateButton = new Image("org.grammaticalframework.ui.gwt.EditorApp/grammar-buttons.png",0,0,20,20);
|
||||||
|
updateButton.setTitle("Edit the grammar definition.");
|
||||||
|
updateButton.setStylePrimaryName("toolbar-button");
|
||||||
|
header.setWidget(0,1,updateButton);
|
||||||
|
header.getColumnFormatter().setWidth(1,"20px");
|
||||||
|
|
||||||
|
final Image deleteButton = new Image("org.grammaticalframework.ui.gwt.EditorApp/grammar-buttons.png",20,0,20,20);
|
||||||
|
deleteButton.setTitle("Delete this grammar.");
|
||||||
|
deleteButton.setStylePrimaryName("toolbar-button");
|
||||||
|
header.setWidget(0,2,deleteButton);
|
||||||
|
header.getColumnFormatter().setWidth(2,"20px");
|
||||||
|
|
||||||
|
final Label descr = new Label(grammar.getDescription());
|
||||||
|
descr.setStylePrimaryName("descr-label");
|
||||||
|
vpanel.add(descr);
|
||||||
|
|
||||||
|
updateButton.addClickListener(new ClickListener () {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
if (form == null) {
|
||||||
|
vpanel.remove(descr);
|
||||||
|
vpanel.add(form = createUploadForm(grammar));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
deleteButton.addClickListener(new ClickListener () {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
contentService.deleteGrammar(grammar.getURL(), new ContentService.DeleteCallback() {
|
||||||
|
public void onResult(ContentService.DeleteResult result) {
|
||||||
|
contentService.updateAvailableGrammars();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
statusPopup.showError("Delete failed", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
FlexTable header = new FlexTable();
|
||||||
|
header.setStylePrimaryName("my-TableHeader");
|
||||||
|
header.setText(0,0,"Add New Grammar");
|
||||||
|
vpanel.add(header);
|
||||||
|
vpanel.add(form = createUploadForm(grammar));
|
||||||
|
}
|
||||||
|
|
||||||
|
initWidget(vpanel);
|
||||||
|
setStylePrimaryName("my-GrammarInfoPanel");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FormPanel createUploadForm(final ContentService.GrammarInfo grammar) {
|
||||||
|
UploadFormHandler uploadFormHandler = new UploadFormHandler();
|
||||||
|
|
||||||
|
final FormPanel form = new FormPanel();
|
||||||
|
form.setWidth("100%");
|
||||||
|
form.setEncoding(FormPanel.ENCODING_MULTIPART);
|
||||||
|
form.setMethod(FormPanel.METHOD_POST);
|
||||||
|
form.setAction(contentService.getBaseURL());
|
||||||
|
form.addSubmitHandler(uploadFormHandler);
|
||||||
|
form.addSubmitCompleteHandler(uploadFormHandler);
|
||||||
|
|
||||||
|
VerticalPanel vPanel = new VerticalPanel();
|
||||||
|
vPanel.setWidth("100%");
|
||||||
|
form.add(vPanel);
|
||||||
|
|
||||||
|
vPanel.add(new HTML("<input type=\"hidden\" name=\"command\" value=\"update_grammar\"/>"));
|
||||||
|
|
||||||
public void onSubmitComplete(FormPanel.SubmitCompleteEvent event) {
|
HorizontalPanel hPanel = new HorizontalPanel();
|
||||||
|
hPanel.setSpacing(8);
|
||||||
|
hPanel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
|
||||||
|
vPanel.add(hPanel);
|
||||||
|
|
||||||
|
final FileUpload fileUpload = new FileUpload();
|
||||||
|
fileUpload.setName("file");
|
||||||
|
hPanel.add(fileUpload);
|
||||||
|
|
||||||
|
hPanel.add(new HTML(" "));
|
||||||
|
|
||||||
|
hPanel.add(new Label("Name:"));
|
||||||
|
final TextBox grammarName = new TextBox();
|
||||||
|
grammarName.setName("name");
|
||||||
|
grammarName.setWidth("300px");
|
||||||
|
hPanel.add(grammarName);
|
||||||
|
|
||||||
|
hPanel.add(new HTML(" "));
|
||||||
|
|
||||||
|
hPanel.add(new Button("Upload", new ClickListener() {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
if (grammar == null &&
|
||||||
|
fileUpload.getFilename().equals(""))
|
||||||
|
statusPopup.showError("You must select a file to upload", null);
|
||||||
|
else
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
hPanel.add(new Button("Cancel", new ClickListener() {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
contentService.updateAvailableGrammars();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
vPanel.add(new Label("Description:"));
|
||||||
|
TextArea grammarDescr = new TextArea();
|
||||||
|
grammarDescr.setName("description");
|
||||||
|
grammarDescr.setWidth("100%");
|
||||||
|
grammarDescr.setHeight("50px");
|
||||||
|
vPanel.add(grammarDescr);
|
||||||
|
|
||||||
|
if (grammar != null) {
|
||||||
|
grammarName.setText(grammar.getName());
|
||||||
|
grammarDescr.setText(grammar.getDescription());
|
||||||
|
|
||||||
|
vPanel.add(new HTML("<input type=\"hidden\" name=\"url\" value=\""+grammar.getURL()+"\"/>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return form;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
private class UploadFormHandler implements FormPanel.SubmitHandler, FormPanel.SubmitCompleteHandler {
|
||||||
|
public void onSubmit(FormPanel.SubmitEvent event) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSubmitComplete(FormPanel.SubmitCompleteEvent event) {
|
||||||
|
contentService.updateAvailableGrammars();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MySettingsListener implements SettingsListener {
|
||||||
|
public void onAvailableGrammarsChanged() {
|
||||||
|
form = null;
|
||||||
|
grammarsPanel.clear();
|
||||||
|
for (ContentService.GrammarInfo grammar : contentService.getGrammars()) {
|
||||||
|
grammarsPanel.add(new GrammarInfoPanel(grammar));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void onSelectedGrammarChanged() { }
|
||||||
|
public void onInputLanguageChanged() { }
|
||||||
|
public void onOutputLanguageChanged() { }
|
||||||
|
public void onStartCategoryChanged() { }
|
||||||
|
public void onSettingsError(String msg, Throwable e) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,6 +100,9 @@ public class PGFWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void updateSelectedGrammar () {
|
protected void updateSelectedGrammar () {
|
||||||
|
if (grammarURL == null)
|
||||||
|
return;
|
||||||
|
|
||||||
clearCachedInfo();
|
clearCachedInfo();
|
||||||
pgf.grammar(grammarURL, new PGF.GrammarCallback() {
|
pgf.grammar(grammarURL, new PGF.GrammarCallback() {
|
||||||
public void onResult(PGF.Grammar grammar) {
|
public void onResult(PGF.Grammar grammar) {
|
||||||
@@ -176,7 +179,7 @@ public class PGFWrapper {
|
|||||||
|
|
||||||
public void setPGFName(String pgfName) {
|
public void setPGFName(String pgfName) {
|
||||||
this.pgfName = pgfName;
|
this.pgfName = pgfName;
|
||||||
this.grammarURL = baseURL + "/" + pgfName;
|
this.grammarURL = (pgfName == null) ? null : baseURL + "/" + pgfName;
|
||||||
this.inputLanguage = null;
|
this.inputLanguage = null;
|
||||||
this.outputLanguage = null;
|
this.outputLanguage = null;
|
||||||
this.cat = null;
|
this.cat = null;
|
||||||
@@ -263,15 +266,6 @@ public class PGFWrapper {
|
|||||||
// Listeners
|
// Listeners
|
||||||
//
|
//
|
||||||
|
|
||||||
public interface SettingsListener {
|
|
||||||
public void onAvailableGrammarsChanged();
|
|
||||||
public void onSelectedGrammarChanged();
|
|
||||||
public void onInputLanguageChanged();
|
|
||||||
public void onOutputLanguageChanged();
|
|
||||||
public void onStartCategoryChanged();
|
|
||||||
public void onSettingsError(String msg, Throwable e);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SettingsAdapter implements SettingsListener {
|
public static class SettingsAdapter implements SettingsListener {
|
||||||
public void onAvailableGrammarsChanged() {}
|
public void onAvailableGrammarsChanged() {}
|
||||||
public void onSelectedGrammarChanged() {}
|
public void onSelectedGrammarChanged() {}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ public class QueryPanel extends Composite {
|
|||||||
return queryPanel;
|
return queryPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class MySettingsListener implements PGFWrapper.SettingsListener {
|
protected class MySettingsListener implements SettingsListener {
|
||||||
|
|
||||||
public MySettingsListener() {
|
public MySettingsListener() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package org.grammaticalframework.ui.gwt.client;
|
||||||
|
|
||||||
|
public interface SettingsListener {
|
||||||
|
public void onAvailableGrammarsChanged();
|
||||||
|
public void onSelectedGrammarChanged();
|
||||||
|
public void onInputLanguageChanged();
|
||||||
|
public void onOutputLanguageChanged();
|
||||||
|
public void onStartCategoryChanged();
|
||||||
|
public void onSettingsError(String msg, Throwable e);
|
||||||
|
}
|
||||||
@@ -5,31 +5,29 @@ import com.google.gwt.user.client.ui.*;
|
|||||||
public class SettingsPanel extends Composite {
|
public class SettingsPanel extends Composite {
|
||||||
|
|
||||||
private PGFWrapper pgf;
|
private PGFWrapper pgf;
|
||||||
|
private ContentService contentService;
|
||||||
|
private StatusPopup statusPopup;
|
||||||
|
|
||||||
private MyListBox grammarBox;
|
private MyListBox grammarBox;
|
||||||
private MyListBox fromLangBox;
|
private MyListBox fromLangBox;
|
||||||
private MyListBox toLangBox;
|
private MyListBox toLangBox;
|
||||||
|
|
||||||
public SettingsPanel (PGFWrapper pgf) {
|
public SettingsPanel (PGFWrapper pgf, ContentService contentService, StatusPopup statusPopup) {
|
||||||
this(pgf, true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SettingsPanel (PGFWrapper pgf, boolean showPGFName, boolean showOutputLanguage) {
|
|
||||||
this.pgf = pgf;
|
this.pgf = pgf;
|
||||||
|
this.contentService = contentService;
|
||||||
|
this.statusPopup = statusPopup;
|
||||||
|
|
||||||
HorizontalPanel settingsPanel = new HorizontalPanel();
|
HorizontalPanel settingsPanel = new HorizontalPanel();
|
||||||
settingsPanel.setHorizontalAlignment(HorizontalPanel.ALIGN_CENTER);
|
settingsPanel.setHorizontalAlignment(HorizontalPanel.ALIGN_CENTER);
|
||||||
settingsPanel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
|
settingsPanel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
|
||||||
|
|
||||||
if (showPGFName) {
|
grammarBox = new MyListBox();
|
||||||
grammarBox = new MyListBox();
|
grammarBox.addChangeListener(new ChangeListener() {
|
||||||
grammarBox.addChangeListener(new ChangeListener() {
|
public void onChange(Widget sender) {
|
||||||
public void onChange(Widget sender) {
|
SettingsPanel.this.pgf.setPGFName(grammarBox.getSelectedValue());
|
||||||
SettingsPanel.this.pgf.setPGFName(grammarBox.getSelectedValue());
|
}
|
||||||
}
|
});
|
||||||
});
|
settingsPanel.add(new FormWidget("Grammar:", grammarBox));
|
||||||
settingsPanel.add(new FormWidget("Grammar:", grammarBox));
|
|
||||||
}
|
|
||||||
|
|
||||||
fromLangBox = new MyListBox();
|
fromLangBox = new MyListBox();
|
||||||
fromLangBox.addChangeListener(new ChangeListener() {
|
fromLangBox.addChangeListener(new ChangeListener() {
|
||||||
@@ -39,20 +37,19 @@ public class SettingsPanel extends Composite {
|
|||||||
});
|
});
|
||||||
settingsPanel.add(new FormWidget("From:", fromLangBox));
|
settingsPanel.add(new FormWidget("From:", fromLangBox));
|
||||||
|
|
||||||
if (showOutputLanguage) {
|
toLangBox = new MyListBox();
|
||||||
toLangBox = new MyListBox();
|
toLangBox.addChangeListener(new ChangeListener() {
|
||||||
toLangBox.addChangeListener(new ChangeListener() {
|
public void onChange(Widget sender) {
|
||||||
public void onChange(Widget sender) {
|
SettingsPanel.this.pgf.setOutputLanguage(toLangBox.getSelectedValue());
|
||||||
SettingsPanel.this.pgf.setOutputLanguage(toLangBox.getSelectedValue());
|
}
|
||||||
}
|
});
|
||||||
});
|
settingsPanel.add(new FormWidget("To:", toLangBox));
|
||||||
settingsPanel.add(new FormWidget("To:", toLangBox));
|
|
||||||
}
|
|
||||||
|
|
||||||
initWidget(settingsPanel);
|
initWidget(settingsPanel);
|
||||||
setStylePrimaryName("my-SettingsPanel");
|
setStylePrimaryName("my-SettingsPanel");
|
||||||
|
|
||||||
pgf.addSettingsListener(new MySettingsListener());
|
pgf.addSettingsListener(new MySettingsListener());
|
||||||
|
contentService.addSettingsListener(new MySettingsListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FormWidget extends HorizontalPanel {
|
private static class FormWidget extends HorizontalPanel {
|
||||||
@@ -64,11 +61,15 @@ public class SettingsPanel extends Composite {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MySettingsListener implements PGFWrapper.SettingsListener {
|
private class MySettingsListener implements SettingsListener {
|
||||||
public void onAvailableGrammarsChanged() {
|
public void onAvailableGrammarsChanged() {
|
||||||
if (grammarBox != null) {
|
if (grammarBox != null) {
|
||||||
grammarBox.clear();
|
grammarBox.clear();
|
||||||
grammarBox.addItems(pgf.getGrammars());
|
|
||||||
|
for (ContentService.GrammarInfo grammar : contentService.getGrammars()) {
|
||||||
|
grammarBox.addItem(grammar.getName(), grammar.getURL());
|
||||||
|
}
|
||||||
|
pgf.setPGFName(grammarBox.getSelectedValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void onSelectedGrammarChanged() {
|
public void onSelectedGrammarChanged() {
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ public class TranslateApp implements EntryPoint {
|
|||||||
vPanel.setWidth("100%");
|
vPanel.setWidth("100%");
|
||||||
vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
|
vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
|
||||||
vPanel.add(createSuggestPanel());
|
vPanel.add(createSuggestPanel());
|
||||||
vPanel.add(createSettingsPanel());
|
vPanel.add(createSettingsPanel());
|
||||||
vPanel.add(createTranslationsPanel());
|
vPanel.add(createTranslationsPanel());
|
||||||
|
|
||||||
return vPanel;
|
return vPanel;
|
||||||
@@ -221,7 +221,7 @@ public class TranslateApp implements EntryPoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Widget createSettingsPanel () {
|
protected Widget createSettingsPanel () {
|
||||||
return new SettingsPanel(pgf);
|
return new SettingsPanel(pgf, null, statusPopup);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Widget createTranslationsPanel () {
|
protected Widget createTranslationsPanel () {
|
||||||
@@ -276,7 +276,7 @@ public class TranslateApp implements EntryPoint {
|
|||||||
// Initialization
|
// Initialization
|
||||||
//
|
//
|
||||||
|
|
||||||
protected class MySettingsListener implements PGFWrapper.SettingsListener {
|
protected class MySettingsListener implements SettingsListener {
|
||||||
// Will only happen on load
|
// Will only happen on load
|
||||||
public void onAvailableGrammarsChanged() {
|
public void onAvailableGrammarsChanged() {
|
||||||
if (pgf.getPGFName() == null) {
|
if (pgf.getPGFName() == null) {
|
||||||
|
|||||||
@@ -15,16 +15,6 @@
|
|||||||
margin: 0 0.4em;
|
margin: 0 0.4em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-DocumentsHeader {
|
|
||||||
width: 100%;
|
|
||||||
background-attachement: scroll;
|
|
||||||
background-color: #E5E5E5;
|
|
||||||
background-image: url("background.png");
|
|
||||||
background-position: 0px -192px;
|
|
||||||
background-repeat: repeat-x;
|
|
||||||
font-size: 150%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.my-DocumentsTable {
|
.my-DocumentsTable {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border: 1px solid #E5E5E5;
|
border: 1px solid #E5E5E5;
|
||||||
@@ -45,6 +35,29 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.my-GrammarInfoPanel {
|
||||||
|
width: 100%;
|
||||||
|
border: 1px solid #E5E5E5;
|
||||||
|
margin-top: 5px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-GrammarInfoPanel .descr-label {
|
||||||
|
width: 100%;
|
||||||
|
height: 50px;
|
||||||
|
padding: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-TableHeader {
|
||||||
|
width: 100%;
|
||||||
|
background-attachement: scroll;
|
||||||
|
background-color: #E5E5E5;
|
||||||
|
background-image: url("background.png");
|
||||||
|
background-position: 0px -192px;
|
||||||
|
background-repeat: repeat-x;
|
||||||
|
font-size: 150%;
|
||||||
|
}
|
||||||
|
|
||||||
.my-EditorPanel {
|
.my-EditorPanel {
|
||||||
padding-top: 1em;
|
padding-top: 1em;
|
||||||
padding-bottom: 1em
|
padding-bottom: 1em
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
Reference in New Issue
Block a user