List of usage examples for com.vaadin.ui Window getCaption
@Override
public String getCaption()
From source file:de.dimm.vsm.vaadin.VSMCMain.java
public void storeWinPos(Window win) { winCoordMap.put(win.getCaption(), new WinCoord(win)); }
From source file:de.dimm.vsm.vaadin.VSMCMain.java
public boolean restoreWinPos(Window win) { WinCoord coord = winCoordMap.get(win.getCaption()); if (coord != null) { coord.setWinCoord(win);// w ww .ja v a2 s .c om return true; } return false; }
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 ww w . j a v a 2 s .com 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;// ww w. j av 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.fossa.rolp.RolpApplication.java
License:Open Source License
private void unlockLasos(final Window window) { if (window instanceof FossaWindow) { ((FossaWindow) window).unlockLaso(); System.out.println(window.getCaption() + " was closed"); }//from ww w . j ava2 s . c o m }
From source file:org.lightframe.components.WindowManager.java
License:Apache License
@Override public void paintContent(PaintTarget target) throws PaintException { super.paintContent(target); Object[] windowNames = new String[managedWindows.size()]; Object[] minimizedWindows = new Integer[managedWindows.size()]; for (int i = 0; i < managedWindows.size(); i++) { final Window window = managedWindows.get(i); windowNames[i] = window.getCaption(); minimizedWindows[i] = window.isVisible() ? 0 : 1; }//from w w w.j a va2s .c o m target.addAttribute(VWindowManager.ATTRIBUTE_SC_WINDOW_NAMES, windowNames); target.addAttribute(VWindowManager.ATTRIBUTE_SC_WINDOW_MINIMZED, minimizedWindows); }
From source file:org.opencms.ui.dialogs.history.CmsHistoryDialog.java
License:Open Source License
/** * Replaces the contents of the window containing a given component with a basic dialog * consisting of a back button to restore the previous window state and another user provided widget.<p> * * @param currentComponent the component whose parent window's content should be replaced * @param newView the user supplied part of the new window content * @param newCaption the caption for the child dialog *//*from ww w .j av a2 s . c o m*/ public static void openChildDialog(Component currentComponent, Component newView, String newCaption) { final Window window = CmsVaadinUtils.getWindow(currentComponent); final String oldCaption = window.getCaption(); CmsBasicDialog dialog = new CmsBasicDialog(); VerticalLayout vl = new VerticalLayout(); dialog.setContent(vl); Button backButton = new Button(CmsVaadinUtils.getMessageText(Messages.GUI_CHILD_DIALOG_GO_BACK_0)); HorizontalLayout buttonBar = new HorizontalLayout(); buttonBar.addComponent(backButton); buttonBar.setMargin(true); vl.addComponent(buttonBar); vl.addComponent(newView); final Component oldContent = window.getContent(); if (oldContent instanceof CmsBasicDialog) { List<CmsResource> infoResources = ((CmsBasicDialog) oldContent).getInfoResources(); dialog.displayResourceInfo(infoResources); if (oldContent instanceof CmsHistoryDialog) { dialog.addButton(((CmsHistoryDialog) oldContent).createCloseButton()); } } backButton.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { window.setContent(oldContent); window.setCaption(oldCaption); window.center(); } }); window.setContent(dialog); window.setCaption(newCaption); window.center(); }