Example usage for com.vaadin.ui Notification show

List of usage examples for com.vaadin.ui Notification show

Introduction

In this page you can find the example usage for com.vaadin.ui Notification show.

Prototype

public static Notification show(String caption, Type type) 

Source Link

Document

Shows a notification message the current page.

Usage

From source file:com.ocs.dynamo.ui.composite.layout.BaseCustomComponent.java

License:Apache License

/**
 * Generic handling of error messages after a save operation
 * //from   w w w.  ja  va  2  s .c  o  m
 * @param ex
 *            the exception that occurred
 */
protected void handleSaveException(RuntimeException ex) {
    if (ex instanceof OCSValidationException) {
        // validation exception
        LOG.error(ex.getMessage(), ex);
        Notification.show(((OCSValidationException) ex).getErrors().get(0), Notification.Type.ERROR_MESSAGE);
    } else if (ex instanceof OCSRuntimeException) {
        // any other OCS runtime exception
        LOG.error(ex.getMessage(), ex);
        Notification.show(ex.getMessage(), Notification.Type.ERROR_MESSAGE);
    } else if (ex instanceof OptimisticLockException) {
        // optimistic lock
        LOG.error(ex.getMessage(), ex);
        Notification.show(message("ocs.optimistic.lock"), Notification.Type.ERROR_MESSAGE);
    } else {
        // any other save exception
        LOG.error(ex.getMessage(), ex);
        Notification.show(message("ocs.error.occurred"), Notification.Type.ERROR_MESSAGE);
    }
}

From source file:com.ocs.dynamo.ui.composite.table.ModelBasedTreeTable.java

License:Apache License

/**
 * Handles an action//from w w w .  j  a  va  2  s.c  om
 * 
 * @param action
 * @param sender
 * @param target
 */
@Override
public void handleAction(Action action, Object sender, Object target) {
    if (action == actionExpandAll || action == actionHideAll) {
        boolean expand = action == actionExpandAll;

        // When there are rows selected collapse them
        Object s = getValue();
        if (s != null && !((Collection<?>) s).isEmpty()) {
            if (s instanceof Collection<?>) {
                Collection<?> col = (Collection<?>) s;
                if (col.size() == 1) {
                    for (Object id : (Collection<?>) s) {
                        setCollapseAll(id, !expand);
                    }
                } else {
                    Notification.show(messageService.getMessage("ocs.select.single.row"),
                            Notification.Type.ERROR_MESSAGE);
                }
            } else {
                setCollapseAll(s, !expand);
            }
        } else if (target != null) {
            Notification.show(messageService.getMessage("ocs.select.row"), Notification.Type.ERROR_MESSAGE);
        }
    }
}

From source file:com.oodrive.nuage.webui.component.DeviceItemComponent.java

License:Apache License

/**
 * Create the component to take a snapshot.
 * //from  ww w.  j  a  va 2s.  co m
 * @return the component
 */
@SuppressWarnings("serial")
private final AbstractComponent createTakeSnap() {

    final VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.setMargin(true);

    final FormLayout takeSnapLayout = new FormLayout();
    takeSnapLayout.setMargin(true);
    takeSnapLayout.setImmediate(true);
    takeSnapLayout.setWidth(null);
    layout.addComponent(takeSnapLayout);
    layout.setComponentAlignment(takeSnapLayout, Alignment.MIDDLE_CENTER);

    // Enter name
    final TextField vvrName = new TextField("Name", "");
    takeSnapLayout.addComponent(vvrName);

    // take button
    final Button take = new Button("Take snapshot");
    layout.addComponent(take);
    layout.setComponentAlignment(take, Alignment.MIDDLE_CENTER);

    take.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            try {
                model.takeDeviceSnapshot(vvrName.getValue());
                Notification.show("New snapshot created", Notification.Type.TRAY_NOTIFICATION);
            } catch (final Exception e) {
                final ErrorWindow err = new ErrorWindow("Snapshot not taken: " + e.getMessage());
                err.add(model);
            }
        }
    });
    return layout;
}

From source file:com.oodrive.nuage.webui.component.DeviceItemComponent.java

License:Apache License

/**
 * Create the component to activate/deactivate a device.
 * /*from   w w  w .j  a  v  a 2  s .c  om*/
 * @return the component
 */
@SuppressWarnings("serial")
private final AbstractComponent createActivate() {

    final VerticalLayout rootlayout = new VerticalLayout();
    rootlayout.setMargin(true);
    rootlayout.setSpacing(true);

    final OptionGroup activate = new OptionGroup("Select an option: ");
    rootlayout.addComponent(activate);
    rootlayout.setComponentAlignment(activate, Alignment.MIDDLE_CENTER);

    activate.setNullSelectionAllowed(false);
    activate.setHtmlContentAllowed(true);
    activate.setImmediate(true);
    activate.addItem(DEACTIVATE);
    activate.addItem(RWACTIVATE);
    activate.addItem(ROACTIVATE);

    final boolean isActivated = model.isDeviceActive();
    if (isActivated) {
        final boolean isReadOnly = model.isDeviceReadOnly();
        if (isReadOnly) {
            activate.select(ROACTIVATE);
            // rw is not authorized, deactivate first
            activate.setItemEnabled(RWACTIVATE, false);
        } else {
            activate.select(RWACTIVATE);
            // ro is not authorized, deactivate first
            activate.setItemEnabled(ROACTIVATE, false);
        }
    } else {
        activate.select(DEACTIVATE);
    }

    activate.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent event) {
            final String valueString = String.valueOf(event.getProperty().getValue());

            if (valueString.equals(DEACTIVATE)) {
                final String action = DEACTIVATE;

                // Run activation in background
                WaitingComponent.executeBackground(model, new Background() {
                    @Override
                    public void processing() {
                        model.deActivateDevice();
                    }

                    @Override
                    public void postProcessing() {
                        activate.setItemEnabled(RWACTIVATE, true);
                        activate.setItemEnabled(ROACTIVATE, true);
                        updateAttributes();
                        Notification.show("Device " + action + "d", Notification.Type.TRAY_NOTIFICATION);
                    }
                });

            } else if (valueString.equals(RWACTIVATE)) {
                final String action = RWACTIVATE;
                WaitingComponent.executeBackground(model, new Background() {
                    @Override
                    public void processing() {
                        model.activateDeviceRW();
                    }

                    @Override
                    public void postProcessing() {
                        // ro is not authorized, deactivate first
                        activate.setItemEnabled(ROACTIVATE, false);
                        updateAttributes();
                        Notification.show("Device " + action + "d", Notification.Type.TRAY_NOTIFICATION);
                    }
                });
            } else if (valueString.equals(ROACTIVATE)) {
                final String action = ROACTIVATE;
                WaitingComponent.executeBackground(model, new Background() {
                    @Override
                    public void processing() {
                        model.activateDeviceRO();
                    }

                    @Override
                    public void postProcessing() {
                        // rw is not authorized, deactivate first
                        activate.setItemEnabled(RWACTIVATE, false);
                        updateAttributes();
                        Notification.show("Device " + action + "d", Notification.Type.TRAY_NOTIFICATION);
                    }
                });
            }

        }
    });

    return rootlayout;
}

From source file:com.oodrive.nuage.webui.component.SnapshotItemComponent.java

License:Apache License

/**
 * Create the component to create a device.
 * /*w  w  w  .ja  va  2  s  . co m*/
 * @return the component
 */
@SuppressWarnings("serial")
private final AbstractComponent createDevice() {

    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);

    final FormLayout createDeviceLayout = new FormLayout();
    createDeviceLayout.setMargin(true);
    createDeviceLayout.setWidth(null);
    createDeviceLayout.setImmediate(true);
    layout.addComponent(createDeviceLayout);
    layout.setComponentAlignment(createDeviceLayout, Alignment.MIDDLE_CENTER);

    // Enter name
    final TextField deviceName = new TextField("Name", "");
    createDeviceLayout.addComponent(deviceName);

    // Enter size
    final TextField deviceSize = new TextField("Size", "");
    createDeviceLayout.addComponent(deviceSize);

    // Create button
    final Button create = new Button("Create device");
    layout.addComponent(create);
    layout.setComponentAlignment(create, Alignment.MIDDLE_CENTER);

    create.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            try {
                model.createDevice(deviceName.getValue(), Long.valueOf(deviceSize.getValue()));
                Notification.show("New device created", Notification.Type.TRAY_NOTIFICATION);
            } catch (final NumberFormatException e) {
                final ErrorWindow err = new ErrorWindow("Size must be a valid number");
                err.add(model);
            } catch (final Exception e) {
                final ErrorWindow err = new ErrorWindow("Device not created: " + e.getMessage());
                err.add(model);
            }
        }
    });
    return layout;
}

From source file:com.oodrive.nuage.webui.component.window.VvrCreateWindow.java

License:Apache License

@SuppressWarnings("serial")
@Override/*from  www .j  a  va2s. c om*/
public final Window init(final AbstractItemModel model) {

    // Add new window
    vvrCreateWindow.center();
    final FormLayout vvrCreateLayout = new FormLayout();
    vvrCreateLayout.setMargin(true);
    vvrCreateWindow.setContent(vvrCreateLayout);
    vvrCreateWindow.setResizable(false);
    vvrCreateWindow.setClosable(false);

    // Enter name
    final TextField vvrName = new TextField("Name");
    vvrName.setValue("");
    vvrCreateLayout.addComponent(vvrName);

    // Enter decription
    final TextField vvrDescription = new TextField("Description");
    vvrDescription.setValue("");
    vvrCreateLayout.addComponent(vvrDescription);

    // Button create
    final Button vvrCreateButton = new Button("Create");
    vvrCreateLayout.addComponent(vvrCreateButton);
    vvrCreateButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            try {
                ((VvrManagerModel) model).createVvr(vvrName.getValue(), vvrDescription.getValue());
                Notification.show("New VVR created", Notification.Type.TRAY_NOTIFICATION);
                postProcessing.execute();
            } catch (final Exception e) {
                final ErrorWindow err = new ErrorWindow("VVR not created: " + e.getMessage());
                err.add(model);
            }
        }
    });
    return vvrCreateWindow;
}

From source file:com.parship.roperty.ui.command.LogoutCommand.java

License:Apache License

@Override
public void menuSelected(MenuItem selectedItem) {

    UserManager.logout();//from  www . j  a  v  a 2  s .co m
    try {
        Navigator navigator = NavigationRegistry.getNavigator(Frames.MAIN);
        navigator.navigateTo(Views.LOGIN.name());
        Notification.show("Successfully logged out", Notification.Type.TRAY_NOTIFICATION);
    } catch (Exception e) {
        Notification.show(e.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE);
    }
}

From source file:com.parship.roperty.ui.LoginUI.java

License:Apache License

@Override
public void buttonClick(ClickEvent event) {

    Navigator navigator;/*from w w  w . java 2 s  .c  o m*/
    try {
        navigator = NavigationRegistry.getNavigator(Frames.MAIN);
    } catch (Exception e) {
        Notification.show(e.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE);
        return;
    }

    if (UserManager.isLoggedIn()) {
        navigator.navigateTo(Views.MAIN.name());
    } else if (UserManager.login(this.userTextField.getValue(), this.passTextField.getValue(),
            this.keeploggedinLabel.getValue())) {
        navigator.navigateTo(Views.MAIN.name());
        Notification.show("Welcome back, " + UserManager.getCurrentUser().getFirstname(),
                Notification.Type.TRAY_NOTIFICATION);
    } else {
        Notification.show("Error logging in, please check your credentials", Notification.Type.WARNING_MESSAGE);
    }

}

From source file:com.parship.roperty.ui.NavigationViewUI.java

License:Apache License

@Override
public void enter(ViewChangeEvent event) {

    if (!UIPermissionManager.getInstance().hasPermission(UserManager.getCurrentUser(), this.getClass())) {
        Notification.show("No Permission to enter this view", Notification.Type.ERROR_MESSAGE);
        event.getNavigator().navigateTo(Views.ERROR.name());
    }/*from ww  w .  ja  v a 2 s .c om*/

    if (!UserManager.isLoggedIn()) {
        try {
            Navigator navigator = NavigationRegistry.getNavigator(Frames.MAIN);
            navigator.navigateTo(Views.LOGIN.name());
        } catch (Exception e) {
            this.setEnabled(false);
            Notification.show(e.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE);
        }
    }

}

From source file:com.piccritic.website.DefaultView.java

public DefaultView() {
    try {//from ww w  . j  a  v  a 2  s.co m
        //TODO
        posts.addAll(MasterService.postService.getPosts(9));
    } catch (PostException e) {
        Notification.show(e.getLocalizedMessage(), Type.WARNING_MESSAGE);
        e.printStackTrace();
    }
    initPosts(posts);
}