List of usage examples for com.vaadin.ui HorizontalLayout HorizontalLayout
public HorizontalLayout()
From source file:com.github.fbhd.view.TicketView.java
private void createDetail() { detailLayout = new HorizontalLayout(); tfSummary = new TextField(); tfSummary.setInputPrompt("Summary"); detailLayout.addComponent(tfSummary); mainLayout.addComponent(detailLayout); }
From source file:com.github.fbhd.view.TicketView.java
private void createButtons() { buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true);/*from www. j a v a2s. c o m*/ Button btnSubmit = new Button("Submit"); btnSubmit.setStyleName(ValoTheme.BUTTON_PRIMARY); btnSubmit.addClickListener((Button.ClickEvent event) -> { persistAndContinue(ConfirmationView.VIEW_NAME); }); Button btnCancel = new Button("Cancel"); btnCancel.addClickListener((Button.ClickEvent event) -> { }); buttonLayout.addComponents(btnSubmit, btnCancel); mainLayout.addComponent(buttonLayout); }
From source file:com.github.lsiu.MyVaadinApplication.java
@Override public void init() { window = new Window("My Vaadin Application"); setMainWindow(window);//from w w w . j a v a 2 s.c o m VerticalLayout layout = new VerticalLayout(); layout.setSizeFull(); table = new FilterTable(); initTable(table); HorizontalLayout topBar = new HorizontalLayout(); initTopBar(topBar); layout.addComponent(topBar); layout.addComponent(table); layout.setExpandRatio(table, 1); window.setContent(layout); }
From source file:com.github.mjvesa.herd.HerdIDE.java
License:Apache License
private Component constructButtons() { HorizontalLayout hl = new HorizontalLayout(); hl.setSpacing(true);// w ww . j a v a 2 s . c om hl.addComponent(createRunButton()); hl.addComponent(createClearAndExecuteButton()); hl.addComponent(createClearConsoleButton()); hl.addComponent(createLogExecutedWordsCheckBox()); hl.addComponent(createLogAddedWordCheckBox()); return hl; }
From source file:com.github.mjvesa.herd.wordset.VaadinWordSet.java
License:Apache License
@Override public Word[] getWords() { return new Word[] { new BaseWord("new-button", "", Word.POSTPONED) { private static final long serialVersionUID = -2492817908731559368L; @Override//from w w w. j av a2 s .co m public void execute(final Interpreter interpreter) { Button b = new Button("", new Button.ClickListener() { private static final long serialVersionUID = -4622489800920283752L; @Override public void buttonClick(ClickEvent event) { Button b = event.getButton(); Word command = (Word) b.getData(); if (command != null) { interpreter.execute(command); } } }); interpreter.pushData(b); } }, new BaseWord("set-click-listener", "", Word.POSTPONED) { private static final long serialVersionUID = 5749856686458297558L; @Override public void execute(Interpreter interpreter) { Object o = interpreter.popData(); Button b = (Button) interpreter.popData(); b.setData(o); interpreter.pushData(b); } }, new BaseWord("new-hl", "", Word.POSTPONED) { private static final long serialVersionUID = 8813556668649386248L; @Override public void execute(Interpreter interpreter) { HorizontalLayout hl = new HorizontalLayout(); hl.setSpacing(true); interpreter.pushData(hl); } }, new BaseWord("new-vl", "", Word.POSTPONED) { private static final long serialVersionUID = -1848213448504804229L; @Override public void execute(Interpreter interpreter) { VerticalLayout vl = new VerticalLayout(); vl.setSpacing(true); interpreter.pushData(vl); } }, new BaseWord("new-gl", "( x y - gl )", Word.POSTPONED) { private static final long serialVersionUID = 4079634885691605257L; @Override public void execute(Interpreter interpreter) { Integer height = (Integer) interpreter.popData(); Integer width = (Integer) interpreter.popData(); interpreter.pushData(new GridLayout(width, height)); } }, new BaseWord("gl-new-line", "", Word.POSTPONED) { private static final long serialVersionUID = 975877390052961807L; @Override public void execute(Interpreter interpreter) { ((GridLayout) interpreter.peekData()).newLine(); } }, new BaseWord("new-window", "", Word.POSTPONED) { private static final long serialVersionUID = -6887364362728545090L; @Override public void execute(Interpreter interpreter) { Window w = new Window(); VerticalLayout vl = new VerticalLayout(); vl.setSpacing(true); w.setContent(vl); interpreter.pushData(w); interpreter.pushData(vl); } }, new BaseWord("main-panel", "", Word.POSTPONED) { private static final long serialVersionUID = -8622281600566696475L; @Override public void execute(Interpreter interpreter) { interpreter.pushData(interpreter.getMainPanel()); } }, new BaseWord("add-window", "", Word.POSTPONED) { private static final long serialVersionUID = 7106029415576813922L; @Override public void execute(Interpreter interpreter) { Window w = (Window) interpreter.popData(); interpreter.getView().getUI().addWindow(w); } }, new BaseWord("add-component", "", Word.POSTPONED) { private static final long serialVersionUID = 5640824046985354091L; @Override public void execute(Interpreter interpreter) { Component comp = (Component) interpreter.popData(); ComponentContainer cc = (ComponentContainer) interpreter.popData(); cc.addComponent(comp); interpreter.pushData(cc); } }, new BaseWord("set-caption", "", Word.POSTPONED) { private static final long serialVersionUID = 5497598050469462487L; @Override public void execute(Interpreter interpreter) { String s = (String) interpreter.popData(); Component c = (Component) interpreter.popData(); c.setCaption(s); interpreter.pushData(c); } }, new BaseWord("set-value", "", Word.POSTPONED) { private static final long serialVersionUID = -1769743552659215058L; @Override public void execute(Interpreter interpreter) { Object o = interpreter.popData(); Property p = (Property) interpreter.popData(); p.setValue(o); interpreter.pushData(p); } }, new BaseWord("get-value", "", Word.POSTPONED) { private static final long serialVersionUID = 8445550546521886374L; @Override public void execute(Interpreter interpreter) { Field f = (Field) interpreter.popData(); interpreter.pushData(f); interpreter.pushData(f.getValue()); } }, new BaseWord("set-size-full", "", Word.POSTPONED) { private static final long serialVersionUID = -1206491811133054467L; @Override public void execute(Interpreter interpreter) { Component comp = (Component) interpreter.popData(); comp.setSizeFull(); interpreter.pushData(comp); } }, new BaseWord("set-size-undefined", "", Word.POSTPONED) { private static final long serialVersionUID = -3450618729379622987L; @Override public void execute(Interpreter interpreter) { Component comp = (Component) interpreter.popData(); comp.setSizeUndefined(); interpreter.pushData(comp); } }, new BaseWord("set-height", "", Word.POSTPONED) { private static final long serialVersionUID = -8426734568403715950L; @Override public void execute(Interpreter interpreter) { String str = (String) interpreter.popData(); Component comp = (Component) interpreter.popData(); comp.setHeight(str); interpreter.pushData(comp); } }, new BaseWord("set-width", "", Word.POSTPONED) { private static final long serialVersionUID = -4558264143049463814L; @Override public void execute(Interpreter interpreter) { String str = (String) interpreter.popData(); Component comp = (Component) interpreter.popData(); comp.setWidth(str); interpreter.pushData(comp); } }, new BaseWord("clear-container", "", Word.POSTPONED) { private static final long serialVersionUID = 1070175466682034329L; @Override public void execute(Interpreter interpreter) { ComponentContainer cc = (ComponentContainer) interpreter.popData(); cc.removeAllComponents(); } }, new BaseWord("new-check-box", "", Word.POSTPONED) { private static final long serialVersionUID = 4018632924389912599L; @Override public void execute(Interpreter interpreter) { interpreter.pushData(new CheckBox()); } }, new BaseWord("new-date-field", "", Word.POSTPONED) { private static final long serialVersionUID = 6313296566085274642L; @Override public void execute(final Interpreter interpreter) { interpreter.pushData(new DateField()); final String dfCommand = (String) interpreter.popData(); DateField df = new DateField(); df.setImmediate(true); df.addValueChangeListener(new ValueChangeListener() { /** * */ private static final long serialVersionUID = 1472139878970514093L; public void valueChange(ValueChangeEvent event) { interpreter.pushData(event.getProperty().getValue()); interpreter.interpret(dfCommand); } }); interpreter.pushData(df); } }, new BaseWord("new-label", "", Word.POSTPONED) { private static final long serialVersionUID = -2825285195439247251L; @Override public void execute(Interpreter interpreter) { interpreter.pushData(new Label()); } }, new BaseWord("new-text-field", "", Word.POSTPONED) { private static final long serialVersionUID = -1064489458253275380L; @Override public void execute(final Interpreter interpreter) { final String tfCommand = interpreter.getNextNonNopWord(); TextField tf = new TextField(); tf.setCaption((String) interpreter.popData()); tf.setValue(""); tf.setImmediate(true); tf.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 4325104922208051065L; public void valueChange(ValueChangeEvent event) { interpreter.pushData(event.getProperty().getValue()); interpreter.interpret(tfCommand); } }); interpreter.pushData(tf); } }, new BaseWord("new-table", "", Word.POSTPONED) { private static final long serialVersionUID = -5052653341575232035L; @Override public void execute(final Interpreter interpreter) { final String tableCommand = interpreter.getParser().getNextWord(); Table table = new Table(); table.setCaption((String) interpreter.popData()); table.setImmediate(true); table.setSelectable(true); table.addItemClickListener(new ItemClickListener() { /** * */ private static final long serialVersionUID = 3585546076571010729L; public void itemClick(ItemClickEvent event) { interpreter.pushData(event.getItem()); interpreter.execute(interpreter.getDictionary().get(tableCommand)); } }); interpreter.pushData(table); } }, new BaseWord("new-combo-box", "", Word.POSTPONED) { private static final long serialVersionUID = 3881577354424928897L; @Override public void execute(final Interpreter interpreter) { final String newItemCommand = interpreter.getParser().getNextWord(); final String itemSelectedCommand = interpreter.getParser().getNextWord(); final ComboBox cb = new ComboBox(); String str = (String) interpreter.popData(); cb.setNullSelectionAllowed(false); cb.setCaption(str); cb.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ITEM); cb.setNewItemsAllowed(true); cb.setNewItemHandler(new NewItemHandler() { /** * */ private static final long serialVersionUID = 3340658590351611289L; public void addNewItem(String newItemCaption) { cb.setImmediate(false); interpreter.pushData(newItemCaption); interpreter.interpret(newItemCommand); cb.setImmediate(true); } }); cb.addValueChangeListener(new ValueChangeListener() { /** * */ private static final long serialVersionUID = 2706579869793251379L; public void valueChange(ValueChangeEvent event) { interpreter.pushData( cb.getContainerDataSource().getItem(event.getProperty().getValue())); interpreter.interpret(itemSelectedCommand); } }); cb.setImmediate(true); interpreter.pushData(cb); } }, new BaseWord("new-select", "", Word.POSTPONED) { private static final long serialVersionUID = -6142351970812196488L; @Override public void execute(final Interpreter interpreter) { final String selCommand = interpreter.getParser().getNextWord(); final ComboBox sel = new ComboBox(); sel.setCaption((String) interpreter.popData()); sel.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ITEM); sel.setNullSelectionAllowed(false); sel.setImmediate(true); sel.addValueChangeListener(new ValueChangeListener() { /** * */ private static final long serialVersionUID = -7705548618092166199L; public void valueChange(ValueChangeEvent event) { Item item = sel.getContainerDataSource().getItem(event.getProperty().getValue()); interpreter.pushData(item); interpreter.interpret(selCommand); } }); interpreter.pushData(sel); } }, new BaseWord("new-list-select", "", Word.POSTPONED) { private static final long serialVersionUID = 8686093227035249035L; @Override public void execute(final Interpreter interpreter) { final String lselCommand = interpreter.getParser().getNextWord(); final ListSelect lsel = new ListSelect(); lsel.setCaption((String) interpreter.popData()); lsel.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ITEM); lsel.setNullSelectionAllowed(false); lsel.setImmediate(true); lsel.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = -5523488417834167806L; public void valueChange(ValueChangeEvent event) { Item item = lsel.getContainerDataSource().getItem(event.getProperty().getValue()); interpreter.pushData(item); interpreter.interpret(lselCommand); } }); interpreter.pushData(lsel); } }, new BaseWord("set-container-data-source", "", Word.POSTPONED) { private static final long serialVersionUID = 8644721936358613031L; @Override public void execute(Interpreter interpreter) { Container cont = (Container) interpreter.popData(); AbstractSelect as = (AbstractSelect) interpreter.popData(); as.setContainerDataSource(cont); interpreter.pushData(as); } }, new BaseWord("set-column-headers", "", Word.POSTPONED) { private static final long serialVersionUID = -7296881714369214846L; @Override public void execute(Interpreter interpreter) { Table table = (Table) interpreter.popData(); table.setColumnHeaders((String[]) getArrayFromList(interpreter, new String[0])); } }, new BaseWord("set-visible-columns", "", Word.POSTPONED) { private static final long serialVersionUID = 5674765074478598320L; @Override public void execute(Interpreter interpreter) { Table table = (Table) interpreter.popData(); table.setVisibleColumns((String[]) getArrayFromList(interpreter, new String[0])); } } }; }
From source file:com.github.moscaville.contactsdb.AbstractSideBarUI.java
License:Apache License
@Override protected void init(VaadinRequest vaadinRequest) { getPage().setTitle("ContactsDb"); final HorizontalLayout rootLayout = new HorizontalLayout(); rootLayout.setSizeFull();/* w w w . j a va 2s. co m*/ setContent(rootLayout); final VerticalLayout viewContainer = new VerticalLayout(); viewContainer.setSizeFull(); final Navigator navigator = new Navigator(this, viewContainer); navigator.setErrorView(new ErrorView()); navigator.addProvider(viewProvider); setNavigator(navigator); rootLayout.addComponent(getSideBar()); rootLayout.addComponent(viewContainer); rootLayout.setExpandRatio(viewContainer, 1.0f); }
From source file:com.github.moscaville.contactsdb.main.ContactsView.java
@PostConstruct void init() {/*from w w w.jav a2 s . com*/ List<CategoryRecord> categories = categoryController.loadItems(100, 0, new CategoryRecord()); List<LevelRecord> levels = levelController.loadItems(100, 0, new LevelRecord()); List<RepresentativeRecord> representatives = representativeController.loadItems(100, 0, new RepresentativeRecord()); contactTable = new ContactTable(controller, categories, levels, representatives); btnEdit = new Button("Edit"); btnExport = new Button("Export"); btnColumns = new Button("Columns"); vLayout = new VerticalLayout(); vLayout.setMargin(true); vControls = new HorizontalLayout(); vControls.setSpacing(true); vControls.setMargin(true); vControls.addComponent(btnEdit); //vControls.addComponent(btnDuplicate); vControls.addComponent(btnExport); vControls.addComponent(btnColumns); hLayout.setSizeFull(); //contactTable = new ContactTable(); vLayout.addComponent(contactTable); vLayout.setHeight("75%"); addComponent(vControls); addComponent(vLayout); setSizeFull(); contactTable.addItemClickListener((ItemClickEvent event) -> { if (event.isDoubleClick()) { editContact(getSelectedContact()); } }); btnEdit.addClickListener((Button.ClickEvent event) -> { editContact(getSelectedContact()); }); btnColumns.addClickListener((Button.ClickEvent event) -> { contactTable.toggleVisibleColumns(); }); OnDemandFileDownloader fd = new OnDemandFileDownloader( new ExportOnDemandStreamResource(contactTable.getContainerDataSource())); fd.extend(btnExport); }
From source file:com.github.moscaville.contactsdb.main.DetailView.java
@PostConstruct private void init() { mainLayout = new VerticalLayout(); mainLayout.setSpacing(true);// w w w. j a v a2 s. c o m nameLayout = new HorizontalLayout(); nameLayout.setSpacing(true); companyName = createTextField("company name", nameLayout); firstName = createTextField("first name", nameLayout); lastName = createTextField("last name", nameLayout); emailPhoneLayout = new HorizontalLayout(); emailPhoneLayout.setSpacing(true); email = createTextField("email", emailPhoneLayout); cellPhone = createTextField("cell phone", emailPhoneLayout); workPhone = createTextField("work phone", emailPhoneLayout); List<CategoryRecord> categoryRecords = categoryController.loadItems(100, 0, new CategoryRecord()); categories = new ArrayList<>(); if (categoryRecords != null) { categoryRecords.stream().forEach((categoryRecord) -> { if (categoryRecord.getName() != null) { categories.add(categoryRecord); } }); } List<RepresentativeRecord> representativeRecords = representativeController.loadItems(100, 0, new RepresentativeRecord()); representatives = new ArrayList<>(); if (representativeRecords != null) { representativeRecords.stream().forEach((representativeRecord) -> { if (representativeRecord.getName() != null) { representatives.add(representativeRecord); } }); } List<LevelRecord> levelRecords = levelController.loadItems(100, 0, new LevelRecord()); levels = new ArrayList<>(); if (levelRecords != null) { levelRecords.stream().forEach((levelRecord) -> { if (levelRecord.getName() != null) { levels.add(levelRecord); } }); } classificationLayout = new HorizontalLayout(); classificationLayout.setSpacing(true); category = createComboBox("Category", categories, classificationLayout); account = createComboBox("Account", representatives, classificationLayout); level = createComboBox("Level", levels, classificationLayout); addressLayout = new HorizontalLayout(); addressLayout.setSpacing(true); addressLayout.setWidth("400px"); address = createTextField("address", addressLayout); address.setWidth("90%"); address2Layout = new HorizontalLayout(); address2Layout.setSpacing(true); city = createTextField("city", address2Layout); state = createTextField("state", address2Layout); zip = createTextField("zip", address2Layout); notesLayout = new HorizontalLayout(); notesLayout.setSpacing(true); notes = createNotesField("notes", notesLayout); buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); btnNew = new Button("New"); btnNew.addClickListener((Button.ClickEvent event) -> { contact = new ContactRecord(); bind(contact); }); buttonLayout.addComponent(btnNew); btnSave = new Button("Save"); btnSave.addClickListener((Button.ClickEvent event) -> { if (fieldGroup.isModified()) { try { fieldGroup.commit(); } catch (FieldGroup.CommitException ex) { Logger.getLogger(DetailView.class.getName()).log(Level.SEVERE, null, ex); } RecordWrapper<ContactRecord> recordWrapper = new RecordWrapper(); recordWrapper.setFields(contact); controller.saveItem(recordWrapper, contact.getId()); enableButtons(false); } }); buttonLayout.addComponent(btnSave); btnCancel = new Button("Cancel"); btnCancel.addClickListener((Button.ClickEvent event) -> { fieldGroup.discard(); enableButtons(false); }); buttonLayout.addComponent(btnCancel); btnDuplicate = new Button("Duplicate"); btnDuplicate.addClickListener((Button.ClickEvent event) -> { ContactRecord duplicate; try { duplicate = (ContactRecord) BeanUtils.cloneBean(contact); duplicate.setId(null); contact = duplicate; bind(contact); btnSave.setEnabled(false); btnCancel.setEnabled(false); } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException ex) { Logger.getLogger(DetailView.class.getName()).log(Level.SEVERE, null, ex); } }); buttonLayout.addComponent(btnDuplicate); btnDelete = new Button("Delete"); btnDelete.addClickListener((Button.ClickEvent event) -> { ConfirmDialog.show(MainUI.getCurrent(), "Are you sure?", (ConfirmDialog dialog) -> { if (dialog.isConfirmed()) { controller.deleteItem(contact.getId()); } }); }); buttonLayout.addComponent(btnDelete); mainLayout.addComponent(nameLayout); mainLayout.addComponent(classificationLayout); mainLayout.addComponent(emailPhoneLayout); mainLayout.addComponent(addressLayout); mainLayout.addComponent(address2Layout); mainLayout.addComponent(notesLayout); mainLayout.addComponent(buttonLayout); addComponent(mainLayout); bind(MainUI.get().getContact()); }
From source file:com.github.peholmst.springsecuritydemo.ui.CategoryBrowser.java
License:Apache License
/** * Creates the category browser component. *///from ww w. ja va2 s . co m @SuppressWarnings("serial") private void createComponent() { categoryContainer = new CategoryContainer(getCategoryService()); categoryContainer.refresh(); /* * The tree will show all the categories returned from the category * service. */ categoryTree = new Tree(); { categoryTree.setSizeFull(); categoryTree.setContainerDataSource(categoryContainer); categoryTree.setItemCaptionPropertyId("name"); categoryTree.setImmediate(true); } /* * The form for editing categories is hidden by default and is shown * when the user clicks the edit or add button. */ categoryForm = new CategoryForm(); /* * The toolbar will be placed at the bottom of the browser and contains * buttons for refreshing the category tree, and adding, editing and * removing categories. */ final HorizontalLayout toolbar = new HorizontalLayout(); { /* * Button: Refresh the category browser */ refreshButton = new Button(); refreshButton.setIcon(new ThemeResource("icons/16/refresh.png")); refreshButton.setStyleName("small"); refreshButton.setDescription(getI18nProvider().getMessage("categories.refresh.descr")); refreshButton.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { actionRefresh(); } }); toolbar.addComponent(refreshButton); /* * Button: Add a new category. The currently selected category will * be used as parent. */ addButton = new Button(); addButton.setIcon(new ThemeResource("icons/16/add.png")); addButton.setStyleName("small"); addButton.setDescription(getI18nProvider().getMessage("categories.add.descr")); addButton.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { actionAdd(); } }); toolbar.addComponent(addButton); /* * Button: Edit the selected category */ editButton = new Button(); editButton.setIcon(new ThemeResource("icons/16/pencil.png")); editButton.setStyleName("small"); editButton.setDescription(getI18nProvider().getMessage("categories.edit.descr")); editButton.setEnabled(false); editButton.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { actionEdit(); } }); toolbar.addComponent(editButton); /* * Button: Delete the selected category */ deleteButton = new Button(); deleteButton.setIcon(new ThemeResource("icons/16/delete.png")); deleteButton.setStyleName("small"); deleteButton.setDescription(getI18nProvider().getMessage("categories.delete.descr")); deleteButton.setEnabled(false); deleteButton.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { actionDelete(); } }); toolbar.addComponent(deleteButton); /* * Button: Show/edit the access control list for the selected * category */ aclButton = new Button(); aclButton.setIcon(new ThemeResource("icons/16/lock_edit.png")); aclButton.setStyleName("small"); aclButton.setDescription(getI18nProvider().getMessage("categories.acl.descr")); aclButton.setEnabled(false); aclButton.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { actionACL(); } }); toolbar.addComponent(aclButton); /* * Button: Show the audit log for the selected category */ auditButton = new Button(); auditButton.setIcon(new ThemeResource("icons/16/key.png")); auditButton.setStyleName("small"); auditButton.setDescription(getI18nProvider().getMessage("categories.audit.descr")); auditButton.setEnabled(false); auditButton.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { actionAudit(); } }); toolbar.addComponent(auditButton); } /* * The browser layout contains the category tree and the toolbar. */ browserComponent = new VerticalLayout(); browserComponent.setSizeFull(); browserComponent.addComponent(categoryTree); browserComponent.addComponent(categoryForm.getComponent()); browserComponent.addComponent(toolbar); browserComponent.setExpandRatio(categoryTree, 1.0f); browserComponent.setComponentAlignment(toolbar, Alignment.BOTTOM_CENTER); /* * Register a listener that updates the enablement state every time the * selection changes. */ categoryTree.addListener(new Property.ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { updateEnablementState(); Long newCategoryId = (Long) event.getProperty().getValue(); Category newCategory = null; if (newCategoryId != null) { BeanItem<Category> item = categoryContainer.getItem(newCategoryId); if (item != null) { newCategory = item.getBean(); } } fireCategorySelectionChanged(newCategory); } }); }
From source file:com.github.peholmst.springsecuritydemo.ui.LoginView.java
License:Apache License
@SuppressWarnings("serial") protected void init() { final Panel loginPanel = new Panel(); loginPanel.setCaption(getApplication().getMessage("login.title")); ((VerticalLayout) loginPanel.getContent()).setSpacing(true); final TextField username = new TextField(getApplication().getMessage("login.username")); username.setWidth("100%"); loginPanel.addComponent(username);/*from w ww . j ava 2 s. co m*/ final TextField password = new TextField(getApplication().getMessage("login.password")); password.setSecret(true); password.setWidth("100%"); loginPanel.addComponent(password); final Button loginButton = new Button(getApplication().getMessage("login.button")); loginButton.setStyleName("primary"); // TODO Make it possible to submit the form by pressing <Enter> in any // of the text fields loginPanel.addComponent(loginButton); ((VerticalLayout) loginPanel.getContent()).setComponentAlignment(loginButton, Alignment.MIDDLE_RIGHT); loginButton.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { final Authentication auth = new UsernamePasswordAuthenticationToken(username.getValue(), password.getValue()); try { if (logger.isDebugEnabled()) { logger.debug("Attempting authentication for user '" + auth.getName() + "'"); } Authentication returned = getAuthenticationManager().authenticate(auth); if (logger.isDebugEnabled()) { logger.debug("Authentication for user '" + auth.getName() + "' succeeded"); } fireEvent(new LoginEvent(LoginView.this, returned)); } catch (BadCredentialsException e) { if (logger.isDebugEnabled()) { logger.debug("Bad credentials for user '" + auth.getName() + "'", e); } getWindow().showNotification(getApplication().getMessage("login.badCredentials.title"), getApplication().getMessage("login.badCredentials.descr"), Notification.TYPE_WARNING_MESSAGE); } catch (DisabledException e) { if (logger.isDebugEnabled()) { logger.debug("Account disabled for user '" + auth.getName() + "'", e); } getWindow().showNotification(getApplication().getMessage("login.disabled.title"), getApplication().getMessage("login.disabled.descr"), Notification.TYPE_WARNING_MESSAGE); } catch (LockedException e) { if (logger.isDebugEnabled()) { logger.debug("Account locked for user '" + auth.getName() + "'", e); } getWindow().showNotification(getApplication().getMessage("login.locked.title"), getApplication().getMessage("login.locked.descr"), Notification.TYPE_WARNING_MESSAGE); } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error("Error while attempting authentication for user '" + auth.getName() + "'"); } ExceptionUtils.handleException(getWindow(), e); } } }); HorizontalLayout languages = new HorizontalLayout(); languages.setSpacing(true); final Button.ClickListener languageListener = new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { Locale locale = (Locale) event.getButton().getData(); if (logger.isDebugEnabled()) { logger.debug("Changing locale to [" + locale + "] and restarting the application"); } getApplication().setLocale(locale); getApplication().close(); } }; for (Locale locale : getApplication().getSupportedLocales()) { if (!getLocale().equals(locale)) { final Button languageButton = new Button(getApplication().getLocaleDisplayName(locale)); languageButton.setStyleName(Button.STYLE_LINK); languageButton.setData(locale); languageButton.addListener(languageListener); languages.addComponent(languageButton); } } loginPanel.addComponent(languages); loginPanel.setWidth("300px"); final HorizontalLayout viewLayout = new HorizontalLayout(); viewLayout.addComponent(loginPanel); viewLayout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER); viewLayout.setSizeFull(); viewLayout.setMargin(true); setCompositionRoot(viewLayout); setSizeFull(); }