Skip to content

Commit

Permalink
Working UiBinder template for SpellingSandboxDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyhorner committed Mar 1, 2012
1 parent d360a86 commit 1f2f2e5
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 25 deletions.
Expand Up @@ -19,21 +19,25 @@
import org.rstudio.studio.client.common.SimpleRequestCallback;
import org.rstudio.studio.client.common.spelling.model.SpellingServerOperations;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JsArrayString;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiFactory;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class SpellingSandboxDialog extends ModalDialogBase
{

interface Binder extends UiBinder<Widget, SpellingSandboxDialog>{}

@Inject
public SpellingSandboxDialog(GlobalDisplay globalDisplay,
SpellingServerOperations server)
Expand All @@ -56,47 +60,32 @@ public void onClick(ClickEvent event)
@Override
protected Widget createMainWidget()
{
VerticalPanel mainPanel = new VerticalPanel();
mainPanel.setWidth("300px");

mainPanel.add(new Label("Not in dictionary"));
txtWord_ = new TextArea();
txtWord_.setVisibleLines(2);
txtWord_.setWidth("100px");
txtWord_.getElement().getStyle().setMarginBottom(7, Unit.PX);
mainPanel.add(txtWord_);
Widget mainPanel = uiBinder.createAndBindUi(this);
//setWidget(mainPanel);

ThemedButton btnCheck = new ThemedButton("Check", new ClickHandler() {
changeButton_.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event)
{
checkSpelling(txtWord_.getText().trim());
}
});
mainPanel.add(btnCheck);


ThemedButton btnSuggest = new ThemedButton("Suggest", new ClickHandler() {
changeAllButton_.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event)
{
suggestionList(txtWord_.getText().trim());
}
});
mainPanel.add(btnSuggest);

mainPanel.add(new Label("Suggestions"));
listBox_ = new ListBox(false);
listBox_.setVisibleItemCount(5);
listBox_.setWidth("100px");
listBox_.getElement().getStyle().setMarginBottom(7, Unit.PX);
listBox_.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event)
{
txtWord_.setText(listBox_.getValue(listBox_.getSelectedIndex()));
}
});
mainPanel.add(listBox_);

return mainPanel;
}
Expand Down Expand Up @@ -143,8 +132,18 @@ private void showResponse(String request, String response)
txtWord_.setFocus(true);
}

private TextArea txtWord_;
private ListBox listBox_;
@UiFactory ThemedButton makeThemedButton()
{
return new ThemedButton("");
}

private static Binder uiBinder = GWT.create(Binder.class);
@UiField TextArea txtWord_;
@UiField ListBox listBox_;
@UiField ThemedButton changeButton_;
@UiField ThemedButton changeAllButton_;
@UiField ThemedButton ignoreButton_;
@UiField ThemedButton ignoreAllButton_;
private final GlobalDisplay globalDisplay_;
private final SpellingServerOperations server_;

Expand Down
@@ -0,0 +1,46 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:r="urn:import:org.rstudio.core.client.widget">
<ui:style>
.rounded {
border: 1px solid black;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
}
</ui:style>
<g:HTMLPanel>
<div class="{style.rounded}">
<!-- Add GWT widgets here. Enter < and hit Ctrl-Space to auto-complete
widget names. The ui:field attribute binds an element to a field in the owner
class. See the GWT docs on UI Binder for more details. -->
<table>
<tr>
<td rowspan="2">
<g:TextArea ui:field="txtWord_" visibleLines="2" width="100px"></g:TextArea>
</td>
<td>
<r:ThemedButton ui:field="ignoreButton_" text="Ignore" width="100px"/>
</td>
</tr>
<td>
<r:ThemedButton ui:field="ignoreAllButton_" text="Ignore All" width="100px"/>
</td>
<tr>
<td rowspan="2">
<g:ListBox ui:field="listBox_" visibleItemCount="5" multipleSelect="false" width="100px"></g:ListBox>
</td>
<td>
<r:ThemedButton ui:field="changeButton_" text="Change" width="100px"/>
</td>
</tr>
<tr>
<td>
<r:ThemedButton ui:field="changeAllButton_" text="Change All" width="100px"/>
</td>
</tr>
</table>
</div>
</g:HTMLPanel>
</ui:UiBinder>
Expand Up @@ -486,7 +486,8 @@ public void dismissSearchResults()
setMode(Mode.Recent);
//searchResults_.clear();
//contextResults_.clear();
searchWidget_.setText("");
//searchWidget_.setText("");
searchWidget_.clear();
}

public void showSearchResults(String query,
Expand Down

0 comments on commit 1f2f2e5

Please sign in to comment.