Example usage for com.vaadin.ui Window setCaption

List of usage examples for com.vaadin.ui Window setCaption

Introduction

In this page you can find the example usage for com.vaadin.ui Window setCaption.

Prototype

@Override
    public void setCaption(String caption) 

Source Link

Usage

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  a v a 2  s. co m*/
        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.hawkbit.ui.artifacts.smtable.SoftwareModuleDetails.java

License:Open Source License

@Override
protected void onEdit(final ClickEvent event) {
    final Window addSoftwareModule = softwareModuleAddUpdateWindow
            .createUpdateSoftwareModuleWindow(getSelectedBaseEntityId());
    addSoftwareModule.setCaption(getI18n().get("upload.caption.update.swmodule"));
    UI.getCurrent().addWindow(addSoftwareModule);
    addSoftwareModule.setVisible(Boolean.TRUE);
}

From source file:org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleTableHeader.java

License:Open Source License

@Override
protected void addNewItem(final ClickEvent event) {
    final Window addSoftwareModule = softwareModuleAddUpdateWindow.createAddSoftwareModuleWindow();
    addSoftwareModule.setCaption(i18n.get("upload.caption.add.new.swmodule"));
    UI.getCurrent().addWindow(addSoftwareModule);
    addSoftwareModule.setVisible(Boolean.TRUE);
}

From source file:org.eclipse.hawkbit.ui.common.detailslayout.AbstractSoftwareModuleDetails.java

License:Open Source License

@Override
protected void onEdit(final ClickEvent event) {
    final Window addSoftwareModule = softwareModuleAddUpdateWindow
            .createUpdateSoftwareModuleWindow(getSelectedBaseEntityId());
    addSoftwareModule.setCaption(
            getI18n().getMessage("caption.update", getI18n().getMessage("caption.software.module")));
    UI.getCurrent().addWindow(addSoftwareModule);
    addSoftwareModule.setVisible(Boolean.TRUE);
}

From source file:org.eclipse.hawkbit.ui.common.table.AbstractSoftwareModuleTableHeader.java

License:Open Source License

@Override
protected void addNewItem(final ClickEvent event) {
    final Window addSoftwareModule = softwareModuleAddUpdateWindow.createAddSoftwareModuleWindow();
    addSoftwareModule
            .setCaption(i18n.getMessage("caption.create.new", i18n.getMessage("caption.software.module")));
    UI.getCurrent().addWindow(addSoftwareModule);
    addSoftwareModule.setVisible(Boolean.TRUE);
}

From source file:org.eclipse.hawkbit.ui.distributions.smtable.SwModuleDetails.java

License:Open Source License

private void showArtifactDetailsWindow(final SoftwareModule softwareModule) {
    final Window artifactDtlsWindow = new Window();
    artifactDtlsWindow.setCaption(HawkbitCommonUtil.getArtifactoryDetailsLabelId(
            softwareModule.getName() + "." + softwareModule.getVersion(), getI18n()));
    artifactDtlsWindow.setCaptionAsHtml(true);
    artifactDtlsWindow.setClosable(true);
    artifactDtlsWindow.setResizable(true);
    artifactDtlsWindow.setImmediate(true);
    artifactDtlsWindow.setWindowMode(WindowMode.NORMAL);
    artifactDtlsWindow.setModal(true);/*  w  w  w  .  ja  v a  2 s.  c o  m*/
    artifactDtlsWindow.addStyleName(SPUIStyleDefinitions.CONFIRMATION_WINDOW_CAPTION);

    artifactDetailsLayout.setFullWindowMode(false);
    artifactDetailsLayout.populateArtifactDetails(softwareModule);
    artifactDetailsLayout.getArtifactDetailsTable().setWidth(700, Unit.PIXELS);
    artifactDetailsLayout.getArtifactDetailsTable().setHeight(500, Unit.PIXELS);
    artifactDtlsWindow.setContent(artifactDetailsLayout.getArtifactDetailsTable());

    artifactDtlsWindow.addWindowModeChangeListener(event -> {
        if (event.getWindowMode() == WindowMode.MAXIMIZED) {
            artifactDtlsWindow.setSizeFull();
            artifactDetailsLayout.setFullWindowMode(true);
            artifactDetailsLayout.createMaxArtifactDetailsTable();
            artifactDetailsLayout.getMaxArtifactDetailsTable().setWidth(100, Unit.PERCENTAGE);
            artifactDetailsLayout.getMaxArtifactDetailsTable().setHeight(100, Unit.PERCENTAGE);
            artifactDtlsWindow.setContent(artifactDetailsLayout.getMaxArtifactDetailsTable());
        } else {
            artifactDtlsWindow.setSizeUndefined();
            artifactDtlsWindow.setContent(artifactDetailsLayout.getArtifactDetailsTable());
        }
    });
    UI.getCurrent().addWindow(artifactDtlsWindow);
}

From source file:org.eclipse.hawkbit.ui.management.dstable.DistributionDetails.java

License:Open Source License

@Override
protected void onEdit(final ClickEvent event) {
    final Window newDistWindow = distributionAddUpdateWindowLayout.getWindow(getSelectedBaseEntityId());
    newDistWindow.setCaption(getI18n().get("caption.update.dist"));
    UI.getCurrent().addWindow(newDistWindow);
    newDistWindow.setVisible(Boolean.TRUE);
}

From source file:org.eclipse.hawkbit.ui.management.targettable.TargetDetails.java

License:Open Source License

private void openWindow() {
    final Window targetWindow = targetAddUpdateWindowLayout
            .getWindow(getSelectedBaseEntity().getControllerId());
    if (targetWindow == null) {
        return;//ww  w . ja va  2 s.  c om
    }
    targetWindow.setCaption(getI18n().getMessage("caption.update", getI18n().getMessage("caption.target")));
    UI.getCurrent().addWindow(targetWindow);
    targetWindow.setVisible(Boolean.TRUE);
}

From source file:org.eclipse.hawkbit.ui.management.targettable.TargetTableHeader.java

License:Open Source License

@Override
protected void addNewItem(final ClickEvent event) {
    targetAddUpdateWindow.resetComponents();
    final Window addTargetWindow = targetAddUpdateWindow.createNewWindow();
    addTargetWindow.setCaption(i18n.getMessage("caption.create.new", i18n.getMessage("caption.target")));
    UI.getCurrent().addWindow(addTargetWindow);
    addTargetWindow.setVisible(Boolean.TRUE);
}

From source file:org.opencms.ui.A_CmsUI.java

License:Open Source License

/**
 * Replaces the ui content with a single dialog.<p>
 *
 * @param caption the caption/*  w  w  w.  j  a  va  2  s .  co m*/
 * @param dialog the dialog content
 */
public void setContentToDialog(String caption, CmsBasicDialog dialog) {

    setContent(new Label());
    Window window = CmsBasicDialog.prepareWindow(DialogWidth.narrow);
    window.setContent(dialog);
    window.setCaption(caption);
    window.setClosable(false);
    addWindow(window);
    window.center();
}