List of usage examples for com.vaadin.ui Window setId
@Override public void setId(String id)
From source file:com.haulmont.cuba.web.exception.NoUserSessionHandler.java
License:Apache License
protected void showNoUserSessionDialog(App app) { Messages messages = AppBeans.get(Messages.NAME); Window dialog = new NoUserSessionExceptionDialog(); dialog.setStyleName("c-nousersession-dialog"); dialog.setCaption(messages.getMainMessage("dialogs.Information", locale)); dialog.setClosable(false);/*from w ww. j a v a 2s .com*/ dialog.setResizable(false); dialog.setModal(true); AppUI ui = app.getAppUI(); if (ui.isTestMode()) { dialog.setCubaId("optionDialog"); dialog.setId(ui.getTestIdManager().getTestId("optionDialog")); } Label messageLab = new CubaLabel(); messageLab.setWidthUndefined(); messageLab.setValue(messages.getMainMessage("noUserSession.message", locale)); VerticalLayout layout = new VerticalLayout(); layout.setSpacing(true); layout.setWidthUndefined(); layout.setStyleName("c-nousersession-dialog-layout"); layout.setSpacing(true); dialog.setContent(layout); Button reloginBtn = new Button(); if (ui.isTestMode()) { reloginBtn.setCubaId("reloginBtn"); reloginBtn.setId(ui.getTestIdManager().getTestId("reloginBtn")); } reloginBtn.addStyleName(WebButton.ICON_STYLE); reloginBtn.addStyleName("c-primary-action"); reloginBtn.addClickListener(event -> relogin()); reloginBtn.setCaption(messages.getMainMessage(Type.OK.getMsgKey())); String iconName = AppBeans.get(Icons.class).get(Type.OK.getIconKey()); reloginBtn.setIcon(WebComponentsHelper.getIcon(iconName)); ClientConfig clientConfig = AppBeans.get(Configuration.class).getConfig(ClientConfig.class); setClickShortcut(reloginBtn, clientConfig.getCommitShortcut()); reloginBtn.focus(); layout.addComponent(messageLab); layout.addComponent(reloginBtn); layout.setComponentAlignment(reloginBtn, Alignment.BOTTOM_RIGHT); ui.addWindow(dialog); dialog.center(); }
From source file:com.naoset.framework.frontend.component.profile.CustomerEditWindowView.java
private void openWindow() { Window myWindow = new Window("Cliente"); myWindow.addStyleName("profile-window"); myWindow.setId(ID); Responsive.makeResponsive(this); myWindow.setModal(true);/* w w w . j av a2s .co m*/ myWindow.setCloseShortcut(ShortcutAction.KeyCode.ESCAPE, null); myWindow.setResizable(false); myWindow.setClosable(false); myWindow.setHeight(90.0f, Unit.PERCENTAGE); VerticalLayout layout = new VerticalLayout(); CustomerPanelView customerPanelView = new CustomerPanelView(); layout.addComponent(customerPanelView.buildCustomerPanel(null)); layout.addComponent(builtButton()); myWindow.setContent(layout); myWindow.setVisible(true); UI.getCurrent().addWindow(myWindow); myWindow.focus(); }
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 . c om*/ 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 . ja v a 2 s . c om 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.eclipse.hawkbit.ui.common.builder.WindowBuilder.java
License:Open Source License
private void decorateWindow(final Window window) { if (id != null) { window.setId(id); }/*ww w .j a v a 2 s . c om*/ if (SPUIDefinitions.CONFIRMATION_WINDOW.equals(type)) { window.setDraggable(false); window.setClosable(true); window.addStyleName(SPUIStyleDefinitions.CONFIRMATION_WINDOW_CAPTION); } else if (SPUIDefinitions.CREATE_UPDATE_WINDOW.equals(type)) { window.setDraggable(true); window.setClosable(true); } }