Example usage for com.vaadin.ui FormLayout setMargin

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

Introduction

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

Prototype

@Override
    public void setMargin(boolean enabled) 

Source Link

Usage

From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.LoginDialog.java

License:Apache License

public void init() {
    //Layout//  w  ww.java 2  s  .c  o  m
    FormLayout layout = new FormLayout();
    setContent(layout);
    HorizontalLayout hlayout = new HorizontalLayout();
    hlayout.addComponent(loginButton);
    hlayout.addComponent(cancelButton);
    layout.addComponent(name);
    layout.addComponent(password);
    name.focus();
    name.setWidth(100, Unit.PERCENTAGE);
    StringLengthValidator nameVal = new StringLengthValidator(Lookup.getDefault()
            .lookup(InternationalizationProvider.class).translate("password.length.message"));
    nameVal.setMinLength(5);
    name.addValidator(nameVal);
    name.setImmediate(true);
    StringLengthValidator passVal = new StringLengthValidator(
            Lookup.getDefault().lookup(InternationalizationProvider.class).translate("password.empty.message"));
    passVal.setMinLength(3);
    password.addValidator(passVal);
    password.setImmediate(true);
    password.setWidth(100, Unit.PERCENTAGE);
    layout.addComponent(hlayout);
    layout.setComponentAlignment(name, Alignment.TOP_LEFT);
    layout.setComponentAlignment(password, Alignment.MIDDLE_LEFT);
    layout.setComponentAlignment(hlayout, Alignment.BOTTOM_LEFT);
    layout.setSpacing(true);
    layout.setMargin(true);

    // Keyboard navigation - enter key is a shortcut to login
    addActionHandler(new Handler() {
        @Override
        public Action[] getActions(Object target, Object sender) {
            return new Action[] { enterKey };
        }

        @Override
        public void handleAction(Action action, Object sender, Object target) {
            tryToLogIn();
        }
    });
}

From source file:nl.kpmg.lcm.ui.view.administration.components.StorageCreateWindow.java

License:Apache License

private void init() {
    optionsArea.setWidth("100%");
    optionsArea.setHeight("100%");
    credentialsArea.setWidth("100%");
    credentialsArea.setHeight("100%");
    enrichmentArea.setWidth("100%");
    enrichmentArea.setHeight("100%");
    saveButton.addClickListener(this);

    FormLayout panelContent = new FormLayout();
    panelContent.setMargin(true);
    panelContent.addComponent(nameField);
    panelContent.addComponent(typeField);
    panelContent.addComponent(optionsArea);
    panelContent.addComponent(credentialsArea);
    panelContent.addComponent(enrichmentArea);
    panelContent.addComponent(saveButton);

    this.setWidth(PANEL_SIZE);
    this.setModal(true);

    this.setContent(panelContent);
}

From source file:nl.kpmg.lcm.ui.view.administration.components.UserCreateWindow.java

License:Apache License

private void init() {
    saveButton.addClickListener(this);

    FormLayout panelContent = new FormLayout();
    panelContent.setMargin(true);
    nameField.setRequired(true);/*  w w  w  .j ava 2s .  co  m*/
    rolesListComboBox = initRolesListComboBox();
    pField.setId("userp");
    pathListArea.setWidth("100%");
    pathListArea.setHeight("100%");
    metadataListArea.setWidth("100%");
    metadataListArea.setHeight("100%");

    panelContent.addComponent(nameField);
    panelContent.addComponent(rolesListComboBox);
    panelContent.addComponent(pField);
    panelContent.addComponent(originField);
    panelContent.addComponent(pathListArea);
    panelContent.addComponent(metadataListArea);
    panelContent.addComponent(saveButton);

    this.setWidth(PANEL_SIZE);
    this.setModal(true);

    this.setContent(panelContent);
}

From source file:nl.kpmg.lcm.ui.view.administration.components.UserGroupCreateWindow.java

License:Apache License

private void init() {
    saveButton.addClickListener(this);

    FormLayout panelContent = new FormLayout();
    panelContent.setMargin(true);
    nameField.setRequired(true);//w w  w . java2  s.  c  o  m
    userListArea.setWidth("100%");
    userListArea.setHeight("100%");
    pathListArea.setWidth("100%");
    pathListArea.setHeight("100%");
    metadataListArea.setWidth("100%");
    metadataListArea.setHeight("100%");

    panelContent.addComponent(nameField);
    panelContent.addComponent(userListArea);
    panelContent.addComponent(pathListArea);
    panelContent.addComponent(metadataListArea);
    panelContent.addComponent(saveButton);

    this.setWidth(PANEL_SIZE);
    this.setModal(true);

    this.setContent(panelContent);
}

From source file:nl.kpmg.lcm.ui.view.transfer.components.StartTransferWindow.java

License:Apache License

private FormLayout initSettingsPanel() throws UnsupportedOperationException {
    FormLayout settingsContent = new FormLayout();
    overwriteComboBox = new ComboBox("Overwrite existing data");
    overwriteComboBox.addItem("true");
    overwriteComboBox.setItemCaption("true", "true");
    overwriteComboBox.addItem("false");
    overwriteComboBox.setItemCaption("false", "false");
    writeChunkSizeField = new TextField("Write chunck size");
    varcharSizeField = new TextField("Varchar size");
    decimalPrecisionField = new TextField("Decinal precision");
    initSettings();/*from w w  w.j  ava 2 s .com*/

    settingsContent.addComponent(overwriteComboBox);
    settingsContent.addComponent(writeChunkSizeField);
    settingsContent.addComponent(varcharSizeField);
    settingsContent.addComponent(decimalPrecisionField);
    settingsContent.setHeight(TAB_HEIGHT);
    settingsContent.setMargin(true);
    return settingsContent;
}

From source file:nl.kpmg.lcm.ui.view.transfer.components.StartTransferWindow.java

License:Apache License

private FormLayout initCommonContentPanel(String metadataId, String metadataName)
        throws UnsupportedOperationException {
    remoteLcmLabel = new Label();
    remoteLcmLabel.setCaption("Remote LCM");
    remoteLcmLabel.setValue(remoteLcmUrl);
    metadataIdLabel = new Label();
    metadataIdLabel.setCaption("Metadata Id");
    metadataIdLabel.setValue(metadataId);
    metadataNameLabel = new Label();
    metadataNameLabel.setCaption("Metadata Name");
    metadataNameLabel.setValue(metadataName);

    FormLayout commonContentPanel = new FormLayout();
    commonContentPanel.setMargin(true);
    storageListComboBox = initStorageListComboBox();
    metadataNameSpaceField = new TextField("Namespace path");
    commonContentPanel.addComponent(remoteLcmLabel);
    commonContentPanel.addComponent(metadataIdLabel);
    commonContentPanel.addComponent(metadataNameLabel);
    commonContentPanel.addComponent(storageListComboBox);
    commonContentPanel.addComponent(metadataNameSpaceField);
    commonContentPanel.addComponent(startButton);
    commonContentPanel.setMargin(true);/*from  w w  w. j a  v a  2 s  .  c o m*/
    commonContentPanel.setHeight(TAB_HEIGHT);
    return commonContentPanel;
}

From source file:org.azrul.langkuik.framework.customtype.attachment.AttachmentCustomTypeUICreator.java

@Override
public Component createUIForForm(final C currentBean, final Class<? extends CustomType> attachmentClass,
        final String pojoFieldName, final BeanView beanView, final DataAccessObject<C> conatainerClassDao,
        final DataAccessObject<? extends CustomType> customTypeDao,
        final RelationManagerFactory relationManagerFactory, final Configuration config,
        final ComponentState componentState, final Window window) {
    final FormLayout form = new FormLayout();

    final DataAccessObject<AttachmentCustomType> attachmentDao = ((DataAccessObject<AttachmentCustomType>) customTypeDao);
    final Collection<AttachmentCustomType> attachments = attachmentDao.find(currentBean, pojoFieldName, null,
            true, 0, Integer.parseInt(config.get("uploadCountLimit")));

    final WebEntityItemContainer attachmentIC = new WebEntityItemContainer(attachmentClass);
    if (!attachments.isEmpty()) {
        attachmentIC.addAll(attachments);
    }/*w ww  .jav a 2s.  co m*/
    final ListSelect attachmentList = new ListSelect("", attachmentIC);
    createAtachmentList(attachmentList, attachments, config, beanView, form);

    final String relativePath = currentBean.getClass().getCanonicalName() + File.separator
            + conatainerClassDao.getIdentifierValue(currentBean);
    final String fullPath = config.get("attachmentRepository") + File.separator + relativePath;
    MyUploadHandler<C> uploadFinishHandler = new MyUploadHandler<>(currentBean,
            Integer.parseInt(config.get("uploadCountLimit").trim()), pojoFieldName, fullPath, relativePath,
            attachmentList, attachmentIC, customTypeDao, attachmentClass, relationManagerFactory);

    //File upload/download/delete buttons
    HorizontalLayout attachmentButtons = new HorizontalLayout();
    attachmentButtons.setSpacing(true);

    UploadStateWindow uploadStateWindow = new UploadStateWindow();
    MultiFileUpload fileUpload = new MultiFileUpload(uploadFinishHandler, uploadStateWindow);
    uploadFinishHandler.setFileUpload(fileUpload);

    fileUpload.getSmartUpload().setEnabled(true);
    fileUpload.getSmartUpload().setMaxFileSize(Integer.parseInt(config.get("uploadSizeLimit").trim()));
    fileUpload.getSmartUpload().setUploadButtonCaptions("Upload files", "Upload files");
    fileUpload.getSmartUpload().setId("Upload files");
    fileUpload.setId("Upload files2");

    Button deleteAttachmentBtn = new Button("Delete file", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            Collection<AttachmentCustomType> attachments = (Collection<AttachmentCustomType>) attachmentList
                    .getValue();
            if (!attachments.isEmpty()) {
                customTypeDao.unlinkAndDelete(attachments, currentBean, pojoFieldName,
                        relationManagerFactory.create(currentBean.getClass(), attachmentClass));
                Collection<AttachmentCustomType> a = attachmentDao.find(currentBean, pojoFieldName, null, true,
                        0, Integer.parseInt(config.get("uploadCountLimit")));
                attachmentIC.removeAllItems();
                attachmentIC.addAll(a);
                attachmentIC.refreshItems();
            }
        }
    });
    deleteAttachmentBtn.setId(deleteAttachmentBtn.getCaption());

    Button downloadAttachmentBtn = new Button("Download file", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {

            Collection<AttachmentCustomType> attachments = (Collection<AttachmentCustomType>) attachmentList
                    .getValue();
            if (!attachments.isEmpty()) {
                AttachmentCustomType attachment = attachments.iterator().next();
                final String fullPath = config.get("attachmentRepository") + File.separator
                        + attachment.getRelativeLocation() + File.separator + attachment.getFileName();
                FileResource res = new FileResource(new File(fullPath));
                beanView.setViewResource("DOWNLOAD", res);
                ResourceReference rr = ResourceReference.create(res, beanView, "DOWNLOAD");
                Page.getCurrent().open(rr.getURL(), null);
            }
        }
    });
    downloadAttachmentBtn.setId(downloadAttachmentBtn.getCaption());

    Button closeWindowBtn = new Button("Close", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            window.close();
        }
    });
    closeWindowBtn.setId(closeWindowBtn.getCaption());

    if (componentState.equals(ComponentState.EDITABLE)) {
        attachmentButtons.addComponent(fileUpload);
        attachmentButtons.addComponent(deleteAttachmentBtn);
    }

    if (componentState.equals(ComponentState.EDITABLE) || componentState.equals(ComponentState.READ_ONLY)) {
        attachmentButtons.addComponent(downloadAttachmentBtn);
    }

    attachmentButtons.addComponent(closeWindowBtn);

    form.addComponent(attachmentButtons);
    form.setMargin(true);
    //beanView.addComponent(form);
    return form;
}

From source file:org.azrul.langkuik.framework.webgui.BeanView.java

@Override
public void enter(final ViewChangeListener.ViewChangeEvent vcevent) {
    setCurrentView(vcevent.getViewName());
    //reset form/*from   w w  w  .j av a 2s  .  co m*/
    this.removeAllComponents();

    //determine user details
    UserDetails userDetails = null;
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (!(auth instanceof AnonymousAuthenticationToken)) {
        userDetails = (UserDetails) auth.getPrincipal();
    } else {
        return;
    }

    final Set<String> currentUserRoles = new HashSet<>();
    for (GrantedAuthority grantedAuth : userDetails.getAuthorities()) {
        currentUserRoles.add(grantedAuth.getAuthority());
    }

    //determine entity rights 
    EntityRight entityRight = null;

    EntityUserMap[] entityUserMaps = ((WebEntity) currentBean.getClass().getAnnotation(WebEntity.class))
            .userMap();
    for (EntityUserMap e : entityUserMaps) {
        if (currentUserRoles.contains(e.role()) || ("*").equals(e.role())) {
            entityRight = e.right();
            break;
        }
    }
    if (entityRight == null) { //if entityRight=EntityRight.NONE, still allow to go through because field level might be accessible
        //Not accessible
        return;
    }

    //create bean utils
    final BeanUtils beanUtils = new BeanUtils();

    //rebuild pageParameter.getBreadcrumb()
    BreadCrumbBuilder.buildBreadCrumb(vcevent.getNavigator(), pageParameter.getBreadcrumb(),
            pageParameter.getHistory());

    //rebuild components
    if (currentBean == null) {
        return;
    }

    //refresh current item
    C newBean = dao.refresh(currentBean);
    if (newBean != null) {
        currentBean = newBean;
    }

    final BeanFieldGroup fieldGroup = new BeanFieldGroup(currentBean.getClass());
    fieldGroup.setItemDataSource(currentBean);
    final FormLayout form = new FormLayout();
    Map<String, Map<Integer, FieldContainer>> groups = beanUtils.createGroupsFromBean(currentBean.getClass());

    //render form according to tab
    if (groups.size() == 1) {
        createForm(entityRight, currentUserRoles, groups, fieldGroup, pageParameter.getCustomTypeDaos(),
                vcevent.getNavigator(), form);
    } else {
        TabSheet tabSheet = new TabSheet();
        for (String group : groups.keySet()) {
            if (("All").equals(group)) {
                createForm(entityRight, currentUserRoles, groups, group, fieldGroup,
                        pageParameter.getCustomTypeDaos(), vcevent.getNavigator(), form);
            } else {
                FormLayout tab = new FormLayout();
                createForm(entityRight, currentUserRoles, groups, group, fieldGroup,
                        pageParameter.getCustomTypeDaos(), vcevent.getNavigator(), tab);
                tabSheet.addTab(tab, group);

            }
        }
        form.addComponent(tabSheet);
    }

    //Navigation and actions
    HorizontalLayout navButtons = new HorizontalLayout();
    navButtons.setSpacing(true);

    Button saveAndBackBtn = new Button("Save and back", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {
                fieldGroup.commit();
                currentBean = (C) fieldGroup.getItemDataSource().getBean();
                currentBean = saveBean(currentBean, parentBean, beanUtils, currentUserRoles);
                if (!pageParameter.getHistory().isEmpty()) {
                    String currentView = pageParameter.getHistory().pop().getViewHandle();
                    String lastView = pageParameter.getHistory().peek().getViewHandle();
                    vcevent.getNavigator().removeView(currentView);
                    vcevent.getNavigator().navigateTo(lastView);
                }
            } catch (FieldGroup.CommitException ex) {
                handleFieldsError(fieldGroup);
            }
        }

    });
    navButtons.addComponent(saveAndBackBtn);
    saveAndBackBtn.setId(saveAndBackBtn.getCaption());

    form.addComponent(navButtons);
    form.setMargin(new MarginInfo(true));
    this.addComponent(form);
}

From source file:org.bitpimp.VaadinCurrencyConverter.MyVaadinApplication.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    // Set the window or tab title
    getPage().setTitle("Yahoo Currency Converter");

    // Create the content root layout for the UI
    final FormLayout content = new FormLayout();
    content.setMargin(true);
    final Panel panel = new Panel(content);
    panel.setWidth("500");
    panel.setHeight("400");
    final VerticalLayout root = new VerticalLayout();
    root.addComponent(panel);// www.j  av a2  s  . com
    root.setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
    root.setSizeFull();
    root.setMargin(true);

    setContent(root);

    content.addComponent(new Embedded("",
            new ExternalResource("https://vaadin.com/vaadin-theme/images/vaadin/vaadin-logo-color.png")));
    content.addComponent(new Embedded("",
            new ExternalResource("http://images.wikia.com/logopedia/images/e/e4/YahooFinanceLogo.png")));

    // Display the greeting
    final Label heading = new Label("<b>Simple Currency Converter " + "Using YQL/Yahoo Finance Service</b>",
            ContentMode.HTML);
    heading.setWidth(null);
    content.addComponent(heading);

    // Build the set of fields for the converter form
    final TextField fromField = new TextField("From Currency", "AUD");
    fromField.setRequired(true);
    fromField.addValidator(new StringLengthValidator(CURRENCY_CODE_REQUIRED, 3, 3, false));
    content.addComponent(fromField);

    final TextField toField = new TextField("To Currency", "USD");
    toField.setRequired(true);
    toField.addValidator(new StringLengthValidator(CURRENCY_CODE_REQUIRED, 3, 3, false));
    content.addComponent(toField);

    final TextField resultField = new TextField("Result");
    resultField.setEnabled(false);
    content.addComponent(resultField);

    final TextField timeField = new TextField("Time");
    timeField.setEnabled(false);
    content.addComponent(timeField);

    final Button submitButton = new Button("Submit", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            // Do the conversion
            final String result = converter.convert(fromField.getValue().toUpperCase(),
                    toField.getValue().toUpperCase());
            if (result != null) {
                resultField.setValue(result);
                timeField.setValue(new Date().toString());
            }
        }
    });
    content.addComponent(submitButton);

    // Configure the error handler for the UI
    UI.getCurrent().setErrorHandler(new DefaultErrorHandler() {
        @Override
        public void error(com.vaadin.server.ErrorEvent event) {
            // Find the final cause
            String cause = "<b>The operation failed :</b><br/>";
            Throwable th = Throwables.getRootCause(event.getThrowable());
            if (th != null)
                cause += th.getClass().getName() + "<br/>";

            // Display the error message in a custom fashion
            content.addComponent(new Label(cause, ContentMode.HTML));

            // Do the default error handling (optional)
            doDefault(event);
        }
    });
}

From source file:org.ikasan.dashboard.ui.framework.window.IkasanMessageDialog.java

License:BSD License

/**
 * Helper method to initialise this object.
 * //from   w w w  . ja  v  a2 s .  co  m
 * @param message
 */
protected void init(String message) {
    super.setModal(true);
    super.setResizable(false);
    super.center();

    FormLayout layout = new FormLayout();
    layout.setMargin(true);
    layout.addComponent(new Label(message));

    Button okButton = new Button("OK");
    okButton.setStyleName(ValoTheme.BUTTON_SMALL);

    okButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            action.exectuteAction();
            close();
        }
    });

    Button cancelButton = new Button("Cancel");
    cancelButton.setStyleName(ValoTheme.BUTTON_SMALL);

    cancelButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            action.ignoreAction();
            close();
        }
    });

    HorizontalLayout wrapper = new HorizontalLayout();
    wrapper.setWidth(100, Unit.PERCENTAGE);
    HorizontalLayout hlayout = new HorizontalLayout();
    wrapper.addComponent(hlayout);
    wrapper.setComponentAlignment(hlayout, Alignment.MIDDLE_CENTER);
    hlayout.addComponent(okButton);
    hlayout.addComponent(cancelButton);

    layout.addComponent(wrapper);

    super.setContent(layout);
}