Example usage for com.vaadin.ui Button addClickListener

List of usage examples for com.vaadin.ui Button addClickListener

Introduction

In this page you can find the example usage for com.vaadin.ui Button addClickListener.

Prototype

public Registration addClickListener(ClickListener listener) 

Source Link

Document

Adds the button click listener.

Usage

From source file:com.etest.view.notification.NotificationMainUI.java

Table populateNoficationTable() {
    notificationTable.removeAllItems();//w ww .  j  a va 2 s  . c  o  m
    int i = 0;
    for (EtestNotification en : ns.getAllNotificationByUser(
            CommonUtilities.convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString()))) {
        VerticalLayout v = new VerticalLayout();
        v.setWidth("100%");

        Button read = new Button();
        read.setWidthUndefined();
        read.setCaption((en.getStatus() == 0) ? "unread" : "read");
        read.setData(en.getNotificationId());
        read.setIcon(FontAwesome.VIDEO_CAMERA);
        read.addStyleName(ValoTheme.BUTTON_LINK);
        read.addStyleName(ValoTheme.BUTTON_TINY);
        read.addStyleName(ValoTheme.BUTTON_QUIET);
        read.addStyleName("button-container");
        read.addClickListener(buttonClickListener);
        v.addComponent(read);
        v.setComponentAlignment(read, Alignment.MIDDLE_LEFT);

        message.setContentMode(ContentMode.HTML);

        String[] split = en.getNotice().split(" ");
        int cellCaseId;
        if (split[0].equals("CellCaseID")) {
            message.setCaption(en.getRemarks() + en.getNotice());
            cellCaseId = CommonUtilities.convertStringToInt(split[1].replace("#", ""));
        } else {
            cellCaseId = cis.getCellItemById(CommonUtilities.convertStringToInt(split[1].replace("#", "")))
                    .getCellCaseId();
            message.setCaption(en.getRemarks() + en.getNotice() + " from CellCaseID #" + cellCaseId);
        }

        Button approve = new Button("status");
        approve.setSizeFull();
        approve.addStyleName(ValoTheme.BUTTON_LINK);
        approve.addStyleName(ValoTheme.BUTTON_TINY);
        approve.addStyleName(ValoTheme.BUTTON_QUIET);
        approve.addStyleName("button-container");
        v.addComponent(approve);
        v.setComponentAlignment(approve, Alignment.MIDDLE_LEFT);

        if (ccs.getCellCaseById(cellCaseId).getApprovalStatus() == 0) {
            approve.setIcon(FontAwesome.THUMBS_DOWN);
        } else {
            approve.setIcon(FontAwesome.THUMBS_UP);
        }

        notificationTable.addItem(new Object[] { message.getCaption().toString(),
                ss.getUsernameById(en.getSenderId()), en.getNoteDate(), v }, i);
        i++;
    }
    notificationTable.setPageLength(0);
    notificationTable.setHeight("100%");

    return notificationTable;
}

From source file:com.etest.view.notification.ViewCaseNotificationWindow.java

VerticalLayout buildForms() {
    VerticalLayout v = new VerticalLayout();
    v.setWidth("700px");
    v.setMargin(true);/*from   w ww.  j a  v a2  s  .c  om*/
    v.setSpacing(true);

    Label cellCase = new Label();
    cellCase.setValue("<b>Case</b>: " + ccs.getCellCaseById(getCellCaseId()).getCaseTopic());
    cellCase.setContentMode(ContentMode.HTML);
    v.addComponent(cellCase);

    Label cellItem = new Label();
    cellItem.setContentMode(ContentMode.HTML);

    Button approvalBtn = new Button();
    approvalBtn.setCaption("Approve CASE");
    approvalBtn.setWidthUndefined();
    approvalBtn.addStyleName(ValoTheme.BUTTON_TINY);
    approvalBtn.addStyleName(ValoTheme.BUTTON_PRIMARY);
    approvalBtn.addClickListener(buttonClickListener);
    if (ccs.getCellCaseById(getCellCaseId()).getApprovalStatus() == 0) {
        approvalBtn.setVisible(true);
    } else {
        approvalBtn.setVisible(false);
    }
    v.addComponent(approvalBtn);

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

    approvalItemBtn.setVisible(false);
    approvalItemBtn.setWidthUndefined();
    approvalItemBtn.addStyleName(ValoTheme.BUTTON_TINY);
    approvalItemBtn.addStyleName(ValoTheme.BUTTON_PRIMARY);

    if (getCellItemId() != 0) {
        approvalBtn.setCaption("Approve ITEM");
        CellItem ci = cis.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>");
        cellItem.setValue("<b>STEM</b>: " + getStem());
        OptionGroup options = new OptionGroup();
        options.addItems(cis.getCellItemById(getCellItemId()).getOptionA(),
                cis.getCellItemById(getCellItemId()).getOptionB(),
                cis.getCellItemById(getCellItemId()).getOptionC(),
                cis.getCellItemById(getCellItemId()).getOptionD());
        h1.addComponent(options);
        h1.setComponentAlignment(options, Alignment.MIDDLE_CENTER);

        if (cis.getCellItemById(getCellItemId()).getCellItemStatus() == 0) {
            approvalItemBtn.setVisible(true);
        } else {
            approvalItemBtn.setVisible(false);
        }
        approvalItemBtn.addClickListener(buttonClickListener);
        approvalItemBtn.setVisible(true);
    }
    v.addComponent(approvalBtn);
    v.addComponent(cellItem);
    v.addComponent(h1);
    v.addComponent(approvalItemBtn);

    Label separator = new Label("<HR>");
    separator.setContentMode(ContentMode.HTML);
    v.addComponent(separator);

    return v;
}

From source file:com.etest.view.systemadministration.curriculum.CurriculumFormWindow.java

FormLayout buildForms() {
    FormLayout form = new FormLayout();
    form.setMargin(true);/*from   w  w w . ja  v a2  s  .  c  om*/

    yearLevel.setWidth("75%");
    form.addComponent(yearLevel);

    subjectField.setWidth("75%");
    form.addComponent(subjectField);

    normCourseOffering.setWidth("75%");
    form.addComponent(normCourseOffering);

    descriptiveTitleField.setWidth("100%");
    descriptiveTitleField.setRows(3);
    descriptiveTitleField.setInputPrompt("Descriptive Title..");
    form.addComponent(descriptiveTitleField);

    Button save = new Button("SAVE");
    save.setWidth("100%");
    save.setIcon(FontAwesome.SAVE);
    save.addStyleName(ValoTheme.BUTTON_PRIMARY);
    save.addStyleName(ValoTheme.BUTTON_SMALL);
    save.addClickListener(buttonClickListener);

    Button update = new Button("UPDATE");
    update.setWidth("100%");
    update.setIcon(FontAwesome.ADJUST);
    update.addStyleName(ValoTheme.BUTTON_PRIMARY);
    update.addStyleName(ValoTheme.BUTTON_SMALL);
    update.addClickListener(buttonClickListener);

    Button delete = new Button("DELETE");
    delete.setWidth("100%");
    delete.setIcon(FontAwesome.ERASER);
    delete.addStyleName(ValoTheme.BUTTON_PRIMARY);
    delete.addStyleName(ValoTheme.BUTTON_SMALL);
    delete.addClickListener(buttonClickListener);

    HorizontalLayout hlayout = new HorizontalLayout();
    hlayout.setWidth("100%");
    hlayout.setSpacing(true);

    if (getCurriculumId() != 0) {
        hlayout.addComponent(update);
        hlayout.addComponent(delete);
        Curriculum c = cs.getCurriculumById(getCurriculumId());
        yearLevel.setValue(c.getYearLevel());
        subjectField.setValue(c.getSubject());
        normCourseOffering.setValue(c.getNormCourseOffering());
        descriptiveTitleField.setValue(c.getDescriptiveTitle());

        if (getButtonCaption().equals("edit")) {
            delete.setVisible(false);
        } else {
            update.setVisible(false);
        }
    } else {
        hlayout.addComponent(save);
    }

    form.addComponent(hlayout);

    return form;
}

From source file:com.etest.view.systemadministration.CurriculumMainUI.java

public CurriculumMainUI() {
    setSizeFull();//from   w  ww.ja va 2s  . c om
    setMargin(true);
    setSpacing(true);

    //        addComponent(buildForms());
    //        populateDataGrid();

    Button newBtn = new Button("ADD NEW CURRICULUM");
    newBtn.setWidth("220px");
    newBtn.setIcon(FontAwesome.OPENID);
    newBtn.addStyleName(ValoTheme.BUTTON_LINK);
    newBtn.addStyleName(ValoTheme.BUTTON_SMALL);
    newBtn.addClickListener(buttonClickListener);

    addComponent(newBtn);
    addComponent(dataGridPanel());
}

From source file:com.etest.view.systemadministration.CurriculumMainUI.java

Table populateDataTable() {
    table.removeAllItems();/* www .  j av  a  2 s  .c om*/
    int i = 0;
    for (Curriculum c : cs.getAllCurriculum()) {
        HorizontalLayout h = new HorizontalLayout();
        h.setWidth("100%");

        Button edit = new Button("edit");
        edit.setSizeFull();
        edit.setIcon(FontAwesome.PENCIL);
        edit.setData(c.getCurriculumId());
        edit.addStyleName(ValoTheme.BUTTON_LINK);
        edit.addStyleName(ValoTheme.BUTTON_TINY);
        edit.addStyleName("button-container");
        edit.addClickListener(buttonClickListener);
        h.addComponent(edit);

        Button delete = new Button("del");
        delete.setSizeFull();
        delete.setIcon(FontAwesome.TRASH_O);
        delete.setData(c.getCurriculumId());
        delete.addStyleName(ValoTheme.BUTTON_LINK);
        delete.addStyleName(ValoTheme.BUTTON_TINY);
        delete.addStyleName("button-container");
        delete.addClickListener(buttonClickListener);
        h.addComponent(delete);

        table.addItem(new Object[] {
                //                c.getCurriculumId(),
                CommonVariableMap.getYearLevel(c.getYearLevel()), c.getSubject(), c.getDescriptiveTitle(),
                CommonVariableMap.getNormCourseOffering(c.getNormCourseOffering()), h }, i);
        i++;
    }
    table.setPageLength(table.size());

    //        table.getListeners(ItemClickEvent.class).stream().forEach((listener) -> {
    //            table.removeListener(ItemClickEvent.class, listener);
    //        });
    //        
    //        table.addItemClickListener((ItemClickEvent event) -> {
    //            Property itemProperty = event.getItem().getItemProperty("id");
    //            
    //            Window sub = new CurriculumFormWindow(CommonUtilities.convertStringToInt(itemProperty.getValue().toString()));
    //            if(sub.getParent() == null){
    //                UI.getCurrent().addWindow(sub);
    //            }
    //            sub.addCloseListener((Window.CloseEvent e) -> {
    //                populateDataTable();
    //            });
    //        });

    return table;
}

From source file:com.etest.view.systemadministration.FacultyMainUI.java

public FacultyMainUI() {
    setSizeFull();/*from ww  w. ja v a  2 s  .com*/
    setSpacing(true);
    setMargin(true);

    Button formBtn = new Button("NEW FACULTY FORM");
    formBtn.setWidth("230px");
    formBtn.setIcon(FontAwesome.OPENID);
    formBtn.addStyleName(ValoTheme.BUTTON_LINK);
    formBtn.addStyleName(ValoTheme.BUTTON_SMALL);
    formBtn.addClickListener(formBtnClickListener);
    addComponent(formBtn);

    addComponent(getDataTablePanel());
}

From source file:com.etest.view.systemadministration.FacultyMainUI.java

Table populateDataTable() {
    table.removeAllItems();//from w w w  .j a v  a2s  .c  o  m
    int i = 0;
    for (Users u : fs.getAllFaculty()) {
        HorizontalLayout hlayout = new HorizontalLayout();
        hlayout.setWidth("100%");

        Button edit = new Button("edit");
        edit.setWidth("100%");
        edit.setData(u.getFacultyId());
        edit.setIcon(FontAwesome.PENCIL);
        edit.addStyleName(ValoTheme.BUTTON_LINK);
        edit.addStyleName(ValoTheme.BUTTON_TINY);
        edit.addStyleName("button-container");
        edit.addClickListener(modifyBtnClickListener);
        hlayout.addComponent(edit);

        Button delete = new Button("del");
        delete.setWidth("100%");
        delete.setData(u.getFacultyId());
        delete.setIcon(FontAwesome.TRASH_O);
        delete.addStyleName(ValoTheme.BUTTON_LINK);
        delete.addStyleName(ValoTheme.BUTTON_TINY);
        delete.addStyleName("button-container");
        delete.addClickListener(modifyBtnClickListener);
        hlayout.addComponent(delete);

        table.addItem(new Object[] { u.getName().toUpperCase(), u.getUsername_(), u.getUserType(), hlayout },
                new Integer(i));
        i++;
    }
    table.setPageLength(table.size());

    //        table.getListeners(ItemClickEvent.class).stream().forEach((listener) -> {
    //            table.removeListener(ItemClickEvent.class, listener);
    //        });

    //        table.addItemClickListener((ItemClickEvent event) -> {
    //            Property itemProperty = event.getItem().getItemProperty("name");
    //            facultyId = fs.getFacultyIdByName(itemProperty.getValue().toString());
    //            
    //            Window sub = new FacultyFormWindow(facultyId);
    //            if(sub.getParent() == null){
    //                UI.getCurrent().addWindow(sub);
    //            }
    //        });

    return table;
}

From source file:com.etest.view.systemadministration.HousekeepingMainUI.java

Table populateDataTable() {
    table.removeAllItems();/* ww w .  j a  v a  2s .  c  om*/
    int i = 0;
    for (CellItem ci : hs.getAllItemsFromArchive()) {
        VerticalLayout v = new VerticalLayout();
        v.setWidth("100%");

        Button recycle = new Button("recycle");
        recycle.setWidthUndefined();
        recycle.setData(ci.getCellItemId());
        recycle.setIcon(FontAwesome.RECYCLE);
        recycle.addStyleName(ValoTheme.BUTTON_LINK);
        recycle.addStyleName(ValoTheme.BUTTON_TINY);
        recycle.addStyleName(ValoTheme.BUTTON_QUIET);
        recycle.addStyleName("button-container");
        v.addComponent(recycle);
        v.setComponentAlignment(recycle, Alignment.MIDDLE_LEFT);

        Button view = new Button("view");
        view.setWidthUndefined();
        view.setData(ci.getCellItemId());
        view.setIcon(FontAwesome.COFFEE);
        view.addStyleName(ValoTheme.BUTTON_LINK);
        view.addStyleName(ValoTheme.BUTTON_TINY);
        view.addStyleName(ValoTheme.BUTTON_QUIET);
        view.addStyleName("button-container");
        view.addClickListener(buttonClickListener);
        v.addComponent(view);
        v.setComponentAlignment(view, Alignment.MIDDLE_LEFT);

        table.addItem(new Object[] { ci.getCellItemId(), ci.getItem(), v }, i);
        i++;
    }
    table.setPageLength(table.size());

    return table;
}

From source file:com.etest.view.systemadministration.SemestralTeam.AddSemestralTeamMembersWindow.java

Table populateDataTable() {
    table.removeAllItems();/*w  w w.j a  v a 2s .  c o  m*/
    int i = 0;
    for (TeamTeach tt : tts.getAllMembersFromTeam(getTeamTeachId())) {
        String position;
        boolean isFacultyTeamLeader = tts.isFacultyTeamLeader(getTeamTeachId(), tt.getFacultyId());
        if (isFacultyTeamLeader) {
            position = "Team Leader";
        } else {
            position = "Member";
        }

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

        Button editPositionBtn = new Button("edit");
        editPositionBtn.setWidthUndefined();
        editPositionBtn.setData(tt.getFacultyId());
        editPositionBtn.setIcon(FontAwesome.EDIT);
        editPositionBtn.addStyleName(ValoTheme.BUTTON_LINK);
        editPositionBtn.addStyleName(ValoTheme.BUTTON_TINY);
        editPositionBtn.addClickListener(modifyBtnClickListener);
        hlayout.addComponent(editPositionBtn);

        Button removeMemberBtn = new Button("del");
        removeMemberBtn.setWidthUndefined();
        removeMemberBtn.setData(tt.getFacultyId());
        removeMemberBtn.setIcon(FontAwesome.TRASH_O);
        removeMemberBtn.addStyleName(ValoTheme.BUTTON_LINK);
        removeMemberBtn.addStyleName(ValoTheme.BUTTON_TINY);
        removeMemberBtn.addClickListener(modifyBtnClickListener);
        hlayout.addComponent(removeMemberBtn);

        if (!position.equals("Member")) {
            editPositionBtn.setEnabled(false);
            removeMemberBtn.setEnabled(false);
        }

        table.addItem(new Object[] { tt.getFacultyId(), tt.getName(), position, hlayout }, i);
        i++;
    }
    table.setPageLength(table.size());

    return table;
}

From source file:com.etest.view.systemadministration.SemestralTeam.AddSemestralTeamMembersWindow.java

Window removeTeamMemberWindow(int facultyRowId) {
    Window sub = new Window();
    sub.setCaption("REMOVE TEAM MEMBER");
    sub.setWidth("250px");
    sub.setModal(true);//from  w  ww.  ja  v a  2 s.  c  o m
    sub.center();

    VerticalLayout vlayout = new VerticalLayout();
    vlayout.setSizeFull();
    vlayout.setMargin(true);

    Button removeBtn = new Button("REMOVE");
    removeBtn.setWidth("100%");
    removeBtn.addStyleName(ValoTheme.BUTTON_PRIMARY);
    removeBtn.addStyleName(ValoTheme.BUTTON_SMALL);
    removeBtn.addClickListener((Button.ClickEvent event) -> {
        boolean result = tts.removeTeamMember(getTeamTeachId(), facultyRowId);
        if (result) {
            populateDataTable();
            sub.close();
        }
    });
    vlayout.addComponent(removeBtn);

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

    return sub;
}