com.vaadin.ui.Notification Java Examples

The following examples show how to use com.vaadin.ui.Notification. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultiSelectTableWithStringCollection.java    From viritin with Apache License 2.0 6 votes vote down vote up
@Override
public Component getTestComponent() {
    
    strings.setOptions(Arrays.asList(options));
    strings.withColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN);
    strings.withRowHeaderMode(Table.RowHeaderMode.ID);
    strings.withProperties();
    
    final Beani beani = new Beani();
    
    MBeanFieldGroup.bindFieldsUnbuffered(beani, this);
    
    
    Button showValue = new Button("show value", new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Notification.show(beani.toString());
        }
    });
    
    return new MVerticalLayout(strings, showValue);
}
 
Example #2
Source File: ErrorView.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void enter(final ViewChangeListener.ViewChangeEvent event) {
    final DashboardMenuItem view = dashboardMenu.getByViewName(event.getViewName());
    if (view == null) {
        message.setValue(i18n.getMessage("message.error.view", event.getViewName()));
        return;
    }
    if (dashboardMenu.isAccessDenied(event.getViewName())) {
        final Notification nt = new Notification("Access denied",
                i18n.getMessage("message.accessdenied.view", event.getViewName()), Type.ERROR_MESSAGE, false);
        nt.setStyleName(SPUIStyleDefinitions.SP_NOTIFICATION_ERROR_MESSAGE_STYLE);
        nt.setPosition(Position.BOTTOM_RIGHT);
        nt.show(UI.getCurrent().getPage());
        message.setValue(i18n.getMessage("message.accessdenied.view", event.getViewName()));
    }
}
 
Example #3
Source File: WebNotifications.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected com.vaadin.ui.Notification.Type convertType(NotificationType notificationType) {
    switch (notificationType) {
        case TRAY:
            return com.vaadin.ui.Notification.Type.TRAY_NOTIFICATION;

        case HUMANIZED:
            return com.vaadin.ui.Notification.Type.HUMANIZED_MESSAGE;

        case WARNING:
            return com.vaadin.ui.Notification.Type.WARNING_MESSAGE;

        case ERROR:
            return com.vaadin.ui.Notification.Type.ERROR_MESSAGE;

        default:
            throw new UnsupportedOperationException("Unsupported notification type");
    }
}
 
Example #4
Source File: SystemInfoWindowCompanion.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void addCopyButton(ComponentContainer container, String description,
                          String successMessage, String failMessage,
                          String cubaCopyLogContentClass, UiComponents uiComponents) {
    if (CubaCopyButtonExtension.browserSupportCopy()) {
        Button copyButton = uiComponents.create(Button.class);

        copyButton.setIconFromSet(CubaIcon.CLIPBOARD);
        copyButton.setId("copy");
        copyButton.setVisible(false);
        copyButton.setDescription(description);

        copyButton.withUnwrapped(com.vaadin.ui.Button.class, vButton -> {
            CubaCopyButtonExtension copyExtension =
                    CubaCopyButtonExtension.copyWith(vButton, cubaCopyLogContentClass);
            copyExtension.addCopyListener(event ->
                    Notification.show(event.isSuccess() ? successMessage : failMessage,
                            Notification.Type.TRAY_NOTIFICATION));
        });

        container.add(copyButton);
    }
}
 
Example #5
Source File: DemoUI.java    From sidemenu-addon with Apache License 2.0 6 votes vote down vote up
private void setUser(String name, Resource icon) {
	sideMenu.setUserName(name);
	sideMenu.setUserIcon(icon);

	sideMenu.clearUserMenu();
       sideMenu.addUserMenuItem("Settings", VaadinIcons.WRENCH, () -> Notification.show("Showing settings", Type.TRAY_NOTIFICATION));
       sideMenu.addUserMenuItem("Sign out", () -> Notification.show("Logging out..", Type.TRAY_NOTIFICATION));

	sideMenu.addUserMenuItem("Hide logo", () -> {
		if (!logoVisible) {
			sideMenu.setMenuCaption(menuCaption, logo);
		} else {
			sideMenu.setMenuCaption(menuCaption);
		}
		logoVisible = !logoVisible;
	});
}
 
Example #6
Source File: DemoUI.java    From sidemenu-addon with Apache License 2.0 6 votes vote down vote up
private void initTreeMenu() {
    sideMenu.addTreeItem("Tree item", () -> Notification.show("Parent!"));
    sideMenu.addTreeItem("Tree item", "sub item", () -> {
        Notification.show("Sub item!");
        sideMenu.addComponent(
            new Button(
                "Add sub sub item",
                event -> subSubTreeItem = sideMenu.addTreeItem("sub item", "sub sub item", () -> Notification.show("Inception!"))));
        sideMenu.addComponent(new Button("Remove sub sub item", event -> {
            if (null != subSubTreeItem) {
                subSubTreeItem.remove();
                subSubTreeItem = null;
            }
        }));
    });
}
 
Example #7
Source File: MyAccount.java    From jpa-invoicer with The Unlicense 6 votes vote down vote up
public void save(Invoicer entity) {
    try {
        if (entity.getId() == null) {
            cf.save(entity);
            session.getUser().getAdministrates().add(entity);
        } else {
            cf.save(entity);
        }
        Notification.show("Saved!");
    } catch (Exception e) {
        Notification.show("Saving failed!",
                "Most probably concurrently edited",
                Notification.Type.WARNING_MESSAGE);
    }
    listEntities();
    form.getPopup().close();
}
 
Example #8
Source File: LogoutClickListener.java    From cia with Apache License 2.0 6 votes vote down vote up
@Override
public final void buttonClick(final ClickEvent event) {
	final ServiceResponse response = getApplicationManager().service(logoutRequest);


	if (ServiceResult.SUCCESS == response.getResult()) {
		UI.getCurrent().getNavigator().navigateTo(CommonsViews.MAIN_VIEW_NAME);
		UI.getCurrent().getSession().close();
		VaadinService.getCurrentRequest().getWrappedSession().invalidate();
	} else {
		showNotification(LOGOUT_FAILED,
                  ERROR_MESSAGE,
                  Notification.Type.WARNING_MESSAGE);
		LOGGER.info(LOG_MSG_LOGOUT_FAILURE,logoutRequest.getSessionId());
	}
}
 
Example #9
Source File: SearchDocumentClickListener.java    From cia with Apache License 2.0 6 votes vote down vote up
@Override
public final void buttonClick(final ClickEvent event) {
	final SearchDocumentResponse response = (SearchDocumentResponse) getApplicationManager().service(reqisterRequest);
	if (ServiceResult.SUCCESS == response.getResult()) {
		LOGGER.info(LOG_MSG_SEARCH_DOCUMENT,reqisterRequest.getSearchExpression());
		showNotification(SEARCH_SUCCESS,
                  "Found :" + response.getResultElement().size(),
                  Notification.Type.HUMANIZED_MESSAGE);
		responseHandler.handle(response);

	} else {
		showNotification(SEARCH_FAILED,
                  ERROR_MESSAGE,
                  Notification.Type.WARNING_MESSAGE);
		LOGGER.info(LOG_MSG_SEARCH_DOCUMENT_FAILURE,reqisterRequest.getSearchExpression());
	}
}
 
Example #10
Source File: GridWithGenericListener.java    From context-menu with Apache License 2.0 6 votes vote down vote up
private void onGenericContextMenu(ContextMenuOpenEvent event) {
    GridContextClickEvent<String[]> gridE = (GridContextClickEvent<String[]>) event
            .getContextClickEvent();
    ContextMenu menu = event.getContextMenu();
    menu.removeItems();
    if (gridE.getColumn() != null) {
        menu.addItem(
                "Called from column " + gridE.getColumn().getCaption()
                        + " on row " + gridE.getRowIndex(),
                f -> Notification.show("did something"));
    } else if (gridE.getRowIndex() >= 0) {
        menu.addItem("Called on row " + gridE.getRowIndex(),
                f -> Notification.show("did something"));
    } else {
        menu.addItem("Called on background",
                f -> Notification.show("did something"));

    }
}
 
Example #11
Source File: ContextMenuUI.java    From context-menu with Apache License 2.0 6 votes vote down vote up
private void addTree(VerticalLayout layout) {
    TreeData<String> data = new TreeData<>();
    data.addItem(null, "Dad");
    data.addItem("Dad", "Daughter");
    data.addItem("Daughter", "Granddaughter");
    data.addItem("Dad", "Son");
    data.addItem("Daughter", "Grandson");

    Tree<String> tree = new Tree<>("A family", data);
    TreeContextMenu<String> treeContextMenu = new TreeContextMenu<>(tree);
    treeContextMenu.addTreeContextMenuListener(e -> {
        treeContextMenu.removeItems();
        //The path is /resources/images/kitten.jpg
        ClassResource ico = new ClassResource("/images/kitten.jpg");
        treeContextMenu.addItem("Who?",ico, menuItem -> Notification.show(e.getItem()));
    });

    layout.addComponent(tree);
}
 
Example #12
Source File: Util.java    From gantt with Apache License 2.0 6 votes vote down vote up
public static TextField createNumberEditor(String caption, float value, final Component component,
        final NumberValueChange valueChange) {
    TextField field = new TextField(caption);
    field.setMaxLength(5);
    field.setValue("" + value);
    field.addValueChangeListener(new ValueChangeListener<String>() {

        @Override
        public void valueChange(ValueChangeEvent<String> event) {
            Object v = event.getValue();
            try {
                float f = Float.parseFloat("" + v);
                valueChange.onValueChange(f);
            } catch (NumberFormatException e) {
                Notification.show("Invalid floating number! Format is 123.345");
            }
        }
    });
    return field;
}
 
Example #13
Source File: Html5InputDemo.java    From serverside-elements with Apache License 2.0 6 votes vote down vote up
@Override
protected Component getDemoView() {
    input.bindAttribute("value", "change");
    input.addEventListener("change", arguments -> {
        Notification
                .show("Value changed to " + input.getAttribute("value"));
    });

    typeSelector.setEmptySelectionAllowed(false);
    typeSelector.addValueChangeListener(event -> {
        String type = String.valueOf(typeSelector.getValue());

        input.setAttribute("value", "");
        input.setAttribute("type", type);

        playground.setCaption("input type=" + type);
    });
    typeSelector.setValue("range");

    Root root = ElementIntegration.getRoot(playground);
    root.appendChild(input);
    HorizontalLayout layout = new HorizontalLayout(typeSelector,
            playground);
    layout.setSpacing(true);
    return layout;
}
 
Example #14
Source File: UploadFileHandlerExample.java    From viritin with Apache License 2.0 6 votes vote down vote up
@Override
public Component getTestComponent() {
    UploadFileHandler uploadFileHandler = new UploadFileHandler(
            (InputStream content, String fileName, String mimeType) -> {
                try {
                    int b = 0;
                    int count = 0;
                    while ((b = content.read()) != -1) {
                        if (b == "\n".getBytes()[0]) {
                            count++;
                        }
                    }
                    String msg = "Counted " + count + " lines";
                    getUI().access(() -> Notification.show(msg));
                } catch (IOException ex) {
                    Logger.getLogger(UploadFileHandlerExample.class.getName()).log(Level.SEVERE, null, ex);
                }
            });
    return uploadFileHandler;
}
 
Example #15
Source File: Issue131.java    From viritin with Apache License 2.0 6 votes vote down vote up
@Override
public Component getTestComponent() {
    Member m = new Member();
    m.initials = "MT";
    m.lastName = "Tahvonen";
    final MemberForm2 memberForm2 = new MemberForm2(m);
    memberForm2.setSavedHandler(new AbstractForm.SavedHandler<Member>() {
        private static final long serialVersionUID = -4100482203816246947L;

        @Override
        public void onSave(Member entity) {
            Notification.show(entity.toString());
        }
    });
    return memberForm2;
}
 
Example #16
Source File: ElementCollectionWithPopupEditor.java    From viritin with Apache License 2.0 6 votes vote down vote up
@Override
public Component getTestComponent() {
    PersonFormManualAddressAddition form = new PersonFormManualAddressAddition();

    Person p = Service.getPerson();
    form.setEntity(p);

    form.setSavedHandler(new AbstractForm.SavedHandler<Person>() {

        private static final long serialVersionUID = 5522176287160062623L;

        @Override
        public void onSave(Person entity) {
            Notification.show(entity.toString());
        }
    });

    return new MVerticalLayout(form);
}
 
Example #17
Source File: EditDude.java    From viritin with Apache License 2.0 6 votes vote down vote up
@Override
public Component getTestComponent() {
    DudeForm form = new DudeForm();

    Dude p = new Dude();
    p.setFirstName("Jorma");
    p.setAge(80);
    p.getAddress().setStreet("Ruukinkatu");
    form.setEntity(p);

    form.setSavedHandler(new AbstractForm.SavedHandler<Dude>() {
        private static final long serialVersionUID = 6646955460224852274L;

        @Override
        public void onSave(Dude entity) {
            Notification.show(entity.toString());
        }
    });

    return new MVerticalLayout(form);
}
 
Example #18
Source File: ElementCollections2.java    From viritin with Apache License 2.0 6 votes vote down vote up
@Override
public Component getTestComponent() {
    PersonFormManualAddressAddition form = new PersonFormManualAddressAddition();

    Person p = Service.getPerson();
    form.setEntity(p);

    form.setSavedHandler(new AbstractForm.SavedHandler<Person>() {
        private static final long serialVersionUID = 1008970415395369248L;

        @Override
        public void onSave(Person entity) {
            Notification.show(entity.toString());
        }
    });


    return new MVerticalLayout(form);
}
 
Example #19
Source File: ContractApplicationEditViewImplEx.java    From vaadinator with Apache License 2.0 5 votes vote down vote up
@Override
public void onValidationError(Map<Field<?>, InvalidValueException> validationErrors) {
	super.onValidationError(validationErrors);
	StringBuilder sb = new StringBuilder();
	for(Field<?> field: validationErrors.keySet()) {
		if(sb.length()!= 0) {
			sb.append(", ");
		}
		sb.append(field.getCaption());		
	}
	Notification.show("Fehler in folgenden Feldern:", sb.toString(), Notification.Type.ERROR_MESSAGE);
}
 
Example #20
Source File: ClearableTextFieldUsageV7.java    From viritin with Apache License 2.0 5 votes vote down vote up
@Override
public Component getTestComponent() {

    ClearableTextField ctf = new ClearableTextField();
    ctf.setCaption("CTF caption");
    ctf.setInputPrompt("Enter text");
    ctf.setValue("Some Text");
    
    ctf.setImmediate(true);

    ctf.addValueChangeListener(e -> {
        Notification.show("Value: " + ctf.getValue());
    });

    MButton b = new MButton("Toggle required", e -> {
        ctf.setRequired(!ctf.isRequired());
    });
    MButton b2 = new MButton("Toggle error", e -> {
        if (ctf.getComponentError() == null) {
            ctf.setComponentError(new UserError("Must be filled"));
        } else {
            ctf.setComponentError(null);
        }
    });

    MButton b3 = new MButton("Toggle readonly", e -> {
        ctf.setReadOnly(!ctf.isReadOnly());
    });

    MButton b4 = new MButton("Toggle enabled", e -> {
        ctf.setEnabled(!ctf.isEnabled());
    });

    return new MPanel()
            .withCaption("ClearableTextField")
            .withDescription("Click the X to clear…")
            .withFullWidth()
            .withFullHeight()
            .withContent(new MVerticalLayout(ctf, b, b2, b3, b4));
}
 
Example #21
Source File: InvoicesView.java    From jpa-invoicer with The Unlicense 5 votes vote down vote up
private void sendInvoiceClicked(final Invoice invoice) {
    try {
        facade.sendInvoice(invoice);
        Notification.show("Invoice sent");
    } catch (EmailException | IOException e) {
        e.printStackTrace();
        Notification.show("Error sending the invoice",
                Notification.Type.ERROR_MESSAGE);
    }
}
 
Example #22
Source File: PersonPickerExample.java    From viritin with Apache License 2.0 5 votes vote down vote up
@Override
public Component getTestComponent() {
    final List<Person> listOfPersons = Service.getListOfPersons(100);

    PersonPicker personPicker = new PersonPicker();
    personPicker.setPersons(listOfPersons);
    personPicker.setValue(listOfPersons.get(0));

    personPicker.addValueChangeListener(e -> Notification.show("New value selected!"));

    return new MVerticalLayout(
            personPicker
    );

}
 
Example #23
Source File: WebNotifications.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void setNotificationDelayMsec(com.vaadin.ui.Notification notification, NotificationType type) {
    if (type == NotificationType.HUMANIZED) {
        notification.setDelayMsec(HUMANIZED_NOTIFICATION_DELAY_MSEC);
    } else if (type == NotificationType.WARNING) {
        notification.setDelayMsec(WARNING_NOTIFICATION_DELAY_MSEC);
    }
}
 
Example #24
Source File: AdminUI.java    From sensorhub with Mozilla Public License 2.0 5 votes vote down vote up
protected Component buildToolbar()
{
    HorizontalLayout toolbar = new HorizontalLayout();
    toolbar.setWidth(100.0f, Unit.PERCENTAGE);
    
    // apply changes button
    Button saveButton = new Button("Save Config");
    saveButton.setDescription("Save Config");
    saveButton.setIcon(UIConstants.APPLY_ICON);
    saveButton.addStyleName(UIConstants.STYLE_SMALL);
    saveButton.setWidth(100.0f, Unit.PERCENTAGE);
    
    // apply button action
    saveButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 1L;
        public void buttonClick(ClickEvent event)
        {
            try
            {
                SensorHub.getInstance().getModuleRegistry().saveModulesConfiguration();
            }
            catch (Exception e)
            {
                AdminUI.log.error("Error while saving SensorHub configuration", e);
                Notification.show("Error", e.getMessage(), Notification.Type.ERROR_MESSAGE);
            }
        }
    });        

    toolbar.addComponent(saveButton);
    return toolbar;
}
 
Example #25
Source File: PresenterFactoryEx.java    From vaadinator with Apache License 2.0 5 votes vote down vote up
@Override
public AddressSelectPresenter createAddressSelectPresenter() {
	AddressSelectPresenter selectPresenter = super.createAddressSelectPresenter();
	selectPresenter.addBeforeSelectListener(new BeforeAddressSelectListener() {
		@Override
		public void beforeSelect(Address entity) {
			Notification.show("Addresse ausgewählt");
		}
	});
	return selectPresenter;
}
 
Example #26
Source File: App.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * Removes all windows in the given {@code uis}.
 *
 * @param uis {@link AppUI} instances
 */
protected void removeAllWindows(List<AppUI> uis) {
    log.debug("Closing all windows in all UIs");
    try {
        for (AppUI ui : uis) {
            Screens screens = ui.getScreens();
            if (screens != null) {
                Screen rootScreen = screens.getOpenedScreens().getRootScreenOrNull();
                if (rootScreen != null) {
                    screens.removeAll();

                    screens.remove(rootScreen);
                }
            }

            // also remove all native Vaadin windows, that is not under CUBA control
            Window[] windows = ui.getWindows().toArray(new Window[0]);

            for (com.vaadin.ui.Window win : windows) {
                ui.removeWindow(win);
            }

            List<Notification> notifications = ui.getExtensions()
                    .stream()
                    .filter(ext -> ext instanceof Notification)
                    .map(ext -> (Notification) ext)
                    .collect(Collectors.toList());

            notifications.forEach(Notification::close);

        }
    } catch (Throwable e) {
        log.error("Error closing all windows", e);
    }
}
 
Example #27
Source File: PolicyWorkspace.java    From XACML with MIT License 5 votes vote down vote up
@Override
public void drop(DragAndDropEvent event) {
	Transferable t = event.getTransferable();
	Component source = t.getSourceComponent();
	if (source != this.treeWorkspace) {
		assert(false);
		throw new IllegalArgumentException();
	}
	TableTransferable tt = (TableTransferable) t;
	File sourceFile = (File) tt.getItemId();
	
	AbstractSelectTargetDetails target = (AbstractSelectTargetDetails)event.getTargetDetails();
	File targetFile = (File) target.getItemIdOver();
	
	if (sourceFile.isFile() && targetFile != null && targetFile.isDirectory()) {
		//
		// Construct destination filename
		//
		Path dest = targetFile.toPath().resolve(sourceFile.getName());
		//
		// Check if the target domain exists
		//
		if (Files.exists(dest)) {
			//
			// Prompt the user
			//
			Notification.show("A policy file with that name already exists in that directory.", Notification.Type.ERROR_MESSAGE);
		} else {
			//
			// Go ahead and rename it
			//
			this.renamePolicyFile(sourceFile, dest.toFile(), targetFile);
		}
	}
}
 
Example #28
Source File: ContextmenuUI.java    From context-menu with Apache License 2.0 5 votes vote down vote up
private Grid createVaadin7Grid() {
    Grid grid = new Grid();
    grid.setCaption("Vaadin 7 Grid");
    grid.setHeightMode(HeightMode.ROW);
    grid.setHeightByRows(3);

    IndexedContainer container = new IndexedContainer();
    container.addContainerProperty(FIRST_NAME, String.class, "");
    container.addContainerProperty(LAST_NAME, String.class, "");
    container.addContainerProperty(SHOE_SIZE, String.class, "");
    grid.setContainerDataSource(container);

    Item item = container.addItem("foo");
    item.getItemProperty(FIRST_NAME).setValue("John");
    item.getItemProperty(LAST_NAME).setValue("Doe");
    item.getItemProperty(SHOE_SIZE).setValue("48");

    GridContextMenu contextMenu2 = new GridContextMenu(grid);
    contextMenu2.addGridHeaderContextMenuListener(e -> {
        contextMenu2.removeItems();
        contextMenu2.addItem(getInfo(e),
                f -> Notification.show("did something"));

    });
    contextMenu2.addGridBodyContextMenuListener(e -> {
        contextMenu2.removeItems();
        contextMenu2.addItem(getInfo(e),
                f -> Notification.show("did something"));

    });

    return grid;
}
 
Example #29
Source File: MainView.java    From jpa-addressbook with The Unlicense 5 votes vote down vote up
public void entrySaved(PhoneBookEntry value) {
    try {
        service.save(value);
        form.setVisible(false);
    } catch (Exception e) {
        // Most likely optimistic locking exception
        Notification.show("Saving entity failed!", e.
                getLocalizedMessage(), Notification.Type.WARNING_MESSAGE);
    }
    // deselect the entity
    entryList.deselectAll();
    // refresh list
    listEntries();

}
 
Example #30
Source File: ContractApplicationChangeViewImplEx.java    From vaadinator with Apache License 2.0 5 votes vote down vote up
@Override
public void onValidationError(Map<Field<?>, InvalidValueException> validationErrors) {
	super.onValidationError(validationErrors);
	StringBuilder sb = new StringBuilder();
	for(Field<?> field: validationErrors.keySet()) {
		if(sb.length()!= 0) {
			sb.append(", ");
		}
		sb.append(field.getCaption());		
	}
	Notification.show("Fehler in folgenden Feldern:", sb.toString(), Notification.Type.ERROR_MESSAGE);
}