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

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

Introduction

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

Prototype

public String getValue(int index) 

Source Link

Document

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

Usage

From source file:ar.com.kyol.jet.client.ReadOnlyCondition.java

License:Open Source License

public boolean isReadOnly(Widget widget) {
    Object value = widget;//from   w ww.  j a v a2 s.  c om

    if (widget instanceof ReadOnlyCondition.HasValueForReadOnlyCondition) {
        value = ((ReadOnlyCondition.HasValueForReadOnlyCondition) widget).getValueForReadOnlyCondition();
    }

    if (value instanceof ValueBoxBase<?>) {
        value = ((ValueBoxBase<?>) value).getValue();
    } else if (value instanceof ListBox) {
        ListBox listBox = (ListBox) value;
        value = listBox.getValue(listBox.getSelectedIndex());
    } else if (value instanceof CheckBox) {
        value = ((CheckBox) value).getValue();
    } else if (value instanceof DateBox) {
        value = ((DateBox) value).getValue();
    }

    return isReadOnly(value);
}

From source file:ar.com.kyol.jet.client.wrappers.TrueFalseListBoxWrapper.java

License:Open Source License

/**
 * Instantiates a new true false list box wrapper.
 *
 * @param objSetter the obj setter//w  ww . ja v  a2s . c  om
 * @param listbox the listbox
 * @param useValueAsString the use value as string
 */
public TrueFalseListBoxWrapper(ObjectSetter objSetter, ListBox listbox, boolean useValueAsString) {
    super(useValueAsString);
    this.objSetter = objSetter;
    listBox = listbox;
    listbox.addItem(NULL, "");
    listBox.addItem(TRUE);
    listBox.addItem(FALSE);
    if (objSetter.getValue() != null) {
        if (useValueAsString) {
            listBox.setSelectedIndex(stringToBoolean((String) objSetter.getValue()) ? 1 : 2);
        } else {
            listBox.setSelectedIndex((Boolean) objSetter.getValue() ? 1 : 2);
        }
    } else {
        listBox.setSelectedIndex(0);
    }

    listBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent arg0) {
            String value = listBox.getValue(listBox.getSelectedIndex());
            if (value.equals("")) {
                setProperty(null);
            } else if (value.equals(TRUE)) {
                setProperty(true);
            } else if (value.equals(FALSE)) {
                setProperty(false);
            }
        }
    });

    initWidget(listBox);
}

From source file:bingo.client.Bingo.java

License:Open Source License

/**
 * This is the entry point method./* www.j a va2s. co m*/
 */
public void onModuleLoad() {
    Label titleLabel = new Label();
    titleLabel.setText(strings.title());
    RootPanel.get("title").add(titleLabel);

    // This is the general notification text box
    RootPanel.get("message").add(message);

    // Cheking if the user has already an user id
    final String cookie = Cookies.getCookie(COOKIE_ID);

    // Validating the cookie
    bingoService.statusUserId(cookie, new AsyncCallback<Integer>() {
        @Override
        public void onFailure(Throwable caught) {
            message.setText(caught.getMessage());
            Cookies.removeCookie(COOKIE_ID);
        }

        @Override
        public void onSuccess(Integer status) {
            // TODO: Control the logged status (I should not get a user if s/he is already logged)
            if (status.intValue() == BingoService.NO_LOGGED || status.intValue() == BingoService.LOGGED) {
                bingoService.getUserId(new AsyncCallback<String>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        message.setText(strings.errorUserCreation());
                    }

                    @Override
                    public void onSuccess(String result) {
                        userId = result;
                    }
                });

                message.setHTML("");

                // Showing image to enter
                ImageResource imageResource = BingoResources.INSTANCE.entry();
                Image entryImage = new Image(imageResource.getSafeUri());
                RootPanel.get("buttons").add(entryImage);

                // Selecting behavior (admin / voter) 
                HorizontalPanel entryPoint = new HorizontalPanel();

                entryPoint.setStyleName("mainSelectorPanel");
                entryPoint.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
                entryPoint.setSpacing(50);

                // 
                // CREATING A BINGO
                //
                VerticalPanel leftPanel = new VerticalPanel();
                leftPanel.setStyleName("selectorPanel");

                Label leftPanelTitle = new Label();
                leftPanelTitle.setStyleName("selectorPanelTitle");
                leftPanelTitle.setText(strings.leftPanelTitle());
                leftPanel.add(leftPanelTitle);
                leftPanel.setCellHorizontalAlignment(leftPanelTitle, HasHorizontalAlignment.ALIGN_CENTER);

                Grid leftSubPanel = new Grid(2, 2);
                leftSubPanel.setWidget(0, 0, new Label(strings.createBingoName()));
                final TextBox bingoNameBox = new TextBox();
                leftSubPanel.setWidget(0, 1, bingoNameBox);

                leftSubPanel.setWidget(1, 0, new Label(strings.createBingoPassword()));
                final PasswordTextBox bingoPasswordBox = new PasswordTextBox();
                leftSubPanel.setWidget(1, 1, bingoPasswordBox);
                leftPanel.add(leftSubPanel);

                final Button createButton = new Button("Create");
                createButton.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        bingoService.createBingo(userId, bingoNameBox.getText(), bingoPasswordBox.getText(),
                                new AsyncCallback<String>() {
                                    @Override
                                    public void onFailure(Throwable caught) {
                                        message.setText(caught.getMessage());
                                    }

                                    @Override
                                    public void onSuccess(final String gameId) {
                                        final BingoGrid bingoGrid = new BingoGrid();
                                        initAdminGrid(userId, bingoGrid, false);
                                        RootPanel.get("bingoTable").clear();
                                        RootPanel.get("bingoTable").add(bingoGrid);
                                        message.setText(strings.welcomeMessageCreation());

                                        // Setting the cookie
                                        Date expirationDate = new Date();
                                        expirationDate.setHours(expirationDate.getHours() + EXPIRATION_VALUE);
                                        Cookies.setCookie(COOKIE_ID, userId, expirationDate);
                                    }
                                });
                    }
                });
                leftPanel.add(createButton);
                leftPanel.setCellHorizontalAlignment(createButton, HasHorizontalAlignment.ALIGN_CENTER);
                entryPoint.add(leftPanel);

                // 
                // JOINING
                //
                VerticalPanel rightPanel = new VerticalPanel();
                rightPanel.setStyleName("selectorPanel");

                Label rightPanelTitle = new Label();
                rightPanelTitle.setStyleName("selectorPanelTitle");
                rightPanelTitle.setText(strings.rightPanelTitle());
                rightPanel.add(rightPanelTitle);
                rightPanel.setCellHorizontalAlignment(rightPanelTitle, HasHorizontalAlignment.ALIGN_CENTER);

                Grid rightSubPanel = new Grid(2, 2);
                rightSubPanel.setWidget(0, 0, new Label(strings.joinToBingoName()));
                final ListBox joinExistingBingoBox = new ListBox();
                bingoService.getBingos(new AsyncCallback<String[][]>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        joinExistingBingoBox.addItem(strings.noBingos());
                    }

                    @Override
                    public void onSuccess(String[][] result) {
                        if (result == null) {
                            joinExistingBingoBox.addItem(strings.noBingos());
                        } else {
                            for (int i = 0; i < result.length; i++) {
                                String gameName = result[i][0];
                                String gameId = result[i][1];
                                joinExistingBingoBox.addItem(gameName, gameId);
                            }
                        }
                    }
                });
                rightSubPanel.setWidget(0, 1, joinExistingBingoBox);

                rightSubPanel.setWidget(1, 0, new Label(strings.joinToBingoPassword()));
                final PasswordTextBox joinBingoPasswordBox = new PasswordTextBox();
                rightSubPanel.setWidget(1, 1, joinBingoPasswordBox);
                rightPanel.add(rightSubPanel);

                final Button joinButton = new Button("Join");
                joinButton.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        int index = joinExistingBingoBox.getSelectedIndex();
                        if (index < 0)
                            message.setText(strings.noSelectedItem());
                        else {
                            final String gameId = joinExistingBingoBox.getValue(index);
                            if (gameId == null)
                                message.setText(strings.noSelectedItem());
                            else {
                                bingoService.joinBingo(userId, gameId, joinBingoPasswordBox.getText(),
                                        new AsyncCallback<Void>() {
                                            @Override
                                            public void onFailure(Throwable caught) {
                                                message.setText(caught.getMessage());
                                            }

                                            @Override
                                            public void onSuccess(Void result) {
                                                final BingoGrid bingoGrid = new BingoGrid();
                                                initUserGrid(bingoGrid);
                                                RootPanel.get("bingoTable").clear();
                                                RootPanel.get("bingoTable").add(bingoGrid);

                                                message.setText(strings.welcomeMessageJoin());

                                                // Setting the cookie
                                                Date expirationDate = new Date();
                                                expirationDate
                                                        .setHours(expirationDate.getHours() + EXPIRATION_VALUE);
                                                Cookies.setCookie(COOKIE_ID, userId, expirationDate);
                                            }
                                        });
                            }
                        }
                    }
                });
                rightPanel.add(joinButton);
                rightPanel.setCellHorizontalAlignment(joinButton, HasHorizontalAlignment.ALIGN_CENTER);
                entryPoint.add(rightPanel);

                RootPanel.get("bingoTable").add(entryPoint);

            } else if (status.intValue() == BingoService.ADMIN) {
                message.setText("Detected cookie: " + cookie + " as admin");
                userId = cookie;

                bingoService.statusBingo(userId, new AsyncCallback<Integer>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        message.setText(caught.getMessage());
                    }

                    @Override
                    public void onSuccess(Integer result) {
                        int status = result.intValue();
                        final BingoGrid bingoGrid = new BingoGrid();
                        if (status == BingoService.RUNNING) {
                            initAdminGrid(userId, bingoGrid, false);
                            message.setText(strings.welcomeMessageCreation());
                        } else if (status == BingoService.FINISHED) {
                            initAdminGrid(userId, bingoGrid, true);
                            message.setText(strings.finishMessage());
                        }
                        RootPanel.get("bingoTable").clear();
                        RootPanel.get("bingoTable").add(bingoGrid);
                    }
                });

            } else if (status.intValue() == BingoService.PARTICIPANT) {
                message.setText("Detected cookie: " + cookie + " as participant");
                userId = cookie;

                final BingoGrid bingoGrid = new BingoGrid();
                initUserGrid(bingoGrid);
                updateUserGrid(bingoGrid, null);
                RootPanel.get("bingoTable").clear();
                RootPanel.get("bingoTable").add(bingoGrid);
            }
        }
    });
}

From source file:ca.aeso.evq.client.widgets.DatePicker.java

License:Apache License

/**
 * Public method onChange which is fired when user clicks on the
 * list menu in the widget./*from w  w  w.  j  a v a  2s . c  om*/
 * @param sender - widget on which user clicked.
 *
 */
public void onChange(Widget sender) {

    if (sender instanceof ListBox) {

        ListBox list = (ListBox) sender;
        String val = list.getValue(list.getSelectedIndex());
        int ival = Integer.valueOf(val).intValue();

        if (list == dateTable.monthNames()) {
            action(monthAction, ival);
        } else {
            action(yearAction, ival);
        }

        changeListeners.fireChange(this);
    }
}

From source file:com.chinarewards.gwt.license.client.widget.DefaultPager.java

/**
 * Get the text to display in the pager that reflects the state of the
 * pager./* w  ww.j a v  a 2 s.c  o m*/
 * 
 * @return the text
 */
@Override
protected String createText() {
    // Default text is 1 based.
    final NumberFormat formatter = NumberFormat.getFormat("#,###");
    final HasRows display = getDisplay();
    Range range = display.getVisibleRange();
    int pageStart = range.getStart() + 1;
    final int pageSize = range.getLength();
    int dataSize = display.getRowCount();
    int endIndex = Math.min(dataSize, pageStart + pageSize - 1);
    endIndex = Math.max(pageStart, endIndex);
    boolean exact = display.isRowCountExact();

    // create listbox
    int currentPage = 0;
    int totalPage = 0;
    final ListBox pages = new ListBox();
    if (dataSize != 0) {
        currentPage = (pageStart - 1) / pageSize + 1;
        totalPage = (dataSize - 1) / pageSize + 1;

        for (int i = 1; i <= totalPage; i++) {
            pages.addItem(i + "", i + "");
        }
        pages.setSelectedIndex(currentPage - 1);
        pages.addChangeHandler(new ChangeHandler() {
            @Override
            public void onChange(ChangeEvent event) {
                String text = pages.getValue(pages.getSelectedIndex());
                int pageNum = (int) formatter.parse(text);
                int index = (pageNum - 1) * pageSize;
                display.setVisibleRange(index, pageSize);
            }
        });
    }

    // create label : total pages
    //getAdditionPanel().clear();
    //getAdditionPanel().add(new Label(" " + totalPage + " ,"));
    //getAdditionPanel().add(pages);
    //getAdditionPanel().add(new Label(""));

    // return formatter.format(pageStart) + "-" + formatter.format(endIndex)
    // + (exact ? " of " : " of over ") + formatter.format(dataSize);
    return "? " + currentPage + " ," + "" + totalPage + "," + dataSize + "?";
}

From source file:com.chinarewards.gwt.license.client.widget.EltNewPager.java

/**
 * Get the text to display in the pager that reflects the state of the
 * pager.// ww w .  j  a  v a  2 s  .c o  m
 * 
 * @return the text
 */
protected String createText() {
    // Default text is 1 based.
    final NumberFormat formatter = NumberFormat.getFormat("#,###");
    final HasRows display = getDisplay();
    Range range = display.getVisibleRange();
    int pageStart = range.getStart() + 1;
    final int pageSize = range.getLength();
    int dataSize = display.getRowCount();
    int endIndex = Math.min(dataSize, pageStart + pageSize - 1);
    endIndex = Math.max(pageStart, endIndex);
    // boolean exact = display.isRowCountExact();

    // create listbox
    int currentPage = 0;
    int totalPage = 0;
    final ListBox pages = new ListBox();
    if (dataSize != 0) {
        currentPage = (pageStart - 1) / pageSize + 1;
        totalPage = (dataSize - 1) / pageSize + 1;

        for (int i = 1; i <= totalPage; i++) {
            pages.addItem(i + "", i + "");
        }
        pages.setSelectedIndex(currentPage - 1);
        pages.addChangeHandler(new ChangeHandler() {
            @Override
            public void onChange(ChangeEvent event) {
                String text = pages.getValue(pages.getSelectedIndex());
                int pageNum = (int) formatter.parse(text);
                int index = (pageNum - 1) * pageSize;
                display.setVisibleRange(index, pageSize);
            }
        });
    }

    setButtonStyle(currentPage, totalPage);
    return "";
    // return "? " + currentPage + " ,"+""+totalPage+","+dataSize+"?";
}

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

License:Open Source License

/**
 * Select item in the field.//w  w w.  j  a va 2s. c o 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.codenvy.ide.client.propertiespanel.connectors.base.parameter.ParameterViewImpl.java

License:Open Source License

/**
 * Returns a selected item of field./*  w w  w.  j a  va  2 s . co m*/
 *
 * @param field
 *         field that contains item
 * @return a selected item
 */
@Nonnull
private String getSelectedItem(@Nonnull ListBox field) {
    int index = field.getSelectedIndex();
    return index != -1 ? field.getValue(field.getSelectedIndex()) : "";
}

From source file:com.cognitivemedicine.metricsdashboard.client.charts.ChartEditorPanel.java

License:Apache License

private void setListBoxValue(ListBox list, String value) {
    for (int i = 0; i < list.getItemCount(); i++) {
        if (list.getValue(i).equals(value)) {
            list.setSelectedIndex(i);//  w w  w . j av  a 2 s .c  om
            return;
        }
    }
}

From source file:com.cognitivemedicine.metricsdashboard.client.dashboard.DashboardSettingsPanel.java

License:Apache License

/**
 * Updates the dashboard settings panel when a dashboard is loaded
 * //from   www  .ja  v  a 2 s . c  o m
 * @param settings
 */
public void updateDashboardSettings(DashboardSettings settings) {
    Granularity g = settings.getGranularity();
    ListBox list = null;
    if (g != null) {
        list = granularitySetting.getList();
        for (int i = 0; i < list.getItemCount(); i++) {
            if (list.getValue(i).equals(g.getSymbol())) {
                list.setSelectedIndex(i);
                granularitySetting.getCheckBox().setValue(true);
                break;
            }
        }
    } else {
        granularitySetting.getCheckBox().setValue(false);
    }

    Period p = settings.getPeriod();
    if (p != null) {
        list = periodSetting.getList();
        for (int i = 0; i < list.getItemCount(); i++) {
            if (list.getValue(i).equals(p.getSymbol())) {
                list.setSelectedIndex(i);
                periodSetting.getCheckBox().setValue(true);
                datetimePicker.setAmPm(settings.getAmPm());
                datetimePicker.setHours(settings.getHours());
                datetimePicker.setMinutes(settings.getMinutes());
                datetimePicker.setDate(settings.getEndDate());
                break;
            }
        }
    } else {
        periodSetting.getCheckBox().setValue(false);
    }
}