Example usage for com.vaadin.ui Button.ClickListener Button.ClickListener

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

Introduction

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

Prototype

Button.ClickListener

Source Link

Usage

From source file:de.unioninvestment.eai.portal.portlet.crud.mvp.views.DefaultTableView.java

License:Apache License

private void addCrudButtonListeners() {
    if (editButton != null) {
        editButton.addClickListener(new Button.ClickListener() {
            @Override/*from  w w  w.  j a  v a  2 s  .  c om*/
            public void buttonClick(ClickEvent event) {
                presenter.switchMode(tableModel.getMode() == Mode.VIEW ? Mode.EDIT : Mode.VIEW);
            }
        });
    } else if (saveButton != null) {
        saveButton.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                commit();
            }
        });
    }
    revertButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            onRevertChanges();
        }
    });
    if (presenter.isInsertable()) {
        insertButton.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                onAddBlankRow();
            }
        });
    }
    if (presenter.isDeleteable()) {
        removeButton.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                onRemoveRow();
            }
        });
    }
}

From source file:de.unioninvestment.eai.portal.portlet.crud.mvp.views.DefaultTableView.java

License:Apache License

private void addExportButtonListeners() {
    if (presenter.isExcelExport()) {
        excelExportButton.addClickListener(new Button.ClickListener() {
            @Override/*from  w ww  .j  a  v a2 s  . c  o  m*/
            public void buttonClick(ClickEvent event) {
                exportExcelSheet(null);
            }

        });
    }

    if (presenter.isCSVExport()) {
        csvExportButton.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                exportCSVSheet(null);
            }
        });
    }
}

From source file:de.unioninvestment.eai.portal.portlet.crud.mvp.views.DefaultTableView.java

License:Apache License

private void addCustomButtonsListeners() {
    if (!actionButtons.isEmpty()) {
        for (final Button button : actionButtons.values()) {
            button.setDisableOnClick(true);
            final TableAction action = buttonToTableActionMap.get(button);
            button.addClickListener(new Button.ClickListener() {

                private static final long serialVersionUID = 42L;

                @Override/*from   ww  w. ja va  2 s .c  o m*/
                public void buttonClick(ClickEvent event) {
                    try {
                        presenter.callClosure(action);

                        if (action.isExportAction()) {
                            switch (action.getExportType()) {
                            case XLS:
                                exportExcelSheet(action.generateExportFilename());
                                break;
                            case CSV:
                                exportCSVSheet(action.generateExportFilename());
                                break;
                            default:
                                throw new IllegalArgumentException("Unknown export type '"
                                        + action.getExportType() + "' set on action with title '"
                                        + action.getTitle() + "' and id '" + action.getId() + "'");
                            }
                        }
                    } finally {
                        button.setEnabled(true);
                    }
                }
            });
        }
    }
}

From source file:dev.DevUI.java

License:Open Source License

@Override
protected void init(VaadinRequest request) {

    final VerticalLayout mainLayout = new VerticalLayout();
    mainLayout.setSpacing(true);//from w w w  .j a  v  a2s . c o m
    mainLayout.setMargin(true);

    PluploadManager mgr = createUploadManager("Manager 1");
    PluploadManager mgr2 = createUploadManager("Manager 2");
    PluploadManager mgr3 = createChunkingUploadManager("Manager 3");

    mgr.getUploader().addFilter(new PluploadFilter("music", "mp3,flac"));

    VerticalLayout dropZone = new VerticalLayout() {
        {
            addComponent(new Label("Additional drop zone for music files"));
            setId("music-drop-zone");
        }
    };

    mgr.getUploader().addDropZone(dropZone);

    mgr2.getUploader().addFilter(new PluploadFilter("images", "jpg, jpeg, png"));
    mgr2.getUploader().setImageResize(
            new PluploadImageResize().setEnabled(true).setCrop(true).setHeight(200).setWidth(400));

    mainLayout.addComponent(mgr);
    mainLayout.addComponent(dropZone);
    mainLayout.addComponent(mgr2);
    mainLayout.addComponent(mgr3);

    PluploadField<File> field = createUploadField();
    final Form form = new Form();
    form.addField("file", field);
    field.addValidator(new NullValidator("file must not be null", false));
    Button submit = new Button("commit form");
    submit.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            form.commit();
        }
    });
    mainLayout.addComponent(form);
    mainLayout.addComponent(submit);

    PluploadField<byte[]> byteField = createByteUploadField();
    mainLayout.addComponent(byteField);

    final Plupload uploader = createSimpleUploader();
    uploader.setEnabled(false);
    Button b = new Button("toggle Enabled!", new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            uploader.setEnabled(!uploader.isEnabled());
        }
    });
    mainLayout.addComponent(b);
    mainLayout.addComponent(uploader);
    final Counter c = new Counter();
    final Button.ClickListener l = new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Window w = new Window("win");

            if (c.get() < 5) {
                w.setContent(new Button("win", this));
                c.increment();
            } else {
                Field f = createUploadField();
                w.setContent(f);
                c.reset();
            }
            w.setWidth("400px");
            w.setHeight("200px");
            getUI().addWindow(w);
        }
    };

    Button win = new Button("Win");
    win.addClickListener(l);
    mainLayout.addComponent(win);

    Button modal = new Button("modal");
    modal.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Window w = new Window("modal");

            final PluploadField f = createUploadField();
            w.addCloseListener(new Window.CloseListener() {

                @Override
                public void windowClose(Window.CloseEvent e) {
                    Notification.show("closed modal");
                    f.getUploader().destroy();
                }
            });
            VerticalLayout lay = new VerticalLayout();
            lay.addComponent(f);
            lay.addComponent(new Button("destroy", new Button.ClickListener() {

                @Override
                public void buttonClick(Button.ClickEvent event) {
                    f.getUploader().destroy();
                }
            }));

            w.setContent(lay);
            w.setModal(true);
            getUI().addWindow(w);
        }
    });

    Accordion acc = new Accordion();
    acc.addTab(this.createUploadManager("mgr3"), "uploader");
    acc.addTab(new HorizontalLayout(), "Stub");

    mainLayout.addComponent(acc);

    mainLayout.addComponent(modal);
    this.setContent(mainLayout);

}

From source file:edu.nps.moves.mmowgli.AbstractMmowgliControllerHelper.java

License:Open Source License

public void handleDumpEmailsTL() {
    final TextField tf;

    final Window dialog = new Window("Filter Player Email Dump");
    dialog.setModal(true);/*from w w w . j ava 2s  .  c om*/

    VerticalLayout layout = new VerticalLayout();
    dialog.setContent(layout);
    layout.setMargin(true);
    layout.setSpacing(true);

    final OptionGroup radios = new OptionGroup(null, Arrays.asList(opts));
    layout.addComponent(radios);

    layout.addComponent(tf = new MTextField().withWidth("50%"));
    tf.setCaption("value");

    Label lab;

    layout.addComponent(lab = new Label());
    lab.setHeight("10px");

    radios.setNullSelectionAllowed(false); // user can not 'unselect'
    radios.select(allp); // select this by default
    radios.setImmediate(false); // don't send the change to the server at once
    radios.setMultiSelect(false);

    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);
    @SuppressWarnings("serial")
    Button cancelButt = new Button("Cancel", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            dialog.close();
        }
    });

    @SuppressWarnings("serial")
    Button addButt = new Button("Dump", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            Float val = null;
            String valS = "";
            boolean parseError = false;
            try {
                val = Float.parseFloat(tf.getValue());
                valS = formatter.valueToString(val);
            } catch (Exception ex) {
                parseError = true;
            }

            HSess.init();
            Object sel = radios.getValue();
            Criteria crit = null;
            String windowTitle = "";
            boolean isExpl = true;
            if (sel == allp) {
                crit = HSess.get().createCriteria(User.class);
                windowTitle = new String("All users");
                isExpl = true;
                if (parseError) {
                    Notification.show("Value ignored", Notification.Type.WARNING_MESSAGE);
                    System.out.println("Tried to show a Notification");
                }
            } else if (sel == grex) {
                crit = getExplorationGreaterThanTL(val);
                windowTitle = "Users with exploration points greater than " + valS;
                isExpl = true;
            } else if (sel == lsex) {
                crit = getExplorationLessThanTL(val);
                windowTitle = "Users with exploration points less than " + valS;
                isExpl = true;
            } else if (sel == grim) {
                crit = getImplementationGreaterThanTL(val);
                windowTitle = "Users with implementation points greater than " + valS;
                isExpl = false;
            } else if (sel == lsim) {
                crit = getImplementationLessThanTL(val);
                windowTitle = "Users with implementation points less than " + valS;
                isExpl = false;
            }

            if (crit != null) {
                @SuppressWarnings("unchecked")
                List<User> lis = (List<User>) crit.list();
                StringBuilder sb = new StringBuilder();
                handleEmailListNoHeader(lis, sb, isExpl);

                String title = windowTitle + " - " + UUID.randomUUID();
                BrowserWindowOpener.openWithInnerHTML(sb.toString(), title, "_blank");
            } else {
                Notification.show("Invalid value", Notification.Type.ERROR_MESSAGE);
                HSess.close();
                return;
            }

            dialog.close();
            HSess.close();
        }
    });

    hl.addComponent(cancelButt);
    hl.addComponent(addButt);
    hl.setComponentAlignment(cancelButt, Alignment.MIDDLE_RIGHT);
    hl.setExpandRatio(cancelButt, 1.0f);

    layout.addComponent(hl);

    hl.setWidth("100%");

    layout.addComponent(lab = new Label());
    layout.setExpandRatio(lab, 1.0f);

    UI.getCurrent().addWindow(dialog);
    dialog.center();
}

From source file:edu.nps.moves.mmowgli.export.BaseExporter.java

License:Open Source License

protected void getMetaStringOrCancel(final MetaListener lis, String title, final Map<String, String> params) {
    final Window dialog = new Window(title);
    final TextField[] parameterFields;

    dialog.setModal(true);// www .j  a v  a 2 s . co m

    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setSizeFull();
    dialog.setContent(layout);

    final TextArea ta = new TextArea();
    ta.setWidth("100%");
    ta.setInputPrompt("Type a description of this data, or the game which generated this data (optional)");

    ta.setImmediate(true);
    layout.addComponent(ta);

    Set<String> keySet = params.keySet();
    parameterFields = new TextField[keySet.size()];
    int i = 0;
    GridLayout pGL = new GridLayout();
    pGL.addStyleName("m-greyborder");
    pGL.setColumns(2);
    Label hdr = new HtmlLabel("<b>Parameters</b>");
    hdr.addStyleName("m-textaligncenter");
    pGL.addComponent(hdr, 0, 0, 1, 0); // top row
    pGL.setComponentAlignment(hdr, Alignment.MIDDLE_CENTER);
    pGL.setSpacing(false);
    for (String key : keySet) {
        pGL.addComponent(new HtmlLabel("&nbsp;" + key + "&nbsp;&nbsp;"));
        pGL.addComponent(parameterFields[i] = new TextField());
        parameterFields[i++].setValue(params.get(key));
    }
    if (i > 0) {
        layout.addComponent(pGL);
        layout.setComponentAlignment(pGL, Alignment.TOP_CENTER);
    }

    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);
    @SuppressWarnings("serial")
    Button cancelButt = new Button("Cancel", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            dialog.close();
            lis.continueOrCancel(null);
        }
    });

    @SuppressWarnings("serial")
    Button exportButt = new Button("Export", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            dialog.close();

            Set<String> keySet = params.keySet();
            int i = 0;
            for (String key : keySet)
                params.put(key, parameterFields[i++].getValue().toString());

            lis.continueOrCancel(ta.getValue().toString());
        }
    });
    hl.addComponent(cancelButt);
    hl.addComponent(exportButt);
    hl.setComponentAlignment(cancelButt, Alignment.MIDDLE_RIGHT);
    hl.setExpandRatio(cancelButt, 1.0f);

    // The components added to the window are actually added to the window's
    // layout; you can use either. Alignments are set using the layout
    layout.addComponent(hl);
    dialog.setWidth("385px");
    dialog.setHeight("310px");
    hl.setWidth("100%");
    ta.setWidth("100%");
    ta.setHeight("100%");
    layout.setExpandRatio(ta, 1.0f);

    UI.getCurrent().addWindow(dialog);
}

From source file:edu.nps.moves.mmowgli.Mmowgli2UIError.java

License:Open Source License

@SuppressWarnings("serial")
@Override//from  ww w. j a va  2 s .  c o  m
protected void init(VaadinRequest request) {
    uuid = UUID.randomUUID();

    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    setContent(layout);
    Page.getCurrent().setTitle("Mmowgli Login Error");
    layout.addComponent(new Label(
            "Whoops!  It looks like you are opening a second mmowgli window or tab without completing your log-in in the first."));
    //layout.addComponent(new Label("You appear to have an incomplete log-in session pending in another tab or window."));
    layout.addComponent(new Label("If this is the case, close this tab and continue with your log-in."));
    layout.addComponent(new Label(
            "If that window or tab is no longer available, begin a new Mmowgli session by clicking the following button."));
    //layout.addComponent(new Label("Any previously entered information will be discarded."));

    Button button = new Button("Begin new Mmowgli session");
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            getPage().setLocation(getPage().getLocation());
            getSession().close();
        }
    });
    layout.addComponent(button);
}

From source file:edu.nps.moves.mmowgli.modules.administration.VipListManager.java

License:Open Source License

private void showAddDialogOrCancel(final DoneListener lis) {
    dialog = new Window("Add to VIP list");
    dialog.setModal(true);/*from   w  ww  . jav a2  s. co m*/
    dialog.setWidth("400px");
    dialog.setHeight("350px");

    VerticalLayout layout = new VerticalLayout();
    dialog.setContent(layout);
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setSizeFull();

    List<String> rtypes = Arrays.asList(new String[] { EMAILTYPE, DOMAINTYPE });
    radios = new OptionGroup("Select type", rtypes);

    radios.setNullSelectionAllowed(false); // user can not 'unselect'
    radios.select("Emails"); // select this by default
    radios.setImmediate(false); // don't send the change to the server at once
    layout.addComponent(radios);

    final TextArea ta = new TextArea();
    //ta.setColumns(40);
    ta.setSizeFull();
    ta.setInputPrompt(
            "Type or paste a tab-, comma- or space-separated list of emails or domains.  For domains, "
                    + "use forms such as \"army.mil\", \"nmci.navy.mil\", \"ucla.edu\", \"gov\", etc.");
    layout.addComponent(ta);

    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);
    @SuppressWarnings("serial")
    Button cancelButt = new Button("Cancel", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            dialog.close();
            lis.continueOrCancel(null);
        }
    });

    @SuppressWarnings("serial")
    Button addButt = new Button("Add", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            String[] returnArr = null;
            String result = ta.getValue().toString();
            if (result == null || result.length() <= 0)
                returnArr = null;
            else if ((returnArr = parseIt(result)) == null)
                return;

            dialog.close();
            lis.continueOrCancel(returnArr);
        }
    });

    hl.addComponent(cancelButt);
    hl.addComponent(addButt);
    hl.setComponentAlignment(cancelButt, Alignment.MIDDLE_RIGHT);
    hl.setExpandRatio(cancelButt, 1.0f);

    // The components added to the window are actually added to the window's
    // layout; you can use either. Alignments are set using the layout
    layout.addComponent(hl);

    hl.setWidth("100%");
    ta.setWidth("100%");
    ta.setHeight("100%");
    layout.setExpandRatio(ta, 1.0f);

    UI.getCurrent().addWindow(dialog);
    dialog.center();
}

From source file:edu.nps.moves.mmowgli.modules.administration.VipListManager.java

License:Open Source License

@SuppressWarnings({ "unchecked", "serial" })
private void showViewOrDelete(final DeleteListener lis) {
    dialog = new Window("View / Delete VIPs");
    dialog.setModal(true);/* w w w  .j  a  va  2 s  . co  m*/

    VerticalLayout layout = new VerticalLayout();
    dialog.setContent(layout);
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setSizeFull();

    List<VipPii> vLis = VHibPii.getAllVips();

    vipListSelect = new ListSelect("Select items to delete");
    StringBuffer sb = new StringBuffer(); // for popup
    vipListSelect.addStyleName("m-greyborder");
    String lf = System.getProperty("line.separator");
    for (int i = 0; i < vLis.size(); i++) {
        VipPii v;
        vipListSelect.addItem(v = vLis.get(i));
        sb.append(v.getEntry());
        sb.append(lf);
    }
    if (sb.length() > 0)
        sb.setLength(sb.length() - 1); // last space

    vipListSelect.setNullSelectionAllowed(true);
    vipListSelect.setMultiSelect(true);
    vipListSelect.setImmediate(true);
    vipListSelect.addValueChangeListener(new VipSelectListener());

    layout.addComponent(vipListSelect);

    Label copyPopupList = new HtmlLabel("<pre>" + sb.toString() + "</pre>");
    Panel p = new Panel();
    VerticalLayout lay = new VerticalLayout();
    p.setContent(lay);
    lay.addComponent(copyPopupList);
    p.setWidth("400px");
    p.setHeight("300px");
    PopupView popup = new PopupView("Display list as copyable text", p);
    popup.setHideOnMouseOut(false);
    if (sb.length() <= 0)
        popup.setEnabled(false);

    layout.addComponent(popup);
    layout.setComponentAlignment(popup, Alignment.MIDDLE_CENTER);

    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);
    Button cancelButt = new Button("Cancel", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            dialog.close();
            lis.continueOrCancel(null);
        }
    });

    deleteButt = new Button("Delete & Close", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            Set<VipPii> set = (Set<VipPii>) vipListSelect.getValue();
            if (set.size() <= 0)
                set = null;
            dialog.close();
            lis.continueOrCancel(set);
        }
    });
    deleteButt.setEnabled(false);
    hl.addComponent(cancelButt);
    hl.addComponent(deleteButt);
    hl.setComponentAlignment(cancelButt, Alignment.MIDDLE_RIGHT);
    hl.setExpandRatio(cancelButt, 1.0f);

    // The components added to the window are actually added to the window's
    // layout; you can use either. Alignments are set using the layout
    layout.addComponent(hl);
    dialog.setWidth("300px");
    dialog.setHeight("350px");
    hl.setWidth("100%");
    vipListSelect.setWidth("99%");
    vipListSelect.setHeight("99%");
    layout.setExpandRatio(vipListSelect, 1.0f);

    UI.getCurrent().addWindow(dialog);
    dialog.center();
}

From source file:edu.nps.moves.mmowgli.modules.registrationlogin.PasswordResetPopup.java

License:Open Source License

private void makeResetAnnounceDialogTL_5(String email, ArrayList<User> aLis) {
    UI myUI = getUI();//from  w  w  w. ja v a2s.c o m
    myUI.removeWindow(PasswordResetPopup.this);

    final Window resetAnnounceDialog = new Window("Password Reset Announcement");
    resetAnnounceDialog.setModal(true);
    resetAnnounceDialog.setClosable(false);
    VerticalLayout vLay = new VerticalLayout();
    resetAnnounceDialog.setContent(vLay);
    vLay.setMargin(true);
    vLay.setSpacing(true);
    vLay.setSizeUndefined();
    vLay.setWidth("400px");

    Label message = new HtmlLabel("An email has been sent to <b>" + email + "</b>.");
    vLay.addComponent(message);

    message = new Label(
            "Follow the link in the message to confirm your password reset request to enable login to your mmowgli player account.");
    vLay.addComponent(message);

    message = new Label(
            "Please be advised that you will only have three hours to complete this process, after which time "
                    + "you will have to re-initiate a new password reset process from the game login page.");
    vLay.addComponent(message);

    message = new HtmlLabel(
            "Now, press <b>Homepage -- Return to login</b> after receiving a reset request confirmation email.");
    vLay.addComponent(message);

    @SuppressWarnings("serial")
    Button laterButt = new Button("Homepage -- Return to login", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            HSess.init();
            Mmowgli2UI.getAppUI().quitAndGoTo(GameLinks.getTL().getGameHomeUrl());
            HSess.close();
        }
    });
    vLay.addComponent(laterButt);

    @SuppressWarnings("serial")
    Button troubleButt = new Button("Send trouble report", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            HSess.init();
            Mmowgli2UI.getAppUI().quitAndGoTo(GameLinks.getTL().getTroubleLink());
            HSess.close();
        }
    });
    vLay.addComponent(troubleButt);

    myUI.addWindow(resetAnnounceDialog);
    resetAnnounceDialog.center();

    // This process generates unique uId for th3 reset process that will
    // need to be confirmed once the user receives a confirmation email and
    // click on the link containing the uId
    Iterator<User> itr = aLis.iterator();
    // sends email to all user accounts (which are at the same email address)
    // if a game name was entered, only that account receives the email
    while (itr.hasNext()) {
        User usr = itr.next();
        PasswordReset pr = new PasswordReset(usr);
        PasswordReset.saveTL(pr);

        String confirmUrl = buildConfirmUrl(pr);
        AppMaster.instance().getMailManager().sendPasswordResetEmailTL(email, usr.getUserName(), confirmUrl);
    }
}