List of usage examples for com.vaadin.ui VerticalLayout setComponentAlignment
@Override public void setComponentAlignment(Component childComponent, Alignment alignment)
From source file:org.sensorhub.ui.ModuleTypeSelectionPopup.java
License:Mozilla Public License
public ModuleTypeSelectionPopup(final Class<?> moduleType, final ModuleTypeSelectionCallback callback) { super("Select Module Type"); VerticalLayout layout = new VerticalLayout(); // generate table with module list final Table table = new Table(); table.setSizeFull();// w w w. j a v a 2s. com table.setSelectable(true); table.setColumnReorderingAllowed(true); table.addContainerProperty(PROP_NAME, String.class, null); table.addContainerProperty(PROP_VERSION, String.class, null); table.addContainerProperty("desc", String.class, null); table.addContainerProperty("author", String.class, null); table.setColumnHeaders(new String[] { "Module Type", "Version", "Description", "Author" }); table.setPageLength(10); table.setMultiSelect(false); final Map<Object, IModuleProvider> providerMap = new HashMap<Object, IModuleProvider>(); for (IModuleProvider provider : SensorHub.getInstance().getModuleRegistry().getInstalledModuleTypes()) { Class<?> configClass = provider.getModuleConfigClass(); Class<?> moduleClass = provider.getModuleClass(); if (moduleType.isAssignableFrom(configClass) || moduleType.isAssignableFrom(moduleClass)) { Object id = table.addItem(new Object[] { provider.getModuleName(), provider.getModuleVersion(), provider.getModuleDescription(), provider.getProviderName() }, null); providerMap.put(id, provider); } } layout.addComponent(table); // add OK button Button okButton = new Button("OK"); okButton.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { Object selectedItemId = table.getValue(); String name = null; try { if (selectedItemId != null) { name = (String) table.getContainerProperty(selectedItemId, PROP_NAME).getValue(); IModuleProvider provider = providerMap.get(selectedItemId); Class<?> configClass = provider.getModuleConfigClass(); ModuleConfig config = (ModuleConfig) configClass.newInstance(); config.id = UUID.randomUUID().toString(); config.moduleClass = provider.getModuleClass().getCanonicalName(); config.name = "New " + name; config.enabled = false; // send back new config object callback.configSelected(moduleType, config); } } catch (Exception e) { close(); String version = (String) table.getContainerProperty(selectedItemId, PROP_VERSION).getValue(); String msg = "Cannot instantiate module " + name + " v" + version; Notification.show(msg, null, Notification.Type.ERROR_MESSAGE); AdminUI.log.error(msg, e); } finally { close(); } } }); layout.addComponent(okButton); layout.setComponentAlignment(okButton, Alignment.MIDDLE_CENTER); setContent(layout); center(); }
From source file:org.sensorhub.ui.ObjectTypeSelectionPopup.java
License:Mozilla Public License
public ObjectTypeSelectionPopup(String title, final Map<String, Class<?>> typeList, final ObjectTypeSelectionCallback callback) { super(title); VerticalLayout layout = new VerticalLayout(); // generate table with type list final Table table = new Table(); table.setSizeFull();//from ww w .j av a 2s . c om table.setSelectable(true); table.setColumnReorderingAllowed(true); table.addContainerProperty(UIConstants.PROP_NAME, String.class, null); table.setColumnHeaderMode(ColumnHeaderMode.HIDDEN); table.setPageLength(10); table.setMultiSelect(false); final Map<Object, Class<?>> idTypeMap = new HashMap<Object, Class<?>>(); for (Entry<String, Class<?>> item : typeList.entrySet()) { Object id = table.addItem(new Object[] { item.getKey() }, null); idTypeMap.put(id, item.getValue()); } layout.addComponent(table); // add OK button Button okButton = new Button("OK"); okButton.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { Object selectedItemId = table.getValue(); if (selectedItemId != null) { Class<?> clazz = idTypeMap.get(selectedItemId); if (clazz != null) callback.typeSelected(clazz); } close(); } }); layout.addComponent(okButton); layout.setComponentAlignment(okButton, Alignment.MIDDLE_CENTER); setContent(layout); center(); }
From source file:org.vaadin.addons.core.window.DialogWindow.java
License:Apache License
private VerticalLayout buildContent(String title, VaadinIcons type, Component content, ButtonType[] buttonTypes) {/*from w w w.j a v a2s . c o m*/ VerticalLayout root = new VerticalLayout(); root.setMargin(false); root.setSpacing(false); float width = -1; float height = 0; if (title != null) { HorizontalLayout header = new HorizontalLayout(); header.setMargin(true); header.setHeightUndefined(); header.setWidth("100%"); header.addStyleName(ValoTheme.WINDOW_TOP_TOOLBAR); Label l = new Label("<font size=\"4\">" + title + "</font>", ContentMode.HTML); width = l.getWidth(); header.addComponent(l); header.setComponentAlignment(l, Alignment.MIDDLE_LEFT); if (type != null) { Label i = new Label(type.getHtml(), ContentMode.HTML); header.addComponent(i); header.setComponentAlignment(i, Alignment.MIDDLE_RIGHT); } height = header.getHeight(); root.addComponent(header); } if (content != null) { content.setSizeFull(); HorizontalLayout contentRoot = new HorizontalLayout(content); contentRoot.setMargin(true); root.addComponent(contentRoot); height = height + contentRoot.getHeight(); } HorizontalLayout footer = new HorizontalLayout(); footer.setHeightUndefined(); footer.setWidth("100%"); footer.setMargin(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); HorizontalLayout buttons = new HorizontalLayout(); if (buttonTypes != null) { Stream.of(buttonTypes).forEach(buttonType -> { Button b = new Button(buttonType.getCaption()); if (buttonType.getIcon() != null) { b.setIcon(buttonType.getIcon()); } if (buttonType.getDescription() != null) { b.setDescription(buttonType.getDescription()); } if (buttonType.getStyle() != null) { b.addStyleName(buttonType.getStyle()); } b.addClickListener(event -> buttonType.getActions().forEach(buttonAction -> { ButtonTypeClickEvent event1 = new ButtonTypeClickEvent(buttonType, DialogWindow.this); buttonAction.getListener().buttonClick(event1); })); buttons.addComponent(b); }); } buttons.setSizeUndefined(); buttons.setMargin(false); buttons.setSpacing(true); footer.addComponent(buttons); footer.setComponentAlignment(buttons, Alignment.MIDDLE_RIGHT); if (buttons.getWidth() > width) { width = buttons.getWidth(); } root.addComponent(footer); root.setComponentAlignment(footer, Alignment.BOTTOM_LEFT); height = height + footer.getHeight(); root.setHeight(height, Unit.PIXELS); root.setWidth(width, Unit.PIXELS); return root; }
From source file:org.vaadin.addons.sitekit.viewlet.anonymous.ImageViewlet.java
License:Apache License
@Override public void attach() { super.attach(); final String logoImageThemeFileName = getViewletDescriptor().getConfiguration(); final VerticalLayout layout = new VerticalLayout(); layout.setMargin(false);//w w w. jav a 2 s. com final Embedded embedded = new Embedded(null, new ThemeResource(logoImageThemeFileName)); embedded.setWidth(32, UNITS_PIXELS); embedded.setHeight(32, UNITS_PIXELS); layout.addComponent(embedded); layout.setComponentAlignment(embedded, Alignment.MIDDLE_CENTER); this.setCompositionRoot(layout); }
From source file:org.vaadin.addons.sitekit.viewlet.user.ProfileImageViewlet.java
License:Apache License
@Override public void enter(final String parameters) { final String user = getSite().getSecurityProvider().getUser(); if (user == null) { final VerticalLayout layout = new VerticalLayout(); layout.setMargin(false);/*from w ww . java 2 s . c o m*/ final Link link = new Link(null, new ExternalResource("#!login")); link.setStyleName("gravatar"); link.setIcon(getSite().getIcon("view-icon-login")); link.setWidth(32, UNITS_PIXELS); link.setHeight(32, UNITS_PIXELS); layout.addComponent(link); layout.setComponentAlignment(link, Alignment.MIDDLE_CENTER); this.setCompositionRoot(layout); return; } try { final VerticalLayout layout = new VerticalLayout(); layout.setMargin(false); if (getSite().getSiteContext().getObject("gravatar-url") == null) { getSite().getSiteContext().putObject("gravatar-url", getGravatarUrl(user)); } final URL gravatarUrl = new URL((String) getSite().getSiteContext().getObject("gravatar-url")); //final Embedded embedded = new Embedded(null, new ExternalResource(gravatarUrl)); final Link link = new Link(null, new ExternalResource("http://www.gravatar.com/")); link.setStyleName("gravatar"); link.setIcon(new ExternalResource(gravatarUrl)); link.setWidth(32, UNITS_PIXELS); link.setHeight(32, UNITS_PIXELS); layout.addComponent(link); layout.setComponentAlignment(link, Alignment.MIDDLE_CENTER); this.setCompositionRoot(layout); } catch (final Exception e) { LOGGER.warn("Error reading gravatar image for user: " + user, e); } }
From source file:org.vaadin.alump.fancylayouts.demo.PanelDemo.java
License:Apache License
/** * Sample content with more stuff/*w w w .j a v a2 s .c o m*/ * * @return */ private ComponentContainer createPanelContentB() { VerticalLayout layout = new VerticalLayout(); layout.setWidth("100%"); layout.setMargin(true); layout.setSpacing(true); Label label = new Label(BECON_STR); layout.addComponent(label); Embedded image = new Embedded(); image.setSource(new ExternalResource("http://misc.siika.fi/kaljanhimo.jpg")); image.setWidth("300px"); image.setHeight("187px"); layout.addComponent(image); layout.setComponentAlignment(image, Alignment.MIDDLE_CENTER); Label label2 = new Label(BECON_STR); layout.addComponent(label2); return layout; }
From source file:org.vaadin.spring.samples.security.shared.LoginUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { getPage().setTitle("Vaadin Shared Security Demo Login"); FormLayout loginForm = new FormLayout(); loginForm.setSizeUndefined();/*from w w w . j a va 2 s. com*/ userName = new TextField("Username"); passwordField = new PasswordField("Password"); rememberMe = new CheckBox("Remember me"); login = new Button("Login"); loginForm.addComponent(userName); loginForm.addComponent(passwordField); loginForm.addComponent(rememberMe); loginForm.addComponent(login); login.addStyleName(ValoTheme.BUTTON_PRIMARY); login.setDisableOnClick(true); login.setClickShortcut(ShortcutAction.KeyCode.ENTER); login.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { login(); } }); VerticalLayout loginLayout = new VerticalLayout(); loginLayout.setSpacing(true); loginLayout.setSizeUndefined(); if (request.getParameter("logout") != null) { loggedOutLabel = new Label("You have been logged out!"); loggedOutLabel.addStyleName(ValoTheme.LABEL_SUCCESS); loggedOutLabel.setSizeUndefined(); loginLayout.addComponent(loggedOutLabel); loginLayout.setComponentAlignment(loggedOutLabel, Alignment.BOTTOM_CENTER); } loginLayout.addComponent(loginFailedLabel = new Label()); loginLayout.setComponentAlignment(loginFailedLabel, Alignment.BOTTOM_CENTER); loginFailedLabel.setSizeUndefined(); loginFailedLabel.addStyleName(ValoTheme.LABEL_FAILURE); loginFailedLabel.setVisible(false); loginLayout.addComponent(loginForm); loginLayout.setComponentAlignment(loginForm, Alignment.TOP_CENTER); VerticalLayout rootLayout = new VerticalLayout(loginLayout); rootLayout.setSizeFull(); rootLayout.setComponentAlignment(loginLayout, Alignment.MIDDLE_CENTER); setContent(rootLayout); setSizeFull(); }
From source file:org.vaadin.tori.view.thread.ReportComponent.java
License:Apache License
private Component newReportLayout() { final VerticalLayout layout = new VerticalLayout(); layout.setWidth("260px"); layout.setSpacing(true);/*from w ww . j ava 2 s . c o m*/ layout.setMargin(true); layout.addComponent(new Label("What's wrong with this post?")); final OptionGroup reason = new OptionGroup(); reason.addItem(Reason.SPAM); reason.setItemCaption(Reason.SPAM, "Spam"); reason.addItem(Reason.OFFENSIVE); reason.setItemCaption(Reason.OFFENSIVE, "Offensive, abusive or hateful."); reason.addItem(Reason.WRONG_CATEGORY); reason.setItemCaption(Reason.WRONG_CATEGORY, "Doesn't belong in the category."); reason.addItem(Reason.MODERATOR_ALERT); reason.setItemCaption(Reason.MODERATOR_ALERT, "A moderator should take a look at it."); reason.setImmediate(true); reason.addValueChangeListener(new OptionGroup.ValueChangeListener() { @Override public void valueChange(final ValueChangeEvent event) { explanationLayout.setVisible(reason.getValue() == Reason.MODERATOR_ALERT); reportButton.setEnabled(reason.getValue() != null); } }); layout.addComponent(reason); explanationLayout = new CssLayout(); explanationLayout.setStyleName("explanationlayout"); explanationLayout.addComponent(new Label("Here's why:")); final TextArea reasonText = createReasonTextArea(); explanationLayout.addComponent(reasonText); explanationLayout.setVisible(false); explanationLayout.setWidth("100%"); layout.addComponent(explanationLayout); final HorizontalLayout footer = new HorizontalLayout(); footer.setSpacing(true); layout.addComponent(footer); layout.setComponentAlignment(footer, Alignment.BOTTOM_RIGHT); reportButton = new Button("Report Post"); reportButton.addClickListener(new NativeButton.ClickListener() { @Override public void buttonClick(final ClickEvent event) { final URI l = Page.getCurrent().getLocation(); final String link = l.getScheme() + "://" + l.getAuthority() + l.getPath() + postPermalink; presenter.handlePostReport(post, (Reason) reason.getValue(), reasonText.getValue(), link); reportPopup.setPopupVisible(false); } }); reportButton.setEnabled(false); footer.addComponent(reportButton); final Button cancel = ComponentUtil.getSecondaryButton("Cancel", new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { reportPopup.setPopupVisible(false); } }); footer.addComponent(cancel); return layout; }
From source file:pl.adrian.pieper.biuwaw.UserPanel.java
public UserPanel(MainUI mainUI) { this.mainUI = mainUI; if (manager.isUserOnline()) { PartyService.getInstance(); // To remove userLabel.setValue(manager.getUser().getName()); comboBox.addItems(manager.getUser().getInvitations()); VerticalLayout root = new VerticalLayout(); Navigator.EmptyView emptyView = new Navigator.EmptyView(); HorizontalLayout userMenu = new HorizontalLayout(userLabel, newPartyButton, comboBox); userMenu.setWidth(40, Unit.PERCENTAGE); userMenu.setComponentAlignment(userLabel, Alignment.MIDDLE_CENTER); userMenu.setComponentAlignment(newPartyButton, Alignment.MIDDLE_CENTER); userMenu.setComponentAlignment(comboBox, Alignment.MIDDLE_CENTER); emptyView.setWidth(80, Unit.PERCENTAGE); emptyView.setHeightUndefined();// ww w . j a v a2 s .c o m root.addComponents(userMenu, emptyView); root.setComponentAlignment(userMenu, Alignment.MIDDLE_CENTER); root.setComponentAlignment(emptyView, Alignment.MIDDLE_CENTER); newPartyButton.addClickListener((com.vaadin.ui.Button.ClickEvent event) -> { userNavigator.navigateTo(MainUI.NEW_PARTY); }); comboBox.setCaption("Imprezy"); comboBox.addValueChangeListener((com.vaadin.data.Property.ValueChangeEvent event) -> { if (comboBox.getValue() instanceof Party) { Party party = (Party) comboBox.getValue(); userNavigator.navigateTo(MainUI.PARTY + "/" + party.getId()); } }); this.userNavigator = new Navigator(mainUI, emptyView); final NewPartyView newPartyView = new NewPartyView(userNavigator); userNavigator.addView("", new Navigator.EmptyView()); userNavigator.addView(NEW_PARTY, newPartyView); partyView = new PartyView(); userNavigator.addView(PARTY, partyView); setCompositionRoot(root); } }
From source file:pl.edu.agh.samm.testapp.SAMMTestApplication.java
License:Apache License
private Panel createChartsPanel() { VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.addComponent(slavesCountChart = new FlotChart("Slaves count", "#0062FF")); verticalLayout.setComponentAlignment(slavesCountChart, Alignment.TOP_CENTER); verticalLayout.addComponent(queueLengthCountChart = new FlotChart("Queue length", "#D11739")); verticalLayout.setComponentAlignment(queueLengthCountChart, Alignment.TOP_CENTER); verticalLayout/*w w w.j a v a 2s . co m*/ .addComponent(processedExpressionsCountChart = new FlotChart("Processed expressions", "#1ABD28")); verticalLayout.setComponentAlignment(processedExpressionsCountChart, Alignment.TOP_CENTER); return new Panel("Charts", verticalLayout); }