Example usage for com.vaadin.ui TextField TextField

List of usage examples for com.vaadin.ui TextField TextField

Introduction

In this page you can find the example usage for com.vaadin.ui TextField TextField.

Prototype

public TextField() 

Source Link

Document

Constructs an empty TextField with no caption.

Usage

From source file:com.peergreen.webconsole.scope.system.internal.bundle.ui.FilteredPackageTable.java

License:Open Source License

public FilteredPackageTable(final String label) {
    this.label = label;

    title = new Label(label);
    title.addStyleName("h3");

    filter = new TextField();
    filter.setInputPrompt("filter...");

    header.addComponent(title);//from w w  w .j a v  a2s .co  m
    header.addComponent(filter);
    header.setComponentAlignment(filter, Alignment.MIDDLE_LEFT);
    header.setComponentAlignment(title, Alignment.MIDDLE_LEFT);
    header.setSpacing(true);

    data.addContainerProperty(DESCRIPTION, String.class, "aaa");

    table = new Table();
    table.setPageLength(DEFAULT_PAGE_LENGTH);
    table.setWidth("100%");
    table.setColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);
    table.setContainerDataSource(data);

    addComponent(header);
    addComponent(table);

    filter.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override
        public void textChange(final FieldEvents.TextChangeEvent event) {
            data.removeAllContainerFilters();
            data.addContainerFilter(new SimpleStringFilter(DESCRIPTION, event.getText().trim(), true, false));
        }
    });
    filter.addShortcutListener(new ShortcutListener("Clear", ShortcutAction.KeyCode.ESCAPE, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            filter.setValue("");
            data.removeAllContainerFilters();
        }
    });

}

From source file:com.peergreen.webconsole.scope.system.internal.bundle.ui.FilteredServiceTable.java

License:Open Source License

public FilteredServiceTable(final String label) {
    this.label = label;

    title = new Label(label);
    title.addStyleName("h3");

    filter = new TextField();
    filter.setInputPrompt("filter...");

    header.addComponent(title);/*from   w ww  .  jav  a2  s.  co m*/
    header.addComponent(filter);
    header.setComponentAlignment(filter, Alignment.MIDDLE_LEFT);
    header.setComponentAlignment(title, Alignment.MIDDLE_LEFT);
    header.setSpacing(true);

    data.addContainerProperty(SERVICE_ID, String.class, "");
    data.addContainerProperty(SERVICE_DETAILS, Label.class, null);

    table = new Table();
    table.setPageLength(DEFAULT_PAGE_LENGTH);
    table.setWidth("100%");
    table.setColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);
    table.setContainerDataSource(data);

    addComponent(header);
    addComponent(table);

    filter.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override
        public void textChange(final FieldEvents.TextChangeEvent event) {
            data.removeAllContainerFilters();
            data.addContainerFilter(
                    new SimpleStringFilter(SERVICE_DETAILS, event.getText().trim(), true, false));
        }
    });
    filter.addShortcutListener(new ShortcutListener("Clear", ShortcutAction.KeyCode.ESCAPE, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            filter.setValue("");
            data.removeAllContainerFilters();
        }
    });

}

From source file:com.peergreen.webconsole.scope.system.internal.service.ServiceViewer.java

License:Open Source License

private void initHeader() {
    HorizontalLayout header = new HorizontalLayout();
    header.setWidth("100%");
    header.setSpacing(true);/*from  w w w .  ja v a 2  s  .  c om*/
    header.setMargin(true);

    Label title = new Label("OSGi Services");
    title.addStyleName("h1");
    title.setSizeUndefined();
    header.addComponent(title);
    header.setComponentAlignment(title, Alignment.MIDDLE_LEFT);

    final TextField filter = new TextField();
    filter.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override
        public void textChange(final FieldEvents.TextChangeEvent event) {
            data.removeAllContainerFilters();
            String trimmed = event.getText().trim();
            Container.Filter or = new Or(new SimpleStringFilter(SERVICE_ID_COLUMN, trimmed, true, false),
                    new InterfacesFilter(trimmed), new BundleFilter(trimmed),
                    new ServicePropertiesFilter(trimmed));

            data.addContainerFilter(or);
        }
    });

    filter.setInputPrompt("Filter");
    filter.addShortcutListener(new ShortcutListener("Clear", ShortcutAction.KeyCode.ESCAPE, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            filter.setValue("");
            data.removeAllContainerFilters();
        }
    });
    header.addComponent(filter);
    header.setExpandRatio(filter, 1);
    header.setComponentAlignment(filter, Alignment.MIDDLE_LEFT);

    // Store the header in the vertical layout (this)
    addComponent(header);
}

From source file:com.peergreen.webconsole.scope.system.internal.shell.ShellConsoleView.java

License:Open Source License

private void initConsole() {

    Table table = new Table();
    table.addStyleName("console-font");
    table.addStyleName("borderless");
    table.setColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);
    IndexedContainer container = new IndexedContainer();
    table.setContainerDataSource(container);
    table.setImmediate(true);//from   w  ww  .  j a v  a2s  .c  o m
    table.setSizeFull();
    table.addContainerProperty("line", Label.class, null);

    addComponent(table);
    // Magic number: use all the empty space
    setExpandRatio(table, 1.5f);

    OutputStream out = new HtmlAnsiOutputStream(new WebConsoleOutputStream(table, container));
    this.printStream = new PrintStream(out);

    session = processor.createSession(new ByteArrayInputStream("".getBytes()), printStream, printStream);

    final TextField input = new TextField();
    input.setWidth("100%");
    input.setInputPrompt(">$ ");

    final ShortcutListener shortcut = new ShortcutListener("Execute", ShortcutAction.KeyCode.ENTER, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            try {
                String value = input.getValue();
                printStream.printf(">$ %s\n", value);
                Object result = session.execute(value);
                //session.put(Constants.LAST_RESULT_VARIABLE, result);
                if (result != null) {
                    session.getConsole().println(session.format(result, Converter.INSPECT));
                }
            } catch (Exception e) {
                printException(printStream, e);
            }
            input.setValue("");
        }
    };

    // Install the shortcut listener only when the input text-field has the focus
    input.addFocusListener(new FieldEvents.FocusListener() {
        @Override
        public void focus(final FieldEvents.FocusEvent event) {
            input.addShortcutListener(shortcut);
        }
    });
    input.addBlurListener(new FieldEvents.BlurListener() {
        @Override
        public void blur(final FieldEvents.BlurEvent event) {
            input.removeShortcutListener(shortcut);
        }
    });

    addComponent(input);

    doSessionBranding(printStream);
}

From source file:com.peter.vaadin.components.vaadin.chart.timeline.MyTimelineDemo.java

public MyTimelineDemo() {

    timeline = new Timeline("My graph");
    timeline.setSizeFull();//  w w  w.  j  ava2  s  .c  om
    timeline.setVerticalAxisRange(-1f, 2f);
    timeline.setZoomLevelsVisible(false);
    timeline.setDateSelectVisible(false);

    // Create the data sources
    firstDataSource = createGraphDataSource();
    datasourcesList.add(firstDataSource);
    final Container.Indexed markerDataSource = createMarkerDataSource();
    final Container.Indexed eventDataSource = createEventDataSource();

    // Add our data sources
    timeline.addGraphDataSource(firstDataSource, Timeline.PropertyId.TIMESTAMP, Timeline.PropertyId.VALUE);

    // Markers and events
    timeline.setMarkerDataSource(markerDataSource, Timeline.PropertyId.TIMESTAMP, Timeline.PropertyId.CAPTION,
            Timeline.PropertyId.VALUE);
    timeline.setEventDataSource(eventDataSource, Timeline.PropertyId.TIMESTAMP, Timeline.PropertyId.CAPTION);

    // Set the caption of the graph
    timeline.setGraphLegend(firstDataSource, "Our cool graph");

    // Set the color of the graph
    timeline.setGraphOutlineColor(firstDataSource, SolidColor.RED);

    // Set the fill color of the graph
    timeline.setGraphFillColor(firstDataSource, new SolidColor(255, 0, 0, 128));

    // Set the width of the graph
    timeline.setGraphOutlineThickness(1);

    // Set the color of the browser graph
    timeline.setBrowserOutlineColor(firstDataSource, SolidColor.BLACK);

    // Set the fill color of the graph
    timeline.setBrowserFillColor(firstDataSource, new SolidColor(0, 0, 0, 128));

    // Add some zoom levels
    timeline.addZoomLevel("Day", 86400000L);
    timeline.addZoomLevel("Week", 7 * 86400000L);
    timeline.addZoomLevel("Month", 2629743830L);

    // Listen to click events from events
    timeline.addListener(new Timeline.EventClickListener() {
        @Override
        public void eventClick(EventButtonClickEvent event) {
            Item item = eventDataSource.getItem(event.getItemIds().iterator().next());
            Date sunday = (Date) item.getItemProperty(Timeline.PropertyId.TIMESTAMP).getValue();
            SimpleDateFormat formatter = new SimpleDateFormat("EEE, MMM d, ''yy");

            Notification.show(formatter.format(sunday));
        }
    });

    addComponent(timeline);

    HorizontalLayout addDateForm = new HorizontalLayout();
    final DateField dateField = new DateField();
    dateField.setImmediate(true);
    addDateForm.addComponent(dateField);
    final TextField valueField = new TextField();
    valueField.setImmediate(true);
    addDateForm.addComponent(valueField);
    Button addBtn = new Button("Add", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {

            java.util.Date d = dateField.getValue();
            Date date = new Date(d.getTime());
            float value = Float.valueOf(valueField.getValue().toString());

            // Create a point in time
            Item item = firstDataSource.addItem(date.getTime());

            if (item == null) {
                item = firstDataSource.getItem(date.getTime());
            }

            // Set the timestamp property
            item.getItemProperty(Timeline.PropertyId.TIMESTAMP).setValue(date);

            // Set the value property
            item.getItemProperty(Timeline.PropertyId.VALUE).setValue(value);
        }
    });
    addDateForm.addComponent(addBtn);
    addComponent(addDateForm);

    Button addGraphDataSource = new Button("Add graph data source", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Container.Indexed ds = createGraphDataSource();
            datasourcesList.add(ds);
            timeline.addGraphDataSource(ds);
            timeline.setGraphFillColor(ds, SolidColor.BLACK);
        }
    });
    addComponent(addGraphDataSource);

    Button removeGraphDataSource = new Button("Remove graph data source", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (datasourcesList.size() > 1) {
                Container.Indexed ds = datasourcesList.get(datasourcesList.size() - 1);
                timeline.removeGraphDataSource(ds);
                datasourcesList.remove(ds);
            }
        }
    });
    addComponent(removeGraphDataSource);

    CheckBox stacked = new CheckBox("Stacked graphs", false);
    stacked.setImmediate(true);
    stacked.addListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            timeline.setGraphStacking((Boolean) event.getProperty().getValue());
        }
    });
    addComponent(stacked);

    CheckBox lock = new CheckBox("Selection lock", true);
    lock.setImmediate(true);
    lock.addListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            timeline.setBrowserSelectionLock((Boolean) event.getProperty().getValue());
        }
    });
    addComponent(lock);

    setExpandRatio(timeline, 1);
}

From source file:com.philippefichet.vaadincdipush.view.FirstView.java

@PostConstruct
public void init() {
    setHeight("100%");
    loginLayout = new HorizontalLayout();
    Label loginLabel = new Label("Login");
    loginChoose = new TextField();
    attach = new Button("Connect");
    attach.addClickListener((Button.ClickEvent event) -> {
        if (chat.loginFree(loginChoose.getValue())) {
            if (login == null) {
                login = loginChoose.getValue();
                chat.getUsernameConnected().forEach((l) -> {
                    newUser(l);/*from  w  w  w.ja v  a 2s. com*/
                });
                chat.attach(this);
            } else {
                chat.rename(loginChoose.getValue(), this);
                login = loginChoose.getValue();
            }
            attach.setStyleName(ValoTheme.BUTTON_FRIENDLY);
            Notification.show("Login \"" + loginChoose.getValue() + "\" valid.", null,
                    Notification.Type.HUMANIZED_MESSAGE);

            messagePanel.setVisible(true);
            sendLayout.setVisible(true);

        } else {
            Notification.show("Login \"" + loginChoose.getValue() + "\" already exist.", null,
                    Notification.Type.ERROR_MESSAGE);
        }
    });

    chatMessage.setWidth("100%");
    sendLayout.setWidth("100%");
    sendMessage.setWidthUndefined();
    sendLayout.addComponent(chatMessage);
    sendLayout.addComponent(sendMessage);
    sendLayout.setExpandRatio(chatMessage, 100);
    sendMessage.addClickListener((event) -> {
        chat.sendMessage(this, chatMessage.getValue());
        chatMessage.setValue("");
    });

    Button next = new Button("next");
    next.addClickListener((eventClick) -> {
        getUI().getNavigator().navigateTo("next");
    });

    loginLayout.addComponent(loginLabel);
    loginLayout.addComponent(loginChoose);
    loginLayout.addComponent(attach);
    loginLayout.setComponentAlignment(loginLabel, Alignment.MIDDLE_RIGHT);
    loginLayout.setComponentAlignment(loginChoose, Alignment.MIDDLE_CENTER);
    loginLayout.setComponentAlignment(attach, Alignment.MIDDLE_LEFT);

    loginLayout.setWidth("100%");
    loginLabel.setWidthUndefined();
    loginChoose.setWidth("100%");
    attach.setWidthUndefined();
    messagePanel.setHeight("100%");
    listUserPanel.setStyleName(ValoTheme.PANEL_WELL);
    listUserPanel.setContent(listUserLayout);
    listUserPanel.setHeight("100%");
    centerLayout.setHeight("100%");
    centerLayout.addComponent(listUserPanel);
    centerLayout.addComponent(messageLayout);
    centerLayout.setExpandRatio(messageLayout, 100);
    messagePanel.setContent(centerLayout);
    addComponent(loginLayout);
    addComponent(messagePanel);
    addComponent(sendLayout);

    messagePanel.setVisible(false);
    sendLayout.setVisible(false);

    setExpandRatio(messagePanel, 100);
}

From source file:com.purebred.core.view.field.SelectField.java

License:Open Source License

public void initialize() {
    setSizeUndefined();//from  w  w  w .  j  ava  2  s  .  c o m
    field = new TextField();
    FormField.initAbstractFieldDefaults(field);
    FormField.initTextFieldDefaults(field);
    field.setReadOnly(true);

    HorizontalLayout layout = new HorizontalLayout();
    layout.addComponent(field);

    searchButton = new Button();
    searchButton.setDescription(uiMessageSource.getMessage("selectField.search.description"));
    searchButton.setSizeUndefined();
    searchButton.addStyleName("borderless");
    searchButton.setIcon(new ThemeResource("../chameleon/img/magnifier.png"));
    searchButton.addListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            entitySelect.open();
        }
    });
    layout.addComponent(searchButton);

    clearButton = new Button();
    clearButton.setDescription(uiMessageSource.getMessage("selectField.clear.description"));
    clearButton.setSizeUndefined();
    clearButton.addStyleName("borderless");
    clearButton.setIcon(new ThemeResource("../runo/icons/16/cancel.png"));
    layout.addComponent(clearButton);

    entitySelect.getResults().setSelectButtonListener(this, "itemSelected");
    addClearListener(this, "itemCleared");

    setCompositionRoot(layout);
}

From source file:com.purebred.core.view.Results.java

License:Open Source License

private TextField createFirstResultTextField() {
    TextField firstResultTextField = new TextField();
    firstResultTextField.setImmediate(true);
    firstResultTextField.setInvalidAllowed(true);
    firstResultTextField.setInvalidCommitted(false);
    firstResultTextField.setWriteThrough(true);
    firstResultTextField.addValidator(//from  w ww .  jav  a2 s .c  o m
            new IntegerValidator(uiMessageSource.getMessage("entityResults.firstResult.invalid")) {
                @Override
                protected boolean isValidString(String value) {
                    boolean isValid = super.isValidString(value);
                    if (!isValid) {
                        return false;
                    } else {
                        Integer intValue = Integer.parseInt(value);
                        if (getEntityQuery().getResultCount() > 0) {
                            return intValue >= 1 && intValue <= getEntityQuery().getResultCount();
                        } else {
                            return intValue == 0;
                        }
                    }
                }
            });
    firstResultTextField.setPropertyDataSource(new MethodProperty(getResultsTable(), "firstResult"));
    firstResultTextField.setWidth(3, Sizeable.UNITS_EM);

    return firstResultTextField;
}

From source file:com.rdonasco.common.vaadin.captcha.views.CaptchaFieldLayout.java

License:Apache License

public CaptchaFieldLayout() {
    setCaption(I18NResource.localize("Captcha"));
    captchaTextField = new TextField();
}

From source file:com.rdonasco.datamanager.listeditor.controller.ListEditorViewPanelController.java

License:Apache License

private void configureEditorTableBehavior() {
    if (null == getVisibleColumns()) {
        throw new IllegalStateException("visibleColumns not yet set");
    }//from   w ww. j a  v  a2  s .  c  o  m
    if (null == getColumnHeaders()) {
        throw new IllegalStateException("columnHeaders not yet set");
    }
    getEditorViewPanel().getEditorTable().setContainerDataSource(dataContainer);
    realVisibleColumns.add(TABLE_PROPERTY_ICON);
    realVisibleColumns.addAll(Arrays.asList(getVisibleColumns()));
    getEditorViewPanel().getEditorTable().setVisibleColumns(getEditableVisibleColumn());
    List<String> realColumnHeaders = new ArrayList<String>();
    realColumnHeaders.add(""); // empty header for the icon
    realColumnHeaders.addAll(Arrays.asList(getColumnHeaders()));
    getEditorViewPanel().getEditorTable().setColumnHeaders(realColumnHeaders.toArray(new String[0]));
    setupDefaultCellStyleGenerator();
    getEditorViewPanel().getEditorTable().setReadOnly(false);

    Table.ColumnGenerator columnGenerator = new Table.ColumnGenerator() {
        private static final long serialVersionUID = 1L;

        @Override
        public Object generateCell(final Table source, final Object itemId, final Object columnId) {
            final TextField textField = new TextField();
            try {
                textField.setPropertyDataSource(source.getContainerProperty(itemId, columnId));
            } catch (Exception ex) {
                LOG.log(Level.SEVERE, ex.getMessage(), ex);
            }
            textField.setReadOnly(true);
            textField.setWriteThrough(true);
            textField.setWidth(100f, TextField.UNITS_PERCENTAGE);
            addFieldToFieldCache(itemId, columnId, textField);
            textField.addListener(new FieldEvents.BlurListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void blur(FieldEvents.BlurEvent event) {
                    if (!textField.isReadOnly()) {
                        try {
                            BeanItem<VO> itemToUpdate = (BeanItem) source.getItem(itemId);
                            textField.commit();
                            if (null != itemToUpdate) {
                                dataContainer.updateItem(itemToUpdate.getBean());
                            } else {
                                LOG.log(Level.FINER, "warning, itemToUpdate is null");
                            }
                            textField.setReadOnly(true);
                        } catch (Exception ex) {
                            LOG.log(Level.SEVERE, ex.getMessage(), ex);
                            getPopupProvider().popUpError(I18NResource
                                    .localizeWithParameter("unable.to.update.record._", getItemName()));
                            textField.focus();
                            textField.selectAll();

                        }
                    }
                }
            });
            return textField;
        }
    };
    if (!getEditorViewPanel().isReadOnly()) {
        for (String propertyName : getVisibleColumns()) {
            getEditorViewPanel().getEditorTable().addGeneratedColumn(propertyName, columnGenerator);
        }
    }

    getEditorViewPanel().getEditorTable().addListener(tableClickListener);
    TableHelper.setupTable(getEditorViewPanel().getEditorTable());
}