Example usage for com.vaadin.ui FormLayout setWidth

List of usage examples for com.vaadin.ui FormLayout setWidth

Introduction

In this page you can find the example usage for com.vaadin.ui FormLayout setWidth.

Prototype

@Override
    public void setWidth(float width, Unit unit) 

Source Link

Usage

From source file:dhbw.ka.mwi.businesshorizon2.ui.process.scenario.ScenarioViewImpl.java

License:Open Source License

/**
 * Die Methode fuegt der View ein Szenario hinzu. Sie baut hierzu saemtliche
 * notwendigen GUI-Elemente und entsprecheenden Listener hinzu.
 * /*w  w w.j  a  v  a2  s  .c om*/
 * @author Julius Hacker
 * @param rateReturnEquity Standardwert fuer die Renditeforderung Eigenkapital
 * @param rateReturnCapitalStock Standardwert fuer die Renditeforderung Fremdkapital
 * @param businessTax Standardwert fuer die Gewerbesteuer
 * @param corporateAndSolitaryTax Standardwert fuer die Koerperschaftssteuer mit Solidaritaetszuschlag.
 */
@Override
public void addScenario(String rateReturnEquity, String rateReturnCapitalStock, String corporateAndSolitaryTax,
        String businessTax, boolean isIncludeInCalculation, final int number) {
    HashMap<String, AbstractComponent> scenarioComponents = new HashMap<String, AbstractComponent>();

    Property.ValueChangeListener changeListener = new Property.ValueChangeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            presenter.updateScenario(number);
            logger.debug("TextChange ausgeloest");
            logger.debug("ChangeListener " + System.identityHashCode(this));
        }
    };

    HorizontalLayout hlScenario = new HorizontalLayout();
    hlScenario.setSizeFull();

    FormLayout formLeft = new FormLayout();
    FormLayout formRight = new FormLayout();
    hlScenario.addComponent(formLeft);
    //hlScenario.addComponent(formRight);

    final Label scenarioName = new Label("<strong>Szenario " + number + "</strong>");
    scenarioName.setContentMode(Label.CONTENT_XHTML);
    scenarioComponents.put("label", scenarioName);
    formLeft.addComponent(scenarioName);
    scenarioName.setWidth(Sizeable.SIZE_UNDEFINED, 0);

    final CheckBox cbBerechnungEinbezug = new CheckBox("In Berechnung einbeziehen");
    cbBerechnungEinbezug.setValue(isIncludeInCalculation);
    cbBerechnungEinbezug.setImmediate(true);
    cbBerechnungEinbezug.addListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            presenter.updateScenario(number);
            logger.debug("ChangeListener " + System.identityHashCode(this));
        }

    });
    scenarioComponents.put("isIncludeInCalculation", cbBerechnungEinbezug);
    formLeft.addComponent(cbBerechnungEinbezug);

    final TextField tfEigenkapital = new TextField("Renditeforderung Eigenkapital: ");
    if (!"0.0".equals(rateReturnEquity)) {
        tfEigenkapital.setValue(rateReturnEquity);
    }
    tfEigenkapital.setImmediate(true);
    tfEigenkapital.addListener(changeListener);
    scenarioComponents.put("rateReturnEquity", tfEigenkapital);
    formLeft.addComponent(tfEigenkapital);

    final TextField tfFremdkapital = new TextField("Renditeforderung Fremdkapital: ");
    if (!"0.0".equals(rateReturnCapitalStock)) {
        tfFremdkapital.setValue(rateReturnCapitalStock);
    }
    tfFremdkapital.setImmediate(true);
    tfFremdkapital.addListener(changeListener);
    scenarioComponents.put("rateReturnCapitalStock", tfFremdkapital);
    formLeft.addComponent(tfFremdkapital);

    final TextField tfGewerbesteuer = new TextField("Gewerbesteuer: ");
    if (!"0.0".equals(businessTax)) {
        tfGewerbesteuer.setValue(businessTax);
    }
    tfGewerbesteuer.setImmediate(true);
    tfGewerbesteuer.addListener(changeListener);
    scenarioComponents.put("businessTax", tfGewerbesteuer);
    formLeft.addComponent(tfGewerbesteuer);

    final TextField tfKoerperschaftssteuer = new TextField(
            "K\u00F6rperschaftssteuer mit Solidarit\u00E4tszuschlag: ");
    if (!"0.0".equals(corporateAndSolitaryTax)) {
        tfKoerperschaftssteuer.setValue(corporateAndSolitaryTax);
    }
    tfKoerperschaftssteuer.setImmediate(true);
    tfKoerperschaftssteuer.addListener(changeListener);
    scenarioComponents.put("corporateAndSolitaryTax", tfKoerperschaftssteuer);
    formLeft.addComponent(tfKoerperschaftssteuer);

    final Button removeScenario = new Button("Szenario entfernen");
    removeScenario.addListener(new ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            presenter.removeScenario(number);
        }

    });
    formLeft.addComponent(removeScenario);

    formLeft.setWidth(Sizeable.SIZE_UNDEFINED, 0);
    formLeft.setWidth(Sizeable.SIZE_UNDEFINED, 0);

    scenarioComponents.put("scenario", hlScenario);

    this.scenarios.add(scenarioComponents);
    this.vlScenarios.addComponent(hlScenario);
}

From source file:org.jumpmind.metl.ui.views.design.PropertySheet.java

License:Open Source License

@SuppressWarnings("unchecked")
public void setSource(Object obj) {
    value = obj;/*from w  w  w.ja v a2 s  .c o m*/
    editButton.setVisible(hasAdvancedEditor());
    FormLayout formLayout = new FormLayout();
    formLayout.setWidth(100, Unit.PERCENTAGE);
    formLayout.setMargin(false);
    formLayout.addStyleName(ValoTheme.FORMLAYOUT_LIGHT);

    if (obj != null) {

        if (obj instanceof List<?>) {
            List<Object> l = (List<Object>) obj;
            if (l.size() == 1) {
                if (l.get(0) instanceof FlowStep) {
                    obj = (FlowStep) l.get(0);
                }
            }
        }

        if (obj instanceof FlowStep) {
            obj = ((FlowStep) obj).getComponent();
        }

        if (obj instanceof Component) {
            Component component = (Component) obj;
            context.getConfigurationService().refresh(component, true);
            addComponentProperties(formLayout, component);
        }

        if (obj instanceof Resource) {
            Resource resource = (Resource) obj;
            addResourceProperties(formLayout, resource);
        }

        if (obj instanceof AbstractObjectWithSettings) {
            List<XMLSetting> settings = buildSettings(obj);
            if (settings != null) {
                for (XMLSetting definition : settings) {
                    addSettingField(definition, (AbstractObjectWithSettings) obj, formLayout);
                }
            }
        }

        if (obj instanceof Component) {
            Component component = (Component) obj;
            XMLComponent componentDefintion = context.getComponentDefinitionFactory()
                    .getDefinition(component.getType());
            addThreadCount(componentDefintion, formLayout, component);
            addComponentShared(formLayout, component);
        }

        if (obj instanceof List<?>) {
            addCommonComponentSettings(formLayout, obj);
        }

    }
    panel.setContent(formLayout);
}

From source file:org.opennms.features.vaadin.dashboard.dashlets.ChartsConfigurationWindow.java

License:Open Source License

/**
 * Constructor for instantiating new objects of this class.
 *
 * @param dashletSpec the {@link DashletSpec} to be edited
 *//*from   ww  w.  j  a va  2s.c o  m*/
public ChartsConfigurationWindow(DashletSpec dashletSpec) {
    /**
     * Setting the members
     */
    m_dashletSpec = dashletSpec;

    /**
     * Setting up the base layouts
     */

    setHeight(410, Unit.PIXELS);
    setWidth(40, Unit.PERCENTAGE);

    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setWidth(100, Unit.PERCENTAGE);
    horizontalLayout.setSpacing(true);
    horizontalLayout.setMargin(true);

    FormLayout formLayout = new FormLayout();
    formLayout.setWidth(100, Unit.PERCENTAGE);
    formLayout.setSpacing(true);
    formLayout.setMargin(true);

    /**
     * Adding the checkboxes
     */
    m_maximizeWidth = new CheckBox();
    m_maximizeWidth.setCaption("Maximize width");
    m_maximizeWidth.setDescription("Maximize width");

    m_maximizeHeight = new CheckBox();
    m_maximizeHeight.setCaption("Maximize height");
    m_maximizeHeight.setDescription("Maximize height");

    String maximizeWidthString = m_dashletSpec.getParameters().get("maximizeWidth");
    String maximizeHeightString = m_dashletSpec.getParameters().get("maximizeHeight");

    boolean maximizeHeight = ("true".equals(maximizeHeightString) || "yes".equals(maximizeHeightString)
            || "1".equals(maximizeHeightString));
    boolean maximizeWidth = ("true".equals(maximizeWidthString) || "yes".equals(maximizeWidthString)
            || "1".equals(maximizeWidthString));

    m_maximizeWidth.setValue(maximizeWidth);
    m_maximizeHeight.setValue(maximizeHeight);

    m_chartSelect = new NativeSelect();
    m_chartSelect.setDescription("Select chart to be displayed");
    m_chartSelect.setCaption("Chart");
    m_chartSelect.setNullSelectionAllowed(false);
    m_chartSelect.setInvalidAllowed(false);
    m_chartSelect.setNewItemsAllowed(false);

    String firstChartName = null;

    try {
        Iterator<BarChart> it = ChartUtils.getChartCollectionIterator();

        while (it.hasNext()) {
            BarChart chartConfig = (BarChart) it.next();

            if (firstChartName == null) {
                firstChartName = chartConfig.getName();
            }

            m_chartSelect.addItem(chartConfig.getName());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    String chartName = m_dashletSpec.getParameters().get("chart");

    if (chartName == null || "".equals(chartName)) {
        chartName = firstChartName;
    }

    final Panel panel = new Panel();

    panel.setWidth(230, Unit.PIXELS);

    panel.setCaption("Preview");

    formLayout.addComponent(m_chartSelect);

    Page.getCurrent().getStyles().add(".preview { width:225px; }");

    m_chartSelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            String newImage = "/opennms/charts?chart-name=" + valueChangeEvent.getProperty().getValue();
            Image image = new Image(null, new ExternalResource(newImage));
            image.setStyleName("preview");
            panel.setContent(image);
        }
    });

    m_chartSelect.setValue(chartName);
    m_chartSelect.setImmediate(true);

    formLayout.addComponent(m_maximizeWidth);
    formLayout.addComponent(m_maximizeHeight);

    horizontalLayout.addComponent(formLayout);
    horizontalLayout.addComponent(panel);

    /**
     * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons
     */
    HorizontalLayout buttonLayout = new HorizontalLayout();

    buttonLayout.setMargin(true);
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth("100%");
    /**
     * Adding the cancel button...
     */
    Button cancel = new Button("Cancel");
    cancel.setDescription("Cancel editing");
    cancel.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            close();
        }
    });

    cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
    buttonLayout.addComponent(cancel);
    buttonLayout.setExpandRatio(cancel, 1.0f);
    buttonLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT);

    /**
     * ...and the OK button
     */
    Button ok = new Button("Save");
    ok.setDescription("Save properties and close");
    ok.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            m_dashletSpec.getParameters().put("maximizeWidth", (m_maximizeWidth.getValue() ? "true" : "false"));
            m_dashletSpec.getParameters().put("maximizeHeight",
                    (m_maximizeHeight.getValue() ? "true" : "false"));
            m_dashletSpec.getParameters().put("chart", String.valueOf(m_chartSelect.getValue()));

            WallboardProvider.getInstance().save();
            ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Properties");

            close();
        }
    });

    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
    buttonLayout.addComponent(ok);

    /**
     * Adding the layout and setting the content
     */
    //verticalLayout.addComponent(buttonLayout);

    VerticalLayout verticalLayout = new VerticalLayout();

    verticalLayout.addComponent(horizontalLayout);
    verticalLayout.addComponent(buttonLayout);

    setContent(verticalLayout);
}

From source file:org.opennms.features.vaadin.dashboard.dashlets.KscDashletConfigurationWindow.java

License:Open Source License

/**
 * Constructor for instantiating new objects of this class.
 *
 * @param dashletSpec the {@link org.opennms.features.vaadin.dashboard.model.DashletSpec} to be edited
 *///from  ww  w  .  j  a v  a  2 s  . c o m
public KscDashletConfigurationWindow(DashletSpec dashletSpec) {
    /**
     * Setting the members
     */
    m_dashletSpec = dashletSpec;

    setHeight(210, Unit.PIXELS);
    setWidth(40, Unit.PERCENTAGE);

    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setWidth(100, Unit.PERCENTAGE);
    horizontalLayout.setSpacing(true);
    horizontalLayout.setMargin(true);

    FormLayout formLayout = new FormLayout();
    formLayout.setWidth(100, Unit.PERCENTAGE);
    formLayout.setSpacing(true);
    formLayout.setMargin(true);

    m_kscSelect = new NativeSelect();
    m_kscSelect.setDescription("Select KSC-report to be displayed");
    m_kscSelect.setCaption("KSC-Report");
    m_kscSelect.setImmediate(true);
    m_kscSelect.setNewItemsAllowed(false);
    m_kscSelect.setMultiSelect(false);
    m_kscSelect.setInvalidAllowed(false);
    m_kscSelect.setNullSelectionAllowed(false);
    m_kscSelect.setImmediate(true);

    final KSC_PerformanceReportFactory kscPerformanceReportFactory = KSC_PerformanceReportFactory.getInstance();

    Map<Integer, String> reportsMap = kscPerformanceReportFactory.getReportList();

    for (Map.Entry<Integer, String> entry : reportsMap.entrySet()) {
        m_kscSelect.addItem(entry.getKey());
        m_kscSelect.setItemCaption(entry.getKey(), entry.getValue());
        if (m_kscSelect.getValue() == null) {
            m_kscSelect.setValue(entry.getKey());
        }
    }

    String chartName = m_dashletSpec.getParameters().get("kscReport");

    if (chartName != null) {
        if (reportsMap.values().contains(chartName)) {
            m_kscSelect.setValue(chartName);
        }
    }

    formLayout.addComponent(m_kscSelect);

    m_kscSelect.setValue(chartName);
    m_kscSelect.setImmediate(true);

    horizontalLayout.addComponent(formLayout);

    /**
     * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons
     */
    HorizontalLayout buttonLayout = new HorizontalLayout();

    buttonLayout.setMargin(true);
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth("100%");
    /**
     * Adding the cancel button...
     */
    Button cancel = new Button("Cancel");
    cancel.setDescription("Cancel editing");
    cancel.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            close();
        }
    });

    cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
    buttonLayout.addComponent(cancel);
    buttonLayout.setExpandRatio(cancel, 1.0f);
    buttonLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT);

    /**
     * ...and the OK button
     */
    Button ok = new Button("Save");
    ok.setDescription("Save properties and close");
    ok.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            Map<Integer, String> reportsMap = kscPerformanceReportFactory.getReportList();

            m_dashletSpec.getParameters().put("kscReport", reportsMap.get(m_kscSelect.getValue()));

            WallboardProvider.getInstance().save();
            ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Properties");

            close();
        }
    });

    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
    buttonLayout.addComponent(ok);

    if (reportsMap.size() == 0) {
        m_kscSelect.setEnabled(false);
        ok.setEnabled(false);
    }

    /**
     * Adding the layout and setting the content
     */

    VerticalLayout verticalLayout = new VerticalLayout();

    verticalLayout.addComponent(horizontalLayout);
    verticalLayout.addComponent(buttonLayout);

    setContent(verticalLayout);
}

From source file:org.ripla.web.internal.views.RiplaLogin.java

License:Open Source License

private void createForm(final VerticalLayout inLayout, final IAppConfiguration inConfiguration) {
    final IMessages lMessages = Activator.getMessages();

    final FormLayout lLayout = new FormLayout();
    lLayout.setStyleName("ripla-login-form"); //$NON-NLS-1$
    lLayout.setWidth(400, Unit.PIXELS);
    inLayout.addComponent(lLayout);//from  www  .  j  av a2 s . co  m
    inLayout.setComponentAlignment(lLayout, Alignment.TOP_CENTER);

    lLayout.addComponent(LabelHelper.createLabel(inConfiguration.getWelcome(), "ripla-welcome"));

    userid = new TextField(String.format("%s:", lMessages.getMessage("login.field.user"))); //$NON-NLS-1$ //$NON-NLS-2$
    lLayout.addComponent(userid);
    userid.focus();

    password = new PasswordField(String.format("%s:", lMessages.getMessage("login.field.pass"))); //$NON-NLS-1$ //$NON-NLS-2$
    lLayout.addComponent(password);

    loginButton = new Button(lMessages.getMessage("login.button")); //$NON-NLS-1$
    lLayout.addComponent(loginButton);

    loginItem = createLoginItem();
    final FieldGroup lBinding = new FieldGroup(loginItem);
    lBinding.bindMemberFields(this);
    lBinding.setBuffered(false);
}

From source file:org.sensorhub.ui.GenericConfigForm.java

License:Mozilla Public License

@Override
public void build(String title, MyBeanItem<? extends Object> beanItem) {
    List<Field<?>> labels = new ArrayList<Field<?>>();
    List<Field<?>> textBoxes = new ArrayList<Field<?>>();
    List<Field<?>> listBoxes = new ArrayList<Field<?>>();
    List<Field<?>> numberBoxes = new ArrayList<Field<?>>();
    List<Field<?>> checkBoxes = new ArrayList<Field<?>>();
    List<Component> otherWidgets = new ArrayList<Component>();

    // prepare header and form layout
    setSpacing(true);// w  ww  .j a v  a  2 s  . c om

    // add main form widgets
    FormLayout form = new FormLayout();
    form.setWidth(100.0f, Unit.PERCENTAGE);
    form.setMargin(false);

    if (title != null) {
        Label sectionLabel = new Label(title);
        sectionLabel.addStyleName(STYLE_H3);
        sectionLabel.addStyleName(STYLE_COLORED);
        form.addComponent(sectionLabel);
    }

    // add widget for each visible attribute
    if (beanItem != null) {
        fieldGroup = new FieldGroup(beanItem);
        for (Object propId : fieldGroup.getUnboundPropertyIds()) {
            Property<?> prop = fieldGroup.getItemDataSource().getItemProperty(propId);

            // sub objects with multiplicity > 1
            if (prop instanceof ContainerProperty) {
                Class<?> eltType = ((ContainerProperty) prop).getValue().getBeanType();

                // use simple table for string lists
                if (eltType == String.class) {
                    Component list = buildSimpleTable((String) propId, (ContainerProperty) prop);
                    fieldGroup.bind((Field<?>) list, propId);
                    listBoxes.add((Field<?>) list);
                }

                // else use tab sheet
                else if (!((ContainerProperty) prop).getValue().getItemIds().isEmpty()) {
                    Component subform = buildTabs((String) propId, (ContainerProperty) prop, fieldGroup);
                    otherWidgets.add(subform);
                }
            }

            // sub object
            else if (prop instanceof ComplexProperty) {
                Component subform = buildSubForm((String) propId, (ComplexProperty) prop);
                otherWidgets.add(subform);
            }

            // scalar field
            else {
                Field<?> field = null;

                try {
                    String label = null;
                    if (prop instanceof FieldProperty)
                        label = ((FieldProperty) prop).getLabel();
                    if (label == null)
                        label = DisplayUtils.getPrettyName((String) propId);

                    String desc = null;
                    if (prop instanceof FieldProperty)
                        desc = ((FieldProperty) prop).getDescription();

                    field = buildAndBindField(label, (String) propId, prop);
                    ((AbstractField<?>) field).setDescription(desc);
                } catch (Exception e) {
                    System.err.println("No UI generator for field " + propId);
                    continue;
                }

                // add to one of the widget lists so we can order by widget type
                Class<?> propType = prop.getType();
                if (propType.equals(String.class)) {
                    if (field instanceof Label)
                        labels.add(field);
                    else
                        textBoxes.add(field);
                } else if (Enum.class.isAssignableFrom(propType))
                    numberBoxes.add(field);
                else if (Number.class.isAssignableFrom(propType))
                    numberBoxes.add(field);
                else if (field instanceof CheckBox)
                    checkBoxes.add(field);
                else
                    otherWidgets.add(field);
            }
        }
    }

    // main form
    for (Field<?> w : labels)
        form.addComponent(w);
    for (Field<?> w : textBoxes)
        form.addComponent(w);
    for (Field<?> w : listBoxes)
        form.addComponent(w);
    for (Field<?> w : numberBoxes)
        form.addComponent(w);
    for (Field<?> w : checkBoxes)
        form.addComponent(w);
    addComponent(form);

    // sub forms
    for (Component w : otherWidgets)
        addComponent(w);
}