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.etest.view.testbank.cellitem.ViewStemWindow.java

FormLayout buildForms() {
    FormLayout form = new FormLayout();
    form.setWidth("100%");
    form.setMargin(true);//from   www  . jav a 2s .com
    form.setSpacing(true);

    CellItem ci = cis.getCellItemById(getCellItemId());
    if (ci.getCellItemId() == 0) {
        ci = hs.getCellItemById(getCellItemId());
    }

    keyList = k.getAllItemKey(getCellItemId());
    keyIndexSize = keyList.size();
    if (keyList.isEmpty()) {
        ShowErrorNotification.error("No Item Key was found for STEM: \n" + ci.getItem());
        return null;
    }
    stem = ci.getItem().replace("{key}", "<u>" + keyList.get(getKeyIndex()) + "</u>");

    label.setValue("<b>STEM</b>: " + getStem());
    label.setContentMode(ContentMode.HTML);
    form.addComponent(label);

    HorizontalLayout h1 = new HorizontalLayout();
    h1.setWidth("100%");

    OptionGroup options = new OptionGroup();
    options.addItems(ci.getOptionA(), ci.getOptionB(), ci.getOptionC(), ci.getOptionD());
    options.addValueChangeListener((Property.ValueChangeEvent event) -> {
        boolean result = k.isAnswerCorrect(getCellItemId(), getItemKey(),
                CommonUtilities.escapeSingleQuote(event.getProperty().getValue()));
        if (result) {
            Notification.show("Correct Answer!", Notification.Type.TRAY_NOTIFICATION);
        } else {
            Notification.show("Wrong Answer", Notification.Type.TRAY_NOTIFICATION);
        }
    });
    h1.addComponent(options);
    h1.setComponentAlignment(options, Alignment.MIDDLE_CENTER);
    form.addComponent(h1);

    GridLayout g = new GridLayout(2, 2);
    g.setWidth("100%");
    g.setSpacing(true);

    prev = new Button();
    prev.setWidth("50px");
    prev.setIcon(FontAwesome.ANGLE_DOUBLE_LEFT);
    prev.addStyleName(ValoTheme.BUTTON_PRIMARY);
    prev.addStyleName(ValoTheme.BUTTON_SMALL);
    prev.addClickListener(prevBtnClickListener);
    g.addComponent(prev, 0, 0);
    g.setComponentAlignment(prev, Alignment.MIDDLE_LEFT);

    next = new Button();
    next.setWidth("50px");
    next.setIcon(FontAwesome.ANGLE_DOUBLE_RIGHT);
    next.addStyleName(ValoTheme.BUTTON_PRIMARY);
    next.addStyleName(ValoTheme.BUTTON_SMALL);
    next.addClickListener(nextBtnClickListener);
    g.addComponent(next, 1, 0);
    g.setComponentAlignment(next, Alignment.MIDDLE_RIGHT);

    if (getKeyIndexSize() == 1) {
        prev.setEnabled(false);
        next.setEnabled(false);
    }

    populateDataTable();
    g.addComponent(table, 0, 1, 1, 1);
    g.setComponentAlignment(table, Alignment.MIDDLE_CENTER);
    form.addComponent(g);

    return form;
}

From source file:com.etest.view.tq.itemanalysis.FileUploadWindow.java

public FileUploadWindow(int tqCoverageId) {
    this.tqCoverageId = tqCoverageId;

    setCaption("UPLOAD FILE");
    setWidth("700px");
    setHeight("100%");
    setModal(true);/*from ww  w.  j  a  va2s .co  m*/
    center();

    v.setWidth("100%");
    v.setMargin(true);
    v.setSpacing(true);

    v.addComponent(new Label("Subject: <b>" + tq.getTQCoverageById(getTqCoverageId()).getSubject() + "</b>",
            ContentMode.HTML));
    v.addComponent(new Label("Exam Tile: <b>" + tq.getTQCoverageById(getTqCoverageId()).getExamTitle() + "</b>",
            ContentMode.HTML));
    v.addComponent(
            new Label("Date Created: <b>" + tq.getTQCoverageById(getTqCoverageId()).getDateCreated() + "</b>",
                    ContentMode.HTML));

    PluploadManager manager = new PluploadManager();
    manager.getUploader().setMaxFileSize("5mb");
    manager.getUploader().addFileUploadedListener((PluploadFile file) -> {
        excelFile = new File(file.getUploadedFile().toString());

        String extension = "";
        int i = excelFile.getName().lastIndexOf('.');
        if (i >= 0) {
            extension = excelFile.getName().substring(i + 1);
        }

        if (extension.equals("xlsx")) {
            Notification.show("Convert Excel File from .xlsx to .xls", Notification.Type.ERROR_MESSAGE);
            return;
        }

        current = 1;
        readContentFromExcelFile(excelFile);
    });

    manager.getUploader().addErrorListener((PluploadError error) -> {
        Notification.show("There was an error: " + error.getMessage() + " (" + error.getType() + ")",
                Notification.Type.ERROR_MESSAGE);
    });

    manager.getUploader().addUploadStartListener(new Plupload.UploadStartListener() {

        @Override
        public void onUploadStart() {
            analyze.setValue("Process Item Analysis... 0%");
            v.addComponent(analyze);
        }
    });

    manager.getUploader().addUploadStopListener(new Plupload.UploadStopListener() {

        @Override
        public void onUploadStop() {
            //TODO
        }
    });

    v.addComponent(manager);

    setContent(v);
}

From source file:com.etest.view.tq.TQCoverageUI.java

public TQCoverageUI() {
    setSizeFull();/*from  www .j a v a  2  s.co  m*/

    addComponent(buildTQCoverageForms());
    addComponent(grid);

    footer = grid.appendFooterRow();

    grid.addItemClickListener((ItemClickEvent event) -> {
        Object itemId = event.getItemId();
        Item item = grid.getContainerDataSource().getItem(itemId);

        if (event.getPropertyId().toString().equals("Topic")) {
            Window sub = getTopicWindow(item);
            if (sub.getParent() == null) {
                UI.getCurrent().addWindow(sub);
            }
        }

        Window sub;
        if (event.getPropertyId().toString().contains("Pick")) {
            boolean isValueInTBNotZero = tq.isValueInTBNotZero(item,
                    CommonUtilities.replaceStringPickToTB(event.getPropertyId()));
            if (!isValueInTBNotZero) {
                Notification.show("There are no Items in Test Bank!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                sub = getPickWindow(item, CommonUtilities.replaceStringPickToTB(event.getPropertyId()));
                if (sub.getParent() == null) {
                    UI.getCurrent().addWindow(sub);
                }
                sub.addCloseListener((Window.CloseEvent e) -> {
                    if (tq.calculateTotalPickItemsPerTopic(grid, itemId) > CommonUtilities
                            .convertStringToDouble(item.getItemProperty("Max Items").getValue().toString())) {
                        item.getItemProperty(event.getPropertyId()).setValue(0);
                        ShowErrorNotification.error("Running Total is greater than Max Items");
                    } else {
                        item.getItemProperty("Running Total")
                                .setValue(tq.calculateTotalPickItemsPerTopic(grid, itemId));
                        footer.getCell("Running Total").setText(String.valueOf(tq.calculateRunningTotal(grid)));
                    }
                });
            }
        }

        if (event.getPropertyId().toString().equals("Max Items")) {
            double value = (double) item.getItemProperty("Max Items").getValue();
            sub = getMaxItemsWindow(item, value);
            if (sub.getParent() == null) {
                UI.getCurrent().addWindow(sub);
            }
        }
    });

    grid.getColumn("remove")
            .setRenderer(new DeleteButtonValueRenderer((ClickableRenderer.RendererClickEvent event) -> {
                grid.getContainerDataSource().removeItem(event.getItemId());
                populateGridFooter();
                footer.getCell("Running Total").setText(String.valueOf(tq.calculateRunningTotal(grid)));
            })).setWidth(100);

    footer.getCell("Topic").setText("Total");
    footer.setStyleName("align-center");

    Button generateTQ = new Button("Generate TQ");
    generateTQ.setWidth("300px");
    generateTQ.addClickListener(buttonClickListener);

    addComponent(new Label("\n"));
    addComponent(generateTQ);
    setComponentAlignment(generateTQ, Alignment.MIDDLE_RIGHT);
}

From source file:com.etest.view.tq.TQCoverageUI.java

Component buildTQCoverageForms() {
    FormLayout form = new FormLayout();
    form.setWidth("500px");

    examTitle.setCaption("Exam Title: ");
    examTitle.setWidth("100%");
    examTitle.setIcon(FontAwesome.TAG);/*from  www .ja v a 2  s . c  om*/
    examTitle.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    form.addComponent(examTitle);

    subject.setCaption("Subject: ");
    subject.setWidth("100%");
    subject.setIcon(FontAwesome.BOOK);
    subject.addStyleName(ValoTheme.COMBOBOX_SMALL);
    subject.addValueChangeListener((new CurriculumPropertyChangeListener(topic)));
    form.addComponent(subject);

    totalItems.setCaption("No. of Test Items: ");
    totalItems.setWidth("50%");
    totalItems.setValue("0");
    totalItems.setIcon(FontAwesome.TAG);
    totalItems.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    totalItems.addValueChangeListener(fieldValueListener);
    form.addComponent(totalItems);

    Button button = new Button("ADD ROW");
    button.setWidth("50%");
    button.setIcon(FontAwesome.GEAR);
    button.addStyleName(ValoTheme.BUTTON_PRIMARY);
    button.addStyleName(ValoTheme.BUTTON_SMALL);
    button.addClickListener((Button.ClickEvent event) -> {
        if (examTitle.getValue() == null || examTitle.getValue().trim().isEmpty()) {
            Notification.show("Select an Exam Title!", Notification.Type.WARNING_MESSAGE);
            return;
        }

        if (subject.getValue() == null) {
            Notification.show("Select a Subject!", Notification.Type.WARNING_MESSAGE);
            return;
        }

        if (totalItems.getValue() == null || totalItems.getValue().trim().isEmpty()) {
            Notification.show("Enter No. of Test Items!", Notification.Type.WARNING_MESSAGE);
            return;
        }

        grid.addRow(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
                null, null, null, null, null, null, null, null, null, null, null, null, null, null, "del");
    });
    form.addComponent(button);

    return form;
}

From source file:com.etest.view.tq.TQCoverageUI.java

Window getTopicWindow(Item item) {
    Window sub = new Window("TOPIC: ");
    sub.setWidth("500px");
    sub.setModal(true);//  ww  w.  ja v  a  2  s.c  o m
    sub.center();
    sub.setResizable(false);

    VerticalLayout v = new VerticalLayout();
    v.setWidth("100%");
    v.setMargin(true);
    v.setSpacing(true);

    topic.setInputPrompt("Select a Topic..");
    topic.addStyleName(ValoTheme.COMBOBOX_SMALL);
    topic.setWidth("100%");
    topic.addValueChangeListener((Property.ValueChangeEvent event) -> {
        if (event.getProperty().getValue() == null) {
        } else {
            syllabusId = (int) event.getProperty().getValue();
            topicStr = topic.getItem(topic.getValue()).toString();
        }
    });
    v.addComponent(topic);

    Button button = new Button("CLOSE");
    button.setWidth("50%");
    button.setIcon(FontAwesome.TASKS);
    button.addStyleName(ValoTheme.BUTTON_PRIMARY);
    button.addStyleName(ValoTheme.BUTTON_SMALL);
    button.addClickListener((Button.ClickEvent event) -> {
        if (topic.getValue() == null) {
            Notification.show("Select a Topic!", Notification.Type.WARNING_MESSAGE);
        } else {
            populateGridRow(item);
            populateGridFooter();
        }
        sub.close();
    });
    v.addComponent(button);
    v.setComponentAlignment(button, Alignment.MIDDLE_RIGHT);

    sub.setContent(v);
    sub.getContent().setHeightUndefined();

    return sub;
}

From source file:com.etest.view.tq.TQCoverageUI.java

Window getPickWindow(Item item, String propertyId) {
    Window sub = new Window("Field Value: ");
    sub.setWidth("150px");
    sub.setModal(true);//from   ww w.  j a  v  a 2 s  . co  m
    sub.center();
    sub.setResizable(false);

    VerticalLayout v = new VerticalLayout();
    v.setWidth("100%");
    v.setMargin(true);
    v.setSpacing(true);

    TextField field = new CommonTextField("Enter Value..", "Enter a Value: ");
    v.addComponent(field);

    Button button = new Button("CLOSE");
    button.setWidth("100%");
    button.setIcon(FontAwesome.TASKS);
    button.addStyleName(ValoTheme.BUTTON_PRIMARY);
    button.addStyleName(ValoTheme.BUTTON_SMALL);
    button.addClickListener((Button.ClickEvent event) -> {
        boolean isNumeric = CommonUtilities.isNumeric(field.getValue().trim());
        if (!isNumeric) {
            return;
        }

        boolean isGreaterThanInTB = tq.isGreaterThanInTB(item, propertyId, field.getValue().trim());
        if (isGreaterThanInTB) {
            Notification.show("Not allowed to exceed in total Items in Test Bank!",
                    Notification.Type.ERROR_MESSAGE);
            return;
        } else {
            item.getItemProperty(CommonUtilities.replaceStringTBToPick(propertyId))
                    .setValue(CommonUtilities.convertStringToInt(field.getValue()));
            footer.getCell(CommonUtilities.replaceStringTBToPick(propertyId)).setText(String.valueOf(
                    tq.calculateTotalPickItems(grid, CommonUtilities.replaceStringTBToPick(propertyId))));
        }
        sub.close();
    });
    v.addComponent(button);
    v.setComponentAlignment(button, Alignment.BOTTOM_CENTER);

    sub.setContent(v);
    sub.getContent().setHeightUndefined();

    return sub;
}

From source file:com.example.sudoku.ButtonListener.java

@Override
public void buttonClick(Button.ClickEvent event) {
    try {/*from   w  w w  . j a v a  2 s . c om*/
        String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
        fis = new FileInputStream(basepath + "/files/" + level);
        isr = new InputStreamReader(fis);
        BufferedReader br = new BufferedReader(isr);
        String sCurrentLine;

        int row = 0;
        int col = 0;
        while ((sCurrentLine = br.readLine()) != null) {

            String[] field = sCurrentLine.split(" ");

            col = 0;
            for (String s : field) {
                // set to ReadOnly to false to allow for update
                board.setReadOnly(col, row, false);
                board.setValue(col, row, s, s.equals("0") ? false : true);
                col++;
            }
            row++;
        }

        // update the tiles for display
        for (col = 0; col < 9; col++) {
            for (row = 0; row < 9; row++) {
                Label label = (Label) ((DragAndDropWrapper) grid.getComponent(col, row)).getData();
                label.setPropertyDataSource(board.getCellElement(col, row));

            }
        }
        Notification.show(level + " mode set succesfully", Notification.Type.WARNING_MESSAGE);

    } catch (FileNotFoundException ex) {
        Logger.getLogger(UploadReceiver.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(UploadReceiver.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.example.sudoku.CheckListener.java

@Override
public void buttonClick(Button.ClickEvent event) {
    cubeList = new ArrayList<Cube>();
    c1 = Cube.createCube(CubeTypes.TOPLEFT_11, board);
    c2 = Cube.createCube(CubeTypes.TOPMIDDLE_12, board);
    c3 = Cube.createCube(CubeTypes.TOPRIGHT_13, board);
    c4 = Cube.createCube(CubeTypes.MIDDLELEFT_21, board);
    c5 = Cube.createCube(CubeTypes.MIDDLEMIDDLE_22, board);
    c6 = Cube.createCube(CubeTypes.MIDDLERIGHT_23, board);
    c7 = Cube.createCube(CubeTypes.BOTTOMLEFT_31, board);
    c8 = Cube.createCube(CubeTypes.BOTTOMMIDDLE_32, board);
    c9 = Cube.createCube(CubeTypes.BOTTOMRIGHT_33, board);
    cubeList.add(c1);/*from   w  w w  .  ja v a 2 s  . co m*/
    cubeList.add(c2);
    cubeList.add(c3);
    cubeList.add(c4);
    cubeList.add(c5);
    cubeList.add(c6);
    cubeList.add(c7);
    cubeList.add(c8);
    cubeList.add(c9);

    check = solveSudoko();
    if (check == true) {
        Notification.show("The Sudoku is correct!", Type.WARNING_MESSAGE);
        return;
    } else {
        Notification.show("The Sudoku is not corret. Try again.", Type.ERROR_MESSAGE);
        return;
    }
}

From source file:com.example.sudoku.UndoListener.java

@Override
public void buttonClick(ClickEvent event) {
    if (!stack.empty()) {
        Undo undo = stack.pop();//from   w w  w  .ja va  2s . c  o m
        Label label = new Label();
        label = undo.getLabel();
        System.out.println("The label is " + label.getValue());
        Property property = label.getPropertyDataSource();
        property.setValue(undo.getOldValue());
        System.out.println("The old value in Undo is " + property.getValue());
        System.out.println("The old value in UndoListener is " + undo.getOldValue());

        label.setPropertyDataSource(property);
    } else
        Notification.show("Nothing to undo", Type.WARNING_MESSAGE);
}

From source file:com.example.testzbox.vista.TabCarga.java

private Plupload uploadContents() {

    Plupload uploader = new Plupload("Cargar", FontAwesome.UPLOAD);
    uploader.setPreventDuplicates(true);
    uploader.setUploadPath("D:\\vaadin\\TestZBox\\upload");
    uploader.setMaxFileSize("5mb");

    //show notification after file is uploaded
    uploader.addFileUploadedListener(new Plupload.FileUploadedListener() {
        @Override/*from   w ww. j a  v a 2  s  . co m*/
        public void onFileUploaded(PluploadFile file) {

            /**
             * CAMBIAR EL NOMBRE DEL ARCHIVO QUE SE SUBE, YA QUE NO RESPETA
             * EL NOMBRE DEL ARCHIVO ORIGINAL
             */
            File uploadedFile = (File) file.getUploadedFile();
            System.out.println("uploadedFile = " + uploadedFile);
            // NOMBRE CORRECTO
            String realName = file.getName();
            // NOMBRE INCORRECTO
            String falseName = uploadedFile.getName();
            // PATH DEL ARCHIVO
            String pathFile = uploadedFile.getAbsolutePath();
            pathFile = pathFile.substring(0, pathFile.lastIndexOf("\\"));
            System.out.println("pathFile = " + pathFile);
            // SE CREAN LOS OBJETIPOS DE TIPO FILE DE CADA UNO
            File fileFalse = new File(pathFile + "\\" + falseName);
            File fileReal = new File(pathFile + "\\" + realName);
            // SE REALIZA EL CAMBIO DE NOMBRE DEL ARCHIVO
            boolean cambio = fileFalse.renameTo(fileReal);

            lblPathArchivo.setCaption(fileReal.toString());

        }
    });

    //update upload progress
    uploader.addUploadProgressListener(new Plupload.UploadProgressListener() {
        @Override
        public void onUploadProgress(PluploadFile file) {

            progressBar.setWidth("128px");
            //progressBar.setStyleName(ValoTheme.PROGRESSBAR_POINT);
            progressBar.setVisible(true);

            progressBar.setValue(new Long(file.getPercent()).floatValue() / 100);
            progressBar.setDescription(file.getPercent() + "%");

            System.out.println("I'm uploading " + file.getName() + " and I'm at " + file.getPercent() + "%");

            lblExtensionArchivo.setCaption(file.getName().substring(file.getName().lastIndexOf('.') + 1));
        }
    });

    //autostart the uploader after addind files
    uploader.addFilesAddedListener(new Plupload.FilesAddedListener() {
        @Override
        public void onFilesAdded(PluploadFile[] files) {
            progressBar.setValue(0f);
            progressBar.setVisible(true);
            uploader.start();
        }
    });

    //notify, when the upload process is completed
    uploader.addUploadCompleteListener(new Plupload.UploadCompleteListener() {
        @Override
        public void onUploadComplete() {
            System.out.println("upload is completed!");
        }
    });

    //handle errors
    uploader.addErrorListener(new Plupload.ErrorListener() {
        @Override
        public void onError(PluploadError error) {
            Notification.show("There was an error: " + error.getMessage(), Notification.Type.ERROR_MESSAGE);
        }
    });

    return uploader;
}