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

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

Introduction

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

Prototype

public void setValue(int index, String value) 

Source Link

Document

Sets the value associated with the item at a given index.

Usage

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  w w  w.  ja  v a 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 www  .ja va2  s  .com
        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:edu.ucdenver.bios.glimmpseweb.client.guided.GaussianCovariateCovariancePanel.java

License:Open Source License

/**
 * Load the responses from the context// www.j a va  2  s.  c o  m
 */
private void loadResponsesFromContext() {
    // clear the data from the screen
    sigmaYGTable.removeAllRows();
    // add the header widgets
    sigmaYGTable.setWidget(0, 0, outcomesHTML);
    sigmaYGTable.setWidget(0, 1, correlationHTML);
    sigmaYGTable.getRowFormatter().setStyleName(0, GlimmpseConstants.STYLE_WIZARD_STEP_TABLE_HEADER);
    // add a row for each response variable
    List<ResponseNode> outcomeList = studyDesignContext.getStudyDesign().getResponseList();
    if (outcomeList != null && outcomeList.size() > 0) {
        // load the display
        int row = 1;
        for (ResponseNode outcome : outcomeList) {
            sigmaYGTable.getRowFormatter().setStyleName(row, GlimmpseConstants.STYLE_WIZARD_STEP_TABLE_ROW);
            sigmaYGTable.setWidget(row, 0, new HTML(outcome.getName()));
            RowColumnTextBox tb = new RowColumnTextBox(row - 1, 0);
            tb.addChangeHandler(this);
            sigmaYGTable.setWidget(row, 1, tb);
            row++;
        }

        // if repeated measures are present, update the column offsets
        if (repeatedMeasuresTable.getRowCount() > 0) {
            int offset = studyDesignContext.getValidTotalResponsesCount();
            for (row = 0; row < repeatedMeasuresTable.getRowCount(); row++) {
                ListBox lb = (ListBox) repeatedMeasuresTable.getWidget(row, LISTBOX_COLUMN);
                offset /= lb.getItemCount();
                for (int i = 0; i < lb.getItemCount(); i++) {
                    lb.setValue(i, Integer.toString(i * offset));
                }
            }
        }
    }
    checkComplete();
}

From source file:edu.ucdenver.bios.glimmpseweb.client.guided.MeanDifferencesPanel.java

License:Open Source License

/**
 * Load response variable information from the context
 *///ww w  .  jav a 2 s.  c  o  m
private void loadResponsesFromContext() {
    // remove existing information about response variables
    if (totalResponseVariables > 0) {
        // remove the columns associated with the responses
        for (int col = totalBetweenFactors + totalResponseVariables - 1; col > totalBetweenFactors; col--) {
            for (int row = meansTable.getRowCount() - 1; row >= 0; row--) {
                meansTable.removeCell(row, col);
            }
        }
    }
    totalResponseVariables = 0;

    // now load the new responses
    List<ResponseNode> outcomeList = studyDesignContext.getStudyDesign().getResponseList();
    if (outcomeList != null && outcomeList.size() > 0) {
        totalResponseVariables = outcomeList.size();
        int col = totalBetweenFactors;
        for (ResponseNode outcome : outcomeList) {
            meansTable.setWidget(0, col, new HTML(outcome.getName()));
            col++;
        }
    }

    // if repeated measures are present, update the column offsets
    if (repeatedMeasuresTable.getRowCount() > 0) {
        int offset = studyDesignContext.getValidTotalResponsesCount();
        for (int row = 0; row < repeatedMeasuresTable.getRowCount(); row++) {
            ListBox lb = (ListBox) repeatedMeasuresTable.getWidget(row, LISTBOX_COLUMN);
            offset /= lb.getItemCount();
            for (int i = 0; i < lb.getItemCount(); i++) {
                lb.setValue(i, Integer.toString(i * offset));
            }
        }
    }

    // create text boxes to hold the means
    fillTextBoxes();
    updateMatrixView();
    checkComplete();
}