Example usage for com.google.gwt.user.client.ui ListBox setItemSelected

List of usage examples for com.google.gwt.user.client.ui ListBox setItemSelected

Introduction

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

Prototype

public void setItemSelected(int index, boolean selected) 

Source Link

Document

Sets whether an individual list item is selected.

Usage

From source file:com.codenvy.ide.client.propertiespanel.connectors.base.parameter.ParameterViewImpl.java

License:Open Source License

/**
 * Select item in the field./*from  www  .  j a va 2 s  .co m*/
 *
 * @param field
 *         field that needs to be changed
 * @param type
 *         a new selected item
 */
private void selectType(@Nonnull ListBox field, @Nullable String type) {
    for (int i = 0; i < field.getItemCount(); i++) {
        if (field.getValue(i).equals(type)) {
            field.setItemSelected(i, true);
            return;
        }
    }
}

From source file:com.eduworks.russel.ui.client.pagebuilder.screen.ResultsScreen.java

License:Apache License

/**
 * setShowFilter Sets current state of Show filter option
 *//*  w ww  . j a  v a2  s  .  c om*/
public void setShowFilter(String searchType) {
    String showType = "";
    ListBox lb = (ListBox) PageAssembler.elementToWidget("resultsSearchSelectShow", PageAssembler.SELECT);
    if (lb != null) {
        if (searchType.equals(RusselApi.FLR_TYPE)) {
            //showType = Utilities.LINK;
        } else {
            showType = Utilities.EVERYTHING;
        }
        for (int x = 0; x < lb.getItemCount(); x++) {
            if (lb.getItemText(x).equals(showType)) {
                lb.setItemSelected(x, true);
                Utilities.showSetting = x;
            }
        }
    }
}

From source file:com.ephesoft.dcma.gwt.admin.bm.client.presenter.scanner.EditScannerPresenter.java

License:Open Source License

/**
 * To add drop down.//from www  . j  a v  a  2  s  .co  m
 * 
 * @param row int
 * @param sampleValueList List<String>
 * @param selectedValue String
 * @return ListBox
 */
public ListBox addDropDown(int row, List<String> sampleValueList, String selectedValue) {
    ListBox fieldValue = new ListBox();
    fieldValue.setVisibleItemCount(1);
    for (String item : sampleValueList) {
        fieldValue.addItem(item);
    }
    fieldValue.setItemSelected(sampleValueList.indexOf(selectedValue), true);
    return fieldValue;
}

From source file:com.ephesoft.dcma.gwt.admin.bm.client.view.plugin.EditPluginView.java

License:Open Source License

/**
 * To add Multiple Select List Box./*  w w w. j  a  va 2s.  c o m*/
 * 
 * @param row int
 * @param sampleValueList List<String>
 * @param MAX_VISIBLE_ITEM_COUNT int
 * @param value String
 * @return ListBox
 */
public ListBox addMultipleSelectListBox(int row, List<String> sampleValueList, int MAX_VISIBLE_ITEM_COUNT,
        String value) {
    ListBox fieldValue = new ListBox(true);
    fieldValue.setVisibleItemCount(MAX_VISIBLE_ITEM_COUNT);
    for (String item : sampleValueList) {
        fieldValue.addItem(item);
    }
    String[] selectedValue = value.split(";");
    for (String string : selectedValue) {
        fieldValue.setItemSelected(sampleValueList.indexOf(string), true);
    }
    return fieldValue;
}

From source file:com.ephesoft.dcma.gwt.admin.bm.client.view.scanner.EditScannerView.java

License:Open Source License

/**
 * To add Drop Down./*from  w  w w.ja v  a 2s  .c  o  m*/
 * 
 * @param row int
 * @param sampleValueList List<String>
 * @param selectedValue String
 * @param htmlID String
 * @param elementMap Map<String, Widget>
 * @return ListBox
 */
public ListBox addDropDown(int row, List<String> sampleValueList, String selectedValue, String htmlID,
        Map<String, Widget> elementMap) {
    ListBox fieldValue = new ListBox();
    elementMap.put(htmlID, fieldValue);
    fieldValue.getElement().setId(htmlID);
    fieldValue.setVisibleItemCount(1);
    for (String item : sampleValueList) {
        fieldValue.addItem(item);
    }
    if (selectedValue == null) {
        fieldValue.setItemSelected(0, true);
    } else {
        fieldValue.setItemSelected(sampleValueList.indexOf(selectedValue), true);
    }

    return fieldValue;
}

From source file:com.ephesoft.dcma.gwt.core.client.view.MultipleSelectTwoSidedListBox.java

License:Open Source License

/**
 * @param toList/*from  w w  w. ja v a 2 s. c  o m*/
 * @param selectedValues
 */
public List<String> addToRightButtonHandler(final Button button, final ListBox fromList, final ListBox toList) {
    Map<Integer, String> selectedValues = new LinkedHashMap<Integer, String>(0);
    List<String> selectedValuesList = new ArrayList<String>(0);
    // toList.setSelectedIndex(-1);
    final int LIST_LENGTH = fromList.getItemCount();
    if (LIST_LENGTH > 0) {

        // populate all selected values from the list
        for (int index = 0; index < LIST_LENGTH; index++) {
            if (fromList.isItemSelected(index)) {
                String item = fromList.getItemText(index);
                selectedValues.put(index, item);
                selectedValuesList.add(item);
            }
        }

        // To enable removing from the left list, un-comment the below method call
        // removeFromRightList(fromList, selectedValues);

        for (int index : selectedValues.keySet()) {
            // add to the other list
            String selectedValue = selectedValues.get(index);
            toList.addItem(selectedValue);
            toList.getElement().getElementsByTagName(OPTION).getItem(index).setTitle(selectedValue);
            // set focus on the transferred values
            toList.setItemSelected(toList.getItemCount() - 1, true);
        }

    }
    return selectedValuesList;
}

From source file:com.ephesoft.dcma.gwt.core.client.view.MultipleSelectTwoSidedListBox.java

License:Open Source License

private void addUpButtonPressHandler(Button button, final ListBox list) {
    button.addClickHandler(new ClickHandler() {

        @Override/*from   www  .  j  a  va  2 s.  c om*/
        public void onClick(ClickEvent clickEvent) {
            final int LIST_LENGTH = list.getItemCount();
            if (list != null && LIST_LENGTH > 0 && !list.isItemSelected(0)) {
                // Map<Integer, String> selectedValues = new HashMap<Integer, String>();
                String tempItemTextString;
                String tempItemValueString;
                List<Integer> selectedValuesIndex = new ArrayList<Integer>(0);

                for (int index = 0; index < LIST_LENGTH; index++) {
                    if (list.isItemSelected(index)) {

                        tempItemTextString = list.getItemText(index);
                        tempItemValueString = list.getValue(index);
                        if (index != 0) {

                            // swap with the previous value in the list, exception being the the first value in the list
                            list.setItemText(index, list.getItemText(index - 1));
                            list.setItemText(index - 1, tempItemTextString);
                            list.setValue(index, list.getValue(index - 1));
                            list.setValue(index - 1, tempItemValueString);
                            // populate the indexes of selected values, required to bring focus on them later
                            selectedValuesIndex.add(index - 1);
                        } else {
                            selectedValuesIndex.add(0);
                        }
                    }
                }

                // remove current focus
                list.setSelectedIndex(-1);

                // set focus on selected indexes after swapping
                for (Integer index : selectedValuesIndex) {
                    if (index != 0) {
                        list.setItemSelected(index, true);
                    } else {
                        list.setItemSelected(0, true);
                    }
                }

            }
        }

    });
}

From source file:com.ephesoft.dcma.gwt.core.client.view.MultipleSelectTwoSidedListBox.java

License:Open Source License

private void addDownButtonPressHandler(Button button, final ListBox listBox) {
    button.addClickHandler(new ClickHandler() {

        @Override/*from  w  ww . ja  va2 s  . co  m*/
        public void onClick(ClickEvent clickEvent) {
            final int LIST_LENGTH = listBox.getItemCount();
            if (listBox != null && LIST_LENGTH > 0 && !listBox.isItemSelected(listBox.getItemCount() - 1)) {
                // Map<Integer, String> selectedValues = new HashMap<Integer, String>();
                String tempString;
                String tempItemValueString;
                List<Integer> selectedValuesIndex = new ArrayList<Integer>(0);

                for (int index = LIST_LENGTH - 1; index > -1; index--) {
                    if (listBox.isItemSelected(index)) {

                        tempString = listBox.getItemText(index);
                        tempItemValueString = listBox.getValue(index);
                        if (index != LIST_LENGTH - 1) {
                            // swap with the next value in the list, exception being the the last value in the list
                            listBox.setItemText(index, listBox.getItemText(index + 1));
                            listBox.setItemText(index + 1, tempString);
                            listBox.setValue(index, listBox.getValue(index + 1));
                            listBox.setValue(index + 1, tempItemValueString);
                            // populate the indexes of selected values, required to bring focus on them later
                            selectedValuesIndex.add(index + 1);
                        }

                    }
                }

                // remove current focus
                listBox.setSelectedIndex(-1);
                // set focus on selected indexes after swapping
                for (Integer index : selectedValuesIndex) {
                    // boolean firstSelected = false;
                    if (index != 0) {
                        listBox.setItemSelected(index, true);
                    } else {
                        listBox.setItemSelected(0, true);
                    }
                }

            }
        }

    });
}

From source file:com.ephesoft.dcma.gwt.uploadbatch.client.view.AssociateBCFView.java

License:Open Source License

public ListBox addDropDown(String fieldOptionValueList, String value) {
    ListBox fieldValue = new ListBox();
    fieldValue.setVisibleItemCount(1);/*from  w  ww.j a v a 2 s .  c o m*/
    String[] selectedValue = fieldOptionValueList.split(";");
    List<String> selectedValueList = Arrays.asList(selectedValue);
    for (String item : selectedValueList) {
        if (!item.trim().isEmpty()) {
            fieldValue.addItem(item);
        }
    }
    if (value != null && !value.isEmpty()) {
        fieldValue.setItemSelected(selectedValueList.indexOf(value), true);
    }
    return fieldValue;
}

From source file:com.google.sampling.experiential.client.FeedbackChooserPanel.java

License:Open Source License

public FeedbackChooserPanel(ExperimentDAO experiment) {
    this.experiment = experiment;
    myConstants = GWT.create(MyConstants.class);

    rootPanel = new VerticalPanel();
    rootPanel.setStyleName("bordered");
    rootPanel.setWidth(SHORT_TEXTBOX_WIDTH);
    initWidget(rootPanel);//from   w w w.  ja v a 2s.  c  o m

    choicePanel = new HorizontalPanel();
    rootPanel.add(choicePanel);

    detailsPanel = new VerticalPanel();
    detailsPanel.setWidth(SHORT_TEXTBOX_WIDTH);
    rootPanel.add(detailsPanel);

    HTML feedbackChoiceLabel = new HTML("<h2>" + myConstants.feedbackChoiceLabel() + ": </h2>");
    choicePanel.add(feedbackChoiceLabel);
    final ListBox feedbackChoices = new ListBox();
    feedbackChoices.addItem(myConstants.staticMessageFeedbackChoice());
    feedbackChoices.addItem(myConstants.retrospectiveMessageFeedbackChoice());
    feedbackChoices.addItem(myConstants.responsiveMessageFeedbackChoice());
    feedbackChoices.addItem(myConstants.customFeedbackChoice());
    feedbackChoices.addItem(myConstants.hideFeedbackChoice());

    choicePanel.add(feedbackChoices);

    if (experiment.getFeedback() == null || experiment.getFeedback().length == 0) {
        FeedbackDAO[] feedback = new FeedbackDAO[1];
        FeedbackDAO feedbackDAO = new FeedbackDAO();
        feedbackDAO.setText(FeedbackDAO.DEFAULT_FEEDBACK_MSG);

        feedback[0] = feedbackDAO;
        experiment.setFeedback(feedback);
        experiment.setFeedbackType(FeedbackDAO.FEEDBACK_TYPE_STATIC_MESSAGE);
        feedbackChoices.setItemSelected(0, true);
    } else {
        Integer feedbackType = experiment.getFeedbackType();
        int selectedIndex = 0;
        if (feedbackType == null) {
            // no existing experiments will have a feedback type unless we write a migration script
            // so, it is either default feedback or custom feedback;
            // assign appropriately
            if (hasNonDefaultFeedback()) {
                selectedIndex = FeedbackDAO.FEEDBACK_TYPE_CUSTOM; // we were retrospective by default
                experiment.setFeedbackType(selectedIndex);
            } else {
                selectedIndex = FeedbackDAO.FEEDBACK_TYPE_STATIC_MESSAGE;
                experiment.setFeedbackType(selectedIndex);
            }
        } else {
            selectedIndex = feedbackType;
        }
        feedbackChoices.setItemSelected(selectedIndex, true);
    }

    updatePanel();

    feedbackChoices.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            int index = feedbackChoices.getSelectedIndex();
            respondToListSelection(index);
        }

    });
}