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

Commit

Permalink
refactor filter state checkbox update code for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed Jul 11, 2013
1 parent 4fdac3a commit f71b384
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 43 deletions.
Expand Up @@ -264,12 +264,12 @@ public void setFilterTranslated(boolean filterTranslated)
{
this.filterTranslated = filterTranslated;
}

public void setFilterApproved(boolean filterApproved)
{
this.filterApproved = filterApproved;
}

public void setFilterRejected(boolean filterRejected)
{
this.filterRejected = filterRejected;
Expand Down
Expand Up @@ -27,15 +27,14 @@
import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Strings;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.SelectElement;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

Expand All @@ -53,10 +52,10 @@ public class TransFilterView extends Composite implements TransFilterDisplay

@UiField
CheckBox translatedChk, fuzzyChk, untranslatedChk, approvedChk, rejectedChk, hasErrorChk;

@UiField
CheckBox incompleteChk, completeChk;

private String hintMessage;

private boolean focused = false;
Expand Down Expand Up @@ -198,52 +197,30 @@ public void onSearchFieldCancel()
@UiHandler({"translatedChk", "fuzzyChk", "untranslatedChk", "approvedChk", "rejectedChk", "hasErrorChk"})
public void onFilterOptionsChanged(ValueChangeEvent<Boolean> event)
{
toggleCompleteChk();
toggleIncompleteChk();

listener.messageFilterOptionChanged(translatedChk.getValue(), fuzzyChk.getValue(), untranslatedChk.getValue(), approvedChk.getValue(), rejectedChk.getValue(), hasErrorChk.getValue());
updateStateCheckboxGroups();
listener.messageFilterOptionChanged(translatedChk.getValue(), fuzzyChk.getValue(),
untranslatedChk.getValue(), approvedChk.getValue(), rejectedChk.getValue(), hasErrorChk.getValue());
}
public void toggleCompleteChk()

private void updateStateCheckboxGroups()
{
if(translatedChk.getValue() == approvedChk.getValue())
{
if(approvedChk.getValue() == true)
{
completeChk.setValue(true);
}
else
{
completeChk.setValue(false);
}
}
else
{
//Should be indeterminate states if all checkboxes has different states, but GWT checkbox doesn't support it
completeChk.setValue(false);
}
// TODO show intermediate state if some but not all are checked
incompleteChk.setValue(allChecked(untranslatedChk, fuzzyChk, rejectedChk));
completeChk.setValue(allChecked(translatedChk, approvedChk));
}
public void toggleIncompleteChk()

private static boolean allChecked(CheckBox... toggles)
{
if(untranslatedChk.getValue() == fuzzyChk.getValue() && fuzzyChk.getValue() == rejectedChk.getValue() && rejectedChk.getValue())
for (HasValue<Boolean> toggle : toggles)
{
if(rejectedChk.getValue() == true)
{
incompleteChk.setValue(true);
}
else
if (!toggle.getValue())
{
incompleteChk.setValue(false);
return false;
}
}
else
{
//Should be indeterminate states if all checkboxes has different states
incompleteChk.setValue(false);
}
return true;
}

@UiHandler("incompleteChk")
public void onIncompleteChkChanged(ValueChangeEvent<Boolean> event)
{
Expand Down

0 comments on commit f71b384

Please sign in to comment.