Package com.ponysdk.ui.server.basic

Examples of com.ponysdk.ui.server.basic.PSuggestBox$MultiWordSuggestion


        final PVerticalPanel panel = new PVerticalPanel();

        panel.add(new PLabel("Choose a word:"));

        final PSuggestBox suggestBox = new PSuggestBox();
        suggestBox.setLimit(10);

        final PMultiWordSuggestOracle suggestOracle = (PMultiWordSuggestOracle) suggestBox.getSuggestOracle();
        suggestBox.addSelectionHandler(new PSelectionHandler<PSuggestion>() {

            @Override
            public void onSelection(final PSelectionEvent<PSuggestion> event) {
                final String msg = "Selected item : " + event.getSelectedItem().getReplacementString();
                UIContext.getRootEventBus().fireEvent(new DemoBusinessEvent(msg));
            }
        });

        final Query query = new Query();
        final FindPonysCommand command = new FindPonysCommand(query);
        final Result<List<Pony>> ponys = command.execute();

        final List<String> datas = new ArrayList<String>();
        for (final Pony pony : ponys.getData()) {
            datas.add(pony.getName());
        }
        suggestOracle.addAll(datas);
        suggestOracle.setDefaultSuggestions(datas.subList(0, 5));

        panel.add(suggestBox);

        panel.add(new PHTML("<br><br>"));

        panel.add(new PLabel("Manipulate the suggest box:"));
        final PListBox operation = new PListBox(true);
        operation.addItem("Select \"Friesian horse\"", 0);
        operation.addItem("Get textbox value", 1);
        operation.addItem("Enable/Disable textbox", 2);
        operation.addItem("Clear", 3);
        operation.addItem("Add items", 4);
        operation.addChangeHandler(new PChangeHandler() {

            @Override
            public void onChange(final PChangeEvent event) {
                final Integer item = (Integer) operation.getSelectedValue();
                if (item == null) return;

                if (item.equals(0)) {
                    suggestBox.setText("Friesian horse");
                } else if (item.equals(1)) {
                    UIContext.getRootEventBus().fireEvent(new DemoBusinessEvent("Text content: " + suggestBox.getText()));
                } else if (item.equals(2)) {
                    suggestBox.getTextBox().setEnabled(!suggestBox.getTextBox().isEnabled());
                } else if (item.equals(3)) {
                    final PMultiWordSuggestOracle oracle = (PMultiWordSuggestOracle) suggestBox.getSuggestOracle();
                    oracle.clear();
                } else if (item.equals(4)) {
                    current++;
                    final Result<List<Pony>> ponys = command.execute();
                    for (final Pony pony : ponys.getData()) {
View Full Code Here


        updateUI(new RequestHandler() {

            @SuppressWarnings("unchecked")
            @Override
            public void onRequest() {
                final PSuggestBox suggestBox1 = new PSuggestBox();
                suggestBox1.getSuggestOracle().add("Suggest 1");
                suggestBox1.getSuggestOracle().add("Suggest 2");
                suggestBox1.getSuggestOracle().add("Suggest 3");
                suggestBox1.getSuggestOracle().add("Suggest 4");
                suggestBox1.ensureDebugId("suggestBox1");
                suggestBox1.addSelectionHandler(eventsListener);
                PRootPanel.get().add(suggestBox1);
                register(suggestBox1);
            }
        });

        WebElement element = findElementById("suggestBox1");
        final PSuggestBox pSuggestBox1 = get("suggestBox1");
        element.sendKeys("su");

        final WebElement popup = findElementById("suggestBox1-popup");
        final List<WebElement> items = popup.findElements(By.className("item"));
        Assert.assertEquals(4, items.size());
        Assert.assertEquals("Suggest 1", items.get(0).getText());
        Assert.assertEquals("Suggest 2", items.get(1).getText());
        Assert.assertEquals("Suggest 3", items.get(2).getText());
        Assert.assertEquals("Suggest 4", items.get(3).getText());

        items.get(2).click();

        final PSelectionEvent<PSuggestion> selection1 = eventsListener.poll();
        Assert.assertEquals("Suggest 3", selection1.getSelectedItem().getReplacementString());
        Assert.assertEquals("Suggest 3", pSuggestBox1.getText());
        Assert.assertEquals("Suggest 3", pSuggestBox1.getTextBox().getText());

        // set text
        updateUI(new RequestHandler() {

            @Override
            public void onRequest() {
                final PSuggestBox suggestBox1 = get("suggestBox1");
                suggestBox1.setText("Custom text");
            }
        });

        element = findElementById("suggestBox1");
        Assert.assertEquals("Custom text", element.getAttribute("value"));
        Assert.assertEquals(true, element.isEnabled());

        // disable
        updateUI(new RequestHandler() {

            @Override
            public void onRequest() {
                final PSuggestBox suggestBox1 = get("suggestBox1");
                suggestBox1.getTextBox().setEnabled(false);
            }
        });

        element = findElementById("suggestBox1");
        Assert.assertEquals(false, element.isEnabled());
View Full Code Here

TOP

Related Classes of com.ponysdk.ui.server.basic.PSuggestBox$MultiWordSuggestion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.