List of usage examples for com.vaadin.ui TextField getValue
@Override
public String getValue()
From source file:uk.org.brindy.guessit.view.MainView.java
License:Apache License
@SuppressWarnings("serial") public MainView(final GuessItApp app) { System.out.println("MainView.MainView()"); VerticalLayout vbox = new VerticalLayout(); vbox.addComponent(new Label("Welcome to Guess It! A demo of Vaadin running in OSGi")); vbox.addComponent(new Label("What is your name?")); final TextField field = new TextField(); vbox.addComponent(field);//from w ww . jav a2s . c om Button button = new Button("Start"); button.setImmediate(true); button.addListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { Session session = null; if ("".equals(((String) field.getValue()).trim())) { session = new Session(app, "Anonymous"); } else { session = new Session(app, ((String) field.getValue()).trim()); } app.setUser(session); new GameView(app); } }); vbox.addComponent(button); app.getMainWindow().setContent(vbox); }
From source file:uk.org.brindy.guessit7.view.GameView.java
License:Apache License
@SuppressWarnings("serial") public GameView(final GuessItUI ui) { System.out.println("GameView.GameView()"); final Session session = (Session) ui.getUser(); if (!session.gameInProgress()) { session.startGame();//from w w w . j av a 2s. c o m } VerticalLayout vbox = new VerticalLayout(); vbox.addComponent(new Label("Hello " + session.name)); vbox.addComponent(new Label("Guess the number between 1 and 100")); final TextField number = new TextField(); vbox.addComponent(number); Button button = new Button("Guess"); button.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { try { if (session.guess(Integer.parseInt((String) number.getValue()))) { new WelldoneView(ui); } else { new GameView(ui); } } catch (NumberFormatException e) { session.guess(-1); new GameView(ui); } } }); switch (session.getHint()) { case NOGUESSES: // do nothing break; case HIGHER: vbox.addComponent(new Label("Try higher...")); break; case LOWER: vbox.addComponent(new Label("Not that high!")); break; case WRONG: vbox.addComponent(new Label("I didn't quite get that.")); break; } vbox.addComponent(button); vbox.addComponent(new Label("You have had " + session.getGuessCount() + " guesses")); ui.setContent(vbox); }
From source file:uk.org.brindy.guessit7.view.MainView.java
License:Apache License
@SuppressWarnings("serial") public MainView(final GuessItUI ui) { System.out.println("MainView.MainView()"); VerticalLayout vbox = new VerticalLayout(); vbox.addComponent(new Label("Welcome to Guess It! A demo of Vaadin running in OSGi")); vbox.addComponent(new Label("What is your name?")); final TextField field = new TextField(); vbox.addComponent(field);// w w w . j a va 2 s . com Button button = new Button("Start"); button.setImmediate(true); button.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { Session session = null; if ("".equals(((String) field.getValue()).trim())) { session = new Session(ui, "Anonymous"); } else { session = new Session(ui, ((String) field.getValue()).trim()); } ui.setUser(session); new GameView(ui); } }); vbox.addComponent(button); ui.setContent(vbox); }
From source file:views.MetadataUploadView.java
License:Open Source License
protected void createConditionWindow(ComboBox selectionBox) { String val = (String) selectionBox.getValue(); // val.equals("[Experimental Condition]") String header = " Experimental Condition Name"; String prefix = "Condition"; Resource icon = FontAwesome.FLASK; if (val.equals("[Other Property]")) { header = " Property Name"; prefix = "Property"; icon = FontAwesome.FILE_TEXT;//from ww w . j a v a2 s .c o m } final String category = prefix; Window subWindow = new Window(header); subWindow.setWidth("300px"); VerticalLayout layout = new VerticalLayout(); layout.setSpacing(true); layout.setMargin(true); TextField label = new TextField(); label.setRequired(true); label.setStyleName(Styles.fieldTheme); RegexpValidator factorLabelValidator = new RegexpValidator("([a-z]+_?[a-z]*)+([a-z]|[0-9]*)", "Name must start with a lower case letter and contain only lower case letter words, which can be connected by underscores ('_'). It can end with one or more numbers."); label.addValidator(factorLabelValidator); label.setValidationVisible(true); label.setImmediate(true); ComboBox unitSelect = new ComboBox("Unit"); unitSelect.setNullSelectionAllowed(false); unitSelect.addItems(properties.Unit.values()); String nullItem = "[None]"; unitSelect.addItem(nullItem); unitSelect.select(nullItem); unitSelect.setStyleName(Styles.boxTheme); unitSelect.setImmediate(true); Button send = new Button("Ok"); send.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (label.isValid()) { String unit = ""; if (!unitSelect.getValue().equals(nullItem)) unit = " [" + unitSelect.getValue() + "]"; String name = category + ": " + label.getValue() + unit; selectionBox.addItem(name); selectionBox.select(name); subWindow.close(); } else { String error = "Please input a name for this " + category + "."; if (!label.isEmpty()) error = factorLabelValidator.getErrorMessage(); Styles.notification("Missing Input", error, NotificationType.DEFAULT); } } }); layout.addComponent(label); layout.addComponent(unitSelect); layout.addComponent(send); subWindow.setContent(layout); // Center it in the browser window subWindow.center(); subWindow.setModal(true); subWindow.setIcon(icon); subWindow.setResizable(false); ProjectwizardUI ui = (ProjectwizardUI) UI.getCurrent(); ui.addWindow(subWindow); }