List of usage examples for com.vaadin.ui Window setModal
public void setModal(boolean modal)
From source file:io.mateu.ui.vaadin.framework.MyUI.java
License:Apache License
/** * are el dilogo para autenticarse/*from w ww . j a v a 2 s. co m*/ */ private void openLoginDialog(boolean gohome) { // Create a sub-window and set the content Window subWindow = new Window("Login"); subWindow.setWidth("375px"); FormLayout f = new FormLayout(); f.setMargin(true); TextField l; f.addComponent(l = new TextField("Username")); PasswordField p; f.addComponent(p = new PasswordField("Password")); Label e; f.addComponent(e = new Label()); VerticalLayout v = new VerticalLayout(); v.addComponent(f); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth("100%"); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); Label footerText = new Label(""); footerText.setSizeUndefined(); Button forgot = new Button("Forgot password", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { e.setValue("Asking for email..."); io.mateu.ui.core.client.app.MateuUI.getBaseService().forgotPassword(l.getValue(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(Void result) { e.setValue("Email sent. Please check your inbox"); } }); } }); //forgot.addStyleName(ValoTheme.BUTTON_); Button ok = new Button("Login", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { e.setValue("Authenticating..."); io.mateu.ui.core.client.app.MateuUI.getBaseService().authenticate(l.getValue(), p.getValue(), new AsyncCallback<UserData>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(UserData result) { e.setValue("OK!"); getApp().setUserData(result); VaadinSession.getCurrent().setAttribute("usuario", "admin"); subWindow.close(); if (MateuUI.getApp().isFavouritesAvailable()) linkFavoritos.setVisible(true); if (MateuUI.getApp().isLastEditedAvailable()) linkUltimosRegistros.setVisible(true); if (MateuUI.getApp().isFavouritesAvailable()) linkNuevoFavorito.setVisible(true); refreshSettings(); refreshMenu(null, null); System.out.println("STATE:" + navigator.getState()); System.out.println("URIFRAGMENT:" + Page.getCurrent().getUriFragment()); navigator.navigateTo((gohome) ? "" : navigator.getState()); } }); } }); ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER); Button cancel = new Button("Cancel"); footer.addComponents(footerText, forgot, ok); //, cancel); footer.setExpandRatio(footerText, 1); v.addComponent(footer); subWindow.setContent(v); // Center it in the browser window subWindow.center(); subWindow.setModal(true); // Open it in the UI UI.getCurrent().addWindow(subWindow); l.focus(); }
From source file:io.mateu.ui.vaadin.framework.MyUI.java
License:Apache License
/** * abre el dilogo para cambiar el password * *///from w w w . j a v a 2s . co m private void changePassword() { // Create a sub-window and set the content Window subWindow = new Window("Change password"); subWindow.setWidth("375px"); FormLayout f = new FormLayout(); f.setMargin(true); PasswordField l; f.addComponent(l = new PasswordField("Current password")); PasswordField p; f.addComponent(p = new PasswordField("New password")); PasswordField p2; f.addComponent(p2 = new PasswordField("Repeat password")); Label e; f.addComponent(e = new Label()); VerticalLayout v = new VerticalLayout(); v.addComponent(f); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth("100%"); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); Label footerText = new Label(""); footerText.setSizeUndefined(); Button ok = new Button("Change it!", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { if (l.getValue() == null || "".equals(l.getValue().trim())) e.setValue("Old password is required"); else if (p.getValue() == null || "".equals(p.getValue().trim())) e.setValue("New password is required"); else if (p2.getValue() == null || "".equals(p2.getValue().trim())) e.setValue("New password repeated is required"); else if (!p.getValue().equals(p2.getValue())) e.setValue("New password and new password repeated must be equal"); else { e.setValue("Changing password..."); io.mateu.ui.core.client.app.MateuUI.getBaseService().changePassword( getApp().getUserData().getLogin(), l.getValue(), p.getValue(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(Void result) { e.setValue("OK!"); subWindow.close(); } }); } } }); ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER); Button cancel = new Button("Cancel"); footer.addComponents(footerText, ok); //, cancel); footer.setExpandRatio(footerText, 1); v.addComponent(footer); subWindow.setContent(v); // Center it in the browser window subWindow.center(); subWindow.setModal(true); // Open it in the UI UI.getCurrent().addWindow(subWindow); l.focus(); }
From source file:io.mateu.ui.vaadin.framework.MyUI.java
License:Apache License
/** * abre el dilogo para editar el perfil/*w w w. j a va 2 s. c o m*/ * */ private void editProfile() { // Create a sub-window and set the content Window subWindow = new Window("My profile"); subWindow.setWidth("375px"); FormLayout f = new FormLayout(); f.setMargin(true); TextField l; f.addComponent(l = new TextField("Name")); l.setValue(getApp().getUserData().getName()); TextField p; f.addComponent(p = new TextField("Email")); p.setValue(getApp().getUserData().getEmail()); Label e; f.addComponent(e = new Label()); VerticalLayout v = new VerticalLayout(); v.addComponent(f); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth("100%"); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); Label footerText = new Label(""); footerText.setSizeUndefined(); Button ok = new Button("Update it!", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { e.setValue("Authenticating..."); io.mateu.ui.core.client.app.MateuUI.getBaseService().updateProfile( getApp().getUserData().getLogin(), l.getValue(), p.getValue(), null, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(Void result) { e.setValue("OK!"); getApp().getUserData().setName(l.getValue()); getApp().getUserData().setEmail(p.getValue()); subWindow.close(); refreshSettings(); } }); } }); ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER); Button cancel = new Button("Cancel"); footer.addComponents(footerText, ok); //, cancel); footer.setExpandRatio(footerText, 1); v.addComponent(footer); subWindow.setContent(v); // Center it in the browser window subWindow.center(); subWindow.setModal(true); // Open it in the UI UI.getCurrent().addWindow(subWindow); l.focus(); }
From source file:io.mateu.ui.vaadin.framework.MyUI.java
License:Apache License
/** * abre el dilogo para cambiar la foto// www . j av a 2 s . c o m * * */ private void uploadFoto() { // Create a sub-window and set the content Window subWindow = new Window("My photo"); subWindow.setWidth("475px"); FormLayout f = new FormLayout(); f.setMargin(true); Label e = new Label(); Image image = new Image(); class MyUploader implements Upload.Receiver, Upload.SucceededListener { File file; public File getFile() { return file; } public OutputStream receiveUpload(String fileName, String mimeType) { // Create and return a file output stream System.out.println("receiveUpload(" + fileName + "," + mimeType + ")"); FileOutputStream os = null; if (fileName != null && !"".equals(fileName)) { long id = fileId++; String extension = ".tmp"; if (fileName == null || "".equals(fileName.trim())) fileName = "" + id + extension; if (fileName.lastIndexOf(".") < fileName.length() - 1) { extension = fileName.substring(fileName.lastIndexOf(".")); fileName = fileName.substring(0, fileName.lastIndexOf(".")); } File temp = null; try { temp = File.createTempFile(fileName, extension); os = new FileOutputStream(file = temp); } catch (IOException e) { e.printStackTrace(); } } return os; } public void uploadSucceeded(Upload.SucceededEvent event) { // Show the uploaded file in the image viewer image.setSource(new FileResource(file)); System.out.println("uploadSucceeded(" + file.getAbsolutePath() + ")"); } public FileLocator getFileLocator() throws IOException { String extension = ".tmp"; String fileName = file.getName(); if (file.getName() == null || "".equals(file.getName().trim())) fileName = "" + getId(); if (fileName.lastIndexOf(".") < fileName.length() - 1) { extension = fileName.substring(fileName.lastIndexOf(".")); fileName = fileName.substring(0, fileName.lastIndexOf(".")).replaceAll(" ", "_"); } java.io.File temp = (System.getProperty("tmpdir") == null) ? java.io.File.createTempFile(fileName, extension) : new java.io.File(new java.io.File(System.getProperty("tmpdir")), fileName + extension); System.out.println("java.io.tmpdir=" + System.getProperty("java.io.tmpdir")); System.out.println("Temp file : " + temp.getAbsolutePath()); if (System.getProperty("tmpdir") == null || !temp.exists()) { System.out.println("writing temp file to " + temp.getAbsolutePath()); Files.copy(file, temp); } else { System.out.println("temp file already exists"); } String baseUrl = System.getProperty("tmpurl"); URL url = null; try { if (baseUrl == null) { url = file.toURI().toURL(); } else url = new URL(baseUrl + "/" + file.getName()); } catch (MalformedURLException e) { e.printStackTrace(); } return new FileLocator(0, file.getName(), url.toString(), file.getAbsolutePath()); } } ; MyUploader receiver = new MyUploader(); Upload upload = new Upload(null, receiver); //upload.setImmediateMode(false); upload.addSucceededListener(receiver); f.addComponent(image); f.addComponent(upload); f.addComponent(e); VerticalLayout v = new VerticalLayout(); v.addComponent(f); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth("100%"); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); Label footerText = new Label(""); footerText.setSizeUndefined(); Button ok = new Button("Change it!", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { e.setValue("Changing photo..."); try { FileLocator loc = receiver.getFileLocator(); io.mateu.ui.core.client.app.MateuUI.getBaseService() .updateFoto(getApp().getUserData().getLogin(), loc, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(Void result) { e.setValue("OK!"); getApp().getUserData().setPhoto(loc.getUrl()); foto = (getApp().getUserData().getPhoto() != null) ? new ExternalResource(getApp().getUserData().getPhoto()) : new ClassResource("profile-pic-300px.jpg"); subWindow.close(); refreshSettings(); } }); } catch (IOException e1) { e1.printStackTrace(); io.mateu.ui.core.client.app.MateuUI.alert("" + e1.getClass().getName() + ":" + e1.getMessage()); } } }); ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER); Button cancel = new Button("Cancel"); footer.addComponents(footerText, ok); //, cancel); footer.setExpandRatio(footerText, 1); v.addComponent(footer); subWindow.setContent(v); // Center it in the browser window subWindow.center(); subWindow.setModal(true); // Open it in the UI UI.getCurrent().addWindow(subWindow); upload.focus(); }
From source file:module.pandabox.presentation.PandaBox.java
License:Open Source License
private void initView() { setCompositionRoot(root);/* w w w. j a v a 2 s. c om*/ root.setSizeFull(); root.setSplitPosition(15); root.setStyleName("small previews"); previewArea.setWidth("100%"); previewTabs = new VerticalLayout(); previewTabs.setSizeFull(); previewTabs.setHeight(null); compoundTabs = new VerticalLayout(); compoundTabs.setSizeFull(); compoundTabs.setHeight(null); bennuStylesTabs = new VerticalLayout(); bennuStylesTabs.setSizeFull(); bennuStylesTabs.setHeight(null); VerticalLayout menu = new VerticalLayout(); menu.setSizeFull(); menu.setStyleName("sidebar-menu"); Button syncThemes = new Button("Sync Themes", new ClickListener() { @Override public void buttonClick(ClickEvent event) { syncThemes(); } }); menu.addComponent(syncThemes); menu.addComponent(new Label("Single Components")); menu.addComponent(previewTabs); menu.addComponent(new Label("Compound Styles")); menu.addComponent(compoundTabs); menu.addComponent(new Label("Bennu Styles")); menu.addComponent(bennuStylesTabs); root.setFirstComponent(menu); CssLayout toolbar = new CssLayout(); toolbar.setWidth("100%"); toolbar.setStyleName("toolbar"); toolbar.addComponent(editorToggle); final Window downloadWindow = new Window("Download Theme"); GridLayout l = new GridLayout(3, 2); l.setSizeUndefined(); l.setMargin(true); l.setSpacing(true); downloadWindow.setContent(l); downloadWindow.setModal(true); downloadWindow.setResizable(false); downloadWindow.setCloseShortcut(KeyCode.ESCAPE, null); downloadWindow.addStyleName("opaque"); Label caption = new Label("Theme Name"); l.addComponent(caption); l.setComponentAlignment(caption, Alignment.MIDDLE_CENTER); final TextField name = new TextField(); name.setValue("my-chameleon"); name.addValidator(new RegexpValidator("[a-zA-Z0-9\\-_\\.]+", "Only alpha-numeric characters allowed")); name.setRequired(true); name.setRequiredError("Please give a name for the theme"); downloadWindow.addComponent(name); Label info = new Label( "This is the name you will use to set the theme in your application code, i.e. <code>setTheme(\"my-cameleon\")</code>.", Label.CONTENT_XHTML); info.addStyleName("tiny"); info.setWidth("200px"); l.addComponent(info, 1, 1, 2, 1); Button download = new Button(null, new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { getApplication().getMainWindow().addWindow(downloadWindow); name.focus(); } }); download.setDescription("Donwload the current theme"); download.setIcon(new ThemeResource("download.png")); download.setStyleName("icon-only"); toolbar.addComponent(download); menu.addComponent(toolbar); menu.setExpandRatio(toolbar, 1); menu.setComponentAlignment(toolbar, Alignment.BOTTOM_CENTER); }
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 w w . j a v a 2s.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;/*from www.j a va 2s . 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.MainCAView.java
License:Open Source License
private void uploadAndSignCsr() throws CAProviderException { final Window csrWindow = new Window("Upload CSR"); csrWindow.setPositionX(200);/*w ww .jav a 2 s . c o m*/ csrWindow.setPositionY(100); csrWindow.setWidth("800px"); csrWindow.setHeight("300px"); csrWindow.addListener(new Window.CloseListener() { private static final long serialVersionUID = 1L; public void windowClose(CloseEvent e) { application.getMainWindow().removeWindow(csrWindow); } }); final TextField csrData = new TextField("DER Encoded CSR"); csrData.setColumns(80); csrData.setRows(20); csrData.setWordwrap(false); csrWindow.addComponent(csrData); HorizontalLayout hl = new HorizontalLayout(); csrWindow.addComponent(hl); hl.addComponent(new Button("Cancel", new Button.ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { application.getMainWindow().removeWindow(csrWindow); } })); hl.addComponent(new Button("Upload", new Button.ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { String csr = (String) csrData.getValue(); try { X509Certificate result = provider.sign(csr); showEncodedCertificate(result, result.getSerialNumber().toString(16)); } catch (CAProviderException cpe) { cpe.printStackTrace(); } } })); csrWindow.setModal(true); application.getMainWindow().addWindow(csrWindow); }
From source file:org.casbah.ui.MainCAView.java
License:Open Source License
private void showEncodedCertificate(X509Certificate cert, String serialNumber) throws CAProviderException { final Window certWindow = new Window(serialNumber); certWindow.setPositionX(200);/*w w w . j a v a2 s . c o m*/ certWindow.setPositionY(100); certWindow.setWidth("800px"); certWindow.setHeight("300px"); certWindow.addListener(new Window.CloseListener() { private static final long serialVersionUID = 1L; public void windowClose(CloseEvent e) { application.getMainWindow().removeWindow(certWindow); } }); String certData = CertificateHelper.encodeCertificate(cert, true); TextField encodedCert = new TextField("Encoded Certificate", certData); encodedCert.setReadOnly(true); encodedCert.setColumns(80); encodedCert.setRows(certData.split("\n").length); encodedCert.setWordwrap(false); certWindow.addComponent(encodedCert); certWindow.addComponent(new Button("Close", new Button.ClickListener() { /** * */ private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { application.getMainWindow().removeWindow(certWindow); } })); certWindow.setModal(true); application.getMainWindow().addWindow(certWindow); }
From source file:org.eclipse.hawkbit.ui.common.builder.WindowBuilder.java
License:Open Source License
/** * Build window based on type./*from ww w. j a v a 2s . 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; }