List of usage examples for com.vaadin.server Page getCurrent
public static 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 ww w.j a v a 2s . 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()); }//from w ww .j a v a 2 s. co 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. *///from ww w . jav 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 w w w . j av a2 s .c o m*/ 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
/** * Build the search view and execute the provided query immediately. * * @param pQuery The query to execute or null if an empty view should be * shown./*from www . j a v a 2 s. c om*/ */ private void buildSearchView(String pQuery) { loginButton.setWidth("70px"); loginButton.setStyleName(BaseTheme.BUTTON_LINK); logoutButton.setWidth("70px"); logoutButton.setStyleName(BaseTheme.BUTTON_LINK); adminButton.setWidth("70px"); adminButton.setStyleName(BaseTheme.BUTTON_LINK); logoutButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { loggedInUser = UserData.NO_USER; refreshMainLayout(); } }); adminButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { Page.getCurrent() .open(DataManagerSettings.getSingleton().getStringProperty( DataManagerSettings.GENERAL_BASE_URL_ID, "http://localhost:8889/BaReDemo") + "/admin", "_blank"); } }); searchField = UIUtils7.factoryTextField(null, "Search for..."); searchField.setWidth("920px"); searchField.setHeight("60px"); searchField.addStyleName("searchField"); paginationPanel = new PaginationPanel(this); paginationPanel.setSizeFull(); paginationPanel.setAllEntries(new LinkedList<DigitalObjectId>()); searchProvider = new FulltextElasticSearchProvider( DataManagerSettings.getSingleton() .getStringProperty(DataManagerSettings.ELASTIC_SEARCH_DEFAULT_CLUSTER_ID, "KITDataManager"), DataManagerSettings.getSingleton() .getStringProperty(DataManagerSettings.ELASTIC_SEARCH_DEFAULT_HOST_ID, "localhost"), DataManagerSettings.getSingleton().getStringProperty( DataManagerSettings.ELASTIC_SEARCH_DEFAULT_INDEX_ID, ElasticsearchHelper.ELASTICSEARCH_TYPE), ElasticsearchHelper.ELASTICSEARCH_TYPE); NativeButton goButton = new NativeButton(); goButton.setIcon(new ThemeResource("img/24x24/search.png")); goButton.setWidth("60px"); goButton.setHeight("60px"); goButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { doSearch(); } }); goButton.setClickShortcut(KeyCode.ENTER); setupLoginForm(); loginForm.setWidth("320px"); loginForm.setHeight("150px"); final PopupView loginPopup = new PopupView(null, loginForm); loginPopup.setHideOnMouseOut(false); loginButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { //mainLayout.replaceComponent(searchLayout, loginForm); loginPopup.setPopupVisible(true); } }); Label filler = new Label(); memberLayout = new HorizontalLayout(filler, adminButton, loginButton, loginPopup); memberLayout.setComponentAlignment(loginButton, Alignment.TOP_RIGHT); memberLayout.setComponentAlignment(adminButton, Alignment.TOP_RIGHT); memberLayout.setComponentAlignment(loginPopup, Alignment.TOP_RIGHT); memberLayout.setExpandRatio(filler, 1.0f); memberLayout.setMargin(false); memberLayout.setSpacing(false); memberLayout.setWidth("100%"); memberLayout.setHeight("30px"); Label spacer = new Label("<hr/>", ContentMode.HTML); spacer.setHeight("20px"); searchLayout = new UIUtils7.GridLayoutBuilder(3, 4) .addComponent(searchField, Alignment.TOP_LEFT, 0, 0, 2, 1) .addComponent(goButton, Alignment.TOP_RIGHT, 2, 0, 1, 1).fillRow(spacer, 0, 1, 1) .addComponent(paginationPanel, Alignment.MIDDLE_CENTER, 0, 2, 3, 2).getLayout(); searchLayout.addStyleName("paper"); searchLayout.setSpacing(true); searchLayout.setMargin(true); paginationPanel.setWidth("980px"); //wrapper Label icon8Link = new Label("<a href=\"http://icons8.com\">Icons by icon8.com</a>", ContentMode.HTML); mainLayout = new VerticalLayout(memberLayout, searchLayout, icon8Link); mainLayout.setComponentAlignment(memberLayout, Alignment.TOP_CENTER); mainLayout.setComponentAlignment(searchLayout, Alignment.TOP_CENTER); mainLayout.setComponentAlignment(icon8Link, Alignment.BOTTOM_RIGHT); mainLayout.setExpandRatio(memberLayout, .05f); mainLayout.setExpandRatio(searchLayout, .93f); mainLayout.setExpandRatio(icon8Link, .02f); VerticalLayout fullscreen = new VerticalLayout(mainLayout); fullscreen.setComponentAlignment(mainLayout, Alignment.TOP_CENTER); fullscreen.setSizeFull(); setContent(fullscreen); mainLayout.setWidth("1024px"); mainLayout.setHeight("768px"); if (pQuery != null) { searchField.setValue(pQuery); doSearch(); } }
From source file:edu.kit.dama.ui.repo.MyVaadinUI.java
License:Apache License
/** * Setup the login form including its logic. *///from www . j a v a 2s.co 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.AbstractMmowgliController.java
License:Open Source License
private void goHome(Mmowgli2UI ui) { String s = Page.getCurrent().getUriFragment(); if (s != null && s.length() > 0) try {//from w ww.ja v a 2s . c o m ui.navigateTo(new AppEvent(s)); return; } catch (IllegalArgumentException iae) { System.err.println("Don't understand uri fragment " + s); } ui.setFrameContent(new CallToActionPage()); }
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);// ww w . j a va 2 s . c om notification.show(Page.getCurrent()); GameEventLogger.logRequestReportGenerationTL(Mmowgli2UI.getGlobals().getUserTL()); }
From source file:edu.nps.moves.mmowgli.AbstractMmowgliControllerHelper.java
License:Open Source License
public void handleAboutMmowgli(MenuBar menubar) { Notification notif = new Notification("<center><span style='color:#777'>Mmowgli</span></center>", "<center>Build " + MMOWGLI_BUILD_ID + "<br/>Vaadin " + VAADIN_BUILD_VERSION + "<br/><br/><span style='color:#777;font-size:70%'>Click to close</span></center>"); notif.setHtmlContentAllowed(true);//from w ww . ja v a 2s . co m notif.setDelayMsec(-1); // user must click notif.show(Page.getCurrent()); }
From source file:edu.nps.moves.mmowgli.AppMaster.java
License:Open Source License
public void oneTimeSetAppUrlFromUI() { MSysOut.println(SYSTEM_LOGS, "AppMaster.oneTimeSetAppUrlFromUI()"); if (appUrlString == null || appUrlString.length() <= 0) { try {// w w w. j a va2 s. c om URL url = Page.getCurrent().getLocation().toURL(); url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile()); //lose any query bit appUrl = url; appUrlString = url.toString(); if (appUrlString.endsWith("/") || appUrlString.endsWith("\\")) appUrlString = appUrlString.substring(0, appUrlString.length() - 1); computeUrls(); MSysOut.println(SYSTEM_LOGS, "AppMaster.oneTimeSetAppUrlFromUI() url set to " + appUrlString); } catch (MalformedURLException ex) { System.err.println("Can't form App URL in AppMaster.oneTimeSetAppUrlFromUI()"); } } else { MSysOut.println(SYSTEM_LOGS, "AppMaster.oneTimeSetAppUrlFromUI() url already set, currently: " + appUrlString); } }