mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-22 19:22:50 -06:00
preliminary UI for storage/retrieval/search of documents in the GF editor
This commit is contained in:
@@ -7,46 +7,67 @@ import com.google.gwt.http.client.*;
|
|||||||
import com.google.gwt.xml.client.*;
|
import com.google.gwt.xml.client.*;
|
||||||
import com.google.gwt.event.logical.shared.*;
|
import com.google.gwt.event.logical.shared.*;
|
||||||
import com.google.gwt.event.dom.client.*;
|
import com.google.gwt.event.dom.client.*;
|
||||||
|
import com.google.gwt.event.shared.*;
|
||||||
|
|
||||||
public class DocumentsPanel extends Composite {
|
public class DocumentsPanel extends Composite implements HasSelectionHandlers<Object> {
|
||||||
|
|
||||||
private PGFWrapper pgf;
|
private PGFWrapper pgf;
|
||||||
|
private ContentService contentService;
|
||||||
|
private StatusPopup statusPopup;
|
||||||
private FlexTable table;
|
private FlexTable table;
|
||||||
|
private ArrayList documentIds = new ArrayList();
|
||||||
|
|
||||||
public DocumentsPanel(PGFWrapper pgf) {
|
public DocumentsPanel(PGFWrapper pgf, ContentService contentService, StatusPopup statusPopup) {
|
||||||
this.pgf = pgf;
|
this.pgf = pgf;
|
||||||
|
this.contentService = contentService;
|
||||||
|
this.statusPopup = statusPopup;
|
||||||
|
|
||||||
VerticalPanel documentsPanel = new VerticalPanel();
|
VerticalPanel documentsPanel = new VerticalPanel();
|
||||||
documentsPanel.setStylePrimaryName("my-DocumentsFrame");
|
documentsPanel.setStylePrimaryName("my-DocumentsFrame");
|
||||||
|
|
||||||
HorizontalPanel searchPanel = new HorizontalPanel();
|
HorizontalPanel searchPanel = new HorizontalPanel();
|
||||||
searchPanel.setStylePrimaryName("my-DocumentsSearchFrame");
|
searchPanel.setStylePrimaryName("my-DocumentsSearchFrame");
|
||||||
TextBox searchBox = new TextBox();
|
final TextBox searchBox = new TextBox();
|
||||||
searchBox.setWidth("20em");
|
searchBox.setWidth("20em");
|
||||||
Button searchBtn = new Button("Search");
|
final Button searchBtn = new Button("Search");
|
||||||
searchPanel.add(searchBox);
|
searchPanel.add(searchBox);
|
||||||
searchPanel.add(searchBtn);
|
searchPanel.add(searchBtn);
|
||||||
documentsPanel.add(searchPanel);
|
documentsPanel.add(searchPanel);
|
||||||
|
|
||||||
Label header = new Label("Documents");
|
Image deleteButton = new Image("org.grammaticalframework.ui.gwt.EditorApp/trash-button.png");
|
||||||
|
deleteButton.setTitle("Deletes the selected documents.");
|
||||||
|
deleteButton.setStylePrimaryName("toolbar-button");
|
||||||
|
deleteButton.addClickListener(new ClickListener () {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
deleteSelected();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
FlexTable header = new FlexTable();
|
||||||
header.setStylePrimaryName("my-DocumentsHeader");
|
header.setStylePrimaryName("my-DocumentsHeader");
|
||||||
|
header.setText(0,0,"Documents");
|
||||||
|
header.setWidget(0,1,deleteButton);
|
||||||
|
header.getColumnFormatter().setWidth(1,"20px");
|
||||||
documentsPanel.add(header);
|
documentsPanel.add(header);
|
||||||
|
|
||||||
table = new FlexTable();
|
table = new FlexTable();
|
||||||
|
table.setCellPadding(2);
|
||||||
table.setStylePrimaryName("my-DocumentsTable");
|
table.setStylePrimaryName("my-DocumentsTable");
|
||||||
|
table.getColumnFormatter().setWidth(1,"80em");
|
||||||
|
table.getColumnFormatter().setWidth(2,"80em");
|
||||||
documentsPanel.add(table);
|
documentsPanel.add(table);
|
||||||
|
|
||||||
addRow(0, "Test0");
|
|
||||||
addRow(1, "Test1");
|
|
||||||
addRow(2, "Test2");
|
|
||||||
addRow(3, "Test3");
|
|
||||||
|
|
||||||
|
searchBtn.addClickHandler(new ClickHandler() {
|
||||||
|
public void onClick(ClickEvent event) {
|
||||||
|
searchDocuments(searchBox.getText());
|
||||||
|
}
|
||||||
|
});
|
||||||
table.addClickHandler(new ClickHandler() {
|
table.addClickHandler(new ClickHandler() {
|
||||||
public void onClick(ClickEvent event) {
|
public void onClick(ClickEvent event) {
|
||||||
HTMLTable.Cell cell = table.getCellForEvent(event);
|
HTMLTable.Cell cell = table.getCellForEvent(event);
|
||||||
if (cell != null) {
|
if (cell != null) {
|
||||||
int row = cell.getRowIndex();
|
int row = cell.getRowIndex();
|
||||||
selectRow(row);
|
selectDocument(row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -54,12 +75,68 @@ public class DocumentsPanel extends Composite {
|
|||||||
initWidget(documentsPanel);
|
initWidget(documentsPanel);
|
||||||
setStylePrimaryName("my-DocumentsPanel");
|
setStylePrimaryName("my-DocumentsPanel");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addRow(int row, String text) {
|
public HandlerRegistration addSelectionHandler(SelectionHandler<Object> handler) {
|
||||||
table.setText(row, 0, text);
|
return addHandler(handler, SelectionEvent.getType());
|
||||||
table.getRowFormatter().addStyleName(row, "row");
|
}
|
||||||
|
|
||||||
|
protected void selectDocument(int row) {
|
||||||
|
SelectionEvent.fire(this, documentIds.get(row));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectRow(int row) {
|
protected void searchDocuments(String fullTextQuery) {
|
||||||
}
|
statusPopup.setStatus("Searching...");
|
||||||
|
|
||||||
|
documentIds.clear();
|
||||||
|
while (table.getRowCount() > 0)
|
||||||
|
table.removeRow(0);
|
||||||
|
|
||||||
|
contentService.search(fullTextQuery, new ContentService.SearchCallback() {
|
||||||
|
public void onResult(IterableJsArray<ContentService.DocumentSignature> documents) {
|
||||||
|
for (ContentService.DocumentSignature sign : documents.iterable()) {
|
||||||
|
int row = table.getRowCount();
|
||||||
|
table.setWidget(row, 0, new CheckBox(sign.getTitle()));
|
||||||
|
table.setText(row, 1, sign.getCreated());
|
||||||
|
table.setText(row, 2, sign.getModified());
|
||||||
|
table.getRowFormatter().addStyleName(row, "row");
|
||||||
|
documentIds.add(sign.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
statusPopup.clearStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
statusPopup.showError("Search failed", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void deleteSelected() {
|
||||||
|
statusPopup.setStatus("Deleting...");
|
||||||
|
|
||||||
|
final ArrayList ids = new ArrayList();
|
||||||
|
final ArrayList<Integer> rows = new ArrayList<Integer>();
|
||||||
|
for (int row = 0; row < table.getRowCount(); row++) {
|
||||||
|
CheckBox checkBox = (CheckBox) table.getWidget(row,0);
|
||||||
|
if (checkBox.isChecked()) {
|
||||||
|
ids.add(documentIds.get(row));
|
||||||
|
rows.add(new Integer(row));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contentService.delete(ids, new ContentService.DeleteCallback() {
|
||||||
|
public void onResult(ContentService.DeleteResult result) {
|
||||||
|
for (Integer row : rows) {
|
||||||
|
table.removeRow(row.intValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
statusPopup.clearStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
statusPopup.showError("Delete failed", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ import com.google.gwt.event.shared.*;
|
|||||||
public class EditorApp implements EntryPoint {
|
public class EditorApp implements EntryPoint {
|
||||||
|
|
||||||
protected static final String pgfBaseURL = "/grammars";
|
protected static final String pgfBaseURL = "/grammars";
|
||||||
|
protected static final String contentBaseURL = "/content.fcgi";
|
||||||
|
|
||||||
|
protected ContentService contentService;
|
||||||
protected PGFWrapper pgf;
|
protected PGFWrapper pgf;
|
||||||
|
|
||||||
protected VerticalPanel outputPanel;
|
protected VerticalPanel outputPanel;
|
||||||
@@ -24,6 +26,7 @@ public class EditorApp implements EntryPoint {
|
|||||||
protected TextInputPanel textPanel;
|
protected TextInputPanel textPanel;
|
||||||
protected FridgeBagPanel bagPanel;
|
protected FridgeBagPanel bagPanel;
|
||||||
protected MagnetFactory magnetFactory;
|
protected MagnetFactory magnetFactory;
|
||||||
|
protected TabBar tabBar;
|
||||||
|
|
||||||
private JSONRequest completeRequest = null;
|
private JSONRequest completeRequest = null;
|
||||||
private JSONRequest translateRequest = null;
|
private JSONRequest translateRequest = null;
|
||||||
@@ -233,7 +236,7 @@ public class EditorApp implements EntryPoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Widget createEditorPanel() {
|
protected Widget createEditorPanel() {
|
||||||
textPanel = new TextInputPanel();
|
textPanel = new TextInputPanel(contentService, statusPopup);
|
||||||
textPanel.addValueChangeHandler(new ValueChangeHandler<String>() {
|
textPanel.addValueChangeHandler(new ValueChangeHandler<String>() {
|
||||||
public void onValueChange(ValueChangeEvent<String> event) {
|
public void onValueChange(ValueChangeEvent<String> event) {
|
||||||
update();
|
update();
|
||||||
@@ -304,11 +307,18 @@ public class EditorApp implements EntryPoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected DocumentsPanel createDocumentsPanel() {
|
protected DocumentsPanel createDocumentsPanel() {
|
||||||
return new DocumentsPanel(pgf);
|
DocumentsPanel panel = new DocumentsPanel(pgf, contentService, statusPopup);
|
||||||
|
panel.addSelectionHandler(new SelectionHandler<Object>() {
|
||||||
|
public void onSelection(SelectionEvent<Object> event) {
|
||||||
|
tabBar.selectTab(1);
|
||||||
|
textPanel.load(event.getSelectedItem());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TabBar createLinksPanel(final Panel parent) {
|
protected TabBar createLinksPanel(final Panel parent) {
|
||||||
TabBar tabBar = new TabBar();
|
tabBar = new TabBar();
|
||||||
tabBar.setStylePrimaryName("my-LinksPanel");
|
tabBar.setStylePrimaryName("my-LinksPanel");
|
||||||
tabBar.addTab("Documents");
|
tabBar.addTab("Documents");
|
||||||
tabBar.addTab("Editor");
|
tabBar.addTab("Editor");
|
||||||
@@ -426,6 +436,7 @@ public class EditorApp implements EntryPoint {
|
|||||||
statusPopup = new StatusPopup();
|
statusPopup = new StatusPopup();
|
||||||
|
|
||||||
pgf = new PGFWrapper(pgfBaseURL);
|
pgf = new PGFWrapper(pgfBaseURL);
|
||||||
|
contentService = new ContentService(contentBaseURL);
|
||||||
RootPanel.get().add(createUI());
|
RootPanel.get().add(createUI());
|
||||||
pgf.addSettingsListener(new MySettingsListener());
|
pgf.addSettingsListener(new MySettingsListener());
|
||||||
pgf.updateAvailableGrammars();
|
pgf.updateAvailableGrammars();
|
||||||
|
|||||||
@@ -56,13 +56,13 @@ public class JSONRequestBuilder {
|
|||||||
public static <T extends JavaScriptObject> JSONRequest sendDataRequest (String base, List<Arg> vars, String content, final JSONCallback<T> callback) {
|
public static <T extends JavaScriptObject> JSONRequest sendDataRequest (String base, List<Arg> vars, String content, final JSONCallback<T> callback) {
|
||||||
String url = getQueryURL(base,vars);
|
String url = getQueryURL(base,vars);
|
||||||
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
|
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
|
||||||
builder.setRequestData(content);
|
|
||||||
builder.setTimeoutMillis(30000);
|
builder.setTimeoutMillis(30000);
|
||||||
|
builder.setHeader("Content-Length", Integer.toString(content.length()));
|
||||||
builder.setHeader("Accept","text/plain, text/html;q=0.5, */*;q=0.1");
|
builder.setHeader("Accept","text/plain, text/html;q=0.5, */*;q=0.1");
|
||||||
Request request = null;
|
Request request = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
request = builder.sendRequest(null, new RequestCallback() {
|
request = builder.sendRequest(content, new RequestCallback() {
|
||||||
public void onError(Request request, Throwable e) {
|
public void onError(Request request, Throwable e) {
|
||||||
callback.onError(e);
|
callback.onError(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import com.google.gwt.event.shared.*;
|
|||||||
|
|
||||||
public class TextInputPanel extends Composite implements Focusable, HasValueChangeHandlers<String>, HasSelectionHandlers<String> {
|
public class TextInputPanel extends Composite implements Focusable, HasValueChangeHandlers<String>, HasSelectionHandlers<String> {
|
||||||
|
|
||||||
|
protected ContentService contentService;
|
||||||
|
protected StatusPopup statusPopup;
|
||||||
protected FlowPanel textPanel = null;
|
protected FlowPanel textPanel = null;
|
||||||
protected FlowPanel mainPanel = null;
|
protected FlowPanel mainPanel = null;
|
||||||
protected FocusPanel focusPanel = null;
|
protected FocusPanel focusPanel = null;
|
||||||
@@ -28,8 +30,13 @@ public class TextInputPanel extends Composite implements Focusable, HasValueChan
|
|||||||
private Map<Integer, Phrase> mapFId2Phrase = new HashMap<Integer, Phrase>();
|
private Map<Integer, Phrase> mapFId2Phrase = new HashMap<Integer, Phrase>();
|
||||||
|
|
||||||
private ChangeListenerCollection changeListeners = null;
|
private ChangeListenerCollection changeListeners = null;
|
||||||
|
|
||||||
|
private Integer docId = null;
|
||||||
|
|
||||||
|
public TextInputPanel(ContentService contentService, StatusPopup statusPopup) {
|
||||||
|
this.contentService = contentService;
|
||||||
|
this.statusPopup = statusPopup;
|
||||||
|
|
||||||
public TextInputPanel() {
|
|
||||||
mainPanel = new FlowPanel();
|
mainPanel = new FlowPanel();
|
||||||
mainPanel.setStylePrimaryName("wordspanel");
|
mainPanel.setStylePrimaryName("wordspanel");
|
||||||
|
|
||||||
@@ -72,7 +79,7 @@ public class TextInputPanel extends Composite implements Focusable, HasValueChan
|
|||||||
|
|
||||||
Image clearButton = new Image("org.grammaticalframework.ui.gwt.EditorApp/textinput-buttons.png",0,0,20,20);
|
Image clearButton = new Image("org.grammaticalframework.ui.gwt.EditorApp/textinput-buttons.png",0,0,20,20);
|
||||||
clearButton.setTitle("Clears the whole document.");
|
clearButton.setTitle("Clears the whole document.");
|
||||||
clearButton.setStylePrimaryName("button");
|
clearButton.setStylePrimaryName("toolbar-button");
|
||||||
clearButton.addClickListener(new ClickListener () {
|
clearButton.addClickListener(new ClickListener () {
|
||||||
public void onClick(Widget sender) {
|
public void onClick(Widget sender) {
|
||||||
clear();
|
clear();
|
||||||
@@ -82,7 +89,7 @@ public class TextInputPanel extends Composite implements Focusable, HasValueChan
|
|||||||
|
|
||||||
Image saveButton = new Image("org.grammaticalframework.ui.gwt.EditorApp/textinput-buttons.png",20,0,20,20);
|
Image saveButton = new Image("org.grammaticalframework.ui.gwt.EditorApp/textinput-buttons.png",20,0,20,20);
|
||||||
saveButton.setTitle("Save the document.");
|
saveButton.setTitle("Save the document.");
|
||||||
saveButton.setStylePrimaryName("button");
|
saveButton.setStylePrimaryName("toolbar-button");
|
||||||
saveButton.addClickListener(new ClickListener () {
|
saveButton.addClickListener(new ClickListener () {
|
||||||
public void onClick(Widget sender) {
|
public void onClick(Widget sender) {
|
||||||
save();
|
save();
|
||||||
@@ -92,7 +99,7 @@ public class TextInputPanel extends Composite implements Focusable, HasValueChan
|
|||||||
|
|
||||||
Image deleteLastButton = new Image("org.grammaticalframework.ui.gwt.EditorApp/textinput-buttons.png",40,0,20,20);
|
Image deleteLastButton = new Image("org.grammaticalframework.ui.gwt.EditorApp/textinput-buttons.png",40,0,20,20);
|
||||||
deleteLastButton.setTitle("Removes the last word.");
|
deleteLastButton.setTitle("Removes the last word.");
|
||||||
deleteLastButton.setStylePrimaryName("button");
|
deleteLastButton.setStylePrimaryName("toolbar-button");
|
||||||
deleteLastButton.addClickListener(new ClickListener () {
|
deleteLastButton.addClickListener(new ClickListener () {
|
||||||
public void onClick(Widget sender) {
|
public void onClick(Widget sender) {
|
||||||
deleteLast();
|
deleteLast();
|
||||||
@@ -168,10 +175,43 @@ public class TextInputPanel extends Composite implements Focusable, HasValueChan
|
|||||||
focusedPanel = null;
|
focusedPanel = null;
|
||||||
errorPanels = null;
|
errorPanels = null;
|
||||||
tempPanel = null;
|
tempPanel = null;
|
||||||
|
docId = null;
|
||||||
fireValueChange();
|
fireValueChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
|
statusPopup.setStatus("Saving...");
|
||||||
|
|
||||||
|
contentService.save(docId, getText(), new ContentService.SaveCallback() {
|
||||||
|
public void onResult(ContentService.DocumentSignature sign) {
|
||||||
|
docId = new Integer(sign.getId());
|
||||||
|
statusPopup.clearStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
statusPopup.showError("Saving failed", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load(Object id) {
|
||||||
|
statusPopup.setStatus("Loading...");
|
||||||
|
|
||||||
|
contentService.load(id, new ContentService.LoadCallback() {
|
||||||
|
public void onResult(ContentService.Document document) {
|
||||||
|
clear();
|
||||||
|
|
||||||
|
docId = new Integer(document.getId());
|
||||||
|
showSearchBox();
|
||||||
|
searchBox.setText(document.getContent());
|
||||||
|
|
||||||
|
statusPopup.clearStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
statusPopup.showError("Saving failed", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMagnet(Magnet magnet) {
|
public void addMagnet(Magnet magnet) {
|
||||||
|
|||||||
@@ -77,12 +77,12 @@
|
|||||||
background-repeat: repeat-x;
|
background-repeat: repeat-x;
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-TextInputPanel .toolbar .button {
|
.toolbar-button {
|
||||||
float: left;
|
float: left;
|
||||||
margin: 2px;
|
margin: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-TextInputPanel .toolbar .button:hover {
|
.toolbar-button:hover {
|
||||||
margin: 1px;
|
margin: 1px;
|
||||||
border: 1px solid rgb(147,194,241);
|
border: 1px solid rgb(147,194,241);
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 930 B |
Reference in New Issue
Block a user