List of usage examples for com.vaadin.ui GridLayout addComponent
public void addComponent(Component component, int column, int row) throws OverlapsException, OutOfBoundsException
From source file:uk.q3c.krail.core.option.DefaultOptionPopup.java
License:Apache License
/** * The context is scanned for {@link OptionKey} instances. If none are found a message is displayed saying there are no options. A context is loaded * only once - the {@link OptionKey} instances are cached. The {@link DefaultOptionBinder} binds a UI Field with an {@link Option} value, combined with a {@link Converter} instance to enable conversion to and from the type needed for presentation (usually String). <p> * Options are displayed in a grid of 2 columns, the first column containing a Vaadin component to display the option value and the second a button to * reset the value to default. The component and button are each wrapped in a FormLayout to position the caption to the left of the value<p> * A value change listener is attached to the Vaadin component to change the option value in response to the user changing the value ion the component. * * @param context the context to take the options from * @param windowCaption the I18NKey to provide a window caption */// www .j a v a 2 s. co m @Override public void popup(OptionContext context, I18NKey windowCaption) { // changing context, so we need to re-read the context fields if (context != activeContext) { contextKeys = contextKeys(context); } Option option = context.optionInstance(); if (window != null) { window.close(); } window = new Window(); window.setCaption(windowCaption(windowCaption)); int rows = contextKeys.size() > 0 ? contextKeys.size() : 1; GridLayout baseLayout = new GridLayout(2, rows); baseLayout.setSizeUndefined(); if (contextKeys.isEmpty()) { Label label = new Label(translate.from(LabelKey.No_Options_to_Show)); baseLayout.addComponent(label, 0, 0); } else { calculateWindowSize(window); int row = 0; for (OptionKey<?> key : contextKeys.keySet()) { AbstractField<?> field = fieldForKey(key); optionBinder.bindOption(key, field); setFieldMetaData(key, field); log.debug("option field {} value is at {}", field.getCaption(), field.getValue()); Button defaultsButton = new Button(translate.from(LabelKey.Reset_to_Default)); Optional<String> optionKeyName = Optional.of(((Enum) key.getKey()).name()); defaultsButton.addClickListener((event -> { // reset to previous level by removing entry for user option.delete(key, 0); // reset the binding - the option value may be different optionBinder.bindOption(key, field); })); baseLayout.addComponent(new FormLayout(field), 0, row); baseLayout.addComponent(new FormLayout(defaultsButton), 1, row); row++; } } window.setClosable(true); //use panel to scroll window.setContent(new Panel(baseLayout)); window.center(); UI.getCurrent().addWindow(window); this.activeContext = context; }
From source file:uk.q3c.krail.core.user.opt.DefaultOptionPopup.java
License:Apache License
@Override public void popup(@Nonnull OptionContext context, I18NKey windowCaption) { // changing context, so we need to clear the context fields if (context != activeContext) { contextFields = null;/*from w ww . j a v a 2 s.c o m*/ if (window != null) { window.close(); } } Option option = context.getOption(); window = new Window(); window.setCaption(windowCaption(windowCaption)); Map<OptionKey, Class<?>> keys = contextKeys(context); GridLayout baseLayout = new GridLayout(2, keys.size()); baseLayout.setSizeUndefined(); if (keys.size() == 0) { Label label = new Label(translate.from(LabelKey.No_Options_to_Show)); baseLayout.addComponent(label, 0, 0); } else { calculateWindowSize(window, keys.size()); int row = 0; for (OptionKey key : keys.keySet()) { Object value = option.get(key); AbstractField uiField = dataTypeToUI.componentFor(value); uiField.setCaption(translate.from(key.getKey())); uiField.setDescription(translate.from(key.getDescriptionKey())); uiField.setId(ID.getId(Optional.of(((Enum) key.getKey()).name()), this, uiField)); log.debug("Component id for '{}' set to: '{}'", uiField.getCaption(), uiField.getId()); //noinspection unchecked uiField.setValue(value); uiField.addValueChangeListener(event -> { option.set(uiField.getValue(), key); context.optionValueChanged(event); }); Button defaultsButton = new Button(translate.from(LabelKey.Reset_to_Default)); defaultsButton.setId(ID.getId(Optional.of(((Enum) key.getKey()).name()), this, defaultsButton)); defaultsButton.addClickListener((event -> { option.delete(0, key); //we create an event to represent the field which whose value will be affected by this change AbstractField.ValueChangeEvent changeEvent = new AbstractField.ValueChangeEvent(uiField); context.optionValueChanged(changeEvent); //update the value of the field - it may have changed uiField.setValue(option.get(key)); })); baseLayout.addComponent(new FormLayout(uiField), 0, row); baseLayout.addComponent(new FormLayout(defaultsButton), 1, row); row++; } } window.setId(ID.getId(Optional.empty(), context, this, window)); window.setClosable(true); window.setContent(baseLayout); window.center(); UI.getCurrent().addWindow(window); this.activeContext = context; }
From source file:uk.q3c.krail.testapp.view.GridViewBase.java
License:Apache License
@Override protected void doBuild() { Label label = new Label("This is the " + this.getClass().getSimpleName()); label.setHeight("100px"); GridLayout grid = new GridLayout(3, 3); grid.addComponent(label, 1, 1); grid.setSizeFull();//from www . j a va 2s . c om grid.setColumnExpandRatio(0, 0.33f); grid.setColumnExpandRatio(1, 0.33f); grid.setColumnExpandRatio(2, 0.33f); grid.setRowExpandRatio(0, 0.4f); grid.setRowExpandRatio(1, 0.2f); grid.setRowExpandRatio(2, 0.4f); label.setSizeFull(); setRootComponent(grid); }
From source file:uk.q3c.krail.testapp.view.WidgetsetView.java
License:Apache License
@Override public void doBuild() { buttonPanel = new Panel(); VerticalLayout verticalLayout = new VerticalLayout(); buttonPanel.setContent(verticalLayout); setRootComponent(new GridLayout(3, 4)); GridLayout grid = getGrid(); grid.addComponent(buttonPanel, 1, 2); grid.setSizeFull();/*from w ww . j ava2 s . c om*/ grid.setColumnExpandRatio(0, 0.400f); grid.setColumnExpandRatio(1, 0.20f); grid.setColumnExpandRatio(2, 0.40f); grid.setRowExpandRatio(0, 0.05f); grid.setRowExpandRatio(1, 0.15f); grid.setRowExpandRatio(2, 0.4f); grid.setRowExpandRatio(3, 0.15f); spinner = new Spinner(SpinnerType.FOLDING_CUBE).large(); verticalLayout.addComponent(spinner); changeSpinnerType = new Button("Change Spinner Type"); changeSpinnerType.addClickListener(e -> spinner.setType(SpinnerType.WAVE)); verticalLayout.addComponent(changeSpinnerType); stepper = new IntStepper("Stepper"); stepper.setValue(5); verticalLayout.addComponent(stepper); infoArea = new Label(); infoArea.setContentMode(ContentMode.HTML); infoArea.setSizeFull(); infoArea.setValue("These components are used purely to ensure that the Widgetset has compiled and included " + "add-ons"); grid.addComponent(infoArea, 0, 1, 1, 1); param1 = new Label(); param2 = new Label(); VerticalLayout parameters = new VerticalLayout(param1, param2); grid.addComponent(parameters, 0, 2, 0, 2); }