Example usage for com.vaadin.ui Notification setDelayMsec

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

Introduction

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

Prototype

public void setDelayMsec(int delayMsec) 

Source Link

Document

Sets the delay before the notification disappears.

Usage

From source file:annis.gui.components.HelpButton.java

License:Apache License

@Override
public void buttonClick(ClickEvent event) {
    String caption = "Help";
    if (getCaption() != null && !getCaption().isEmpty()) {
        caption = "Help for \"" + getCaption();
    }/*from  w w  w  .ja v a 2  s.co m*/
    caption = caption + "<br/><br/>(Click here to close)";
    Notification notify = new Notification(caption, Notification.Type.HUMANIZED_MESSAGE);
    notify.setHtmlContentAllowed(true);
    notify.setDescription(field.getDescription());
    notify.setDelayMsec(-1);
    notify.show(UI.getCurrent().getPage());
}

From source file:annis.gui.exporter.TextColumnExporter.java

License:Apache License

/**
 * Writes the specified record (if applicable, as multiple result lines) from
 * query result set to the output file.//from  w  w w.j  av  a2  s.  co m
 * 
 * @param graph        the org.corpus_tools.salt.common.SDocumentGraph
 *                     representation of a specified record
 * @param alignmc      a boolean, which indicates, whether the data should be
 *                     aligned by match numbers or not
 * @param recordNumber the number of record within the record set
 * @param out          the specified Writer
 * 
 * @throws IOException, if an I/O error occurs
 * 
 */

@Override
public void outputText(SDocumentGraph graph, boolean alignmc, int recordNumber, Writer out) throws IOException {

    String currSpeakerName = "";
    String prevSpeakerName = "";

    if (graph != null) {
        List<SToken> orderedToken = graph.getSortedTokenByText();

        if (orderedToken != null) {

            // iterate over token
            ListIterator<SToken> it = orderedToken.listIterator();
            long lastTokenWasMatched = -1;
            boolean noPreviousTokenInLine = false;

            // if match number == 0, reset global variables and output warning, if necessary
            if (recordNumber == 0) {
                isFirstSpeakerWithMatch = true;
                counterGlobal = 0;

                // create warning message
                String numbersString = "";
                String warnMessage = "";
                StringBuilder sb = new StringBuilder();

                List<Integer> copyOfFilterNumbersSetByUser = new ArrayList<Integer>();

                for (Long filterNumber : filterNumbersSetByUser) {
                    copyOfFilterNumbersSetByUser.add(Integer.parseInt(String.valueOf(filterNumber)));
                }

                for (Integer matchNumberGlobal : matchNumbersGlobal) {
                    copyOfFilterNumbersSetByUser.remove(matchNumberGlobal);
                }

                Collections.sort(copyOfFilterNumbersSetByUser);

                if (!copyOfFilterNumbersSetByUser.isEmpty()) {
                    for (Integer filterNumber : copyOfFilterNumbersSetByUser) {
                        sb.append(filterNumber + ", ");
                    }

                    if (copyOfFilterNumbersSetByUser.size() == 1) {
                        numbersString = "number";
                    } else {
                        numbersString = "numbers";
                    }

                    warnMessage = "1. Filter " + numbersString + " "
                            + sb.toString().substring(0, sb.lastIndexOf(",")) + " couldn't be represented.";

                }

                if (alignmc && !dataIsAlignable) {
                    if (!warnMessage.isEmpty()) {
                        warnMessage += (NEWLINE + NEWLINE + "2. ");
                    } else {
                        warnMessage += "1. ";
                    }

                    warnMessage += "You have tried to align matches by node number via check box."
                            + "Unfortunately this option is not applicable for this data set, "
                            + "so the data couldn't be aligned.";

                }

                if (!warnMessage.isEmpty()) {

                    String warnCaption = "Some export options couldn't be realized.";
                    Notification warn = new Notification(warnCaption, warnMessage,
                            Notification.Type.WARNING_MESSAGE);
                    warn.setDelayMsec(20000);
                    warn.show(Page.getCurrent());
                }
            } // global variables reset; warning issued

            int matchesWrittenForSpeaker = 0;

            while (it.hasNext()) {
                SToken tok = it.next();
                counterGlobal++;
                // get current speaker name
                String name;
                if ((name = CommonHelper.getTextualDSForNode(tok, graph).getName()) == null) {
                    name = "";
                }

                currSpeakerName = (recordNumber + 1) + "_" + name;

                // if speaker has no matches, skip token
                if (speakerHasMatches.get(currSpeakerName) == false) {
                    prevSpeakerName = currSpeakerName;
                    // continue;
                }

                // if speaker has matches
                else {

                    // if the current speaker is new, write header and append his name
                    if (!currSpeakerName.equals(prevSpeakerName)) {
                        // reset the counter of matches, which were written for this speaker
                        matchesWrittenForSpeaker = 0;

                        if (isFirstSpeakerWithMatch) {

                            out.append("match_number" + TAB_MARK);
                            out.append("speaker" + TAB_MARK);

                            // write header for meta data columns
                            if (!listOfMetakeys.isEmpty()) {
                                for (String metakey : listOfMetakeys) {
                                    out.append(metakey + TAB_MARK);
                                }
                            }

                            out.append("left_context" + TAB_MARK);

                            String prefixAlignmc = "match_";
                            String prefix = "match_column";
                            String middle_context = "middle_context_";

                            if (alignmc && dataIsAlignable) {

                                for (int i = 0; i < orderedMatchNumbersGlobal.size(); i++) {
                                    out.append(prefixAlignmc + orderedMatchNumbersGlobal.get(i) + TAB_MARK);

                                    if (i < orderedMatchNumbersGlobal.size() - 1) {
                                        out.append(middle_context + (i + 1) + TAB_MARK);
                                    }
                                }
                            } else {

                                for (int i = 0; i < maxMatchesPerLine; i++) {
                                    out.append(prefix + TAB_MARK);

                                    if (i < (maxMatchesPerLine - 1)) {
                                        out.append(middle_context + (i + 1) + TAB_MARK);
                                    }
                                }

                            }

                            out.append("right_context");
                            out.append(NEWLINE);

                            isFirstSpeakerWithMatch = false;
                        } else {
                            out.append(NEWLINE);
                        }

                        out.append(String.valueOf(recordNumber + 1) + TAB_MARK);

                        String trimmedName = "";
                        if (currSpeakerName.indexOf("_") < currSpeakerName.length()) {
                            trimmedName = currSpeakerName.substring(currSpeakerName.indexOf("_") + 1);
                        }

                        out.append(trimmedName + TAB_MARK);

                        // write meta data
                        if (!listOfMetakeys.isEmpty()) {
                            // get metadata
                            String docName = graph.getDocument().getName();
                            List<String> corpusPath = CommonHelper.getCorpusPath(graph.getDocument().getGraph(),
                                    graph.getDocument());
                            String corpusName = corpusPath.get(corpusPath.size() - 1);
                            corpusName = urlPathEscape.escape(corpusName);
                            List<Annotation> metadata = Helper.getMetaData(corpusName, docName);

                            Map<String, String> annosWithoutNamespace = new HashMap<String, String>();
                            Map<String, Map<String, String>> annosWithNamespace = new HashMap<String, Map<String, String>>();

                            // put metadata annotations into hash maps for better access
                            for (Annotation metaAnno : metadata) {
                                String ns;
                                Map<String, String> data = new HashMap<String, String>();
                                data.put(metaAnno.getName(), metaAnno.getValue());

                                // a namespace is present
                                if ((ns = metaAnno.getNamespace()) != null && !ns.isEmpty()) {
                                    Map<String, String> nsMetadata = new HashMap<String, String>();

                                    if (annosWithNamespace.get(ns) != null) {
                                        nsMetadata = annosWithNamespace.get(ns);
                                    }
                                    nsMetadata.putAll(data);
                                    annosWithNamespace.put(ns, nsMetadata);
                                } else {
                                    annosWithoutNamespace.putAll(data);
                                }

                            }

                            for (String metakey : listOfMetakeys) {
                                String metaValue = "";

                                // try to get meta value specific for current speaker
                                if (!trimmedName.isEmpty() && annosWithNamespace.containsKey(trimmedName)) {

                                    Map<String, String> speakerAnnos = annosWithNamespace.get(trimmedName);
                                    if (speakerAnnos.containsKey(metakey)) {
                                        metaValue = speakerAnnos.get(metakey).trim();
                                    }
                                }

                                // try to get meta value, if metaValue is not set
                                if (metaValue.isEmpty() && annosWithoutNamespace.containsKey(metakey)) {
                                    metaValue = annosWithoutNamespace.get(metakey).trim();
                                }
                                out.append(metaValue + TAB_MARK);
                            }
                        } // metadata written

                        lastTokenWasMatched = -1;
                        noPreviousTokenInLine = true;

                    } // header, speaker name and metadata ready

                    String separator = SPACE; // default to space as separator

                    Long matchedNode;
                    // token matched
                    if ((matchedNode = tokenToMatchNumber.get(counterGlobal)) != null) {
                        // is dominated by a (new) matched node, thus use tab to separate the
                        // non-matches from the matches
                        if (lastTokenWasMatched < 0) {
                            if (alignmc && dataIsAlignable) {
                                int orderInList = orderedMatchNumbersGlobal.indexOf(matchedNode);
                                if (orderInList >= matchesWrittenForSpeaker) {
                                    int diff = orderInList - matchesWrittenForSpeaker;
                                    matchesWrittenForSpeaker++;

                                    StringBuilder sb = new StringBuilder(TAB_MARK);
                                    for (int i = 0; i < diff; i++) {
                                        sb.append(TAB_MARK + TAB_MARK);
                                        matchesWrittenForSpeaker++;
                                    }
                                    separator = sb.toString();
                                }

                            } else {
                                separator = TAB_MARK;
                            }

                        } else if (lastTokenWasMatched != matchedNode) {
                            // always leave an empty column between two matches, even if there is no actual
                            // context
                            if (alignmc && dataIsAlignable) {
                                int orderInList = orderedMatchNumbersGlobal.indexOf(matchedNode);
                                if (orderInList >= matchesWrittenForSpeaker) {
                                    int diff = orderInList - matchesWrittenForSpeaker;
                                    matchesWrittenForSpeaker++;

                                    StringBuilder sb = new StringBuilder(TAB_MARK + TAB_MARK);
                                    for (int i = 0; i < diff; i++) {
                                        sb.append(TAB_MARK + TAB_MARK);
                                        matchesWrittenForSpeaker++;
                                    }

                                    separator = sb.toString();

                                }

                            } else {

                                separator = TAB_MARK + TAB_MARK;
                            }

                        }
                        lastTokenWasMatched = matchedNode;
                    }
                    // token not matched, but last token matched
                    else if (lastTokenWasMatched >= 0) {

                        // handle crossing edges
                        if (!tokenToMatchNumber.containsKey(counterGlobal)
                                && tokenToMatchNumber.containsKey(counterGlobal - 1)
                                && tokenToMatchNumber.containsKey(counterGlobal + 1)) {

                            if (Objects.equals(tokenToMatchNumber.get(counterGlobal - 1),
                                    tokenToMatchNumber.get(counterGlobal + 1))) {

                                separator = SPACE;
                                lastTokenWasMatched = tokenToMatchNumber.get(counterGlobal + 1);
                            } else {

                                separator = TAB_MARK;
                                lastTokenWasMatched = -1;
                            }

                        }
                        // mark the end of a match with the tab
                        else {

                            separator = TAB_MARK;
                            lastTokenWasMatched = -1;
                        }

                    }

                    // if tok is the first token in the line and not matched, set separator to empty
                    // string
                    if (noPreviousTokenInLine && separator.equals(SPACE)) {
                        separator = "";
                    }
                    out.append(separator);

                    // append the current token
                    out.append(graph.getText(tok));
                    noPreviousTokenInLine = false;
                    prevSpeakerName = currSpeakerName;

                }

            }

        }

    }

}

From source file:annis.gui.SearchView.java

License:Apache License

@Override
public void notifyCannotPlayMimeType(String mimeType) {
    if (mimeType == null) {
        return;/* ww  w.j  a va 2  s.  c  o m*/
    }

    if (mimeType.startsWith("audio/ogg") || mimeType.startsWith("video/web")) {
        String browserList = "<ul>"
                + "<li>Mozilla Firefox: <a href=\"http://www.mozilla.org/firefox\" target=\"_blank\">http://www.mozilla.org/firefox</a></li>"
                + "<li>Google Chrome: <a href=\"http://www.google.com/chrome\" target=\"_blank\">http://www.google.com/chrome</a></li>"
                + "</ul>";

        WebBrowser browser = Page.getCurrent().getWebBrowser();

        // IE9 users can install a plugin
        Set<String> supportedByIE9Plugin = new HashSet<>();
        supportedByIE9Plugin.add("video/webm");
        supportedByIE9Plugin.add("audio/ogg");
        supportedByIE9Plugin.add("video/ogg");

        if (browser.isIE() && browser.getBrowserMajorVersion() >= 9
                && supportedByIE9Plugin.contains(mimeType)) {
            Notification n = new Notification("Media file type unsupported by your browser",
                    "Please install the WebM plugin for Internet Explorer 9 from "
                            + "<a target=\"_blank\" href=\"https://tools.google.com/dlpage/webmmf\">https://tools.google.com/dlpage/webmmf</a> "
                            + " or use a browser from the following list "
                            + "(these are known to work with WebM or OGG files)<br/>" + browserList
                            + "<br/><br /><strong>Click on this message to hide it</strong>",
                    Notification.Type.WARNING_MESSAGE, true);
            n.setDelayMsec(15000);

            n.show(Page.getCurrent());
        } else {
            Notification n = new Notification("Media file type unsupported by your browser",
                    "Please use a browser from the following list "
                            + "(these are known to work with WebM or OGG files)<br/>" + browserList
                            + "<br/><br /><strong>Click on this message to hide it</strong>",
                    Notification.Type.WARNING_MESSAGE, true);
            n.setDelayMsec(15000);
            n.show(Page.getCurrent());
        }
    } else {
        Notification.show("Media file type \"" + mimeType + "\" unsupported by your browser!",
                "Try to check your browsers documentation how to enable "
                        + "support for the media type or inform the corpus creator about this problem.",
                Notification.Type.WARNING_MESSAGE);
    }

}

From source file:by.bigvova.ui.LoginUI.java

License:Apache License

private void notification() {
    Notification notification = new Notification("Welcome to Dashboard Demo");
    notification.setDescription(/*w  w  w. j a  v  a 2 s . c  o  m*/
            "<span>This application is not real, it only demonstrates an application built with the <a href=\"https://vaadin.com\">Vaadin framework</a>.</span> <span>No username or password is required, just click the <b>Sign In</b> button to continue.</span>");
    notification.setHtmlContentAllowed(true);
    notification.setStyleName("tray dark small closable login-help");
    notification.setPosition(Position.BOTTOM_CENTER);
    notification.setDelayMsec(20000);
    notification.show(Page.getCurrent());
}

From source file:ch.bfh.blue.UI.RegisterView.java

License:Open Source License

/**
 * configure handlers and settings for the buttons here
 *//*from   w w  w  .j  a v a  2s . c  o m*/
private void configureButtons() {
    buttonBar.addComponents(homeBtn, registerBtn);
    //buttonBar.setMargin(true);
    buttonBar.setSpacing(true);

    registerBtn.addClickListener(e -> {
        if (passwd.getValue().equals(retypepw.getValue())) {
            controller.createPerson(email.getValue(), user.getValue(), passwd.getValue());
            navigator.navigateTo("home");
            Notification notif = new Notification(REGISTRATION_SUCCESS, Notification.Type.WARNING_MESSAGE);
            notif.setDelayMsec(3500);
            notif.show(Page.getCurrent());
        } else {
            notif.setCaption(REGISTRATION_FAIL_PW_MISSMATCH);
            notif.show(Page.getCurrent());
        }

    });

    homeBtn.addClickListener(e -> {
        navigator.navigateTo("home");
    });
}

From source file:ch.bfh.ti.soed.hs16.srs.black.view.loginView.LoginController.java

License:Open Source License

public void login(Button.ClickEvent event) {
    String userName = loginView.getUsernameField().getValue();
    String password = loginView.getPasswordField().getValue();

    try {//from  w w w.  j a  v a 2  s. c  o  m
        Customer customer = dataModel.getCustomer(userName);
        if (customer.getPassword().equals(password)) {
            // Store the current user in the service session
            VaadinSession.getCurrent().setAttribute("user", userName);

            // Navigate to the reservation view
            navigator.navigateTo(ReservationView.NAME);

            // Clear the fields of the login view
            loginView.getUsernameField().clear();
            loginView.getPasswordField().clear();
        } else {
            throw new AuthenticationException();
        }
    } catch (Exception e) {
        Notification accessDeniedNf = new Notification("Access Denied!",
                "Please enter a valid username/password combination.");
        accessDeniedNf.show(Page.getCurrent());
        accessDeniedNf.setDelayMsec(2000);
        loginView.getPasswordField().clear();
        loginView.getPasswordField().focus();
    }
}

From source file:ch.bfh.ti.soed.hs16.srs.black.view.reservationView.ReservationController.java

License:Open Source License

public ReservationController(DataModel dataModel, ReservationView reservationView, Navigator navigator) {
    this.dataModel = dataModel;
    this.reservationView = reservationView;
    this.navigator = navigator;

    reservationView.getLogoutButton().addClickListener(clickEvent -> {
        // Logout the user / end the session
        VaadinSession.getCurrent().setAttribute("user", null);

        // Refresh this view, the navigator should redirect to login view$
        navigator.navigateTo(LoginView.NAME);
    });/*w w w.  j a v  a  2s .  c om*/

    reservationView.getRoomSelect()
            .addValueChangeListener(e -> roomNumber = Integer.parseInt(e.getProperty().getValue().toString()));

    for (int i = 1; i < dataModel.getRooms().size() + 1; i++) {
        reservationView.getRoomSelect().addItem(i);
        reservationView.getRoomSelect().setItemCaption(i, "Room " + i);
    }

    reservationView.getMakeReservationButton().addClickListener(clickEvent -> {
        Date begin = reservationView.getFromField().getValue();
        Date end = reservationView.getToField().getValue();
        SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm");
        Notification notification = new Notification("");
        notification.setDelayMsec(2000);
        String username = String.valueOf(VaadinSession.getCurrent().getAttribute("user"));

        try {
            Customer customer = dataModel.getCustomer(username);
            Room room = dataModel.getRoom(roomNumber);
            dataModel.addReservation(customer, room, begin, end);
            notification.setCaption("Success");
            notification.setDescription("Added reservation for: " + username + ", Room Nr.: " + roomNumber
                    + ", From: " + df.format(begin) + " until " + df.format(end));
            notification.show(Page.getCurrent());
            try {
                createList(username);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (IllegalArgumentException iae) {
            notification.setCaption("Error!");
            notification.setDescription("Please check the entries you made for your reservation.");
            notification.show(Page.getCurrent());
        } catch (RuntimeException re) {
            notification.setCaption("Error!");
            notification.setDescription("Room couldn't be found.\nCurrently available rooms: "
                    + dataModel.getRooms().stream().map(Object::toString).collect(Collectors.joining(", "))
                            .replaceAll("[^\\d , ][^\\@]*\\@", ""));
            notification.show(Page.getCurrent());
        } catch (Exception e) {
            notification.setCaption("Error!");
            notification.setDescription("There already exists a reservation for the chosen time range.");
            notification.show(Page.getCurrent());
        }
    });

    reservationView.getLogoutButton().addClickListener(clickEvent -> {
        reservationView.getFromField().clear();
        reservationView.getToField().clear();
        reservationView.getRoomSelect().clear();
    });
}

From source file:ch.bfh.ti.soed.hs16.srs.black.view.signUpView.SignUpController.java

License:Open Source License

public void addUser(Button.ClickEvent event) {
    String username = signUpView.getUsernameField().getValue();
    String password = signUpView.getPasswordField().getValue();
    String passwordRepeat = signUpView.getPasswordFieldRepeat().getValue();
    Notification alertNf = new Notification("");
    alertNf.setDelayMsec(2000);

    if (username.isEmpty() || password.isEmpty() || passwordRepeat.isEmpty()) {
        alertNf.setCaption("Please fill out the complete form!");
        alertNf.show(Page.getCurrent());
    } else if (!password.equals(passwordRepeat)) {
        alertNf.setCaption("The given passwords aren't identical!");
        alertNf.show(Page.getCurrent());
        signUpView.getPasswordFieldRepeat().clear();
        signUpView.getPasswordFieldRepeat().focus();
    } else {/*from   w  w  w  .ja v a2  s  .c  om*/
        try {
            dataModel.addCustomer(username, password);
            navigator.navigateTo(ReservationView.NAME);
            alertNf.setCaption("Account: " + username + " has been successfully created.");
            alertNf.setDescription("You can now login with your credentials.");
            alertNf.show(Page.getCurrent());
        } catch (IllegalStateException e) {
            alertNf.setCaption("User already exists!");
            alertNf.setDescription("Please enter a different username.");
            alertNf.show(Page.getCurrent());
            signUpView.getUsernameField().focus();
        } finally {
            signUpView.getUsernameField().clear();
            signUpView.getPasswordField().clear();
            signUpView.getPasswordFieldRepeat().clear();
        }
    }
}

From source file:com.anphat.list.controller.ListDeptAndStaffController.java

public void deptActionListener() {

    ShortcutUtils.setShortcutKey(listDepartmentsAndStaffUI.getBtnSearchDept());
    ShortcutUtils.doTextChangeUppercase(searchFormDeptController.getSearchDepartmentForm().getTxtDeptCode());
    listDepartmentsAndStaffUI.getBtnSearchDept().addClickListener(new Button.ClickListener() {

        @Override//  w  w  w . j a v  a  2s .c o m
        public void buttonClick(Button.ClickEvent event) {
            doSearchDepartments();
            CommonFunction.enableButtonAfterClick(event);
        }
    });

    btnResetDept.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            doResetInputDept();
            CommonFunction.enableButtonAfterClick(event);
        }
    });

    btnAddDept.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            DialogCreateDepartment dialogCreateDepartment = new DialogCreateDepartment(
                    BundleUtils.getString("department.management.panel.addDepartment"), new DepartmentDTO());
            dialogCreateDepartmentController = new DialogCreateDepartmentController(dialogCreateDepartment,
                    Constants.ADD, tblDepartment, tblStaff, staffForm.getF9Departments());
            dialogCreateDepartmentController.init(new DepartmentDTO());
            UI.getCurrent().addWindow(dialogCreateDepartment);
            CommonFunction.enableButtonAfterClick(event);
        }
    });

    btnEditDept.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Set<DepartmentDTO> selectedValues = (Set<DepartmentDTO>) tblDepartment.getValue();
            if (selectedValues != null) {
                List<DepartmentDTO> lstDepartment = Lists.newArrayList();
                for (DepartmentDTO departmentDTO : selectedValues) {
                    lstDepartment.add(departmentDTO);
                }
                if (selectedValues.size() == 1) {
                    DepartmentDTO departmentDTO;
                    departmentDTO = (DepartmentDTO) selectedValues.toArray()[0];
                    DialogCreateDepartment dialogCreateContract = new DialogCreateDepartment(
                            BundleUtils.getString("department.management.panel.updateDepartment"),
                            departmentDTO);
                    dialogCreateDepartmentController = new DialogCreateDepartmentController(
                            dialogCreateContract, Constants.EDIT, tblDepartment, tblStaff,
                            staffForm.getF9Departments());
                    dialogCreateDepartmentController.init(departmentDTO);
                    UI.getCurrent().addWindow(dialogCreateContract);
                } else {
                    Notification.show(BundleUtils.getString("dept.staff.alert.message.pleasechoose"));
                }
            } else {
                CommonUtils.showChoseOne();
            }
            CommonFunction.enableButtonAfterClick(event);
        }
    });

    btnCopyDept.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            //                DepartmentDTO selectedValues = (DepartmentDTO) tblDepartment.getValue();
            Set<DepartmentDTO> selectedValues = (Set<DepartmentDTO>) tblDepartment.getValue();
            if (selectedValues != null) {
                List<DepartmentDTO> lstDepartment = Lists.newArrayList();
                for (DepartmentDTO departmentDTO : selectedValues) {
                    lstDepartment.add(departmentDTO);
                }
                if (selectedValues.size() == 1) {
                    DepartmentDTO departmentDTO = (DepartmentDTO) selectedValues.toArray()[0];
                    DialogCreateDepartment dialogCreateContract = new DialogCreateDepartment(
                            BundleUtils.getString("department.management.panel.copyDepartment"), departmentDTO);
                    dialogCreateDepartmentController = new DialogCreateDepartmentController(
                            dialogCreateContract, Constants.COPY, tblDepartment, tblStaff,
                            staffForm.getF9Departments());
                    dialogCreateDepartmentController.init(departmentDTO);
                    UI.getCurrent().addWindow(dialogCreateContract);
                } else {
                    Notification.show(BundleUtils.getString("dept.staff.alert.message.pleasechoose"));
                }
            } else {
                CommonUtils.showChoseOne();
            }
            CommonFunction.enableButtonAfterClick(event);
        }
    });

    listDepartmentController.getBtnDel().addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            selectedValues = (Set<DepartmentDTO>) tblDepartment.getValue();

            if (selectedValues.isEmpty()) {
                CommonUtils.showChoseOne();
            } else {
                final DepartmentDTO departmentDTO = (DepartmentDTO) selectedValues.toArray()[0];
                ConfirmDialog.show(UI.getCurrent(), BundleUtils.getString("titleMessage") + "",
                        BundleUtils.getString("bodyMessage"), BundleUtils.getString("yes"),
                        BundleUtils.getString("no"), new ConfirmDialog.Listener() {
                            @Override
                            public void onClose(ConfirmDialog dialog) {
                                // tiepnv6 edit 16h 15/07/15
                                // check neu phong ban la cha thi khong xoa
                                if (deptIsParent(departmentDTO)) {
                                    Notification.show(
                                            BundleUtils.getString("dept.staff.required.delete.staff.1"),
                                            Notification.Type.HUMANIZED_MESSAGE);
                                    return;
                                }
                                //check neu bang phong ban co nhan vien thi xoa phong ban fai xoa het nv
                                if (!checkHasValue(departmentDTO)) {
                                    if (dialog.isConfirmed()) {
                                        List<DepartmentDTO> lstDeptDel = Lists.newArrayList();
                                        lstDeptDel.addAll(selectedValues);
                                        if (selectedValues.size() > 1) {
                                            //neu dept khong co dept cap con thi xoa
                                            List<DepartmentDTO> listChildOfDept = Lists.newArrayList();
                                            DepartmentDTO deptDTODel = new DepartmentDTO();
                                            deptDTODel = lstDeptDel.get(0);
                                            listChildOfDept = getChildDepartment(deptDTODel);
                                            if (listChildOfDept != null) {
                                                // Notification with default settings for a warning
                                                String showDepartmentChild = "";
                                                for (DepartmentDTO listChildOfDept1 : listChildOfDept) {
                                                    listChildOfDept1.getName();
                                                    showDepartmentChild += listChildOfDept1.getName() + ", ";
                                                }
                                                Notification notif = new Notification(
                                                        BundleUtils.getString("Warning"),
                                                        BundleUtils
                                                                .getString("message.required.deleteDepartment")
                                                                + "<br/>" + showDepartmentChild,
                                                        Notification.Type.TRAY_NOTIFICATION);
                                                notif.setDelayMsec(20000);
                                                notif.setPosition(Position.BOTTOM_RIGHT);
                                                notif.setStyleName("mystyle");
                                                notif.show(Page.getCurrent());
                                                //
                                            } else {
                                                message = doDeleteLstDept(lstDeptDel);
                                            }
                                            if (message.contains(Constants.SUCCESS)) {
                                                for (DepartmentDTO deptDTO : lstDeptDel) {
                                                    tblDepartment.removeItem(deptDTO);
                                                }
                                                tblDepartment.refreshRowCache();
                                                tblDepartment.resetPage();
                                                CommonUtils
                                                        .showDeleteSuccess(BundleUtils.getString("department"));
                                            } else {
                                                CommonUtils.showDeleteFail(BundleUtils.getString("department"));
                                            }
                                        } else {
                                            //                                                tblDepartment = listDepartmentsAndStaffUI.getTblListDepartmentUI().getMainTable();
                                            List<DepartmentDTO> listDepartment = Lists.newArrayList();
                                            selectedValues = (Set<DepartmentDTO>) tblDepartment.getValue();
                                            DepartmentDTO departmentDTO = (DepartmentDTO) selectedValues
                                                    .toArray()[0];
                                            //                                                departmentDTO.setUserNameLogging("Username");
                                            listDepartment.add(departmentDTO);
                                            message = doDeleteLstDept(listDepartment);
                                            if (message.contains(Constants.SUCCESS)) {

                                                tblDepartment.removeItem(departmentDTO);
                                                tblDepartment.resetPage();
                                                CommonUtils
                                                        .showDeleteSuccess(BundleUtils.getString("department"));
                                            } else {
                                                CommonUtils.showDeleteFail(BundleUtils.getString("department"));
                                            }
                                        }
                                    }
                                } else {
                                    Notification.show(BundleUtils.getString("dept.staff.required.delete.staff"),
                                            Notification.Type.HUMANIZED_MESSAGE);
                                }
                            }
                        });
            }
            CommonFunction.enableButtonAfterClick(event);
        }

    });
    btnAddMapStaffCusts.setDisableOnClick(true);
    btnAddMapStaffCusts.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Set<StaffDTO> selectedValues = (Set<StaffDTO>) tblStaff.getValue();
            if (!DataUtil.isListNullOrEmpty(Lists.newArrayList(selectedValues))) {
                MapStaffCustomerDialog dialogAddMapStaffGoods = new MapStaffCustomerDialog();
                MapStaffCustomerController mapStaffCustomerController = new MapStaffCustomerController(
                        dialogAddMapStaffGoods, Lists.newArrayList(selectedValues), lstAllAppParams);
                DataUtil.reloadWindow(dialogAddMapStaffGoods);
                UI.getCurrent().addWindow(dialogAddMapStaffGoods);
            } else {
                CommonMessages.showWarningMessage(BundleUtils.getString("notification.staff.customer.choice"));
            }
            CommonFunction.enableButtonAfterClick(event);
        }
    });
}

From source file:com.cms.component.CommonFunction.java

public static void showMessage(String message) {
    Notification noti = new Notification(message);
    noti.setDelayMsec(1500);
    Notification.show(message);/*from  w  w w. ja va2 s .  c  om*/
}