List of usage examples for com.vaadin.ui Component setCaption
public void setCaption(String caption);
From source file:com.mymita.vaadlets.VaadletsBuilder.java
License:Apache License
private static void setComponentAttributes(final com.vaadin.ui.Component vaadinComponent, final com.mymita.vaadlets.core.Component c) { vaadinComponent.setCaption(c.getCaption()); vaadinComponent.setEnabled(c.isEnabled()); vaadinComponent.setReadOnly(c.isReadonly()); vaadinComponent.setVisible(c.isVisible()); if (c.getHeight() != null) { vaadinComponent.setHeight(c.getHeight()); }/*from w w w . j av a 2 s . com*/ if (c.getWidth() != null) { vaadinComponent.setWidth(c.getWidth()); } if (c.isSizeUndefined() != null && c.isSizeUndefined().booleanValue()) { vaadinComponent.setSizeUndefined(); } if (c.isSizeFull() != null && c.isSizeFull().booleanValue()) { vaadinComponent.setSizeFull(); } }
From source file:com.vaadHL.i18n.VaadHLi18n.java
License:Apache License
@SuppressWarnings("unchecked") public void changeAll(HasComponents root) { for (Component child : root) { if (child instanceof HasComponents) { changeAll((HasComponents) child); } else {//from w ww . jav a 2 s .c o m String s; s = valueI18(child, "caption"); if (s != null) child.setCaption(s); if (child instanceof Property) { s = valueI18(child, "value"); if (s != null) ((Property<String>) child).setValue(s); } } } }
From source file:com.validation.manager.core.VaadinUtils.java
License:Apache License
/** * Change all {@code Locale} dependant properties of the * {@code com.vaadin.ui.Component}s within of the given component container * (typically an {@link UI} or other top level layout component). If the * specified {@code Locale} is the same as the current {@code Locale} of the * component container, this method does nothing. Otherwise it'll go thru * the components searching for it's component id. If it is in the resource * bundle, it'll set it's caption to the right translated string. * * <p>/*from w w w . j ava 2s.c o m*/ * To use this method, do something like: * <pre> * public class MyUI extends UI { * * {@literal @}Override * public void init(final VaadinRequest request) { * // ... usual code * // somewhere in the UI the user can change the "Form Locale". This code must * // call myUI#setLocale(newLocale); * } * * // ... * * } * * String key = "demo.tab.message"; * VerticalLayout vl = new VerticalLayout(); * Button b = new Button(key); * vl.addComponent(b); * ResourceBundle rb = ResourceBundle.getBundle( * "resource.bundle", * new Locale("es")); * VaadinUtils.updateLocale(vl, new Locale("es"), rb); * * It also works with components implementing Property: * * VerticalLayout vl = new VerticalLayout(); * Label l = new Label(key); * vl.addComponent(l); * ResourceBundle rb = ResourceBundle.getBundle( * "resource.bundle", * new Locale("es")); * VaadinUtils.updateLocale(vl, new Locale("es"), rb); * </pre> * * @param ui The component container for which the {@code Locale} dependent * component properties must be changed, never {@code null} * @param locale The new {@code Locale}, never {@code null} * @param rb The {@code ResourceBundle} for the specified {@code Locale}, * never {@code null} */ public static void updateLocale(final HasComponents ui, final Locale locale, final ResourceBundle rb) { // locale may not be null, however the current UI Locale may be null! if (locale.equals(ui.getLocale())) { return; } final long time = System.currentTimeMillis(); walkComponentTree(ui, (Component c) -> { String id = c.getId(); String caption; if (c instanceof Property && ((Property) c).getValue() instanceof String) { caption = (String) ((Property) c).getValue(); } else { caption = c.getCaption(); } if (id != null && !id.trim().isEmpty()) { if (rb.containsKey(id)) { try { c.setCaption(new String(rb.getString(id).getBytes("ISO-8859-1"), "UTF-8")); } catch (UnsupportedEncodingException ex) { LOG.log(Level.SEVERE, null, ex); } } } else if (caption != null && !caption.trim().isEmpty()) { /** * This is a more complex scenario where the caption uses more * than one key for translation. Sort the keys in reverse so * substitutions are correct. */ final SortedSet<String> ss = new TreeSet<>(Collections.reverseOrder()); for (Enumeration<String> e = rb.getKeys(); e.hasMoreElements();) { try { String key = e.nextElement(); ss.add(key); caption = caption.replaceAll(key, new String(rb.getString(key).getBytes("ISO-8859-1"), "UTF-8")); } catch (UnsupportedEncodingException ex) { LOG.log(Level.SEVERE, null, ex); } } if (c instanceof Property) { ((Property) c).setValue(caption); } else { c.setCaption(caption); } } }); LOG.log(Level.FINE, "Locale updated: {0} -> {1} in {2} ms.", new Object[] { ui.getLocale(), locale, System.currentTimeMillis() - time }); }
From source file:helpers.Utils.java
License:Open Source License
public static HorizontalLayout questionize(Component c, final String info, final String header) { final HorizontalLayout res = new HorizontalLayout(); res.setSpacing(true);/*from w ww . j a v a 2s . c o m*/ if (c instanceof CustomVisibilityComponent) { CustomVisibilityComponent custom = (CustomVisibilityComponent) c; c = custom.getInnerComponent(); custom.addListener(new VisibilityChangeListener() { @Override public void setVisible(boolean b) { res.setVisible(b); } }); } res.setVisible(c.isVisible()); res.setCaption(c.getCaption()); c.setCaption(null); res.addComponent(c); PopupView pv = new PopupView(new Content() { @Override public Component getPopupComponent() { Label l = new Label(info, ContentMode.HTML); l.setCaption(header); l.setIcon(FontAwesome.INFO); l.setWidth("250px"); l.addStyleName("info"); return new VerticalLayout(l); } @Override public String getMinimizedValueAsHTML() { return "[?]"; } }); pv.setHideOnMouseOut(false); res.addComponent(pv); return res; }
From source file:org.azrul.langkuik.framework.webgui.BeanView.java
private void createForm(EntityRight entityRight, final Set<String> currentUserRoles, final Map<String, Map<Integer, FieldContainer>> groups, String group, final BeanFieldGroup fieldGroup, final List<DataAccessObject<?>> customTypeDaos, final Navigator nav, final FormLayout form) throws FieldGroup.BindException, UnsupportedOperationException { //create bean utils final BeanUtils beanUtils = new BeanUtils(); //select which group we want Map<Integer, FieldContainer> fieldContainerMap = null; if (group == null) { fieldContainerMap = groups.entrySet().iterator().next().getValue(); } else {// w ww. j ava 2 s. com fieldContainerMap = groups.get(group); } //collect all activechoices Map<com.vaadin.ui.ComboBox, ActiveChoiceTarget> activeChoicesWithFieldAsKey = new HashMap<>(); Map<String, com.vaadin.ui.ComboBox> activeChoicesFieldWithHierarchyAsKey = new HashMap<>(); //collect all cutsom types List<Class> customTypes = new ArrayList<>(); for (DataAccessObject<?> ctDao : customTypeDaos) { customTypes.add(ctDao.getType()); } //deal with every field everyField: for (Map.Entry<Integer, FieldContainer> entry : fieldContainerMap.entrySet()) { final FieldContainer fieldContainer = entry.getValue(); final ComponentState effectiveFieldState = beanUtils .calculateEffectiveComponentState(fieldContainer.getPojoField(), currentUserRoles, entityRight); //Create form if (ComponentState.INVISIBLE.equals(effectiveFieldState)) { continue everyField; //Continue with next field } //deal with normal form element com.vaadin.ui.Field uifield = null; //deal with plain choices if (fieldContainer.getWebField().choices().length > 0) { //deal with choices com.vaadin.ui.ComboBox formComboBox = new com.vaadin.ui.ComboBox( fieldContainer.getWebField().name()); formComboBox.setImmediate(true); fieldGroup.bind(formComboBox, fieldContainer.getPojoField().getName()); for (Choice choice : fieldContainer.getWebField().choices()) { if (choice.value() == -1) { formComboBox.addItem(choice.textValue()); formComboBox.setItemCaption(choice.textValue(), choice.display()); } else { formComboBox.addItem(choice.value()); formComboBox.setItemCaption(choice.value(), choice.display()); } } form.addComponent(formComboBox); uifield = formComboBox; //deal with active choices } else if (fieldContainer.getWebField().activeChoice().enumTree() != EmptyEnum.class) { //collect active choices - com.vaadin.ui.ComboBox formComboBox = new com.vaadin.ui.ComboBox( fieldContainer.getWebField().name()); formComboBox.setImmediate(true); fieldGroup.bind(formComboBox, fieldContainer.getPojoField().getName()); String hierarchy = fieldContainer.getWebField().activeChoice().hierarchy(); Class<ActiveChoiceEnum> enumTree = (Class<ActiveChoiceEnum>) fieldContainer.getWebField() .activeChoice().enumTree(); ActiveChoiceTarget activeChoiceTarget = ActiveChoiceUtils.build(enumTree, hierarchy); for (String choice : activeChoiceTarget.getSourceChoices()) { formComboBox.addItem(choice); activeChoicesWithFieldAsKey.put(formComboBox, activeChoiceTarget); activeChoicesFieldWithHierarchyAsKey.put(hierarchy, formComboBox); } form.addComponent(formComboBox); uifield = formComboBox; //deal with relationship } else if (fieldContainer.getPojoField().isAnnotationPresent(OneToMany.class) || fieldContainer.getPojoField().isAnnotationPresent(ManyToOne.class) || fieldContainer.getPojoField().isAnnotationPresent(ManyToMany.class)) { //special relationship: deal with custom type form element int state = 0; Class classOfField = null; while (true) { if (state == 0) { if (Collection.class.isAssignableFrom(fieldContainer.getPojoField().getType())) { classOfField = (Class) ((ParameterizedType) fieldContainer.getPojoField() .getGenericType()).getActualTypeArguments()[0]; state = 1; } else { state = 3; break; } } if (state == 1) { if (CustomType.class.isAssignableFrom(classOfField)) { state = 2; break; } else { state = 3; break; } } } if (state == 2) { //Custom type Button openCustom = new Button("Manage " + fieldContainer.getWebField().name(), new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { try { fieldGroup.commit(); currentBean = (C) fieldGroup.getItemDataSource().getBean(); currentBean = saveBean(currentBean, parentBean, beanUtils, currentUserRoles); fieldGroup.setItemDataSource(currentBean); //field class Class iclassOfField = (Class) ((ParameterizedType) fieldContainer .getPojoField().getGenericType()).getActualTypeArguments()[0]; //find a custom type dao DataAccessObject<? extends CustomType> chosenCTDao = null; for (DataAccessObject cdao : customTypeDaos) { if (cdao.getType().isAssignableFrom(iclassOfField)) { chosenCTDao = cdao; break; } } //deal with windows final Window window = new Window(); final AttachmentCustomTypeUICreator<C> attachmentCustomTypeUICreator = new AttachmentCustomTypeUICreator(); Component customTypeComponent = attachmentCustomTypeUICreator .createUIForForm(currentBean, iclassOfField, fieldContainer.getPojoField().getName(), BeanView.this, dao, chosenCTDao, pageParameter.getRelationManagerFactory(), pageParameter.getConfig(), effectiveFieldState, window); customTypeComponent .setCaption("Manage " + fieldContainer.getWebField().name()); customTypeComponent.setId(customTypeComponent.getCaption()); window.setCaption(customTypeComponent.getCaption()); window.setId(window.getCaption()); window.setContent(customTypeComponent); window.setModal(true); BeanView.this.getUI().addWindow(window); } catch (CommitException ex) { handleFieldsError(fieldGroup); } } }); openCustom.setId(openCustom.getCaption()); form.addComponent(openCustom); } else { //relationship try { fieldContainer.getPojoField().setAccessible(true); final WebField webField = fieldContainer.getPojoField().getAnnotation(WebField.class); Button relationshipButton = null; if (fieldContainer.getPojoField().isAnnotationPresent(OneToMany.class)) { relationshipButton = new Button("Manage " + webField.name(), new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { try { fieldGroup.commit(); currentBean = (C) fieldGroup.getItemDataSource().getBean(); currentBean = saveBean(currentBean, parentBean, beanUtils, currentUserRoles); Class classOfField = (Class) ((ParameterizedType) fieldContainer .getPojoField().getGenericType()) .getActualTypeArguments()[0]; EditorTableView view = new EditorTableView(currentBean, fieldContainer.getPojoField().getName(), effectiveFieldState, classOfField, ChoiceType.CHOOSE_MANY, pageParameter); String targetView = "BEAN_VIEW_" + UUID.randomUUID().toString(); History his = new History(targetView, "Manage " + webField.name()); pageParameter.getHistory().push(his); nav.addView(targetView, view); nav.navigateTo(targetView); } catch (CommitException ex) { handleFieldsError(fieldGroup); } } }); } else if (fieldContainer.getPojoField().isAnnotationPresent(ManyToOne.class)) { relationshipButton = new Button("Manage " + webField.name(), new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { try { fieldGroup.commit(); currentBean = (C) fieldGroup.getItemDataSource().getBean(); fieldGroup.commit(); currentBean = (C) fieldGroup.getItemDataSource().getBean(); currentBean = saveBean(currentBean, parentBean, beanUtils, currentUserRoles); EditorTableView view = new EditorTableView(currentBean, fieldContainer.getPojoField().getName(), effectiveFieldState, fieldContainer.getPojoField().getType(), ChoiceType.CHOOSE_ONE, pageParameter); String targetView = "BEAN_VIEW_" + UUID.randomUUID().toString(); History his = new History(targetView, "Manage " + webField.name()); pageParameter.getHistory().push(his); nav.addView(targetView, view); nav.navigateTo(targetView); } catch (CommitException ex) { handleFieldsError(fieldGroup); } } }); } else if (fieldContainer.getPojoField().isAnnotationPresent(ManyToMany.class)) { relationshipButton = new Button("Manage " + webField.name(), new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { try { fieldGroup.commit(); currentBean = (C) fieldGroup.getItemDataSource().getBean(); fieldGroup.commit(); currentBean = (C) fieldGroup.getItemDataSource().getBean(); currentBean = saveBean(currentBean, parentBean, beanUtils, currentUserRoles); Class classOfField = (Class) ((ParameterizedType) fieldContainer .getPojoField().getGenericType()) .getActualTypeArguments()[0]; EditorTableView view = new EditorTableView(currentBean, fieldContainer.getPojoField().getName(), effectiveFieldState, classOfField, ChoiceType.CHOOSE_MANY, pageParameter); String targetView = "BEAN_VIEW_" + UUID.randomUUID().toString(); History his = new History(targetView, "Manage " + webField.name()); pageParameter.getHistory().push(his); nav.addView(targetView, view); nav.navigateTo(targetView); } catch (CommitException ex) { handleFieldsError(fieldGroup); } } }); } relationshipButton.setId(relationshipButton.getCaption()); form.addComponent(relationshipButton); } catch (IllegalArgumentException ex) { Logger.getLogger(BeanView.class.getName()).log(Level.SEVERE, null, ex); } } //deal with id } else if (fieldContainer.getPojoField().isAnnotationPresent(Id.class)) { com.vaadin.ui.Field formField = fieldGroup.buildAndBind(fieldContainer.getWebField().name(), fieldContainer.getPojoField().getName()); if (Number.class.isAssignableFrom(fieldContainer.getPojoField().getType())) { ((TextField) formField).setConverter( new NumberBasedIDConverter((Class<Number>) fieldContainer.getPojoField().getType())); } form.addComponent(formField); uifield = formField; //deal with nominal form element } else { com.vaadin.ui.Field formField = fieldGroup.buildAndBind(fieldContainer.getWebField().name(), fieldContainer.getPojoField().getName()); if (fieldContainer.getPojoField().getType().equals(Date.class)) { //deal with date DateField dateField = (DateField) formField; dateField.setDateFormat(pageParameter.getConfig().get("dateFormat")); dateField.setWidth(100f, Unit.PIXELS); } else if (fieldContainer.getPojoField().getType().equals(BigDecimal.class)) { TextField bdField = (TextField) formField; bdField.setConverter(new StringToBigDecimalConverter()); } form.addComponent(formField); uifield = formField; } if (uifield != null) { //deal with read only if (ComponentState.READ_ONLY.equals(effectiveFieldState)) { uifield.setReadOnly(true); } else { uifield.setReadOnly(false); if (fieldContainer.getWebField().required() == true) { uifield.setRequired(true); } } //set null presentation if (uifield instanceof AbstractTextField) { AbstractTextField textField = (AbstractTextField) uifield; textField.setNullRepresentation(""); } //set debug id uifield.setId(uifield.getCaption()); } } //deal with active choice for (final com.vaadin.ui.ComboBox sourceField : activeChoicesWithFieldAsKey.keySet()) { final ActiveChoiceTarget target = activeChoicesWithFieldAsKey.get(sourceField); final com.vaadin.ui.ComboBox targetField = activeChoicesFieldWithHierarchyAsKey .get(target.getTargetHierarchy()); sourceField.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { List<String> targetValues = target.getTargets().get(sourceField.getValue()); if (targetValues != null && !targetValues.isEmpty() && targetField != null) { targetField.removeAllItems(); for (String targetValue : targetValues) { targetField.addItem(targetValue); } } } }); } }
From source file:org.eclipse.emf.ecp.view.core.vaadin.AbstractControlRendererVaadin.java
License:Open Source License
@Override protected void applyCaption() { final Setting setting = getVElement().getDomainModelReference().getIterator().next(); final IItemPropertyDescriptor itemPropertyDescriptor = VaadinRendererUtil .getItemPropertyDescriptor(setting); final Component controlComponent = getControlComponent(); if (!hasCaption(itemPropertyDescriptor)) { controlComponent.setCaption(null); return;// ww w . j av a2 s. com } String extra = StringUtils.EMPTY; extra = getMandatoryText(setting, extra); controlComponent.setCaption(itemPropertyDescriptor.getDisplayName(setting.getEObject()) + extra); final String description = itemPropertyDescriptor.getDescription(setting.getEObject()); if (controlComponent instanceof AbstractComponent && !StringUtils.isEmpty(description)) { ((AbstractComponent) controlComponent).setDescription(description); } }
From source file:org.ikasan.dashboard.ui.framework.panel.LandingViewPanel.java
License:BSD License
private Component createContentWrapper(final Component content) { final CssLayout slot = new CssLayout(); slot.setWidth("100%"); slot.addStyleName("dashboard-panel-slot"); CssLayout card = new CssLayout(); card.setWidth("100%"); card.addStyleName(ValoTheme.LAYOUT_CARD); HorizontalLayout toolbar = new HorizontalLayout(); toolbar.addStyleName("dashboard-panel-toolbar"); toolbar.setWidth("100%"); Label caption = new Label(content.getCaption()); caption.addStyleName(ValoTheme.LABEL_H4); caption.addStyleName(ValoTheme.LABEL_COLORED); caption.addStyleName(ValoTheme.LABEL_NO_MARGIN); content.setCaption(null); MenuBar tools = new MenuBar(); tools.addStyleName(ValoTheme.MENUBAR_BORDERLESS); MenuItem max = tools.addItem("", VaadinIcons.EXPAND, new Command() { @Override//from www.j a va 2s . co m public void menuSelected(final MenuItem selectedItem) { if (!slot.getStyleName().contains("max")) { selectedItem.setIcon(FontAwesome.COMPRESS); toggleMaximized(slot, true); } else { slot.removeStyleName("max"); selectedItem.setIcon(FontAwesome.EXPAND); toggleMaximized(slot, false); } } }); max.setStyleName("icon-only"); MenuItem root = tools.addItem("", VaadinIcons.COG, null); root.addItem("Configure", new Command() { @Override public void menuSelected(final MenuItem selectedItem) { Notification.show("Not implemented in this demo"); } }); root.addSeparator(); root.addItem("Close", new Command() { @Override public void menuSelected(final MenuItem selectedItem) { Notification.show("Not implemented in this demo"); } }); toolbar.addComponents(caption, tools); toolbar.setExpandRatio(caption, 1); toolbar.setComponentAlignment(caption, Alignment.MIDDLE_LEFT); card.addComponents(toolbar, content); slot.addComponent(card); return slot; }
From source file:org.ikasan.dashboard.ui.monitor.component.MonitorPanel.java
License:BSD License
protected Component createContentWrapper(final Component small, final Component large) { final CssLayout slot = new CssLayout(); slot.setWidth("100%"); slot.addStyleName("monitor-panel-slot"); final CssLayout card1 = new CssLayout(); card1.setWidth("100%"); card1.addStyleName(ValoTheme.LAYOUT_CARD); final CssLayout card2 = new CssLayout(); card2.setWidth("100%"); card2.addStyleName(ValoTheme.LAYOUT_CARD); final HorizontalLayout toolbar = new HorizontalLayout(); toolbar.addStyleName("dashboard-panel-toolbar"); toolbar.setWidth("100%"); Label caption = new Label(large.getCaption()); caption.addStyleName(ValoTheme.LABEL_H4); caption.addStyleName(ValoTheme.LABEL_COLORED); caption.addStyleName(ValoTheme.LABEL_NO_MARGIN); large.setCaption(null); MenuBar tools = new MenuBar(); tools.addStyleName(ValoTheme.MENUBAR_BORDERLESS); MenuItem max = tools.addItem("", VaadinIcons.EXPAND, new Command() { @Override// www . j av a2 s .c o m public void menuSelected(final MenuItem selectedItem) { if (!slot.getStyleName().contains("max")) { selectedItem.setIcon(FontAwesome.COMPRESS); slot.removeAllComponents(); card2.removeAllComponents(); card2.addComponents(toolbar, large); slot.addComponents(card2); toggleMaximized(slot, true); } else { slot.removeStyleName("max"); selectedItem.setIcon(FontAwesome.EXPAND); toggleMaximized(slot, false); card1.removeAllComponents(); card1.addComponents(toolbar, small); slot.removeAllComponents(); slot.addComponents(card1); } } }); max.setStyleName("icon-only"); MenuItem root = tools.addItem("", VaadinIcons.COG, null); root.addItem("Configure", new Command() { @Override public void menuSelected(final MenuItem selectedItem) { Notification.show("Not implemented in this demo"); } }); root.addSeparator(); root.addItem("Close", new Command() { @Override public void menuSelected(final MenuItem selectedItem) { Notification.show("Not implemented in this demo"); } }); toolbar.addComponents(caption, tools); toolbar.setExpandRatio(caption, 1); toolbar.setComponentAlignment(caption, Alignment.MIDDLE_LEFT); card1.addComponents(toolbar, small); // card2.addComponents(toolbar, large); slot.addComponent(card1); return slot; }
From source file:org.jdal.vaadin.ui.form.SimpleBoxFormBuilder.java
License:Apache License
public void add(Component c, String label, int width, Alignment alignment) { if (rows == 0 && rowsHeight.isEmpty()) { log.warn("You must call row() before adding components. I will add a row with default height for you"); row();//from w w w .j av a 2 s. co m } if (label != null) c.setCaption(label); VerticalLayout column = getColumn(); column.addComponent(c); index++; setWidth(width); if (alignment != null) { column.setComponentAlignment(c, alignment); } if (rowCellSpand) { c.setWidth(100, Unit.PERCENTAGE); } if (useTabIndex && c instanceof Field) { ((Field<?>) c).setTabIndex(tabIndex++); } }
From source file:org.jdal.vaadin.ui.form.SimpleBoxFormBuilder.java
License:Apache License
/** * Add a component with label, increments cursor by two. * @param name label string/* www. java2s .c om*/ * @param c component. */ public void add(String name, Component c) { c.setCaption(name); add(c); }