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

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

Introduction

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

Prototype

public boolean isItemSelected(int index) 

Source Link

Document

Determines whether an individual list item is selected.

Usage

From source file:com.controlj.addon.gwttree.client.TreeOptions.java

License:Open Source License

public void showDialog() {
    VerticalPanel dialogContents = new VerticalPanel();
    dialogContents.setSpacing(4);/*from  w  w w  .j a v  a  2  s  .  c  om*/

    // Add the tree type radio buttons
    RadioButton dynamicChoice = createTreeChoice("treeTypeGroup", "Dynamic Tree", false);
    RadioButton staticChoice = createTreeChoice("treeTypeGroup", "Static Tree", true);
    if (state.isStaticTree)
        staticChoice.setValue(true);
    else
        dynamicChoice.setValue(true);
    dialogContents.add(dynamicChoice);
    dialogContents.add(staticChoice);

    // Add filtering support
    dialogContents.add(new Label("Filter by trend name (leave empty to not filter)"));
    HorizontalPanel sourcesPanel = new HorizontalPanel();
    sourcesPanel.setSpacing(10);
    final ListBox sourceListBox = new ListBox(true);
    sourceListBox.setSize("10em", "5em");
    for (String sourceName : state.sourceNames)
        sourceListBox.addItem(sourceName);
    sourcesPanel.add(sourceListBox);
    VerticalPanel sourcesButtonPanel = new VerticalPanel();
    sourcesButtonPanel.add(new Button("Add...", new ClickHandler() {
        @Override
        public void onClick(ClickEvent clickEvent) {
            final TextBox textBox = new TextBox();
            Dialog.showInputDialog("Add Filter", textBox, new Dialog.Handler() {
                @Override
                public void setupButtons(final Button ok, final Button cancel) {
                    textBox.addKeyPressHandler(new KeyPressHandler() {
                        @Override
                        public void onKeyPress(KeyPressEvent keyPressEvent) {
                            if (keyPressEvent.getCharCode() == (char) 13)
                                ok.click();
                            else if (keyPressEvent.getCharCode() == (char) 27)
                                cancel.click();
                        }
                    });
                }

                @Override
                public void dialogClosed(boolean wasCancelled) {
                    String name = textBox.getText().trim();
                    if (!wasCancelled && !name.isEmpty()) {
                        state.sourceNames.add(name);
                        sourceListBox.addItem(name);
                    }
                }
            });
            textBox.setFocus(true);
        }
    }));
    sourcesButtonPanel.add(new Button("Remove", new ClickHandler() {
        @Override
        public void onClick(ClickEvent clickEvent) {
            int count = sourceListBox.getItemCount();
            for (int i = count - 1; i >= 0; i--)
                if (sourceListBox.isItemSelected(i)) {
                    state.sourceNames.remove(sourceListBox.getItemText(i));
                    sourceListBox.removeItem(i);
                }
        }
    }));
    sourcesPanel.add(sourcesButtonPanel);
    dialogContents.add(sourcesPanel);

    final State originalState = state.copy();
    Dialog.showInputDialog("Tree Options", dialogContents, new Dialog.Handler() {
        @Override
        public void setupButtons(Button ok, Button cancel) {
        }

        @Override
        public void dialogClosed(boolean wasCancelled) {
            if (wasCancelled)
                state = originalState;
            else if (!state.equals(originalState))
                handler.optionsChanged(TreeOptions.this);
        }
    });
}

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

License:Open Source License

public List<Integer> getAllSelectedIndexes(ListBox fromList) {
    List<Integer> selectedValuesList = new ArrayList<Integer>(0);
    final int LIST_LENGTH = fromList.getItemCount();
    if (LIST_LENGTH > 0) {
        // populate all selected indexes from the list
        for (int index = 0; index < LIST_LENGTH; index++) {
            if (fromList.isItemSelected(index)) {
                selectedValuesList.add(index);
            }/*from   w ww  .j  ava  2s .c  om*/
        }
    }
    return selectedValuesList;
}

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

License:Open Source License

private List<String> addToLeftButtonHandler(final ListBox fromList) {
    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);
            }/*w  ww.  j  ava  2s  . c  om*/
        }
        int temp = 0;
        for (int index : selectedValues.keySet()) {
            // remove from the current list
            fromList.removeItem(index - temp);

            temp++;
        }

        // To enable adding to the left list, uncomment the below method call
        // addToRightList(toList, selectedValues);
    }
    return selectedValuesList;
}

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

License:Open Source License

/**
 * @param toList/* w  ww . j a  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/* w  w w  .j av a  2 s. co  m*/
        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 w w.  j  ava 2s  .c om*/
        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.moesol.gwt.maps.client.controls.TagControl.java

License:Open Source License

public RemoveTagDialog removeDialogWidget(final String header) {//, String content) {
    final List<Icon> icons = m_mapView.getIconLayer().getIcons();
    if (icons.isEmpty()) {
        return null;
    }// ww w  . j a  va  2 s .co  m
    final RemoveTagDialog box = new RemoveTagDialog();
    box.setText(header);

    final VerticalPanel panel = new VerticalPanel();
    final ListBox lb = new ListBox();

    m_nameCount = 0;
    for (Icon icon : icons) {
        String name = icon.getLabelText();
        if (name != null) {
            m_nameCount++;
            lb.addItem(name);
        }
    }
    lb.setVisibleItemCount(m_nameCount);
    panel.add(lb);
    final Button btnDelete = new Button("delete");
    final Button btnExit = new Button("exit");
    ClickHandler deleteHandler = new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            for (int j = 0; j < m_nameCount; j++) {
                if (lb.isItemSelected(j)) {
                    String val = lb.getValue(j);
                    for (Icon icon : icons) {
                        String name = icon.getLabelText();
                        if (name != null && name.compareTo(val) == 0) {
                            m_nameCount -= 1;
                            lb.removeItem(j);
                            m_mapView.getIconLayer().removeIcon(icon);
                            deleteTagFromDisk(name);
                            break;
                        }
                    }
                }
            }
            m_mapView.updateView();
            m_bTagOn = false;
        }

        private void deleteTagFromDisk(String name) {
            if (tagControlServiceOn) {
                // Set up the callback object.
                AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        Window.alert("Internal Server Error:" + caught.getMessage());
                    }

                    @Override
                    public void onSuccess(Boolean result) {
                    }
                };
                tagControlService.deleteTagFromDisk(name, callback);
            }
        }
    };
    btnDelete.addClickHandler(deleteHandler);

    ClickHandler exitHandler = new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            box.hide();
        }
    };
    btnExit.addClickHandler(exitHandler);

    // few empty labels to make widget larger
    final Label emptyLabel = new Label("          ");
    emptyLabel.setSize("auto", "25px");
    final HorizontalPanel btnPanel = new HorizontalPanel();
    btnPanel.add(btnDelete);
    btnPanel.add(emptyLabel);
    btnPanel.add(btnExit);
    panel.add(btnPanel);
    box.add(panel);
    box.getElement().getStyle().setProperty("zIndex", Integer.toString(9000));
    return box;
}

From source file:com.qualogy.qafe.gwt.client.vo.handlers.BuiltinHandlerHelper.java

License:Apache License

private static Object getValue(ListBox listBox, boolean idValueOnly) {
    Object value = null;//  w ww . j  av a  2 s.  c  o m

    if (!(listBox.isMultipleSelect()) && listBox.getSelectedIndex() != -1) { // dropdown
        int index = listBox.getSelectedIndex();
        if (idValueOnly) {
            value = listBox.getValue(index);
        } else {
            DataMap dm = new DataMap();
            dm.put("id", new DataContainerGVO(listBox.getValue(index)));
            dm.put("value", new DataContainerGVO(listBox.getItemText(index)));

            DataContainerGVO dtcMap = new DataContainerGVO();
            dtcMap.setKind(DataContainerGVO.KIND_MAP);
            dtcMap.setDataMap(dm);
            value = dtcMap;

            // TODO: refactor, this is a workaround for checking simple
            // value
            dtcMap.setDataString(listBox.getValue(index));
        }

        handleSimpleValue(listBox, value);
    } else if (listBox.getSelectedIndex() != -1) {
        DataContainerGVO dtclist = new DataContainerGVO();
        dtclist.setKind(DataContainerGVO.KIND_COLLECTION);
        List<DataContainerGVO> list = new ArrayList<DataContainerGVO>();
        dtclist.setListofDC(list);
        int items = listBox.getItemCount();
        for (int itemIndex = 0; itemIndex < items; itemIndex++) {
            if (listBox.isItemSelected(itemIndex)) {
                DataMap dataMap = new DataMap();
                DataContainerGVO dtcId = new DataContainerGVO();
                dtcId.setKind(DataContainerGVO.KIND_STRING);
                dtcId.setDataString(listBox.getValue(itemIndex));
                dtcId.setStringDataType(DataContainerGVO.TYPE_STRING);
                dataMap.put("id", dtcId);

                DataContainerGVO dtcValue = new DataContainerGVO();
                dtcValue.setKind(DataContainerGVO.KIND_STRING);
                dtcValue.setDataString(listBox.getItemText(itemIndex));
                dtcValue.setStringDataType(DataContainerGVO.TYPE_STRING);
                dataMap.put("value", dtcValue);

                list.add(new DataContainerGVO(dataMap));
            }
        }
        value = dtclist;
    }

    return value;
}

From source file:com.redspr.redquerybuilder.core.client.expression.ValueMultiListBox.java

License:Open Source License

public ValueMultiListBox(Renderer<T> renderer2, ProvidesKey<T> keyProvider2) {
    this.keyProvider = keyProvider2;
    this.renderer = renderer2;
    initWidget(new ListBox(true));
    getListBox().setVisibleItemCount(2);

    getListBox().addChangeHandler(new ChangeHandler() {
        @Override//  w ww  .j  ava  2  s.co  m
        public void onChange(ChangeEvent event) {
            ListBox lb = getListBox();
            Collection<T> newValue = new ArrayList<T>();
            for (int i = 0; i < values.size(); i++) {
                if (lb.isItemSelected(i)) {
                    newValue.add(values.get(i));
                }
            }

            setValue(newValue, true);
        }
    });
}

From source file:com.tasktop.c2c.server.common.web.client.widgets.Pager.java

License:Open Source License

public static void select(ListBox listBox, String object) {
    if (object == null) {
        return;//w  w  w .  j a  v a 2 s.  co  m
    }
    int itemCount = listBox.getItemCount();
    for (int x = 0; x < itemCount; ++x) {
        String itemValue = listBox.getValue(x);
        if (object.equals(itemValue)) {
            if (!listBox.isItemSelected(x)) {
                listBox.setSelectedIndex(x);
            }
            return;
        }
    }
    // Plug in the String itself as the value
    listBox.addItem(object, object);

    // Recurse - this will succeed since we just added this object to our list.
    select(listBox, object);
}