List of usage examples for com.vaadin.ui Notification Notification
public Notification(String caption, String description, Type type)
From source file:edu.kit.dama.ui.commons.AbstractApplication.java
License:Apache License
/** * Show a notification to the user. This notification is a tray notification * provided by Vaadin, shown in the lower right of the main window. * * @param caption A custom caption./* w w w . ja v a2 s.c o m*/ * @param message The message to show. */ @Override public void showNotification(String caption, String message) { if (caption == null) { caption = "Notification"; } new Notification(caption, message, Type.TRAY_NOTIFICATION).show(Page.getCurrent()); }
From source file:edu.kit.dama.ui.commons.AbstractApplication.java
License:Apache License
/** * Show a notification to the user. This notification is a warning * notification provided by Vaadin, shown in the middle of the main window. * * @param caption A custom caption./*from ww w. j a va 2 s . c om*/ * @param message The message to show. */ public void showWarning(String caption, String message) { if (caption == null) { caption = "Warning"; } new Notification(caption, message, Type.WARNING_MESSAGE).show(Page.getCurrent()); }
From source file:edu.kit.dama.ui.commons.AbstractApplication.java
License:Apache License
/** * Show a notification to the user. This notification is a modal error * notification provided by Vaadin, shown in the middle of the main window. * * @param caption A custom caption.//from w w w .jav a2s . co m * @param message The message to show. */ public void showError(String caption, String message) { if (caption == null) { caption = "Error"; } new Notification(caption, message, Type.ERROR_MESSAGE).show(Page.getCurrent()); }
From source file:edu.kit.dama.ui.components.FilteredComboBox.java
License:Apache License
public void valueChange(ValueChangeEvent event) { Property selected = beanItems.getContainerProperty(event.getProperty().getValue(), property); if (debugMode) { new Notification("Selection", "Selected item: " + selected, Notification.Type.TRAY_NOTIFICATION) .show(Page.getCurrent()); }/*ww w . ja v a2s .c o m*/ }
From source file:edu.kit.dama.ui.repo.components.EntryRenderPanel.java
License:Apache License
/** * Build the main layout of the representation of one digital object. * * @param pContext The authorization context used to decide whether special * administrative features are available or not. */// ww w .j a v a2s . c o m private void buildMainLayout(IAuthorizationContext pContext) { //check if the object could be obtained or not, e.g. due to missing permissions. If not, show an error message. if (ERROR_PLACEHOLDER.equals(object.getLabel())) { Label warnLabel = new Label("<h3>Failed to obtain entry with identifier '" + object.getDigitalObjectIdentifier() + "' from database.</h3>", ContentMode.HTML); final Button cleanup = new Button("Cleanup"); cleanup.setDescription("Click to remove object from search index."); cleanup.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { cleanup.setEnabled(false); new Notification("Information", "Cleanup not implemented, yet.", Notification.Type.TRAY_NOTIFICATION).show(Page.getCurrent()); } }); if (pContext.getRoleRestriction().atLeast(Role.ADMINISTRATOR)) { //show cleanup button mainLayout = new HorizontalLayout(warnLabel, cleanup); } else { //no cleanup available mainLayout = new HorizontalLayout(warnLabel); } mainLayout.setSizeFull(); return; } //initialize image field typeImage = new Image(); typeImage.setSizeFull(); setImage(object); //initialize title label/field titleField = UIUtils7.factoryTextField(null, "dc:title"); titleField.addStyleName("basic_title"); titleLabel = new Label("dc:title"); titleLabel.setWidth("100%"); titleLabel.addStyleName("basic_title"); //initialize creator label if (object.getUploader() != null) { creatorLabel = new Label(StringUtils.abbreviate(object.getUploader().getFullname(), 100)); creatorLabel.setEnabled(true); } else { creatorLabel = new Label("dc:creator"); creatorLabel.setEnabled(false); } creatorLabel.setWidth("100%"); creatorLabel.addStyleName("basic_left"); //initialize creation label if (object.getStartDate() != null) { creationLabel = new Label(new SimpleDateFormat().format(object.getStartDate())); creationLabel.setEnabled(true); } else { creationLabel = new Label("dc:date"); creationLabel.setEnabled(false); } creationLabel.setWidth("100%"); //initialize identifier label objectIdLabel = new Label(StringUtils.abbreviate(object.getDigitalObjectIdentifier(), 100)); objectIdLabel.setWidth("100%"); //initialize description label/area descriptionLabel = new Label("dc:description"); descriptionArea = UIUtils7.factoryTextArea(null, "dc:description"); descriptionArea.setHeight("50px"); descriptionLabel.setHeight("50px"); descriptionLabel.setWidth("100%"); //action buttons downloadButton = new NativeButton("Download"); downloadButton.setIcon(new ThemeResource("img/32x32/download.png")); downloadButton.setStyleName(BaseTheme.BUTTON_LINK); downloadButton.setDescription("Download the data of this digital object."); downloadButton.setWidth("100%"); shareButton = new NativeButton("Share"); shareButton.setIcon(new ThemeResource("img/16x16/share.png")); shareButton.setStyleName(BaseTheme.BUTTON_LINK); shareButton.setDescription("Share this digital object."); Role eligibleRole = Role.GUEST; if (parent.getParentUI().isUserLoggedIn()) { //obtain role only if a user is logged in and we are not in ingest mode. //Otherwise, the dummy context of MyVaadinUI would be used and will cause unwanted access. try { //Determine eligible role of currently logged in user eligibleRole = ResourceServiceLocal.getSingleton().getGrantRole(object.getSecurableResourceId(), parent.getParentUI().getAuthorizationContext().getUserId(), AuthorizationContext.factorySystemContext()); } catch (EntityNotFoundException | UnauthorizedAccessAttemptException ex) { LOGGER.warn("Failed to determine eligable role for context " + parent.getParentUI().getAuthorizationContext() + ". Continue with GUEST permissions.", ex); } } //Update share button depending on role. Only possessing the role MANAGER (being the owner) entitles to share an object. if (eligibleRole.atLeast(Role.MANAGER)) { shareButton.setEnabled(true); shareButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (parent != null) { parent.showSharingPopup(object); } } }); } else { shareButton.setEnabled(false); shareButton.setDescription("Only the object owner is allowed to change sharing information."); } editButton = new NativeButton("Edit Metadata"); editButton.setIcon(new ThemeResource("img/16x16/edit.png")); editButton.setStyleName(BaseTheme.BUTTON_LINK); editButton.setDescription("Edit this digital object's metadata."); //Update edit button depending on role. If the object is shared with or owned by the logged in user, editing will be allowed. if (eligibleRole.atLeast(Role.MEMBER)) { editButton.setEnabled(true); editButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { switchEditMode(); } }); } else { editButton.setEnabled(false); editButton.setDescription( "Only the object owner and users the object is shared with are allowed to change metadata information."); } starButton = new NativeButton("Favorite"); starButton.setImmediate(true); starButton.setIcon(new ThemeResource("img/16x16/unstarred.png")); starButton.setStyleName(BaseTheme.BUTTON_LINK); starButton.setDescription("Add/remove digital object to/from favorites."); //Update star button depending on role. If the object is shared with or owned by the logged in user, "star'ing" will be allowed. if (eligibleRole.atLeast(Role.MEMBER)) { starButton.setEnabled(true); starButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { IMetaDataManager mdm = MetaDataManagement.getMetaDataManagement().getMetaDataManager(); mdm.setAuthorizationContext(AuthorizationContext.factorySystemContext()); try { DigitalObjectType favoriteType = mdm .findSingleResult("SELECT t FROM DigitalObjectType t WHERE t.identifier='" + MyVaadinUI.FAVORITE_TYPE_IDENTIFIER + "' AND t.typeDomain='" + MyVaadinUI.FAVORITE_TYPE_DOMAIN + "'", DigitalObjectType.class); if (DigitalObjectTypeHelper.isTypeAssignedToObject(object, favoriteType, AuthorizationContext.factorySystemContext())) { //remove favorite status DigitalObjectTypeHelper.removeTypeFromObject(object, favoriteType, AuthorizationContext.factorySystemContext()); starButton.setIcon(new ThemeResource("img/16x16/unstarred.png")); new Notification("Information", "Successfully removed favorite tag from object " + object.getDigitalObjectIdentifier() + ".", Notification.Type.TRAY_NOTIFICATION).show(Page.getCurrent()); } else { //assign favorite status DigitalObjectTypeHelper.assignTypeToObject(object, favoriteType, AuthorizationContext.factorySystemContext()); starButton.setIcon(new ThemeResource("img/16x16/starred.png")); new Notification("Information", "Successfully added favorite tag to object " + object.getDigitalObjectIdentifier() + ".", Notification.Type.TRAY_NOTIFICATION).show(Page.getCurrent()); } } catch (Exception e) { LOGGER.error("Failed to change 'favorite' status of digital object.", e); new Notification("Warning", "Failed to update favorite status.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); } } }); } else { starButton.setEnabled(false); starButton.setDescription( "Only the object owner and users the object is shared with are allowed to change the favorite state."); } dcLayout = new UIUtils7.GridLayoutBuilder(3, 5).addComponent(titleLabel, 0, 0, 2, 1) .addComponent(creationLabel, 2, 0, 1, 1).addComponent(creatorLabel, 0, 1, 3, 1) .addComponent(objectIdLabel, 0, 2, 3, 1).fill(descriptionLabel, 0, 3).getLayout(); dcLayout.setSizeFull(); Button.ClickListener saveCancelButtonListener = new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (saveEditButton.equals(event.getButton())) { //do save IMetaDataManager mdm = MetaDataManagement.getMetaDataManagement().getMetaDataManager(); mdm.setAuthorizationContext(AuthorizationContext.factorySystemContext()); try { String title = titleField.getValue(); String description = descriptionArea.getValue(); Investigation investigation = object.getInvestigation(); boolean wasError = false; if (description != null && description.length() <= 1024 && investigation != null) { if (!description.equals(investigation.getDescription())) { investigation.setDescription(description); //store investigation mdm.save(investigation); } } else { LOGGER.warn( "Failed to commit updated description '{}'. Either length is exceeded or investigation '{}' is null.", description, investigation); wasError = true; } //store object if (title != null && title.length() >= 3 && title.length() <= 255) { if (!title.equals(object.getLabel())) { //store object object.setLabel(title); object = mdm.save(object); } } else { LOGGER.warn("Failed to commit updated title '{}'. Length is invalid (3<=l<=255).", title); wasError = true; } if (wasError) { new Notification("Warning", "Failed to update title and/or description. See logfile for details.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); } //As there is not automatic sync between database and search index the entry has to be reindexed at this point in order //to keep both systems consistent. However, changes taking place in between are lost. LOGGER.debug("Object committed to database. Updating index."); ElasticsearchHelper.indexEntry(object); } catch (UnauthorizedAccessAttemptException ex) { LOGGER.error("Failed to commit changes.", ex); new Notification("Warning", "Failed to commit changes. See logfile for details.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); } finally { mdm.close(); } } //do cancel/reload and switch back to read-mode reset(); switchEditMode(); } }; //save/cancel buttons saveEditButton = new NativeButton("Commit Update"); saveEditButton.setIcon(new ThemeResource("img/16x16/save.png")); saveEditButton.setStyleName(BaseTheme.BUTTON_LINK); saveEditButton.setDescription("Save changes to this digital object's metadata."); saveEditButton.addClickListener(saveCancelButtonListener); cancelEditButton = new NativeButton("Cancel Update"); cancelEditButton.setIcon(new ThemeResource("img/16x16/cancel.png")); cancelEditButton.setStyleName(BaseTheme.BUTTON_LINK); cancelEditButton.setDescription("Withdraw all changes to this digital object's metadata."); cancelEditButton.addClickListener(saveCancelButtonListener); //default action layout Label spacerMiscActionLayout = new Label(); miscActionLayout = new HorizontalLayout(editButton, shareButton, starButton, spacerMiscActionLayout); miscActionLayout.setWidth("100%"); miscActionLayout.setHeight("18px"); miscActionLayout.setSpacing(false); miscActionLayout.setMargin(false); miscActionLayout.setExpandRatio(spacerMiscActionLayout, .9f); //edit action layout Label spacerEditActionLayout = new Label(); editActionLayout = new HorizontalLayout(saveEditButton, cancelEditButton, spacerEditActionLayout); editActionLayout.setWidth("100%"); editActionLayout.setHeight("18px"); editActionLayout.setSpacing(false); editActionLayout.setMargin(false); editActionLayout.setExpandRatio(spacerEditActionLayout, .9f); //divider generation Label dividerTop = new Label(); dividerTop.setHeight("5px"); dividerTop.addStyleName("horizontal-line"); dividerTop.setWidth("90%"); Label dividerBottom = new Label(); dividerBottom.setHeight("5px"); dividerBottom.addStyleName("horizontal-line"); dividerBottom.setWidth("90%"); Label dividerLeft = new Label(); dividerLeft.addStyleName("vertical-line"); dividerLeft.setWidth("5px"); dividerLeft.setHeight("90%"); Label dividerRight = new Label(); dividerRight.addStyleName("vertical-line"); dividerRight.setWidth("5px"); dividerRight.setHeight("90%"); //build content layout HorizontalLayout contentLayout = new HorizontalLayout(typeImage, dividerLeft, dcLayout, dividerRight, downloadButton); contentLayout.setSizeFull(); contentLayout.setSpacing(true); contentLayout.setComponentAlignment(typeImage, Alignment.TOP_RIGHT); contentLayout.setComponentAlignment(dividerLeft, Alignment.MIDDLE_CENTER); contentLayout.setComponentAlignment(dcLayout, Alignment.MIDDLE_CENTER); contentLayout.setComponentAlignment(dividerRight, Alignment.MIDDLE_CENTER); contentLayout.setComponentAlignment(downloadButton, Alignment.BOTTOM_CENTER); contentLayout.setExpandRatio(typeImage, .1f); contentLayout.setExpandRatio(dcLayout, .8f); contentLayout.setExpandRatio(downloadButton, .1f); //build main layout mainLayout = new VerticalLayout(dividerTop, contentLayout, dividerBottom, miscActionLayout); mainLayout.setExpandRatio(dividerTop, .05f); mainLayout.setComponentAlignment(dividerTop, Alignment.TOP_LEFT); mainLayout.setExpandRatio(contentLayout, .80f); mainLayout.setExpandRatio(dividerBottom, .05f); mainLayout.setComponentAlignment(dividerBottom, Alignment.BOTTOM_RIGHT); mainLayout.setExpandRatio(miscActionLayout, .1f); mainLayout.setSpacing(true); mainLayout.setMargin(true); mainLayout.addStyleName("basic"); mainLayout.setWidth("100%"); mainLayout.setHeight("185px"); //do reset to load title and description reset(); LOGGER.debug("Layout successfully build up."); }
From source file:edu.kit.dama.ui.repo.components.ShareObjectComponent.java
/** * Synchronize the selected values with the database. *///from ww w.j av a2 s . c om private void syncShares() { Set<Object> selection = (Set<Object>) shareList.getValue(); if (selection.isEmpty()) { //not allowed new Notification("Warning", "Failed to update sharing information. At least one user must have access.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); return; } List<UserId> authorizedUsers; List<UserId> privilegedUsers; try { //obtain all users allowed to access the object with write access authorizedUsers = ResourceServiceLocal.getSingleton().getAuthorizedUsers( object.getSecurableResourceId(), Role.MEMBER, AuthorizationContext.factorySystemContext()); //obtain all users allowed to manage the object (add new shares)...this should be typically only one user privilegedUsers = ResourceServiceLocal.getSingleton().getAuthorizedUsers( object.getSecurableResourceId(), Role.MANAGER, AuthorizationContext.factorySystemContext()); } catch (EntityNotFoundException | UnauthorizedAccessAttemptException ex) { LOGGER.error("Failed to obtain authorized users. Committing sharing information failed.", ex); new Notification("Warning", "Failed to obtain authorized users. Updating sharing information failed.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); return; } List<UserId> newShares = new LinkedList<>(); //flag that tells us whether there is at least one privileged user (user with MANAGER role) left. boolean privilegedUserRemains = false; for (Object o : selection) { final UserId uid = new UserId(((String) o)); final UserId existing = (UserId) CollectionUtils.find(authorizedUsers, new Predicate() { @Override public boolean evaluate(Object o) { return ((UserId) o).getStringRepresentation().equals(uid.getStringRepresentation()); } }); if (existing == null) { //not shared with this user yet ... add newShares.add(uid); } else { //The object is already shared with this user and therefore the user should be in the list of authorized users. //As we use this list later for removal, remove the current user id from the list as nothing changes for this user. authorizedUsers.remove(existing); if (!privilegedUserRemains) { //check if the current user is a privileged user. If this is the case, the object is shared with at least one privileged user. UserId privilegedUser = (UserId) CollectionUtils.find(privilegedUsers, new Predicate() { @Override public boolean evaluate(Object o) { return ((UserId) o).getStringRepresentation() .equals(existing.getStringRepresentation()); } }); if (privilegedUser != null) { privilegedUserRemains = true; } } } } //At least one user with the role MANAGER must be left. However, normally only this one user should be able to change sharing information, //therefore this check is actually just to avoid removing yourself from the list of authorized users. if (!privilegedUserRemains) { new Notification("Warning", "Failed to update sharing information. Obviously you tried to remove the owner who has privileged permissions.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); return; } //finally, newShares contains all userIds that have to be added as authorized users, //and authorizedUsers contains all userIds that were authorized before but are currently //not in the selected list, so their sharing status will be dropped. for (UserId newShare : newShares) { try { ResourceServiceLocal.getSingleton().addGrant(object.getSecurableResourceId(), newShare, Role.MEMBER, AuthorizationContext.factorySystemContext()); } catch (EntityNotFoundException | EntityAlreadyExistsException | UnauthorizedAccessAttemptException ex) { LOGGER.error("Failed to grant access for user " + newShare + " to resource " + object.getSecurableResourceId(), ex); new Notification("Error", "Failed to update sharing information.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); return; } } //remove all users that have been authorized before but aren't in the "shared with" side of the list. for (UserId dropShare : authorizedUsers) { try { ResourceServiceLocal.getSingleton().revokeGrant(object.getSecurableResourceId(), dropShare, AuthorizationContext.factorySystemContext()); } catch (EntityNotFoundException | UnauthorizedAccessAttemptException ex) { LOGGER.error("Failed to revoke access for user " + dropShare + " to resource " + object.getSecurableResourceId(), ex); new Notification("Error", "Failed to update sharing information.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); return; } } new Notification("Information", "Successfully updated sharing information.", Notification.Type.TRAY_NOTIFICATION).show(Page.getCurrent()); }
From source file:edu.kit.dama.ui.repo.MyVaadinUI.java
License:Apache License
/** * Setup the login form including its logic. *//* ww w . j a va 2 s . c o m*/ private void setupLoginForm() { email = UIUtils7.factoryTextField("Email", "Please enter your email.", "300px", true, -1, 255); password = UIUtils7.factoryPasswordField("Password", "300px", true, -1, 255); Button doLoginButton = new Button("Login"); //login.setClickShortcut(KeyCode.ENTER); doLoginButton.setWidth("100px"); loginForm = new UIUtils7.GridLayoutBuilder(2, 3).addComponent(email, 0, 0, 2, 1) .addComponent(password, 0, 1, 2, 1).addComponent(doLoginButton, 0, 2, 1, 1).getLayout(); loginForm.setComponentAlignment(doLoginButton, Alignment.MIDDLE_LEFT); //login listener doLoginButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (!UIUtils7.validate(loginForm)) { new Notification("Warning", "Please correct the error(s) above.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); return; } String userMail = email.getValue(); String userPassword = password.getValue(); IMetaDataManager manager = MetaDataManagement.getMetaDataManagement().getMetaDataManager(); manager.setAuthorizationContext(AuthorizationContext.factorySystemContext()); try { ServiceAccessToken token = ServiceAccessUtil.getAccessToken(manager, userMail, MAIN_LOGIN_TOKEN_KEY); if (token == null) { new Notification("Login Failed", "No login information found for email " + userMail + ".", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); return; } if (!userPassword.equals(token.getSecret())) { new Notification("Login Failed", "Wrong password for email " + userMail + ".", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); } else { //login successful UserData template = new UserData(); template.setDistinguishedName(token.getUserId()); List<UserData> result = manager.find(template, template); if (result.isEmpty() || result.size() > 1) { throw new Exception("Invalid number of user entries found for userId " + token.getUserId() + ". Please contact a system administrator."); } //done loggedInUser = result.get(0); refreshMainLayout(); } } catch (Exception ex) { new Notification("Login Failed", "Failed to access login database. Please contact an administrator.", Notification.Type.ERROR_MESSAGE).show(Page.getCurrent()); LOGGER.error("Login failed.", ex); } finally { manager.close(); } } }); loginForm.setSpacing(true); loginForm.setMargin(true); }
From source file:edu.nps.moves.mmowgli.AbstractMmowgliControllerHelper.java
License:Open Source License
private void showNotifInAllBrowserWindows(String content, String title, String style) { StringBuilder sb = new StringBuilder(); sb.append("<br/>"); sb.append(content);/*from ww w.j av a 2s. c o m*/ filterContent(sb); sb.append("<br/><span style='font-size:x-small'>Click to close.</span>"); Notification notif = new Notification(title, sb.toString(), Notification.Type.ERROR_MESSAGE); notif.setHtmlContentAllowed(true); notif.setPosition(Position.MIDDLE_CENTER); notif.setStyleName(style); iterateUIs(notif, new UIHandler() { public boolean handle(Mmowgli2UI ui, Object notif) { ((Notification) notif).show(ui.getPage()); return true; } }); }
From source file:edu.nps.moves.mmowgli.AbstractMmowgliControllerHelper.java
License:Open Source License
public void handlePublishReportsTL() { AppMaster.instance().requestPublishReportsTL(); Notification notification = new Notification("", "Report publication begun", Notification.Type.WARNING_MESSAGE); notification.setPosition(Position.TOP_CENTER); notification.setDelayMsec(5000);/*from w ww .ja v a 2s .c o m*/ notification.show(Page.getCurrent()); GameEventLogger.logRequestReportGenerationTL(Mmowgli2UI.getGlobals().getUserTL()); }
From source file:edu.nps.moves.mmowgli.AbstractMmowgliControllerHelper2.java
License:Open Source License
private void showNotification(String content, String title, String style) { StringBuilder sb = new StringBuilder(); sb.append("<br/>"); sb.append(content);//from ww w . j a v a 2 s . co m // filterContent(sb); sb.append("<br/><span style='font-size:x-small'>Click to close.</span>"); Notification notif = new Notification(title, sb.toString(), Notification.Type.ERROR_MESSAGE); notif.setHtmlContentAllowed(true); notif.setPosition(Position.MIDDLE_CENTER); notif.setStyleName(style); notif.show(myUI.getPage()); }