Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Change stats option into radio button in document list view
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Oct 3, 2012
1 parent 881fc68 commit 2fa4862
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 26 deletions.
Expand Up @@ -128,8 +128,6 @@ public void onSelectionChange(SelectionChangeEvent event)
}
});

display.addStatsOption(messages.byWords(), STATS_OPTION_WORDS);
display.addStatsOption(messages.byMessage(), STATS_OPTION_MESSAGE);
setStatsFilter(STATS_OPTION_WORDS);

registerHandler(eventBus.addHandler(DocumentSelectionEvent.getType(), this));
Expand Down Expand Up @@ -196,9 +194,9 @@ public void fireCaseSensitiveToken(boolean value)
}

@Override
public void statsOptionChange()
public void statsOptionChange(String option)
{
setStatsFilter(display.getSelectedStatsOption());
setStatsFilter(option);
dataProvider.refresh();
}

Expand Down
Expand Up @@ -458,10 +458,10 @@ public interface WebTransMessages extends Messages
@DefaultMessage("Editor")
String editor();

@DefaultMessage("By Words")
@DefaultMessage("By words")
String byWords();

@DefaultMessage("By Message")
@DefaultMessage("By message")
String byMessage();

}
Expand Up @@ -49,8 +49,6 @@ public interface DocumentListDisplay extends WidgetDisplay

String getSelectedStatsOption();

void addStatsOption(String item, String value);

void setStatsFilter(String option);

void setListener(Listener documentListPresenter);
Expand All @@ -59,7 +57,7 @@ public interface DocumentListDisplay extends WidgetDisplay

interface Listener
{
void statsOptionChange();
void statsOptionChange(String option);

void fireCaseSensitiveToken(boolean value);

Expand Down
Expand Up @@ -24,10 +24,10 @@
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.ui.DocumentListTable;
import org.zanata.webtrans.client.ui.DocumentNode;
import org.zanata.webtrans.client.ui.HasStatsFilter;
import org.zanata.webtrans.shared.model.DocumentInfo;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.logical.shared.HasSelectionHandlers;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
Expand All @@ -41,7 +41,7 @@
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.HasData;
Expand All @@ -64,8 +64,11 @@ public class DocumentListView extends Composite implements DocumentListDisplay,
@UiField
CheckBox exactSearchCheckBox, caseSensitiveCheckBox;

// @UiField
// ListBox statsOptions;

@UiField
ListBox statsOptions;
RadioButton statsByMsg, statsByWord;

@UiField
SimplePager pager;
Expand All @@ -89,7 +92,8 @@ public DocumentListView(Resources resources, WebTransMessages messages)

caseSensitiveCheckBox.setTitle(messages.docListFilterCaseSensitiveDescription());
exactSearchCheckBox.setTitle(messages.docListFilterExactMatchDescription());

statsByMsg.setText(messages.byMessage());
statsByWord.setText(messages.byWords());
this.addSelectionHandler(new SelectionHandler<DocumentInfo>()
{
@Override
Expand All @@ -107,16 +111,18 @@ public Widget asWidget()
return this;
}

@Override
public void addStatsOption(String item, String value)
{
statsOptions.addItem(item, value);
}

@Override
public String getSelectedStatsOption()
{
return statsOptions.getValue(statsOptions.getSelectedIndex());
if (statsByMsg.getValue())
{
return HasStatsFilter.STATS_OPTION_MESSAGE;
}
else
{
return HasStatsFilter.STATS_OPTION_WORDS;
}
}

@Override
Expand Down Expand Up @@ -173,15 +179,35 @@ public void renderTable(SingleSelectionModel<DocumentNode> selectionModel)
documentListContainer.add(documentListTable);
}

@UiHandler("statsOptions")
public void onStatsOptionChange(ChangeEvent event)
@UiHandler("statsByMsg")
public void onStatsByMsgChange(ValueChangeEvent<Boolean> event)
{
listener.statsOptionChange();
if (event.getValue())
{
listener.statsOptionChange(HasStatsFilter.STATS_OPTION_MESSAGE);
}
}

@UiHandler("statsByWord")
public void onStatsByWordChange(ValueChangeEvent<Boolean> event)
{
if (event.getValue())
{
listener.statsOptionChange(HasStatsFilter.STATS_OPTION_WORDS);
}
}

@Override
public void setStatsFilter(String option)
{
if (option.equals(HasStatsFilter.STATS_OPTION_MESSAGE))
{
statsByMsg.setValue(true);
}
else
{
statsByWord.setValue(true);
}
documentListTable.setStatsFilter(option);
}

Expand Down
Expand Up @@ -57,10 +57,11 @@
<g:layer top="10px" height="34px" left="585px" width="140px">
<g:CheckBox ui:field="exactSearchCheckBox" styleName="{style.optionStyle}"><ui:msg>Exact match only</ui:msg></g:CheckBox>
</g:layer>
<g:layer right="0" width="200px" top="10px" bottom="0">
<g:layer right="0" width="240px" top="10px" bottom="0">
<g:HTMLPanel>
<g:InlineLabel styleName="{style.optionStyle}"><ui:msg>Statistic: </ui:msg></g:InlineLabel>
<g:ListBox ui:field="statsOptions"/>
<g:RadioButton ui:field="statsByWord" styleName="{style.optionStyle}" name="statsOption"/>
<g:RadioButton ui:field="statsByMsg" styleName="{style.optionStyle}" name="statsOption"/>
</g:HTMLPanel>
</g:layer>
</g:LayoutPanel>
Expand Down
Expand Up @@ -103,8 +103,6 @@ public void onBind()
documentListPresenter.onBind();

verify(mockDisplay).renderTable(isA(SingleSelectionModel.class));
verify(mockDisplay).addStatsOption(TEST_BY_WORDS_MESSAGE, "Words");
verify(mockDisplay).addStatsOption(TEST_BY_MESSAGE_MESSAGE, "Message");
verify(mockDisplay).setStatsFilter("Words");
verify(mockDisplay).setPageSize(TEST_PAGE_SIZE);
verify(mockDisplay).setListener(documentListPresenter);
Expand Down

0 comments on commit 2fa4862

Please sign in to comment.