Example usage for com.google.gwt.event.logical.shared ValueChangeEvent getValue

List of usage examples for com.google.gwt.event.logical.shared ValueChangeEvent getValue

Introduction

In this page you can find the example usage for com.google.gwt.event.logical.shared ValueChangeEvent getValue.

Prototype

public T getValue() 

Source Link

Document

Gets the value.

Usage

From source file:net.exclaimindustries.paste.braket.client.BraketEntryPoint.java

License:Open Source License

/**
 * Process the incoming history token and route the user appropriately. These
 * actions should only result in asynchronous loads. Other things happen after
 * the call to <code>History.fireCurrentHistoryState()</code> that, if
 * circumvented with a synchronous load here, might result in bad behavior of
 * the site./*from   w  w w. j  a v a2 s .c  o m*/
 */
@Override
public void onValueChange(ValueChangeEvent<String> event) {

    // If you're not logged in, all you get is the log-in page

    if (currentUser == null || !currentUser.isLoggedIn()) {
        // Make the log-in info stuff
        logger.log(Level.INFO, "user not logged in: displaying login info");
        layout.setCenter(new LogInPage());
        return;
    }

    String eventString = event.getValue();

    // Yay Java 1.7!
    switch (eventString) {

    case UiConstants.HistoryToken.ABOUT:
        // TODO Make an "About" page
        logger.log(Level.INFO, "loading about page");
        break;

    case UiConstants.HistoryToken.MY_BRACKET:
        logger.log(Level.INFO, "loading user bracket page");
        GWT.runAsync(braketDisplayCallback);
        break;

    case UiConstants.HistoryToken.USER_OPTIONS:
        logger.log(Level.INFO, "loading user options page");
        // TODO Make a "User Options" page
        break;

    case UiConstants.HistoryToken.LEADERBOARDS:
        logger.log(Level.INFO, "loading leaderboard page");
        // TODO Make a "Leaderboard" page.
        break;

    case UiConstants.HistoryToken.EXCITE_O_MATIC:
        logger.log(Level.INFO, "loading excite-o-matic");
        // TODO Make an "Excite-o-Matic" page
        break;

    case UiConstants.HistoryToken.ADMIN:
        logger.log(Level.INFO, "loading admin page");
        // Make sure the user is logged in as an admin
        if (!currentUser.isAdmin()) {
            Toast.showErrorToast("You need to be an administrator to use this function");
        } else {
            layout.setCenter(new BraketAdminLayout());
        }
        break;

    case UiConstants.HistoryToken.TOURNAMENT_STATUS:
    case "":
        // TODO Make a "Tournament Status" page
        logger.log(Level.INFO, "loading tournament status page");
        break;

    default:
        Toast.showErrorToast("History token [" + eventString + "] not recognized");
        logger.log(Level.WARNING, "History token [" + eventString + "] not recognized");
        break;
    }

}

From source file:net.imgseek.server.admin.client.Iskdaemon_admin.java

License:GNU General Public License

@Override
public void onValueChange(ValueChangeEvent<String> event) {
    // Find the SinkInfo associated with the history context. If one is
    // found, show it (It may not be found, for example, when the user mis-
    // types a URL, or on startup, when the first context will be "").
    String token = event.getValue();
    SinkInfo info = list.find(token);//from   w  w  w . j a v  a 2  s.c  om
    if (info == null) {
        showInfo();
        return;
    }
    show(info, false);

}

From source file:net.imgseek.server.demo.client.Iskdaemon_demo.java

License:Open Source License

@Override
public void onValueChange(ValueChangeEvent<String> event) {
    int tid = 0;// ww w . j av a2s .  c o  m
    try {
        tid = Integer.parseInt(event.getValue().substring(8));
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }

    iskDemoService.queryImgID(tid, NUMRES, false, new AsyncCallback<List<DbImageResult>>() {
        public void onFailure(Throwable caught) {
            // TODO Show the RPC error message to the user
        }

        public void onSuccess(List<DbImageResult> result) {
            showResults(result);
        }

    });
}

From source file:net.randomhacks.wave.voting.approval.client.ChoicesTable.java

License:Apache License

private void insertChoiceRow(int i, final Choice choice) {
    Log.debug("Inserting row " + Integer.toString(i) + ": " + choice.key);
    knownChoices.add(i, choice.key);//from ww  w .  j av a  2 s  . c o m
    int row = rowForChoiceIndex(i);
    insertRow(row);
    final CheckBox checkBox = new CheckBox(choice.name);
    setWidget(row, 0, checkBox);
    checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            model.setChosen(choice.name, event.getValue());
        }
    });
}

From source file:net.s17fabu.vip.gwt.showcase.client.content.widgets.CwDatePicker.java

License:Apache License

/**
 * Initialize this example./*from  w  ww. j a  v a  2  s .c o m*/
 */
@Override
public Widget onInitialize() {
    // Create a basic date picker
    DatePicker datePicker = new DatePicker();
    final Label text = new Label();

    // Set the value in the text box when the user selects a date
    datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {
        public void onValueChange(ValueChangeEvent<Date> event) {
            Date date = event.getValue();
            String dateString = DateTimeFormat.getMediumDateFormat().format(date);
            text.setText(dateString);
        }
    });

    // Set the default value
    datePicker.setValue(new Date(), true);

    // Create a DateBox
    DateBox dateBox = new DateBox();

    // Combine the widgets into a panel and return them
    VerticalPanel vPanel = new VerticalPanel();
    vPanel.add(new HTML(constants.cwDatePickerLabel()));
    vPanel.add(text);
    vPanel.add(datePicker);
    vPanel.add(new HTML(constants.cwDatePickerBoxLabel()));
    vPanel.add(dateBox);
    return vPanel;
}

From source file:net.s17fabu.vip.gwt.showcase.client.Showcase.java

License:Apache License

/**
 * This is the entry point method.//ww w.  j ava 2  s .  c  o m
 */
public void onModuleLoad() {
    RootPanel.get("loading_div").setVisible(false);
    // Create the constants
    ShowcaseConstants constants = (ShowcaseConstants) GWT.create(ShowcaseConstants.class);

    // Swap out the style sheets for the RTL versions if needed.
    updateStyleSheets();

    // Create the application
    setupTitlePanel(constants);
    setupMainLinks(constants);
    setupOptionsPanel(constants);
    setupMainMenu(constants);

    // Setup a history handler to reselect the associate menu item
    final ValueChangeHandler<String> historyHandler = new ValueChangeHandler<String>() {
        public void onValueChange(ValueChangeEvent<String> event) {
            TreeItem item = itemTokens.get(event.getValue());
            if (item == null) {
                item = app.getMainMenu().getItem(0).getChild(0);
            }

            // Select the associated TreeItem
            app.getMainMenu().setSelectedItem(item, false);
            app.getMainMenu().ensureSelectedItemVisible();

            // Show the associated ContentWidget
            displayContentWidget(itemWidgets.get(item));
        }
    };
    History.addValueChangeHandler(historyHandler);

    // Add a handler that sets the content widget when a menu item is selected
    app.addSelectionHandler(new SelectionHandler<TreeItem>() {
        public void onSelection(SelectionEvent<TreeItem> event) {
            TreeItem item = event.getSelectedItem();
            ContentWidget content = itemWidgets.get(item);
            if (content != null && !content.equals(app.getContent())) {
                History.newItem(getContentWidgetToken(content));
            }
        }
    });

    // Show the initial example
    if (History.getToken().length() > 0) {
        History.fireCurrentHistoryState();
    } else {
        // Use the first token available
        TreeItem firstItem = app.getMainMenu().getItem(0).getChild(0);
        app.getMainMenu().setSelectedItem(firstItem, false);
        app.getMainMenu().ensureSelectedItemVisible();
        displayContentWidget(itemWidgets.get(firstItem));
    }
}

From source file:net.scran24.admin.client.NewSurvey.java

License:Apache License

public NewSurvey() {
    contents = new FlowPanel();

    final Grid surveyParametersGrid = new Grid(7, 2);
    surveyParametersGrid.setCellPadding(5);

    contents.add(surveyParametersGrid);/*  www .ja  v  a  2s . c om*/

    final Label idLabel = new Label("Survey identifier: ");
    final TextBox idTextBox = new TextBox();

    surveyParametersGrid.setWidget(0, 0, idLabel);
    surveyParametersGrid.setWidget(0, 1, idTextBox);

    final Label schemeBoxLabel = new Label("Survey scheme: ");
    final ListBox schemeBox = new ListBox();
    schemeBox.setMultipleSelect(false);

    final Label localeLabel = new Label("Locale: ");
    final ListBox localeBox = new ListBox();
    localeBox.setMultipleSelect(false);

    localeBox.addItem("English (UK)", "en_GB");
    localeBox.addItem("English (New Zealand)", "en_NZ");
    localeBox.addItem("Portuguese (Portugal)", "pt_PT");
    localeBox.addItem("Danish (Denmark)", "da_DK");
    localeBox.addItem("Arabic (UAE)", "ar_AE");

    for (SurveySchemeReference s : SurveySchemes.allSchemes)
        schemeBox.addItem(s.description(), s.id());

    schemeBox.setSelectedIndex(0);

    surveyParametersGrid.setWidget(1, 0, schemeBoxLabel);
    surveyParametersGrid.setWidget(1, 1, schemeBox);

    surveyParametersGrid.setWidget(2, 0, localeLabel);
    surveyParametersGrid.setWidget(2, 1, localeBox);

    final Label genUserLabel = new Label("Allow auto login: ");
    final CheckBox genCheckBox = new CheckBox();

    surveyParametersGrid.setWidget(3, 0, genUserLabel);
    surveyParametersGrid.setWidget(3, 1, genCheckBox);

    final Label forwardToSurveyMonkey = new Label("SurveyMonkey support:");
    final CheckBox smCheckBox = new CheckBox();

    surveyParametersGrid.setWidget(4, 0, forwardToSurveyMonkey);
    surveyParametersGrid.setWidget(4, 1, smCheckBox);

    final Label surveyMonkeyUrl = new Label("SurveyMonkey link:");
    final TextBox smUrlTextBox = new TextBox();

    surveyParametersGrid.setWidget(5, 0, surveyMonkeyUrl);
    surveyParametersGrid.setWidget(5, 1, smUrlTextBox);

    smUrlTextBox.setEnabled(false);

    final Label supportEmailLabel = new Label("Support e-mail:");
    final TextBox supportEmailTextBox = new TextBox();

    surveyParametersGrid.setWidget(6, 0, supportEmailLabel);
    surveyParametersGrid.setWidget(6, 1, supportEmailTextBox);

    smCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
            smUrlTextBox.setEnabled(valueChangeEvent.getValue());
        }
    });

    final FlowPanel errorDiv = new FlowPanel();
    errorDiv.getElement().addClassName("scran24-admin-survey-id-error-message");

    contents.add(errorDiv);

    final Button createButton = WidgetFactory.createButton("Create survey");

    createButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            createButton.setEnabled(false);
            final String id = idTextBox.getText();
            errorDiv.clear();

            String smUrlText = smUrlTextBox.getText();

            Option<String> smUrl;

            if (smCheckBox.getValue())
                smUrl = smUrlText.isEmpty() ? Option.<String>none() : Option.some(smUrlText);
            else
                smUrl = Option.<String>none();

            if (smCheckBox.getValue() && smUrlText.isEmpty()) {
                errorDiv.add(new Label("Please paste the SurveyMonkey link!"));
                createButton.setEnabled(true);
                return;
            } else if (smCheckBox.getValue()
                    && !smUrlText.contains("intake24_username=[intake24_username_value]")) {
                errorDiv.add(new Label("Invalid SurveyMonkey link: intake24_username variable missing!"));
                createButton.setEnabled(true);
                return;
            }

            service.createSurvey(id, schemeBox.getValue(schemeBox.getSelectedIndex()),
                    localeBox.getValue(localeBox.getSelectedIndex()), genCheckBox.getValue(), smUrl,
                    supportEmailTextBox.getValue(), new AsyncCallback<Option<String>>() {
                        @Override
                        public void onSuccess(Option<String> result) {
                            result.accept(new Option.SideEffectVisitor<String>() {
                                @Override
                                public void visitSome(String error) {
                                    errorDiv.add(new Label(error));
                                    createButton.setEnabled(true);
                                }

                                @Override
                                public void visitNone() {
                                    contents.clear();
                                    contents.add(new HTMLPanel(SafeHtmlUtils.fromSafeConstant(
                                            "<h2>Survey created!</h2><p>Please go to <strong>Survey management</strong> and upload the staff accounts for the new survey.</p>")));
                                }
                            });
                        }

                        @Override
                        public void onFailure(Throwable caught) {
                            createButton.setEnabled(true);
                            errorDiv.add(
                                    new Label("Server error (" + SafeHtmlUtils.htmlEscape(caught.getMessage())
                                            + "), please check server logs"));
                        }
                    });
        }
    });
    createButton.getElement().addClassName("scran24-admin-button");

    VerticalPanel buttonsPanel = new VerticalPanel();
    buttonsPanel.add(createButton);

    contents.add(buttonsPanel);

    initWidget(contents);
}

From source file:net.scran24.user.client.survey.flat.StateManager.java

public StateManager(Survey initialState, String scheme_id, String version_id, final Callback showNextPage,
        final PortionSizeScriptManager scriptManager) {
    this.scheme_id = scheme_id;
    this.version_id = version_id;
    this.currentState = initialState;

    log.info("Making initial history entry");
    makeHistoryEntry();/* w w  w.  jav  a  2 s .  co m*/

    History.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {

            try {
                final int state_id = Integer.parseInt(event.getValue());

                StateManagerUtil.getHistoryState(CurrentUser.getUserInfo().userName, state_id, scriptManager)
                        .accept(new Option.SideEffectVisitor<Survey>() {
                            @Override
                            public void visitSome(Survey item) {
                                log.info("Switching to historical state #" + state_id);
                                updateState(item, false);
                                showNextPage.call();
                            }

                            @Override
                            public void visitNone() {
                                log.warning("Failed to load historical state, keeping current state");
                            }
                        });
            } catch (NumberFormatException e) {
                // Ignore malformed state ids
            }
        }
    });
}

From source file:net.sf.mmm.client.ui.gwt.widgets.richtext.AbstractColorFeatureBehavior.java

License:Apache License

/**
 * {@inheritDoc}/*from  w  w  w. j  a va  2  s.  c o  m*/
 */
@Override
public void setFontSettingsPreviewElement(final Element element) {

    super.setFontSettingsPreviewElement(element);
    ValueChangeHandler<Color> handler = new ValueChangeHandler<Color>() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void onValueChange(ValueChangeEvent<Color> event) {

            Color value = event.getValue();
            if (value != null) {
                Style style = element.getStyle();
                applyFontSettings(value, style);
            }
        }
    };
    getColorBox().addValueChangeHandler(handler);
}

From source file:net.sf.mmm.client.ui.gwt.widgets.richtext.AbstractSelectionFeatureBehavior.java

License:Apache License

/**
 * {@inheritDoc}/*from   w  w  w.j  a va2 s  . c  o m*/
 */
@Override
public void setFontSettingsPreviewElement(final Element element) {

    super.setFontSettingsPreviewElement(element);
    ValueChangeHandler<String> handler = new ValueChangeHandler<String>() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {

            String value = event.getValue();
            if (value != null) {
                Style style = element.getStyle();
                applyFontSettings(value, style);
            }
        }
    };
    getCombobox().addValueChangeHandler(handler);
}