Example usage for com.vaadin.ui Window setContent

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

Introduction

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

Prototype

@Override
public void setContent(Component content) 

Source Link

Document

Sets the content of this container.

Usage

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

License:Apache License

private void createRequirementSpecNodeMenu(ContextMenu menu) {
    MenuItem create = menu.addItem(TRANSLATOR.translate("create.requiremnet"), VaadinIcons.PLUS,
            (MenuItem selectedItem) -> {
                Requirement r = new Requirement();
                r.setRequirementSpecNode((RequirementSpecNode) tree.getValue());
                displayRequirement(r, true);
            });//from   www  .  j av  a2 s .c om
    create.setEnabled(checkRight("requirement.modify"));
    MenuItem edit = menu.addItem(TRANSLATOR.translate("edit.req.spec.node"), EDIT_ICON,
            (MenuItem selectedItem) -> {
                displayRequirementSpecNode((RequirementSpecNode) tree.getValue(), true);
            });
    edit.setEnabled(checkRight("requirement.modify"));
    MenuItem importRequirement = menu.addItem(TRANSLATOR.translate("import.requirement"), IMPORT_ICON,
            (MenuItem selectedItem) -> {// Create a sub-window and set the content
                Window subWindow = new VMWindow(TRANSLATOR.translate("import.requirement"));
                VerticalLayout subContent = new VerticalLayout();
                subWindow.setContent(subContent);

                //Add a checkbox to know if file has headers or not
                CheckBox cb = new CheckBox(TRANSLATOR.translate("file.has.header"));

                FileUploader receiver = new FileUploader();
                Upload upload = new Upload(TRANSLATOR.translate("upload.excel"), receiver);
                upload.addSucceededListener((Upload.SucceededEvent event1) -> {
                    try {
                        subWindow.close();
                        //TODO: Display the excel file (partially), map columns and import
                        //Process the file
                        RequirementImporter importer = new RequirementImporter(receiver.getFile(),
                                (RequirementSpecNode) tree.getValue());

                        importer.importFile(cb.getValue());
                        importer.processImport();
                        buildProjectTree(tree.getValue());
                        updateScreen();
                    } catch (RequirementImportException ex) {
                        LOG.log(Level.SEVERE, TRANSLATOR.translate("import.error"), ex);
                        Notification.show(TRANSLATOR.translate("import.unsuccessful"),
                                Notification.Type.ERROR_MESSAGE);
                    } catch (VMException ex) {
                        LOG.log(Level.SEVERE, null, ex);
                    }
                });
                upload.addFailedListener((Upload.FailedEvent event1) -> {
                    LOG.log(Level.SEVERE, "Upload unsuccessful!\n{0}", event1.getReason());
                    Notification.show(TRANSLATOR.translate("upload.unsuccessful"),
                            Notification.Type.ERROR_MESSAGE);
                    subWindow.close();
                });
                subContent.addComponent(cb);
                subContent.addComponent(upload);
                // Open it in the UI
                addWindow(subWindow);
            });
    importRequirement.setEnabled(checkRight("requirement.modify"));
}

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

License:Apache License

private void createTestCaseMenu(ContextMenu menu) {
    MenuItem create = menu.addItem(TRANSLATOR.translate("create.step"), VaadinIcons.PLUS,
            (MenuItem selectedItem) -> {
                TestCase tc = (TestCase) tree.getValue();
                Step s = new Step();
                s.setStepSequence(tc.getStepList().size() + 1);
                s.setTestCase(tc);//w w  w.  jav  a  2 s .c o m
                displayStep(s, true);
            });
    create.setEnabled(checkRight("requirement.modify"));
    MenuItem edit = menu.addItem(TRANSLATOR.translate("edit.test.case"), EDIT_ICON, (MenuItem selectedItem) -> {
        displayTestCase((TestCase) tree.getValue(), true);
    });
    edit.setEnabled(checkRight("testcase.modify"));
    MenuItem importSteps = menu.addItem(TRANSLATOR.translate("import.step"), IMPORT_ICON,
            (MenuItem selectedItem) -> { // Create a sub-window and set the content
                Window subWindow = new VMWindow(TRANSLATOR.translate("import.test.case.step"));
                VerticalLayout subContent = new VerticalLayout();
                subWindow.setContent(subContent);

                //Add a checkbox to know if file has headers or not
                CheckBox cb = new CheckBox(TRANSLATOR.translate("file.has.header"));

                FileUploader receiver = new FileUploader();
                Upload upload = new Upload(TRANSLATOR.translate("upload.excel"), receiver);
                upload.addSucceededListener((Upload.SucceededEvent event1) -> {
                    try {
                        subWindow.close();
                        //TODO: Display the excel file (partially), map columns and import
                        //Process the file
                        TestCase tc = (TestCase) tree.getValue();
                        StepImporter importer = new StepImporter(receiver.getFile(), tc);
                        importer.importFile(cb.getValue());
                        importer.processImport();
                        SortedMap<Integer, Step> map = new TreeMap<>();
                        tc.getStepList().forEach((s) -> {
                            map.put(s.getStepSequence(), s);
                        });
                        //Now update the sequence numbers
                        int count = 0;
                        for (Entry<Integer, Step> entry : map.entrySet()) {
                            entry.getValue().setStepSequence(++count);
                            try {
                                new StepJpaController(DataBaseManager.getEntityManagerFactory())
                                        .edit(entry.getValue());
                            } catch (Exception ex) {
                                LOG.log(Level.SEVERE, null, ex);
                            }
                        }
                        buildProjectTree(new TestCaseServer(tc.getTestCasePK()).getEntity());
                        updateScreen();
                    } catch (TestCaseImportException ex) {
                        LOG.log(Level.SEVERE, TRANSLATOR.translate("import.error"), ex);
                        Notification.show(TRANSLATOR.translate("import.unsuccessful"),
                                Notification.Type.ERROR_MESSAGE);
                    }
                });
                upload.addFailedListener((Upload.FailedEvent event1) -> {
                    LOG.log(Level.SEVERE, "Upload unsuccessful!\n{0}", event1.getReason());
                    Notification.show(TRANSLATOR.translate("upload.unsuccessful"),
                            Notification.Type.ERROR_MESSAGE);
                    subWindow.close();
                });
                subContent.addComponent(cb);
                subContent.addComponent(upload);
                // Open it in the UI
                addWindow(subWindow);
            });
    importSteps.setEnabled(checkRight("requirement.modify"));
    MenuItem export = menu.addItem(TRANSLATOR.translate("general.export"), VaadinIcons.DOWNLOAD,
            (MenuItem selectedItem) -> {
                TestCase tc = (TestCase) tree.getValue();
                UI.getCurrent().addWindow(TestCaseExporter.getTestCaseExporter(Arrays.asList(tc)));
            });
    export.setEnabled(checkRight("testcase.view"));
    addExecutionDashboard(menu);
}

From source file:org.activiti.kickstart.KickStartApplication.java

License:Apache License

protected void initMainWindow() {

    Window mainWindow = new Window(TITLE);
    setMainWindow(mainWindow);/*ww  w. j  a v a2s.c o m*/
    Panel p = new Panel();
    p.setSizeFull();
    mainWindow.setContent(p);

    mainLayout = new CustomLayout(THEME_NAME); // uses layout defined in webapp/Vaadin/themes/yakalo
    mainLayout.setSizeFull();
    p.setContent(mainLayout);

    initSplitPanel();
    initViewManager();
    initActionsPanel();
}

From source file:org.aksw.autosparql.tbsl.gui.vaadin.TBSLApplication.java

License:Apache License

@Override
public void init() {
    // Create the application data instance
    UserSession sessionData = new UserSession(this);
    // Register it as a listener in the application context
    getContext().addTransactionListener(sessionData);

    setTheme("custom");

    ViewHandler.initialize(this);
    SessionHandler.initialize(this);
    Permissions.initialize(this, new JPAPermissionManager());

    Window mainWindow = new Window("AutoSPARQL TBSL");
    mainWindow.addParameterHandler(this);
    setMainWindow(mainWindow);// w  w  w  .j a v  a2 s  . c o m

    mainView = new MainView();
    mainWindow.setContent(mainView);
    mainWindow.setSizeFull();

    setLogoutURL("http://aksw.org");

    mainWindow.addActionHandler(new Action.Handler() {

        @Override
        public void handleAction(Action action, Object sender, Object target) {
            if (action == action_query) {
                onShowLearnedQuery();
            }

        }

        @Override
        public Action[] getActions(Object target, Object sender) {
            return new Action[] { action_query };
        }
    });

}

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 {//from  w  w  w  .  j a v a2 s  .c o 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.azrul.langkuik.framework.webgui.EditorTableView.java

public void enter(final ViewChangeListener.ViewChangeEvent vcevent) {
    setCurrentView(vcevent.getViewName());
    this.removeAllComponents();

    //get user roles
    UserDetails userDetails = null;//w w w  .  jav a 2  s. c o m
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (!(auth instanceof AnonymousAuthenticationToken)) {
        userDetails = (UserDetails) auth.getPrincipal();
    } else {
        return;
    }
    Set<String> currentUserRoles = new HashSet<>();
    for (GrantedAuthority grantedAuth : userDetails.getAuthorities()) {
        currentUserRoles.add(grantedAuth.getAuthority());
    }

    //determine entity rights 
    EntityRight entityRight = null;

    EntityUserMap[] entityUserMaps = classOfBean.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
    BeanUtils beanUtils = new BeanUtils();

    //creat bread crumb
    BreadCrumbBuilder.buildBreadCrumb(vcevent.getNavigator(), pageParameter.getBreadcrumb(),
            pageParameter.getHistory());

    //create form
    FormLayout form = new FormLayout();
    FindAnyEntityParameter<C> searchQuery = new FindAnyEntityParameter<>(classOfBean);
    FindEntityCollectionParameter<P, C> entityCollectionQuery = new FindEntityCollectionParameter<>(parentBean,
            parentToBeanField,
            pageParameter.getRelationManagerFactory().create((Class<P>) parentBean.getClass(), classOfBean));

    final SearchDataTableLayout<C> allDataTableLayout = new SearchDataTableLayout<>(searchQuery, classOfBean,
            dao, noBeansPerPage, pageParameter.getCustomTypeDaos(), pageParameter.getConfig(), currentUserRoles,
            entityRight);
    final CollectionDataTableLayout<P, C> beanTableLayout = new CollectionDataTableLayout<>(
            entityCollectionQuery, classOfBean, dao, noBeansPerPage, pageParameter.getCustomTypeDaos(),
            pageParameter.getConfig(), currentUserRoles, entityRight);

    //handle associate existing data
    final Window window = new Window("Associate");
    window.setId(window.getCaption());
    window.setContent(allDataTableLayout);
    window.setModal(true);

    HorizontalLayout popupButtonLayout = new HorizontalLayout();

    Button associateToCurrentBtn = new Button("Associate to current", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            Collection<C> allDataList = allDataTableLayout.getTableValues();
            beanTableLayout.associateEntities(allDataList, choiceType);
            window.close();
        }
    });
    associateToCurrentBtn.setId(associateToCurrentBtn.getCaption());
    popupButtonLayout.addComponent(associateToCurrentBtn);

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

    popupButtonLayout.setSpacing(true);
    MarginInfo marginInfo = new MarginInfo(true);

    allDataTableLayout.setMargin(marginInfo);
    allDataTableLayout.addComponent(popupButtonLayout);
    if (parentToBeanFieldState.equals(ComponentState.EDITABLE)) {
        Button associateExistingBtn = new Button("Associate existing", new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {

                EditorTableView.this.getUI().addWindow(window);
            }
        });
        form.addComponent(associateExistingBtn);
        associateExistingBtn.setId(associateExistingBtn.getCaption());
    }
    form.addComponent(beanTableLayout);

    //Navigation and actions
    HorizontalLayout buttonLayout = new HorizontalLayout();
    if (beanUtils.isCreatable(classOfBean, currentUserRoles)
            && parentToBeanFieldState.equals(ComponentState.EDITABLE)) {
        Button addNewBtn = new Button("Add new", new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                C currentBean = dao.createNew(true);//dao.createAndSave(parentBean, parentToBeanField, pageParameter.getRelationManagerFactory().create((Class<P>) parentBean.getClass(), classOfBean));
                BeanView<P, C> beanView = new BeanView<P, C>(currentBean, parentBean, parentToBeanField,
                        pageParameter);
                String targetView = "CHOOSE_ONE_TABLE_VIEW_" + UUID.randomUUID().toString();
                WebEntity myObject = (WebEntity) currentBean.getClass().getAnnotation(WebEntity.class);
                History his = new History(targetView, "Add new " + myObject.name());
                pageParameter.getHistory().push(his);
                vcevent.getNavigator().addView(targetView, beanView);
                vcevent.getNavigator().navigateTo(targetView);

            }
        });
        buttonLayout.addComponent(addNewBtn);
        addNewBtn.setId(addNewBtn.getCaption());
    }

    if (beanUtils.isEditable(classOfBean, currentUserRoles)
            || beanUtils.isViewable(classOfBean, currentUserRoles)) {
        Button manageBtn = new Button("Manage", new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                C currentBean = beanTableLayout.getTableValues().iterator().next();
                if (currentBean != null) {
                    BeanView<P, C> beanView = new BeanView<P, C>(currentBean, parentBean, parentToBeanField,
                            pageParameter);
                    String targetView = "CHOOSE_ONE_TABLE_VIEW_" + UUID.randomUUID().toString();
                    WebEntity myObject = (WebEntity) currentBean.getClass().getAnnotation(WebEntity.class);
                    History his = new History(targetView, "Manage " + myObject.name());
                    pageParameter.getHistory().push(his);
                    vcevent.getNavigator().addView(targetView, beanView);
                    vcevent.getNavigator().navigateTo(targetView);
                }
            }
        });
        buttonLayout.addComponent(manageBtn);
        manageBtn.setId(manageBtn.getCaption());
    }

    if (parentToBeanFieldState.equals(ComponentState.EDITABLE)) {

        if (beanUtils.isCreatable(classOfBean, currentUserRoles)
                && parentToBeanFieldState.equals(ComponentState.EDITABLE)) {
            Button deleteBtn = new Button("Delete", new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent event) {
                    final Collection<C> currentBeans = (Collection<C>) beanTableLayout.getTableValues();
                    if (!currentBeans.isEmpty()) {
                        ConfirmDialog.show(EditorTableView.this.getUI(), "Please Confirm:",
                                "Are you really sure you want to delete these entries?", "I am", "Not quite",
                                new ConfirmDialog.Listener() {
                                    @Override
                                    public void onClose(ConfirmDialog dialog) {
                                        if (dialog.isConfirmed()) {
                                            EditorTableView.this.parentBean = beanTableLayout
                                                    .deleteData(currentBeans);
                                        }
                                    }
                                });
                    }
                }
            });
            buttonLayout.addComponent(deleteBtn);
            deleteBtn.setId(deleteBtn.getCaption());
        }
    }

    Button saveAndBackBtn = new Button("Save and back", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            //parentDao.save(parentBean);
            if (!pageParameter.getHistory().isEmpty()) {
                String currentView = pageParameter.getHistory().pop().getViewHandle();
                String lastView = pageParameter.getHistory().peek().getViewHandle();
                vcevent.getNavigator().removeView(currentView);
                vcevent.getNavigator().navigateTo(lastView);
            }
        }
    });
    buttonLayout.addComponent(saveAndBackBtn);
    saveAndBackBtn.setId(saveAndBackBtn.getCaption());

    buttonLayout.setSpacing(true);
    form.addComponent(buttonLayout);
    this.addComponent(form);
}

From source file:org.casbah.ui.IssuedCertificateList.java

License:Open Source License

private void collectKeyCertificateInfo() throws CAProviderException {
    final Window principalWindow = new Window("Specify Certificate Details");
    principalWindow.setPositionX(200);/*w  w w. j  av a  2 s . c o m*/
    principalWindow.setPositionY(100);
    principalWindow.setWidth("600px");
    principalWindow.setHeight("500px");
    principalWindow.addListener(new Window.CloseListener() {

        private static final long serialVersionUID = 1L;

        public void windowClose(CloseEvent e) {
            parentApplication.getMainWindow().removeWindow(principalWindow);

        }
    });

    VerticalLayout vl = new VerticalLayout();
    final PrincipalComponent pc = new PrincipalComponent();
    Principal parentPrincipal = new Principal(provider.getCACertificate().getSubjectX500Principal());
    pc.init(new Principal(parentPrincipal, provider.getRuleMap()));
    vl.addComponent(pc);
    HorizontalLayout passLayout = new HorizontalLayout();
    vl.addComponent(passLayout);
    final TextField pass1 = new TextField("Private key/keystore passphrase");
    pass1.setSecret(true);
    final TextField pass2 = new TextField();
    pass2.setSecret(true);
    passLayout.addComponent(pass1);
    passLayout.addComponent(pass2);
    passLayout.setComponentAlignment(pass1, Alignment.BOTTOM_CENTER);
    passLayout.setComponentAlignment(pass2, Alignment.BOTTOM_CENTER);

    final OptionGroup type = new OptionGroup("Bundle Type");
    type.addItem(BundleType.OPENSSL);
    type.addItem(BundleType.PKCS12);
    type.addItem(BundleType.JKS);
    type.setValue(BundleType.OPENSSL);
    vl.addComponent(type);

    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.addComponent(new Button("Create", new Button.ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            if (pass1.getValue().equals(pass2.getValue())) {
                try {
                    createKeyCertificatePair(pc.toPrincipal(), (String) pass1.getValue(),
                            (BundleType) type.getValue());
                    parentApplication.getMainWindow().removeWindow(principalWindow);
                } catch (Exception e) {
                    logger.severe(e.getMessage());
                    parentApplication.getMainWindow().showNotification(
                            "An error prevented the correct creation of the key/certificate pair",
                            Notification.TYPE_ERROR_MESSAGE);
                }
            } else {
                parentApplication.getMainWindow().showNotification("Passphrases do not match",
                        Notification.TYPE_ERROR_MESSAGE);
            }
        }
    }));
    buttonsLayout.addComponent(new Button("Cancel", new Button.ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            parentApplication.getMainWindow().removeWindow(principalWindow);
        }
    }));

    vl.addComponent(buttonsLayout);
    principalWindow.setContent(vl);
    parentApplication.getMainWindow().addWindow(principalWindow);
}

From source file:org.eclipse.hawkbit.ui.common.builder.WindowBuilder.java

License:Open Source License

/**
 * Build window based on type./*from   w  ww.j  av  a  2  s .  c  o m*/
 *
 * @return Window
 */
public Window buildWindow() {
    final Window window = new Window(caption);
    window.setContent(content);
    window.setSizeUndefined();
    window.setModal(true);
    window.setResizable(false);

    decorateWindow(window);

    if (SPUIDefinitions.CREATE_UPDATE_WINDOW.equals(type)) {
        window.setClosable(false);
    }

    return window;
}

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);//from   ww w  .j av  a2 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.escidoc.browser.ui.OrganizationSelectionView.java

License:Open Source License

public Window modalWindow() {
    final Window modalWindow = new Window("Select an Organization");
    modalWindow.setHeight("600px");
    modalWindow.setWidth("400px");
    VerticalLayout modalWindowLayout = (VerticalLayout) modalWindow.getContent();
    modalWindow.setModal(true);/*  w  ww  .  j av a2  s .  co m*/

    modalWindow.setContent(modalWindowLayout);

    modalWindowLayout.setMargin(true);
    modalWindowLayout.setSpacing(true);

    // modalWindowLayout.setWidth("400px");
    // modalWindowLayout.setHeight("600px");
    modalWindowLayout.setSizeUndefined();

    orgUnitFilter = new TextField(ViewConstants.ORGANIZATIONAL_UNIT);

    orgUnitFilter.setWidth("300px");
    modalWindowLayout.addComponent(orgUnitFilter);

    orgUnitFilter.addListener(new TextChangeListener() {

        private SimpleStringFilter filter;

        @Override
        public void textChange(TextChangeEvent event) {
            // // TODO refactor this, the list should not return the data
            // source
            Filterable ds = (Filterable) tree.getDataSource();
            ds.removeAllContainerFilters();
            filter = new SimpleStringFilter(PropertyId.NAME, event.getText(), true, false);
            ds.addContainerFilter(filter);
        }
    });

    buildOrganizationTreeView();
    modalWindowLayout.addComponent(tree);

    Button saveButton = new Button(ViewConstants.SAVE, new Button.ClickListener() {

        @Override
        public void buttonClick(@SuppressWarnings("unused") ClickEvent event) {
            try {
                ResourceModel selected = tree.getSelected();
                List<ResourceModel> list = new ArrayList<ResourceModel>();
                list.add(selected);

                UserGroup updateGroup = repositories.group().updateGroup(resourceProxy.getId(),
                        (String) nameField.getValue(), list);
                mw.showNotification("Group, " + updateGroup.getXLinkTitle() + ", is updated",
                        Window.Notification.TYPE_TRAY_NOTIFICATION);

                dataSource.addBean(selected);
                mw.removeWindow(modalWindow);
            } catch (EscidocClientException e) {
                StringBuilder errorMessage = new StringBuilder();
                errorMessage.append("Can not update a group. Reason: ");
                errorMessage.append(e.getMessage());
                mw.showNotification(ViewConstants.ERROR, errorMessage.toString(),
                        Window.Notification.TYPE_ERROR_MESSAGE);
            }
        }
    });
    modalWindowLayout.addComponent(saveButton);
    return modalWindow;
}