List of usage examples for com.vaadin.ui Button addListener
@Override
public Registration addListener(Component.Listener listener)
From source file:se.natusoft.osgi.aps.apsuseradminweb.vaadin.components.editors.RoleDeleteEditor.java
License:Open Source License
/** * Creates a new RoleDeleteEditor instance. * * @param userServiceAdmin The user admin service for editing the role. *//*from w ww.ja v a 2 s . co m*/ public RoleDeleteEditor(APSSimpleUserServiceAdmin userServiceAdmin) { this.userServiceAdmin = userServiceAdmin; this.setStyleName(CSS.APS_EDITING_TEXT); VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setMargin(true); verticalLayout.setSpacing(true); verticalLayout.setStyleName(CSS.APS_EDITING_TEXT + " " + CSS.APS_CONTENT_PANEL); this.idPanel = new Panel(); this.idPanel.setCaption("Role id"); this.idLabel = new Label(""); this.idPanel.addComponent(this.idLabel); verticalLayout.addComponent(idPanel); this.descriptionPanel = new Panel(); this.descriptionPanel.setCaption("Description"); this.descriptionLabel = new Label(""); this.descriptionPanel.addComponent(this.descriptionLabel); verticalLayout.addComponent(this.descriptionPanel); this.subRolesPanel = new Panel(); this.subRolesPanel.setCaption("Sub roles"); this.subRolesLabel = new Label(""); this.subRolesPanel.addComponent(this.subRolesLabel); verticalLayout.addComponent(this.subRolesPanel); HorizontalLayout horizontalLayout = new HorizontalLayout(); verticalLayout.addComponent(horizontalLayout); horizontalLayout.setSpacing(true); Button deleteButton = new Button("Delete"); deleteButton.addListener(new Button.ClickListener() { /** Click handling. */ @Override public void buttonClick(Button.ClickEvent event) { delete(); } }); horizontalLayout.addComponent(deleteButton); Button cancelButton = new Button("Cancel"); cancelButton.addListener(new Button.ClickListener() { /** Click handling. */ @Override public void buttonClick(Button.ClickEvent event) { cancel(); } }); horizontalLayout.addComponent(cancelButton); setContent(verticalLayout); }
From source file:se.natusoft.osgi.aps.apsuseradminweb.vaadin.components.editors.RoleEditor.java
License:Open Source License
/** * Creates a new RoleEditor instance./*from www .j a va 2 s . co m*/ * * @param userServiceAdmin The user admin service for editing the role. */ public RoleEditor(APSSimpleUserServiceAdmin userServiceAdmin) { this.userServiceAdmin = userServiceAdmin; this.setStyleName(CSS.APS_EDITING_TEXT); VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setMargin(true); verticalLayout.setSpacing(true); verticalLayout.setStyleName(CSS.APS_EDITING_TEXT + " " + CSS.APS_CONTENT_PANEL); // Role id, master and description. { HorizontalLayout horizLayout = new HorizontalLayout(); horizLayout.setSpacing(true); this.idTextField = new TextField("Role id"); this.idTextField.setColumns(30); this.idTextField.setImmediate(false); this.idTextField.setEnabled(true); horizLayout.addComponent(this.idTextField); this.masterRole = new CheckBox("Master Role"); this.masterRole.setImmediate(false); this.masterRole.setEnabled(true); horizLayout.addComponent(this.masterRole); verticalLayout.addComponent(horizLayout); this.descriptionTextArea = new TextArea("Description of role"); this.descriptionTextArea.setRows(3); this.descriptionTextArea.setColumns(60); this.descriptionTextArea.setImmediate(false); this.descriptionTextArea.setEnabled(true); verticalLayout.addComponent(this.descriptionTextArea); } // Roles { HorizontalLayout rolesLayout = new HorizontalLayout(); rolesLayout.setSizeFull(); // Available this.availableRoles = new Table("Available roles"); this.availableRoles.setImmediate(true); this.availableRoles.setPageLength(10); this.availableRoles.setSortAscending(true); this.availableRoles.setSizeFull(); this.availableRoles.setDragMode(Table.TableDragMode.ROW); this.availableRoles.setDropHandler(new DropHandler() { @Override public void drop(DragAndDropEvent event) { DataBoundTransferable t = (DataBoundTransferable) event.getTransferable(); Object itemId = t.getItemId(); removeSubRole(itemId); } @Override public AcceptCriterion getAcceptCriterion() { return new RoleAcceptCriterion(RoleEditor.this.availableRoles); } }); VerticalLayout availableRolesFrame = new VerticalLayout(); availableRolesFrame.setMargin(false, true, false, false); availableRolesFrame.addComponent(this.availableRoles); rolesLayout.addComponent(availableRolesFrame); // Selected this.selectedRoles = new Table("Selected sub roles of the role"); this.selectedRoles.setImmediate(true); this.selectedRoles.setPageLength(10); this.selectedRoles.setSortAscending(true); this.selectedRoles.setSizeFull(); this.selectedRoles.setDragMode(Table.TableDragMode.ROW); this.selectedRoles.setDropHandler(new DropHandler() { @Override public void drop(DragAndDropEvent event) { DataBoundTransferable t = (DataBoundTransferable) event.getTransferable(); Object itemId = t.getItemId(); addSubRole(itemId); } @Override public AcceptCriterion getAcceptCriterion() { return new RoleAcceptCriterion(RoleEditor.this.selectedRoles); } }); VerticalLayout selectedRolesFrame = new VerticalLayout(); selectedRolesFrame.setMargin(false, false, false, true); selectedRolesFrame.addComponent(this.selectedRoles); rolesLayout.addComponent(selectedRolesFrame); rolesLayout.setExpandRatio(availableRolesFrame, 0.5f); rolesLayout.setExpandRatio(selectedRolesFrame, 0.5f); verticalLayout.addComponent(rolesLayout); /* Help text for the role tables. */ HelpText roleHelptext = new HelpText( "Drag and drop roles back and forth to set or remove a role. Also note that it is fully possible to " + "create circular role dependencies. Don't!"); verticalLayout.addComponent(roleHelptext); } // Save / Cancel { HorizontalLayout horizontalLayout = new HorizontalLayout(); verticalLayout.addComponent(horizontalLayout); horizontalLayout.setSpacing(true); Button saveButton = new Button("Save"); saveButton.addListener(new Button.ClickListener() { /** Click handling. */ @Override public void buttonClick(Button.ClickEvent event) { save(); } }); horizontalLayout.addComponent(saveButton); Button cancelButton = new Button("Cancel"); cancelButton.addListener(new Button.ClickListener() { /** Click handling. */ @Override public void buttonClick(Button.ClickEvent event) { cancel(); } }); horizontalLayout.addComponent(cancelButton); } setContent(verticalLayout); }
From source file:se.natusoft.osgi.aps.apsuseradminweb.vaadin.components.editors.UserEditor.java
License:Open Source License
/** * Creates a new UserEditor instance.//from www. j av a 2 s .co m * * @param userServiceAdmin The user admin service for editing the user. */ public UserEditor(APSSimpleUserServiceAdmin userServiceAdmin) { this.userServiceAdmin = userServiceAdmin; this.setStyleName(CSS.APS_EDITING_TEXT); VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setSpacing(true); verticalLayout.setMargin(true); verticalLayout.setStyleName(CSS.APS_EDITING_TEXT + " " + CSS.APS_CONTENT_PANEL); // User id & Auth { HorizontalLayout firstRowLayout = new HorizontalLayout(); firstRowLayout.setSpacing(true); this.userId = new TextField("User id"); this.userId.setColumns(30); this.userId.setImmediate(true); this.userId.setEnabled(true); firstRowLayout.addComponent(this.userId); this.authCurrent = new PasswordField("Current auth"); this.authCurrent.setColumns(30); this.authCurrent.setImmediate(true); this.authCurrent.setEnabled(true); firstRowLayout.addComponent(this.authCurrent); verticalLayout.addComponent(firstRowLayout); HorizontalLayout secondRowLayout = new HorizontalLayout(); secondRowLayout.setSpacing(true); this.authNewOne = new PasswordField("New auth"); this.authNewOne.setColumns(30); this.authNewOne.setImmediate(true); this.authNewOne.setEnabled(true); secondRowLayout.addComponent(this.authNewOne); this.authNewTwo = new PasswordField("New auth confirm"); this.authNewTwo.setColumns(30); this.authNewTwo.setImmediate(true); this.authNewTwo.setEnabled(true); secondRowLayout.addComponent(this.authNewTwo); verticalLayout.addComponent(secondRowLayout); } // User Properties { this.propertiesEditor = new Table(); this.propertiesEditor.setSelectable(true); this.propertiesEditor.setCaption("User properties"); this.propertiesEditor.setPageLength(8); this.propertiesEditor.setEditable(true); this.propertiesEditor.setSizeFull(); this.propertiesEditor.setColumnExpandRatio(USER_PROPS_KEY, 0.3f); this.propertiesEditor.setColumnExpandRatio(USER_PROPS_VALUE, 0.7f); this.propertiesEditor.setTableFieldFactory(new EditFieldFactory()); this.propertiesEditor.addListener(new ItemClickEvent.ItemClickListener() { @Override public void itemClick(ItemClickEvent event) { selectDeselectProperty(event.getItemId()); } }); verticalLayout.addComponent(this.propertiesEditor); // Buttons + info row { HorizontalLayout plusMinusRow = new HorizontalLayout(); plusMinusRow.setSpacing(true); this.plusButton = new Button("+"); this.plusButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { addProperty(); } }); plusMinusRow.addComponent(this.plusButton); this.minusButton = new Button("-"); this.minusButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { deleteProperty(); } }); this.minusButton.setEnabled(false); plusMinusRow.addComponent(this.minusButton); this.propsHelpText = new HelpText( "Press + to add new property, select property and press - to delete."); plusMinusRow.addComponent(this.propsHelpText); verticalLayout.addComponent(plusMinusRow); } } // Roles { HorizontalLayout rolesLayout = new HorizontalLayout(); rolesLayout.setSizeFull(); // Available this.availableRoles = new Table("Available roles"); this.availableRoles.setImmediate(true); this.availableRoles.setPageLength(10); this.availableRoles.setSortAscending(true); this.availableRoles.setSizeFull(); this.availableRoles.setDragMode(Table.TableDragMode.ROW); this.availableRoles.setDropHandler(new DropHandler() { @Override public void drop(DragAndDropEvent event) { DataBoundTransferable t = (DataBoundTransferable) event.getTransferable(); Object itemId = t.getItemId(); removeRole(itemId); } @Override public AcceptCriterion getAcceptCriterion() { return new RoleAcceptCriterion(UserEditor.this.availableRoles); } }); VerticalLayout availableRolesFrame = new VerticalLayout(); availableRolesFrame.setMargin(false, true, false, false); availableRolesFrame.addComponent(this.availableRoles); rolesLayout.addComponent(availableRolesFrame); // Selected this.selectedRoles = new Table("Selected roles"); this.selectedRoles.setImmediate(true); this.selectedRoles.setPageLength(10); this.selectedRoles.setSortAscending(true); this.selectedRoles.setSizeFull(); this.selectedRoles.setDragMode(Table.TableDragMode.ROW); this.selectedRoles.setDropHandler(new DropHandler() { @Override public void drop(DragAndDropEvent event) { DataBoundTransferable t = (DataBoundTransferable) event.getTransferable(); Object itemId = t.getItemId(); addRole(itemId); } @Override public AcceptCriterion getAcceptCriterion() { return new RoleAcceptCriterion(UserEditor.this.selectedRoles); } }); VerticalLayout selectedRolesFrame = new VerticalLayout(); selectedRolesFrame.setMargin(false, false, false, true); selectedRolesFrame.addComponent(this.selectedRoles); rolesLayout.addComponent(selectedRolesFrame); rolesLayout.setExpandRatio(availableRolesFrame, 0.5f); rolesLayout.setExpandRatio(selectedRolesFrame, 0.5f); verticalLayout.addComponent(rolesLayout); this.roleHelptext = new HelpText("Drag and drop roles back and forth to set or remove a role."); verticalLayout.addComponent(this.roleHelptext); } // Save & Cancel { HorizontalLayout saveCancelLayout = new HorizontalLayout(); saveCancelLayout.setSpacing(true); this.saveButton = new Button("Save"); this.saveButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { save(); } }); saveCancelLayout.addComponent(saveButton); Button cancelButton = new Button("Cancel"); cancelButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { cancel(); } }); saveCancelLayout.addComponent(cancelButton); verticalLayout.addComponent(saveCancelLayout); } setContent(verticalLayout); }
From source file:se.natusoft.osgi.aps.tools.web.vaadin.VaadinLoginDialogHandler.java
License:Open Source License
/** * Creates a new VaadinLoginDialogHandler. * * @param appWindow The Vaadin application window to add the popup login dialog to. * @param loginHandler A handler for doing the login from the login dialog input. *//*from ww w . j a v a 2 s. c om*/ public VaadinLoginDialogHandler(Window appWindow, LoginHandler loginHandler) { this.appWindow = appWindow; this.loginHandler = loginHandler; // Create Login window dialog this.loginWindow = new Window("Login"); this.loginWindow.setModal(true); this.loginWindow.setWidth("300px"); VerticalLayout dialogLayout = new VerticalLayout(); dialogLayout.setSpacing(true); dialogLayout.setMargin(true); this.userName = new TextField("User:"); this.userName.setColumns(20); dialogLayout.addComponent(this.userName); this.password = new PasswordField("Password"); this.password.setColumns(20); this.password.setImmediate(true); this.password.addListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { login(); } }); dialogLayout.addComponent(password); Button loginButton = new Button("Login"); loginButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { login(); } }); dialogLayout.addComponent(loginButton); this.loginWindow.setContent(dialogLayout); }
From source file:taxi.com.MyVaadinApplication.java
License:Apache License
@Override public void init() { window = new Window("My Vaadin Application"); setMainWindow(window);/* www. j a va 2s .c o m*/ Button button = new Button("Click Me"); button.addListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { window.addComponent(new ApplicationMainLayout()); } }); window.addComponent(button); }
From source file:uk.org.brindy.guessit.view.GameView.java
License:Apache License
@SuppressWarnings("serial") public GameView(final GuessItApp app) { System.out.println("GameView.GameView()"); final Session session = (Session) app.getUser(); if (!session.gameInProgress()) { session.startGame();//from w w w. j a va 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.addListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { try { if (session.guess(Integer.parseInt((String) number.getValue()))) { new WelldoneView(app); } else { new GameView(app); } } catch (NumberFormatException e) { session.guess(-1); new GameView(app); } } }); 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")); app.getMainWindow().setContent(vbox); }
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);// w w w. ja v a2s.c o m 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.guessit.view.WelldoneView.java
License:Apache License
@SuppressWarnings("serial") public WelldoneView(final GuessItApp app) { System.out.println("WelldoneView.WelldoneView()"); final Session session = (Session) app.getUser(); VerticalLayout vbox = new VerticalLayout(); vbox.addComponent(new Label("Yay! You guessed it in " + session.getGuessCount() + " guesses")); Button button = new Button("Play again"); button.addListener(new ClickListener() { @Override//from w w w.java 2s . c om public void buttonClick(ClickEvent event) { session.startGame(); new GameView(app); } }); vbox.addComponent(button); app.getMainWindow().setContent(vbox); }
From source file:v7cr.ProjectEditor.java
License:Open Source License
ProjectEditor(V7CR v7) { setCaption(v7.getMessage("projectEditor.name")); setIcon(new ThemeResource("../runo/icons/16/settings.png")); reload(v7);//from ww w .j a va2 s .co m projTable.setSelectable(true); projTable.addListener(this); rightSide.setWidth("500"); HorizontalLayout hl = new HorizontalLayout(); hl.setWidth("100%"); VerticalLayout leftSide = new VerticalLayout(); leftSide.addComponent(projTable); Button add = new Button(v7.getMessage("button.newProject")); add.addListener(this); leftSide.addComponent(add); hl.addComponent(leftSide); hl.addComponent(rightSide); setCompositionRoot(hl); }
From source file:v7cr.ProjectEditor.java
License:Open Source License
public void itemClick(ItemClickEvent event) { String projectId = (String) event.getItemId(); if (projectId == null) return;// w w w . ja v a2 s . c o m V7CR v7 = V7CR.getInstance(); final Project p = new Project(v7.load("projects", projectId)); final DBObject b = p.getDBObject(); rightSide.removeAllComponents(); rightSide.addComponent(new Label(projectId)); final Form form = new Form(); rightSide.addComponent(form); form.setFormFieldFactory(new BSONFormFieldFactory(p.getSchemaDefinition())); form.setItemDataSource(new BSONItem(b)); form.setVisibleItemProperties(new String[] { "name", "repo", "viewChanges" }); form.setWidth("100%"); Button submit = new Button(v7.getMessage("button.submit")); rightSide.addComponent(submit); submit.addListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { form.commit(); V7CR v7 = V7CR.getInstance(); v7.update("projects", b); rightSide.removeAllComponents(); reload(v7); } }); }