Example usage for com.google.gwt.user.client.ui CheckBox addValueChangeHandler

List of usage examples for com.google.gwt.user.client.ui CheckBox addValueChangeHandler

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui CheckBox addValueChangeHandler.

Prototype

@Override
    public HandlerRegistration addValueChangeHandler(ValueChangeHandler<Boolean> handler) 

Source Link

Usage

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.ui.ChooseEncodingDialog.java

License:Open Source License

@Override
protected Widget createMainWidget() {
    listBox_ = new ListBox();
    listBox_.setMultipleSelect(true);//from w w w . j  a v a  2 s  .co  m
    listBox_.setVisibleItemCount(15);
    listBox_.setWidth("350px");

    setEncodings(commonEncodings_, currentEncoding_);

    CheckBox showAll = new CheckBox("Show all encodings");
    showAll.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        public void onValueChange(ValueChangeEvent<Boolean> e) {
            if (e.getValue())
                setEncodings(allEncodings_, currentEncoding_);
            else
                setEncodings(commonEncodings_, currentEncoding_);
        }
    });
    setCheckBoxMargins(showAll, 8, 12);

    VerticalPanel panel = new VerticalPanel();
    panel.add(listBox_);
    panel.add(showAll);

    if (includeSaveAsDefault_) {
        saveAsDefault_ = new CheckBox("Set as default encoding for " + "source files");
        setCheckBoxMargins(showAll, 8, 0);
        setCheckBoxMargins(saveAsDefault_, 3, 12);
        panel.add(saveAsDefault_);
    }

    return panel;
}

From source file:org.thechiselgroup.biomixer.client.BioMixerViewWindowContentProducer.java

License:Apache License

private VerticalPanel createArcTypeContainerControl(String label, final ArcItemContainer arcItemContainer) {

    final TextBox arcColorText = new TextBox();
    arcColorText.setText(arcItemContainer.getArcColor());

    final ListBox arcStyleDropDown = new ListBox();
    arcStyleDropDown.setVisibleItemCount(1);
    arcStyleDropDown.addItem(ArcSettings.ARC_STYLE_SOLID);
    arcStyleDropDown.addItem(ArcSettings.ARC_STYLE_DASHED);
    arcStyleDropDown.addItem(ArcSettings.ARC_STYLE_DOTTED);
    String arcStyle = arcItemContainer.getArcStyle();
    if (ArcSettings.ARC_STYLE_DOTTED.equals(arcStyle)) {
        arcStyleDropDown.setSelectedIndex(2);
    } else if (ArcSettings.ARC_STYLE_DASHED.equals(arcStyle)) {
        arcStyleDropDown.setSelectedIndex(1);
    } else {/* www . j  a v  a2  s . c  o m*/
        arcStyleDropDown.setSelectedIndex(0);
    }

    final ListBox arcHeadDropDown = new ListBox();
    arcHeadDropDown.setVisibleItemCount(1);
    arcHeadDropDown.addItem(ArcSettings.ARC_HEAD_NONE);
    arcHeadDropDown.addItem(ArcSettings.ARC_HEAD_TRIANGLE_EMPTY);
    arcHeadDropDown.addItem(ArcSettings.ARC_HEAD_TRIANGLE_FULL);
    String arcHead = arcItemContainer.getArcHead();
    if (ArcSettings.ARC_HEAD_TRIANGLE_FULL.equals(arcHead)) {
        arcHeadDropDown.setSelectedIndex(2);
    } else if (ArcSettings.ARC_HEAD_TRIANGLE_EMPTY.equals(arcHead)) {
        arcHeadDropDown.setSelectedIndex(1);
    } else if (ArcSettings.ARC_HEAD_NONE.equals(arcHead)) {
        arcHeadDropDown.setSelectedIndex(0);
    }

    final String defaultEntry = "Default";
    final ListBox arcThicknessDropDown = new ListBox();
    arcThicknessDropDown.setVisibleItemCount(1);
    arcThicknessDropDown.addItem(defaultEntry);
    arcThicknessDropDown.addItem("1");
    arcThicknessDropDown.addItem("2");
    arcThicknessDropDown.addItem("3");
    arcThicknessDropDown.addItem("4");
    arcThicknessDropDown.addItem("5");
    arcThicknessDropDown.setSelectedIndex(0);

    final Button updateButton = new Button("Update Arcs");
    updateButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            arcItemContainer.setArcColor(arcColorText.getText());
            arcItemContainer.setArcStyle(arcStyleDropDown.getItemText(arcStyleDropDown.getSelectedIndex()));

            String selectedThicknessText = arcThicknessDropDown
                    .getItemText(arcThicknessDropDown.getSelectedIndex());
            if (selectedThicknessText.equals(defaultEntry)) {
                arcItemContainer.setArcThicknessLevel(0);
            } else {
                arcItemContainer.setArcThicknessLevel(Integer.parseInt(selectedThicknessText));
            }

            arcItemContainer.setArcHead(arcHeadDropDown.getItemText(arcHeadDropDown.getSelectedIndex()));

        }
    });

    final CheckBox visibleCheckBox = new CheckBox("Arcs Visible");
    visibleCheckBox.setValue(true);
    visibleCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            boolean value = visibleCheckBox.getValue();
            updateButton.setEnabled(value);
            arcStyleDropDown.setEnabled(value);
            arcHeadDropDown.setEnabled(value);
            arcThicknessDropDown.setEnabled(value);
            arcColorText.setEnabled(value);
            arcItemContainer.setVisible(value);
        }

    });

    VerticalPanel containerPanel = new VerticalPanel();

    containerPanel.add(new Label(label));
    containerPanel.add(visibleCheckBox);
    containerPanel.add(new Label("Arc Color"));
    containerPanel.add(arcColorText);
    containerPanel.add(new Label("Arc Style"));
    containerPanel.add(arcStyleDropDown);
    containerPanel.add(new Label("Arc Head"));
    containerPanel.add(arcHeadDropDown);
    containerPanel.add(new Label("Arc Thickness"));
    containerPanel.add(arcThicknessDropDown);
    containerPanel.add(updateButton);

    // Handler runs and removes itself internally.
    @SuppressWarnings("unused")
    Handler handler = new Handler() {
        private HandlerRegistration register = arcColorText.addAttachHandler(this);

        @Override
        public void onAttachOrDetach(AttachEvent event) {
            $(arcColorText).as(Enhance).colorBox(ColorPickerType.SIMPLE);
            // Only want this run once, so let's do a trick to remove it.
            register.removeHandler();
        }
    };

    return containerPanel;
}

From source file:org.thechiselgroup.biomixer.client.BioMixerViewWindowContentProducer.java

License:Apache License

private SidePanelSection createOntologyGraphNodesSidePanelSection(final ResourceModel resourceModel,
        final VisualizationModel visualizationModel) {

    final VerticalPanel panel = new VerticalPanel();

    final Map<String, CheckBox> ontologyToFilterBox = CollectionFactory.createStringMap();

    final CheckBox colorByOntologyCheckBox = new CheckBox("Color Nodes by Ontology");
    colorByOntologyCheckBox.setValue(true);
    colorByOntologyCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override//from   ww w .  j  a v a 2s. c om
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            boolean value = colorByOntologyCheckBox.getValue();

            VisualItemValueResolver resolver;
            if (value) {
                resolver = NODE_COLOR_BY_ONTOLOGY_RESOLVER_FACTORY.create();
            } else {
                resolver = NODE_BACKGROUND_COLOR_RESOLVER_FACTORY.create();
            }

            visualizationModel.setResolver(Graph.NODE_BACKGROUND_COLOR, resolver);
        }
    });

    resourceModel.getResources().addEventHandler(new ResourceSetChangedEventHandler() {
        @Override
        public void onResourceSetChanged(ResourceSetChangedEvent event) {
            LightweightCollection<Resource> addedResources = event.getAddedResources();
            for (Resource resource : addedResources) {
                if (Ontology.isOntology(resource)) {
                    String ontologyAcronym = (String) resource.getValue(Ontology.ONTOLOGY_ACRONYM);
                    if (!ontologyToFilterBox.containsKey(ontologyAcronym)) {

                        CheckBox checkBox = new CheckBox("<span style='color: "
                                + BioMixerConceptByOntologyColorResolver.getColor(ontologyAcronym)
                                + "'>&#9609;</span>" + "&nbsp;" + "Show "
                                + resource.getValue(Ontology.ONTOLOGY_ACRONYM), true);
                        checkBox.setValue(true);
                        ontologyToFilterBox.put(ontologyAcronym, checkBox);
                        panel.add(checkBox);
                        checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
                            @Override
                            public void onValueChange(ValueChangeEvent<Boolean> event) {
                                updatePredicate(resourceModel, false, ontologyToFilterBox);
                            }
                        });
                    }
                }
            }
        }
    });

    panel.add(colorByOntologyCheckBox);

    updatePredicate(resourceModel, false, ontologyToFilterBox);

    return new SidePanelSection("Nodes", panel);
}

From source file:org.thechiselgroup.biomixer.client.BioMixerViewWindowContentProducer.java

License:Apache License

private SidePanelSection createConceptGraphNodesSidePanelSection(final ResourceModel resourceModel,
        final VisualizationModel visualizationModel) {

    final VerticalPanel panel = new VerticalPanel();

    final Map<String, CheckBox> ontologyToFilterBox = CollectionFactory.createStringMap();

    // code below removes the "Show Mapping Nodes" checkbox under the
    // "Nodes" view part in the vertical panel
    // final CheckBox mappingNodesCheckbox = new
    // CheckBox("Show Mapping Nodes");
    // mappingNodesCheckbox.setValue(false);
    // mappingNodesCheckbox
    // .addValueChangeHandler(new ValueChangeHandler<Boolean>() {
    // @Override//from  w w  w.j a v  a  2s . c  o m
    // public void onValueChange(ValueChangeEvent<Boolean> event) {
    // updatePredicate(resourceModel,
    // mappingNodesCheckbox.getValue(),
    // ontologyToFilterBox);
    // }
    // });

    final CheckBox colorByOntologyCheckBox = new CheckBox("Color Concept Nodes by Ontology");
    colorByOntologyCheckBox.setValue(true);
    colorByOntologyCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            boolean value = colorByOntologyCheckBox.getValue();

            VisualItemValueResolver resolver;
            if (value) {
                resolver = NODE_COLOR_BY_ONTOLOGY_RESOLVER_FACTORY.create();
            } else {
                resolver = NODE_BACKGROUND_COLOR_RESOLVER_FACTORY.create();
            }

            visualizationModel.setResolver(Graph.NODE_BACKGROUND_COLOR, resolver);
        }
    });

    resourceModel.getResources().addEventHandler(new ResourceSetChangedEventHandler() {
        @Override
        public void onResourceSetChanged(ResourceSetChangedEvent event) {
            LightweightCollection<Resource> addedResources = event.getAddedResources();
            for (Resource resource : addedResources) {
                if (Concept.isConcept(resource)) {
                    String ontologyAcronym = (String) resource.getValue(Concept.ONTOLOGY_ACRONYM);
                    if (!ontologyToFilterBox.containsKey(ontologyAcronym)) {

                        CheckBox checkBox = new CheckBox("<span style='color: "
                                + BioMixerConceptByOntologyColorResolver.getColor(ontologyAcronym)
                                + "'>&#9609;</span>" + "&nbsp;" + "Show "
                                + resource.getValue(Concept.ONTOLOGY_ACRONYM), true);
                        checkBox.setValue(true);
                        ontologyToFilterBox.put(ontologyAcronym, checkBox);
                        panel.add(checkBox);
                        checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
                            @Override
                            public void onValueChange(ValueChangeEvent<Boolean> event) {
                                updatePredicate(resourceModel, false, ontologyToFilterBox);

                                // the code below updates the
                                // "Show Mapping Nodes" checkbox
                                // under "Nodes" view part in the
                                // vertical panel
                                // updatePredicate(resourceModel,
                                // mappingNodesCheckbox
                                // .getValue(),
                                // ontologyToFilterBox);
                            }
                        });
                    }
                }
            }
        }
    });

    // next line commented out so the "Show Mapping Nodes" checkbox is not
    // added to the "Nodes" view part in the vertical panel
    // panel.add(mappingNodesCheckbox);
    panel.add(colorByOntologyCheckBox);

    updatePredicate(resourceModel, false, ontologyToFilterBox);

    return new SidePanelSection("Nodes", panel);
}

From source file:org.thechiselgroup.biomixer.client.visualization_component.text.TextVisualization.java

License:Apache License

@Override
public SidePanelSection[] getSidePanelSections() {
    FlowPanel settingsPanel = new FlowPanel();

    final CheckBox oneItemPerRowBox = new CheckBox("One item per row");
    oneItemPerRowBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override//  w w  w .  ja  va 2 s.c om
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            setTagCloud(!oneItemPerRowBox.getValue());
        }

    });
    settingsPanel.add(oneItemPerRowBox);
    oneItemPerRowBox.setValue(!tagCloud);

    return new SidePanelSection[] { new SidePanelSection("Settings", settingsPanel), };
}

From source file:org.thechiselgroup.choosel.visualization_component.chart.client.barchart.BarChart.java

License:Apache License

@Override
public SidePanelSection[] getSidePanelSections() {
    FlowPanel settingsPanel = new FlowPanel();

    {//from w  ww . j a  va2 s  .  c om
        settingsPanel.add(new Label("Chart orientation"));
        final ListBox layoutBox = new ListBox(false);
        layoutBox.setVisibleItemCount(1);
        for (LayoutType layout : LayoutType.values()) {
            layoutBox.addItem(layout.getName(), layout.toString());
        }
        layoutBox.setSelectedIndex(1);
        layoutBox.addChangeHandler(new ChangeHandler() {
            @Override
            public void onChange(ChangeEvent event) {
                setLayout(LayoutType.valueOf(layoutBox.getValue(layoutBox.getSelectedIndex())));
            }
        });
        settingsPanel.add(layoutBox);
    }
    {
        settingsPanel.add(new Label("Bar spacing"));

        CheckBox checkBox = new CheckBox();
        checkBox.setText("separate");
        checkBox.setValue(barSpacing);
        checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
            @Override
            public void onValueChange(ValueChangeEvent<Boolean> event) {
                setBarSpacing(event.getValue());
            }
        });
        settingsPanel.add(checkBox);
    }
    {
        settingsPanel.add(new Label("Value labels"));

        CheckBox checkBox = new CheckBox();
        checkBox.setText("visible");
        checkBox.setValue(valueLabelVisibility);
        checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
            @Override
            public void onValueChange(ValueChangeEvent<Boolean> event) {
                setValueLabelVisibility(event.getValue());
            }
        });
        settingsPanel.add(checkBox);
    }
    {
        settingsPanel.add(new Label("Partial bar width"));

        CheckBox checkBox = new CheckBox();
        checkBox.setText("thinner");
        checkBox.setValue(partialBarThinner);
        checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
            @Override
            public void onValueChange(ValueChangeEvent<Boolean> event) {
                setThinPartialBars(event.getValue());
            }
        });
        settingsPanel.add(checkBox);
    }
    return new SidePanelSection[] { new SidePanelSection("Settings", settingsPanel), };
}

From source file:org.unitime.timetable.gwt.client.admin.ScriptPage.java

License:Apache License

private void scriptChanged() {
    ScriptInterface script = getScript();
    if (script == null) {
        iForm.getRowFormatter().setVisible(iDescriptionRow, false);
        while (iForm.getRowCount() > iDescriptionRow + 2)
            iForm.removeRow(1 + iDescriptionRow);
        iHeader.setEnabled("edit", false);
        iHeader.setEnabled("execute", false);
        iParams.clear();// ww w.  ja  v  a2 s .c  o  m
    } else {
        iDescription.setHTML(script.getDescription());
        iForm.getRowFormatter().setVisible(iDescriptionRow, true);
        iHeader.setEnabled("edit", script.canEdit());
        iHeader.setEnabled("execute", script.canExecute());
        iParams.clear();
        while (iForm.getRowCount() > iDescriptionRow + 2)
            iForm.removeRow(1 + iDescriptionRow);
        if (script.hasParameters()) {
            for (final ScriptParameterInterface param : script.getParameters()) {
                Widget widget = null;
                if (param.hasOptions()) {
                    final ListBox list = new ListBox();
                    list.setMultipleSelect(param.isMultiSelect());
                    if (!param.isMultiSelect())
                        list.addItem(MESSAGES.itemSelect());
                    for (ScriptInterface.ListItem item : param.getOptions()) {
                        list.addItem(item.getText(), item.getValue());
                        if (param.getDefaultValue() != null
                                && param.getDefaultValue().equalsIgnoreCase(item.getValue()))
                            list.setSelectedIndex(list.getItemCount() - 1);
                    }
                    list.addChangeHandler(new ChangeHandler() {
                        @Override
                        public void onChange(ChangeEvent event) {
                            if (param.isMultiSelect()) {
                                String value = "";
                                for (int i = 0; i < list.getItemCount(); i++)
                                    if (list.isItemSelected(i))
                                        value += (value.isEmpty() ? "" : ",") + list.getValue(i);
                                iParams.put(param.getName(), value);
                            } else {
                                if (list.getSelectedIndex() <= 0)
                                    iParams.remove(param.getName());
                                else
                                    iParams.put(param.getName(), list.getValue(list.getSelectedIndex()));
                            }
                        }
                    });
                    widget = list;
                } else if ("boolean".equalsIgnoreCase(param.getType())) {
                    CheckBox ch = new CheckBox();
                    ch.setValue("true".equalsIgnoreCase(param.getDefaultValue()));
                    ch.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> event) {
                            if (event.getValue() == null)
                                iParams.remove(param.getName());
                            else
                                iParams.put(param.getName(), event.getValue() ? "true" : "false");
                        }
                    });
                    widget = ch;
                } else if ("file".equalsIgnoreCase(param.getType())) {
                    UniTimeFileUpload upload = new UniTimeFileUpload();
                    upload.reset();
                    widget = upload;
                } else if ("textarea".equalsIgnoreCase(param.getType())) {
                    TextArea textarea = new TextArea();
                    textarea.setStyleName("unitime-TextArea");
                    textarea.setVisibleLines(5);
                    textarea.setCharacterWidth(80);
                    if (param.getDefaultValue() != null)
                        textarea.setText(param.getDefaultValue());
                    textarea.addValueChangeHandler(new ValueChangeHandler<String>() {
                        @Override
                        public void onValueChange(ValueChangeEvent<String> event) {
                            if (event.getValue() == null)
                                iParams.remove(param.getName());
                            else
                                iParams.put(param.getName(), event.getValue());
                        }
                    });
                    widget = textarea;
                } else {
                    TextBox text = new TextBox();
                    text.setStyleName("unitime-TextBox");
                    text.setWidth("400px");
                    if (param.getDefaultValue() != null)
                        text.setText(param.getDefaultValue());
                    text.addValueChangeHandler(new ValueChangeHandler<String>() {
                        @Override
                        public void onValueChange(ValueChangeEvent<String> event) {
                            if (event.getValue() == null)
                                iParams.remove(param.getName());
                            else
                                iParams.put(param.getName(), event.getValue());
                        }
                    });
                    widget = text;
                }
                int row = iForm.insertRow(iForm.getRowCount() - 1);
                iForm.setWidget(row, 0,
                        new Label((param.getLabel() == null || param.getLabel().isEmpty() ? param.getName()
                                : param.getLabel()) + ":", false));
                iForm.setWidget(row, 1, widget);
            }
        }
    }
}

From source file:org.unitime.timetable.gwt.client.admin.TaskEditor.java

License:Apache License

private void scriptChanged(boolean clear) {
    ScriptInterface script = getScript();
    if (script == null) {
        iForm.getRowFormatter().setVisible(iDescriptionRow, false);
        while (iForm.getRowCount() > iDescriptionRow + 2)
            iForm.removeRow(1 + iDescriptionRow);
        iBottom.setEnabled("save", false);
        iTask.clearParameters();/*from   w ww .  ja  va2  s. com*/
    } else {
        iDescription.setHTML(script.getDescription());
        iForm.getRowFormatter().setVisible(iDescriptionRow,
                script.getDescription() != null && !script.getDescription().isEmpty());
        iBottom.setEnabled("save", script.canExecute());
        if (clear)
            iTask.clearParameters();
        while (iForm.getRowCount() > iDescriptionRow + 2)
            iForm.removeRow(1 + iDescriptionRow);
        if (script.hasParameters()) {
            for (final ScriptParameterInterface param : script.getParameters()) {
                if (param.getValue() != null)
                    iTask.setParameter(param.getName(), param.getValue());
                String defaultValue = iTask.getParameter(param.getName());
                if (defaultValue == null)
                    defaultValue = param.getValue();
                if (defaultValue == null)
                    defaultValue = param.getDefaultValue();
                Widget widget = null;
                if (param.hasOptions()) {
                    final ListBox list = new ListBox();
                    list.setMultipleSelect(param.isMultiSelect());
                    if (!param.isMultiSelect())
                        list.addItem(MESSAGES.itemSelect());
                    for (ScriptInterface.ListItem item : param.getOptions()) {
                        list.addItem(item.getText(), item.getValue());
                        if (defaultValue != null) {
                            if (param.isMultiSelect()) {
                                for (String id : defaultValue.split(","))
                                    if (!id.isEmpty() && (id.equalsIgnoreCase(item.getValue())
                                            || id.equalsIgnoreCase(item.getText())
                                            || item.getText().startsWith(id + " - "))) {
                                        list.setItemSelected(list.getItemCount() - 1, true);
                                        break;
                                    }
                            } else if (defaultValue.equalsIgnoreCase(item.getValue())
                                    || defaultValue.equalsIgnoreCase(item.getText())
                                    || item.getText().startsWith(defaultValue + " - "))
                                list.setSelectedIndex(list.getItemCount() - 1);
                        }
                    }
                    list.addChangeHandler(new ChangeHandler() {
                        @Override
                        public void onChange(ChangeEvent event) {
                            if (param.isMultiSelect()) {
                                String value = "";
                                for (int i = 0; i < list.getItemCount(); i++)
                                    if (list.isItemSelected(i))
                                        value += (value.isEmpty() ? "" : ",") + list.getValue(i);
                                iTask.setParameter(param.getName(), value);
                            } else {
                                iTask.setParameter(param.getName(), list.getValue(list.getSelectedIndex()));
                            }
                        }
                    });
                    widget = list;
                } else if ("boolean".equalsIgnoreCase(param.getType())) {
                    CheckBox ch = new CheckBox();
                    ch.setValue("true".equalsIgnoreCase(defaultValue));
                    ch.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
                        @Override
                        public void onValueChange(ValueChangeEvent<Boolean> event) {
                            iTask.setParameter(param.getName(), event.getValue() ? "true" : "false");
                        }
                    });
                    widget = ch;
                } else if ("file".equalsIgnoreCase(param.getType())) {
                    UniTimeFileUpload upload = new UniTimeFileUpload();
                    upload.reset();
                    widget = upload;
                } else if ("textarea".equalsIgnoreCase(param.getType())) {
                    TextArea textarea = new TextArea();
                    textarea.setStyleName("unitime-TextArea");
                    textarea.setVisibleLines(5);
                    textarea.setCharacterWidth(80);
                    if (defaultValue != null)
                        textarea.setText(defaultValue);
                    textarea.addValueChangeHandler(new ValueChangeHandler<String>() {
                        @Override
                        public void onValueChange(ValueChangeEvent<String> event) {
                            iTask.setParameter(param.getName(), event.getValue());
                        }
                    });
                    widget = textarea;
                } else if ("integer".equalsIgnoreCase(param.getType())
                        || "int".equalsIgnoreCase(param.getType()) || "long".equalsIgnoreCase(param.getType())
                        || "short".equalsIgnoreCase(param.getType())
                        || "byte".equalsIgnoreCase(param.getType())) {
                    NumberBox text = new NumberBox();
                    text.setDecimal(false);
                    text.setNegative(true);
                    if (defaultValue != null)
                        text.setText(defaultValue);
                    text.addValueChangeHandler(new ValueChangeHandler<String>() {
                        @Override
                        public void onValueChange(ValueChangeEvent<String> event) {
                            iTask.setParameter(param.getName(), event.getValue());
                        }
                    });
                    widget = text;
                } else if ("number".equalsIgnoreCase(param.getType())
                        || "float".equalsIgnoreCase(param.getType())
                        || "double".equalsIgnoreCase(param.getType())) {
                    NumberBox text = new NumberBox();
                    text.setDecimal(true);
                    text.setNegative(true);
                    if (defaultValue != null)
                        text.setText(defaultValue);
                    text.addValueChangeHandler(new ValueChangeHandler<String>() {
                        @Override
                        public void onValueChange(ValueChangeEvent<String> event) {
                            iTask.setParameter(param.getName(), event.getValue());
                        }
                    });
                    widget = text;
                } else if ("date".equalsIgnoreCase(param.getType())) {
                    SingleDateSelector text = new SingleDateSelector();
                    if (defaultValue != null)
                        text.setText(defaultValue);
                    final DateTimeFormat format = DateTimeFormat.getFormat(CONSTANTS.eventDateFormat());
                    text.addValueChangeHandler(new ValueChangeHandler<Date>() {
                        @Override
                        public void onValueChange(ValueChangeEvent<Date> event) {
                            iTask.setParameter(param.getName(), format.format(event.getValue()));
                        }
                    });
                    widget = text;
                } else if ("slot".equalsIgnoreCase(param.getType())
                        || "time".equalsIgnoreCase(param.getType())) {
                    TimeSelector text = new TimeSelector();
                    if (defaultValue != null)
                        text.setText(defaultValue);
                    text.addValueChangeHandler(new ValueChangeHandler<Integer>() {
                        @Override
                        public void onValueChange(ValueChangeEvent<Integer> event) {
                            iTask.setParameter(param.getName(), event.getValue().toString());
                        }
                    });
                    widget = text;
                } else if ("datetime".equalsIgnoreCase(param.getType())
                        || "timestamp".equalsIgnoreCase(param.getType())) {
                    DateTimeBox text = new DateTimeBox();
                    if (defaultValue != null)
                        text.setText(defaultValue);
                    text.addValueChangeHandler(new ValueChangeHandler<String>() {
                        @Override
                        public void onValueChange(ValueChangeEvent<String> event) {
                            iTask.setParameter(param.getName(), event.getValue());
                        }
                    });
                    widget = text;
                } else {
                    TextBox text = new TextBox();
                    text.setStyleName("unitime-TextBox");
                    text.setWidth("400px");
                    if (defaultValue != null)
                        text.setText(defaultValue);
                    text.addValueChangeHandler(new ValueChangeHandler<String>() {
                        @Override
                        public void onValueChange(ValueChangeEvent<String> event) {
                            iTask.setParameter(param.getName(), event.getValue());
                        }
                    });
                    widget = text;
                }
                int row = iForm.insertRow(iForm.getRowCount() - 1);
                iForm.setWidget(row, 0,
                        new Label((param.getLabel() == null || param.getLabel().isEmpty() ? param.getName()
                                : param.getLabel()) + ":", false));
                iForm.setWidget(row, 1, widget);
            }
        }
    }
    if (isShowing())
        center();
}

From source file:org.unitime.timetable.gwt.client.curricula.CurriculaTable.java

License:Apache License

private void fillRow(CurriculumInterface c) {
    int row = iTable.getRowCount();
    List<Widget> line = new ArrayList<Widget>();
    if (c.isEditable()) {
        CheckBox ch = new CheckBox();
        final Long cid = c.getId();
        ch.setValue(iSelectedCurricula.contains(cid));
        ch.addClickHandler(new ClickHandler() {
            @Override//  ww w  .  j  a v a 2s  .  c om
            public void onClick(ClickEvent event) {
                event.stopPropagation();
            }
        });
        ch.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
            @Override
            public void onValueChange(ValueChangeEvent<Boolean> event) {
                if (event.getValue())
                    iSelectedCurricula.add(cid);
                else
                    iSelectedCurricula.remove(cid);
            }
        });
        line.add(ch);
    } else {
        line.add(new Label(""));
    }
    DisplayMode m = CurriculumCookie.getInstance().getCurriculaDisplayMode();
    line.add(new Label(m.isCurriculumAbbv() ? c.getAbbv() : c.getName(), false));
    line.add(new Label(m.isAreaAbbv() ? c.getAcademicArea().getAbbv() : c.getAcademicArea().getName(), false));
    line.add(new HTML(m.isMajorAbbv() ? c.getMajorCodes(", ") : c.getMajorNames("<br>"), m.isMajorAbbv()));
    line.add(new Label(m.formatDepartment(c.getDepartment()), false));
    line.add(new Label(c.getLastLike() == null ? "" : c.getLastLikeString(), false));
    line.add(new Label(c.getProjection() == null ? "" : c.getProjectionString(), false));
    line.add(new Label(c.getExpected() == null ? "" : c.getExpectedString(), false));
    line.add(new Label(c.getEnrollment() == null ? "" : c.getEnrollmentString(), false));
    line.add(new Label(c.getRequested() == null ? "" : c.getRequestedString(), false));
    iTable.setRow(row, c, line);
    iTable.getCellFormatter().addStyleName(row, 0, "unitime-NoPrint");
    iTable.getFlexCellFormatter().setHorizontalAlignment(row, 5, HasHorizontalAlignment.ALIGN_RIGHT);
    iTable.getFlexCellFormatter().setHorizontalAlignment(row, 6, HasHorizontalAlignment.ALIGN_RIGHT);
    iTable.getFlexCellFormatter().setHorizontalAlignment(row, 7, HasHorizontalAlignment.ALIGN_RIGHT);
    iTable.getFlexCellFormatter().setHorizontalAlignment(row, 8, HasHorizontalAlignment.ALIGN_RIGHT);
    iTable.getFlexCellFormatter().setHorizontalAlignment(row, 9, HasHorizontalAlignment.ALIGN_RIGHT);
}

From source file:org.unitime.timetable.gwt.client.events.EventFilterBox.java

License:Apache License

public EventFilterBox(AcademicSessionProvider session) {
    super(session);

    addFilter(new FilterBox.StaticSimpleFilter("type", MESSAGES.tagEventType()) {
        @Override/*from w w w.ja  va 2 s . c  o m*/
        public void validate(String text, AsyncCallback<Chip> callback) {
            String translatedValue = null;
            if ("class".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventTypeShort()[0];
            else if ("final exam".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventTypeShort()[1];
            else if ("midterm exam".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventTypeShort()[2];
            else if ("course".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventTypeShort()[3];
            else if ("special".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventTypeShort()[4];
            else if ("not available".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventTypeShort()[5];
            callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel())
                    .withTranslatedValue(translatedValue));
        }
    });

    iSponsors = new ListBox();
    iSponsors.setMultipleSelect(true);
    iSponsors.setWidth("100%");
    iSponsors.setVisibleItemCount(3);

    addFilter(new FilterBox.CustomFilter("sponsor", MESSAGES.tagSponsor(), iSponsors) {
        @Override
        public void getSuggestions(List<Chip> chips, String text,
                AsyncCallback<Collection<Suggestion>> callback) {
            if (text.isEmpty()) {
                callback.onSuccess(null);
            } else {
                List<Suggestion> suggestions = new ArrayList<Suggestion>();
                for (int i = 0; i < iSponsors.getItemCount(); i++) {
                    Chip chip = new Chip("sponsor", iSponsors.getValue(i))
                            .withTranslatedCommand(MESSAGES.tagSponsor());
                    String name = iSponsors.getItemText(i);
                    if (iSponsors.getValue(i).toLowerCase().startsWith(text.toLowerCase())) {
                        suggestions.add(new Suggestion(name, chip));
                    } else if (text.length() > 2 && name.toLowerCase().contains(" " + text.toLowerCase())) {
                        suggestions.add(new Suggestion(name, chip));
                    }
                }
                callback.onSuccess(suggestions);
            }
        }

        @Override
        public boolean isVisible() {
            return iSponsors.getItemCount() > 0;
        }
    });
    iSponsors.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            boolean changed = false;
            for (int i = 0; i < iSponsors.getItemCount(); i++) {
                Chip chip = new Chip("sponsor", iSponsors.getValue(i))
                        .withTranslatedCommand(MESSAGES.tagSponsor());
                if (iSponsors.isItemSelected(i)) {
                    if (!hasChip(chip)) {
                        addChip(chip, false);
                        changed = true;
                    }
                } else {
                    if (hasChip(chip)) {
                        removeChip(chip, false);
                        changed = true;
                    }
                }
            }
            if (changed)
                fireValueChangeEvent();
        }
    });

    FilterBox.StaticSimpleFilter mode = new FilterBox.StaticSimpleFilter("mode", MESSAGES.tagEventMode()) {
        @Override
        public void validate(String text, AsyncCallback<Chip> callback) {
            String translatedValue = null;
            if ("all".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventModeAbbv()[0];
            else if ("my".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventModeAbbv()[1];
            else if ("approved".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventModeAbbv()[2];
            else if ("unapproved".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventModeAbbv()[3];
            else if ("awaiting".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventModeAbbv()[4];
            else if ("conflicting".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventModeAbbv()[5];
            else if ("my awaiting".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventModeAbbv()[6];
            else if ("cancelled".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventModeAbbv()[7];
            else if ("expiring".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventModeAbbv()[8];
            callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel())
                    .withTranslatedValue(translatedValue));
        }
    };
    mode.setMultipleSelection(false);
    addFilter(mode);

    addFilter(new FilterBox.StaticSimpleFilter("role", MESSAGES.tagEventRole()) {
        @Override
        public void getPopupWidget(final FilterBox box, final AsyncCallback<Widget> callback) {
            callback.onSuccess(null);
        }

        @Override
        public void validate(String text, AsyncCallback<Chip> callback) {
            String translatedValue = null;
            if ("all".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventRole()[0];
            else if ("student".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventRole()[1];
            else if ("instructor".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventRole()[2];
            else if ("coordinator".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventRole()[3];
            else if ("contact".equalsIgnoreCase(text))
                translatedValue = CONSTANTS.eventRole()[4];
            callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel())
                    .withTranslatedValue(translatedValue));
        }
    });

    Label reqLab = new Label(MESSAGES.propRequestedBy());

    iRequested = new AriaSuggestBox(new RequestedByOracle());
    iRequested.setStyleName("unitime-TextArea");
    iRequested.setWidth("200px");

    final CheckBox conflicts = new CheckBox(MESSAGES.checkDisplayConflicts());
    conflicts.getElement().getStyle().setMarginLeft(10, Unit.PX);

    final CheckBox sessions = new CheckBox(MESSAGES.checkSpanMultipleSessions());
    sessions.getElement().getStyle().setMarginLeft(10, Unit.PX);

    iOther = new FilterBox.CustomFilter("other", MESSAGES.tagOther(), reqLab, iRequested, conflicts, sessions) {
        @Override
        public void getSuggestions(final List<Chip> chips, final String text,
                AsyncCallback<Collection<FilterBox.Suggestion>> callback) {
            if (text.isEmpty()) {
                callback.onSuccess(null);
            } else {
                List<FilterBox.Suggestion> suggestions = new ArrayList<FilterBox.Suggestion>();
                if ("conflicts".startsWith(text.toLowerCase())
                        || MESSAGES.checkDisplayConflicts().toLowerCase().startsWith(text.toLowerCase())) {
                    suggestions.add(new Suggestion(MESSAGES.checkDisplayConflicts(),
                            new Chip("flag", "Conflicts").withTranslatedCommand(MESSAGES.tagEventFlag())
                                    .withTranslatedValue(MESSAGES.attrFlagShowConflicts())));
                }
                if ("sessinons".startsWith(text.toLowerCase())
                        || MESSAGES.checkSpanMultipleSessions().toLowerCase().startsWith(text.toLowerCase())) {
                    suggestions.add(new Suggestion(MESSAGES.checkSpanMultipleSessions(),
                            new Chip("flag", "All Sessions").withTranslatedCommand(MESSAGES.tagEventFlag())
                                    .withTranslatedValue(MESSAGES.attrFlagAllSessions())));
                }
                callback.onSuccess(suggestions);
            }
        }
    };
    addFilter(iOther);

    addFilter(new FilterBox.StaticSimpleFilter("requested", MESSAGES.tagRequested()));
    addFilter(new FilterBox.StaticSimpleFilter("flag", MESSAGES.tagEventFlag()) {
        @Override
        public void validate(String text, AsyncCallback<Chip> callback) {
            String translatedValue = null;
            if ("conflicts".equalsIgnoreCase(text))
                translatedValue = MESSAGES.attrFlagShowConflicts();
            else if ("all sessions".equalsIgnoreCase(text))
                translatedValue = MESSAGES.attrFlagAllSessions();
            callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel())
                    .withTranslatedValue(translatedValue));
        }
    });

    iRequested.getValueBox().addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            requestedChanged(true);
        }
    });
    iRequested.getValueBox().addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                @Override
                public void execute() {
                    requestedChanged(false);
                }
            });
        }
    });
    iRequested.getValueBox().addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE)
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                    @Override
                    public void execute() {
                        requestedChanged(false);
                    }
                });
        }
    });
    iRequested.getValueBox().addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            requestedChanged(true);
        }
    });
    iRequested.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
        @Override
        public void onSelection(SelectionEvent<com.google.gwt.user.client.ui.SuggestOracle.Suggestion> event) {
            requestedChanged(true);
        }
    });
    conflicts.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            Chip chip = new Chip("flag", "Conflicts").withTranslatedCommand(MESSAGES.tagEventFlag())
                    .withTranslatedValue(MESSAGES.attrFlagShowConflicts());
            if (event.getValue()) {
                if (!hasChip(chip))
                    addChip(chip, true);
            } else {
                if (hasChip(chip))
                    removeChip(chip, true);
            }
        }
    });
    conflicts.addMouseDownHandler(new MouseDownHandler() {
        @Override
        public void onMouseDown(MouseDownEvent event) {
            event.getNativeEvent().stopPropagation();
            event.getNativeEvent().preventDefault();
        }
    });

    sessions.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            Chip chip = new Chip("flag", "All Sessions").withTranslatedCommand(MESSAGES.tagEventFlag())
                    .withTranslatedValue(MESSAGES.attrFlagAllSessions());
            if (event.getValue()) {
                if (!hasChip(chip))
                    addChip(chip, true);
            } else {
                if (hasChip(chip))
                    removeChip(chip, true);
            }
        }
    });
    sessions.addMouseDownHandler(new MouseDownHandler() {
        @Override
        public void onMouseDown(MouseDownEvent event) {
            event.getNativeEvent().stopPropagation();
            event.getNativeEvent().preventDefault();
        }
    });

    AbsolutePanel m = new AbsolutePanel();
    m.setStyleName("unitime-DateSelector");
    final SingleDateSelector.SingleMonth m1 = new SingleDateSelector.SingleMonth(MESSAGES.tagDateFrom());
    m1.setAllowDeselect(true);
    m.add(m1);
    final SingleDateSelector.SingleMonth m2 = new SingleDateSelector.SingleMonth(MESSAGES.tagDateTo());
    m2.setAllowDeselect(true);
    m.add(m2);
    addFilter(new FilterBox.CustomFilter("date", MESSAGES.tagDate(), m) {
        @Override
        public void getSuggestions(List<Chip> chips, String text,
                AsyncCallback<Collection<Suggestion>> callback) {
            List<FilterBox.Suggestion> suggestions = new ArrayList<FilterBox.Suggestion>();
            Chip chFrom = null, chTo = null;
            for (Chip c : chips) {
                if (c.getCommand().equals("from"))
                    chFrom = c;
                if (c.getCommand().equals("to"))
                    chTo = c;
            }
            try {
                Date date = DateTimeFormat.getFormat("MM/dd").parse(text);
                suggestions.add(new FilterBox.Suggestion(
                        new Chip("from", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateFrom())
                                .withTranslatedValue(sLocalDateFormat.format(date)),
                        chFrom));
                suggestions.add(new FilterBox.Suggestion(
                        new Chip("to", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateTo())
                                .withTranslatedValue(sLocalDateFormat.format(date)),
                        chTo));
            } catch (Exception e) {
            }
            try {
                Date date = DateTimeFormat.getFormat("dd.MM").parse(text);
                suggestions.add(new FilterBox.Suggestion(
                        new Chip("from", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateFrom())
                                .withTranslatedValue(sLocalDateFormat.format(date)),
                        chFrom));
                suggestions.add(new FilterBox.Suggestion(
                        new Chip("to", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateTo())
                                .withTranslatedValue(sLocalDateFormat.format(date)),
                        chTo));
            } catch (Exception e) {
            }
            try {
                Date date = DateTimeFormat.getFormat("MM/dd/yy").parse(text);
                suggestions.add(new FilterBox.Suggestion(
                        new Chip("from", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateFrom())
                                .withTranslatedValue(sLocalDateFormat.format(date)),
                        chFrom));
                suggestions.add(new FilterBox.Suggestion(
                        new Chip("to", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateTo())
                                .withTranslatedValue(sLocalDateFormat.format(date)),
                        chTo));
            } catch (Exception e) {
            }
            try {
                Date date = DateTimeFormat.getFormat("dd.MM.yy").parse(text);
                suggestions.add(new FilterBox.Suggestion(
                        new Chip("from", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateFrom())
                                .withTranslatedValue(sLocalDateFormat.format(date)),
                        chFrom));
                suggestions.add(new FilterBox.Suggestion(
                        new Chip("to", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateTo())
                                .withTranslatedValue(sLocalDateFormat.format(date)),
                        chTo));
            } catch (Exception e) {
            }
            try {
                Date date = DateTimeFormat.getFormat("MMM dd").parse(text);
                suggestions.add(new FilterBox.Suggestion(
                        new Chip("from", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateFrom())
                                .withTranslatedValue(sLocalDateFormat.format(date)),
                        chFrom));
                suggestions.add(new FilterBox.Suggestion(
                        new Chip("to", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateTo())
                                .withTranslatedValue(sLocalDateFormat.format(date)),
                        chTo));
            } catch (Exception e) {
            }
            try {
                Date date = DateTimeFormat.getFormat("MMM dd yy").parse(text);
                suggestions.add(new FilterBox.Suggestion(
                        new Chip("from", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateFrom())
                                .withTranslatedValue(sLocalDateFormat.format(date)),
                        chFrom));
                suggestions.add(new FilterBox.Suggestion(
                        new Chip("to", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateTo())
                                .withTranslatedValue(sLocalDateFormat.format(date)),
                        chTo));
            } catch (Exception e) {
            }
            callback.onSuccess(suggestions);
        }
    });
    addFilter(new FilterBox.StaticSimpleFilter("from", MESSAGES.tagDateFrom()) {
        @Override
        public void validate(String value, AsyncCallback<Chip> callback) {
            String translatedValue = null;
            try {
                translatedValue = sLocalDateFormat.format(sDateFormat.parse(value));
            } catch (IllegalArgumentException e) {
            }
            callback.onSuccess(new Chip(getCommand(), value).withTranslatedCommand(getLabel())
                    .withTranslatedValue(translatedValue));
        }
    });
    addFilter(new FilterBox.StaticSimpleFilter("to", MESSAGES.tagDateTo()) {
        @Override
        public void validate(String value, AsyncCallback<Chip> callback) {
            String translatedValue = null;
            try {
                translatedValue = sLocalDateFormat.format(sDateFormat.parse(value));
            } catch (IllegalArgumentException e) {
            }
            callback.onSuccess(new Chip(getCommand(), value).withTranslatedCommand(getLabel())
                    .withTranslatedValue(translatedValue));
        }
    });

    session.addAcademicSessionChangeHandler(new AcademicSessionChangeHandler() {
        @Override
        public void onAcademicSessionChange(AcademicSessionChangeEvent event) {
            if (event.isChanged() && event.getNewAcademicSessionId() != null) {
                RPC.execute(new RequestSessionDetails(event.getNewAcademicSessionId()),
                        new AsyncCallback<GwtRpcResponseList<SessionMonth>>() {

                            @Override
                            public void onFailure(Throwable caught) {
                            }

                            @Override
                            public void onSuccess(GwtRpcResponseList<SessionMonth> result) {
                                m1.setMonths(result);
                                m2.setMonths(result);
                            }
                        });
            }
        }
    });

    m1.addValueChangeHandler(new ValueChangeHandler<Date>() {
        @Override
        public void onValueChange(ValueChangeEvent<Date> event) {
            Chip ch = getChip("from");
            Date value = event.getValue();
            if (value == null) {
                if (ch != null)
                    removeChip(ch, true);
            } else {
                if (ch != null) {
                    if (ch.getValue().equals(sDateFormat.format(value)))
                        return;
                    removeChip(ch, false);
                }
                addChip(new Chip("from", sDateFormat.format(value))
                        .withTranslatedCommand(MESSAGES.tagDateFrom())
                        .withTranslatedValue(sLocalDateFormat.format(value)), true);
            }
        }
    });
    m2.addValueChangeHandler(new ValueChangeHandler<Date>() {
        @Override
        public void onValueChange(ValueChangeEvent<Date> event) {
            Chip ch = getChip("to");
            Date value = event.getValue();
            if (value == null) {
                if (ch != null)
                    removeChip(ch, true);
            } else {
                if (ch != null) {
                    if (ch.getValue().equals(sDateFormat.format(value)))
                        return;
                    removeChip(ch, false);
                }
                addChip(new Chip("to", sDateFormat.format(value)).withTranslatedCommand(MESSAGES.tagDateTo())
                        .withTranslatedValue(sLocalDateFormat.format(value)), true);
            }
        }
    });

    List<Chip> days = new ArrayList<Chip>();
    days.add(new Chip("day", "Monday").withTranslatedCommand(MESSAGES.tagDayOfWeek())
            .withTranslatedValue(CONSTANTS.longDays()[0]));
    days.add(new Chip("day", "Tuesday").withTranslatedCommand(MESSAGES.tagDayOfWeek())
            .withTranslatedValue(CONSTANTS.longDays()[1]));
    days.add(new Chip("day", "Wednesday").withTranslatedCommand(MESSAGES.tagDayOfWeek())
            .withTranslatedValue(CONSTANTS.longDays()[2]));
    days.add(new Chip("day", "Thursday").withTranslatedCommand(MESSAGES.tagDayOfWeek())
            .withTranslatedValue(CONSTANTS.longDays()[3]));
    days.add(new Chip("day", "Friday").withTranslatedCommand(MESSAGES.tagDayOfWeek())
            .withTranslatedValue(CONSTANTS.longDays()[4]));
    days.add(new Chip("day", "Saturday").withTranslatedCommand(MESSAGES.tagDayOfWeek())
            .withTranslatedValue(CONSTANTS.longDays()[5]));
    days.add(new Chip("day", "Sunday").withTranslatedCommand(MESSAGES.tagDayOfWeek())
            .withTranslatedValue(CONSTANTS.longDays()[6]));
    addFilter(new FilterBox.StaticSimpleFilter("day", MESSAGES.tagDayOfWeek(), days));

    final TimeSelector st = new TimeSelector(null);
    final TimeSelector et = new TimeSelector(st);
    st.setStyleName("unitime-TextArea");
    st.addStyleName("unitime-TimeSelector");
    et.setStyleName("unitime-TextArea");
    et.addStyleName("unitime-TimeSelector");
    addFilter(new FilterBox.CustomFilter("time", MESSAGES.tagTime(), new Label(MESSAGES.propAfter()), st,
            new Label(" " + MESSAGES.propBefore()), et) {
        @Override
        public void getSuggestions(List<Chip> chips, String text,
                AsyncCallback<Collection<Suggestion>> callback) {
            List<FilterBox.Suggestion> suggestions = new ArrayList<FilterBox.Suggestion>();
            Chip chStart = null, chStop = null;
            for (Chip c : chips) {
                if (c.getCommand().equals("after"))
                    chStart = c;
                if (c.getCommand().equals("before"))
                    chStop = c;
            }
            Integer start = TimeSelector.TimeUtils.parseTime(CONSTANTS, text, null);
            Integer stop = TimeSelector.TimeUtils.parseTime(CONSTANTS, text,
                    chStart == null ? null : TimeSelector.TimeUtils.parseMilitary(chStart.getValue()));
            if (chStart == null) {
                if (start != null) {
                    suggestions.add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start))
                            .withTranslatedCommand(MESSAGES.tagTimeAfter())
                            .withTranslatedValue(TimeUtils.slot2time(start)), chStart));
                    suggestions
                            .add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start + 3))
                                    .withTranslatedCommand(MESSAGES.tagTimeAfter())
                                    .withTranslatedValue(TimeUtils.slot2time(start + 3)), chStart));
                    suggestions
                            .add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start + 6))
                                    .withTranslatedCommand(MESSAGES.tagTimeAfter())
                                    .withTranslatedValue(TimeUtils.slot2time(start + 6)), chStart));
                    suggestions
                            .add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start + 9))
                                    .withTranslatedCommand(MESSAGES.tagTimeAfter())
                                    .withTranslatedValue(TimeUtils.slot2time(start + 9)), chStart));
                }
                if (stop != null) {
                    suggestions.add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop))
                            .withTranslatedCommand(MESSAGES.tagTimeBefore())
                            .withTranslatedValue(TimeUtils.slot2time(stop)), chStop));
                    suggestions
                            .add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop + 3))
                                    .withTranslatedCommand(MESSAGES.tagTimeBefore())
                                    .withTranslatedValue(TimeUtils.slot2time(stop + 3)), chStop));
                    suggestions
                            .add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop + 6))
                                    .withTranslatedCommand(MESSAGES.tagTimeBefore())
                                    .withTranslatedValue(TimeUtils.slot2time(stop + 6)), chStop));
                    suggestions
                            .add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop + 9))
                                    .withTranslatedCommand(MESSAGES.tagTimeBefore())
                                    .withTranslatedValue(TimeUtils.slot2time(stop + 9)), chStop));
                }
            } else {
                if (stop != null) {
                    suggestions.add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop))
                            .withTranslatedCommand(MESSAGES.tagTimeBefore())
                            .withTranslatedValue(TimeUtils.slot2time(stop)), chStop));
                    suggestions
                            .add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop + 3))
                                    .withTranslatedCommand(MESSAGES.tagTimeBefore())
                                    .withTranslatedValue(TimeUtils.slot2time(stop + 3)), chStop));
                    suggestions
                            .add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop + 6))
                                    .withTranslatedCommand(MESSAGES.tagTimeBefore())
                                    .withTranslatedValue(TimeUtils.slot2time(stop + 6)), chStop));
                    suggestions
                            .add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop + 9))
                                    .withTranslatedCommand(MESSAGES.tagTimeBefore())
                                    .withTranslatedValue(TimeUtils.slot2time(stop + 9)), chStop));
                }
                if (start != null) {
                    suggestions.add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start))
                            .withTranslatedCommand(MESSAGES.tagTimeAfter())
                            .withTranslatedValue(TimeUtils.slot2time(start)), chStart));
                    suggestions
                            .add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start + 3))
                                    .withTranslatedCommand(MESSAGES.tagTimeAfter())
                                    .withTranslatedValue(TimeUtils.slot2time(start + 3)), chStart));
                    suggestions
                            .add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start + 6))
                                    .withTranslatedCommand(MESSAGES.tagTimeAfter())
                                    .withTranslatedValue(TimeUtils.slot2time(start + 6)), chStart));
                    suggestions
                            .add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start + 9))
                                    .withTranslatedCommand(MESSAGES.tagTimeAfter())
                                    .withTranslatedValue(TimeUtils.slot2time(start + 9)), chStart));
                }
            }
            callback.onSuccess(suggestions);
        }
    });
    st.addValueChangeHandler(new ValueChangeHandler<Integer>() {
        @Override
        public void onValueChange(ValueChangeEvent<Integer> event) {
            Chip ch = getChip("after");
            Integer start = event.getValue();
            if (start == null) {
                if (ch != null)
                    removeChip(ch, true);
            } else {
                if (ch != null) {
                    if (ch.getCommand().equals(TimeUtils.slot2military(start)))
                        return;
                    removeChip(ch, false);
                }
                addChip(new Chip("after", TimeUtils.slot2military(start))
                        .withTranslatedCommand(MESSAGES.tagTimeAfter())
                        .withTranslatedValue(TimeUtils.slot2time(start)), true);
            }
            Chip ch2 = getChip("before");
            Integer stop = et.getValue();
            if (stop == null) {
                if (ch2 != null)
                    removeChip(ch2, true);
            } else {
                if (ch2 != null) {
                    if (ch2.getCommand().equals(TimeUtils.slot2military(stop)))
                        return;
                    removeChip(ch2, false);
                }
                addChip(new Chip("before", TimeUtils.slot2military(stop))
                        .withTranslatedCommand(MESSAGES.tagTimeBefore())
                        .withTranslatedValue(TimeUtils.slot2time(stop)), true);
            }
        }
    });
    et.addValueChangeHandler(new ValueChangeHandler<Integer>() {
        @Override
        public void onValueChange(ValueChangeEvent<Integer> event) {
            Chip ch = getChip("before");
            Integer stop = event.getValue();
            if (stop == null) {
                if (ch != null)
                    removeChip(ch, true);
            } else {
                if (ch != null) {
                    if (ch.getCommand().equals(TimeUtils.slot2military(stop)))
                        return;
                    removeChip(ch, false);
                }
                addChip(new Chip("before", TimeUtils.slot2military(stop))
                        .withTranslatedCommand(MESSAGES.tagTimeBefore())
                        .withTranslatedValue(TimeUtils.slot2time(stop)), true);
            }
        }
    });

    addFilter(new FilterBox.StaticSimpleFilter("after", MESSAGES.tagTimeAfter()) {
        @Override
        public void validate(String text, AsyncCallback<Chip> callback) {
            String translatedValue = null;
            Integer slot = TimeUtils.parseTime2(CONSTANTS, text, null);
            if (slot != null)
                translatedValue = TimeUtils.slot2time(slot);
            callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel())
                    .withTranslatedValue(translatedValue));
        }
    });
    addFilter(new FilterBox.StaticSimpleFilter("before", MESSAGES.tagTimeBefore()) {
        @Override
        public void validate(String text, AsyncCallback<Chip> callback) {
            String translatedValue = null;
            Integer slot = TimeUtils.parseTime2(CONSTANTS, text, null);
            if (slot != null)
                translatedValue = TimeUtils.slot2time(slot);
            callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel())
                    .withTranslatedValue(translatedValue));
        }
    });

    addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            iLastRequested = getChip("requested");
            if (!isFilterPopupShowing()) {
                conflicts.setValue(hasChip(new Chip("flag", "Conflicts")));
                sessions.setValue(hasChip(new Chip("flag", "All Sessions")));
                Chip req = getChip("requested");
                if (req == null)
                    iRequested.setText("");
                else
                    iRequested.setText(req.getValue());
                for (int i = 0; i < iSponsors.getItemCount(); i++) {
                    String value = iSponsors.getValue(i);
                    iSponsors.setItemSelected(i, hasChip(new Chip("sponsor", value)));
                }
                Chip chFrom = getChip("from");
                if (chFrom != null)
                    m1.setDate(sDateFormat.parse(chFrom.getValue()));
                else
                    m1.clearSelection();
                Chip chTo = getChip("to");
                if (chTo != null)
                    m2.setDate(sDateFormat.parse(chTo.getValue()));
                else
                    m2.clearSelection();
                Chip chStart = getChip("after");
                if (chStart != null)
                    st.setValue(TimeSelector.TimeUtils.parseMilitary(chStart.getValue()));
                else
                    st.setValue(null);
                Chip chStop = getChip("before");
                if (chStop != null)
                    et.setValue(TimeSelector.TimeUtils.parseMilitary(chStop.getValue()));
                else
                    et.setValue(null);
            }
            if (getAcademicSessionId() != null)
                init(false, getAcademicSessionId(), new Command() {
                    @Override
                    public void execute() {
                        if (isFilterPopupShowing())
                            showFilterPopup();
                    }
                });
            setAriaLabel(ARIA.eventFilter(toAriaString()));
        }
    });

    addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            setAriaLabel(ARIA.eventFilter(toAriaString()));
        }
    });
}