Example usage for com.vaadin.ui Button addListener

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

Introduction

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

Prototype

@Override
    public Registration addListener(Component.Listener listener) 

Source Link

Usage

From source file:net.larbig.ScriptRunnerApplication.java

License:Apache License

@Override
public void init() {
    window = new Window("Scriptrunner");
    setMainWindow(window);//from  w w  w .  ja  v a 2s  .c o m

    VerticalLayout layout = new VerticalLayout();
    final TextField tfDriver = new TextField("Driver");
    tfDriver.setWidth(300, Sizeable.UNITS_PIXELS);
    tfDriver.setValue("com.mysql.jdbc.Driver");
    final TextField tfURL = new TextField("URL");
    tfURL.setWidth(300, Sizeable.UNITS_PIXELS);
    tfURL.setValue("jdbc:mysql://mysql.host.net:3306/datenbank");
    final TextField tfUser = new TextField("User");
    tfUser.setWidth(300, Sizeable.UNITS_PIXELS);
    final TextField tfPasswort = new TextField("Password");
    tfPasswort.setWidth(300, Sizeable.UNITS_PIXELS);
    final TextArea taSQL = new TextArea("SQL");
    taSQL.setWidth(300, Sizeable.UNITS_PIXELS);
    taSQL.setHeight(150, Sizeable.UNITS_PIXELS);

    Button button = new Button("Execute");
    button.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {

            try {
                Class.forName((String) tfDriver.getValue()).newInstance();
                Connection con = DriverManager.getConnection(tfURL.getValue().toString(),
                        tfUser.getValue().toString(), tfPasswort.getValue().toString());
                ScriptRunner runner = new ScriptRunner(con, false, true);
                Reader r = new StringReader(taSQL.getValue().toString());
                runner.runScript(r);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    });

    layout.addComponent(tfDriver);
    layout.addComponent(tfURL);
    layout.addComponent(tfUser);
    layout.addComponent(tfPasswort);
    layout.addComponent(taSQL);
    layout.addComponent(button);
    window.addComponent(layout);

}

From source file:nl.amc.biolab.nsg.display.component.LoginUI.java

License:Open Source License

public LoginUI(final MainControl mainControl) {
    setWidth("100%");
    setHeight("300px");

    layout.setWidth("100%");
    layout.setHeight("300px");
    layout.addComponent(form);//from w w  w.  ja v  a  2  s.  com

    setCompositionRoot(layout);

    final TextField name = new TextField("Please enter your XNAT username");
    final PasswordField xnatPassword = new PasswordField("Please enter your XNAT password");

    xnatPassword.setRequired(true);

    form.addField("xnatUsername", name);
    form.addField("xnatPassword", xnatPassword);

    final Button okButton = new Button("ok");

    okButton.setClickShortcut(KeyCode.ENTER);
    okButton.addListener(new Button.ClickListener() {
        private static final long serialVersionUID = -6535226372165482804L;

        public void buttonClick(ClickEvent event) {
            User user = null;

            user = login((String) name.getValue(), (String) xnatPassword.getValue());
            xnatPassword.setValue("");

            if (user == null) {
                return;
            }

            okButton.setData(user);
            mainControl.init(user);

            app.getMainWindow().executeJavaScript("window.location.reload();");
        }
    });

    form.getFooter().addComponent(okButton);
}

From source file:nl.amc.biolab.nsg.display.component.ProcessingForm.java

License:Open Source License

public void setButtons() {
    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setHeight("40px");
    buttons.setSpacing(true);/*from  w w  w . j  ava  2  s . c o m*/
    getLayout().addComponent(buttons);

    final Button startButton = new NativeButton();

    startButton.setCaption(SUBMIT);
    startButton.setImmediate(true);
    startButton.setWidth("-1px");
    startButton.setHeight("-1px");
    startButton.addListener(new Button.ClickListener() {
        private static final long serialVersionUID = 1906358615316029946L;

        public void buttonClick(ClickEvent event) {
            System.out.println(app.getValue());

            Set<Long> inputDbIds = new HashSet<Long>();

            for (Object iid : inputData.getItemIds()) {
                inputData.select(iid);

                inputDbIds.add(((DataElement) iid).getDbId());
            }

            ((VaadinTestApplication) getApplication()).getUserDataService().setDataElementDbIds(inputDbIds);

            form.commit();

            processing.setApplication((Application) app.getValue());

            startButton.setData(processing);

            form.fireEvent(new Event(startButton));
        }
    });

    buttons.addComponent(startButton);
    buttons.setComponentAlignment(startButton, Alignment.TOP_RIGHT);

    final Button delButton = new NativeButton();
    delButton.setCaption("remove inputs");
    delButton.setImmediate(true);
    delButton.setWidth("-1px");
    delButton.setHeight("-1px");
    delButton.addListener(new Button.ClickListener() {
        private static final long serialVersionUID = -3377452914254101817L;

        @SuppressWarnings("unchecked")
        public void buttonClick(ClickEvent event) {
            if (inputData.getValue() != null) {
                for (DataElement de : (Set<DataElement>) inputData.getValue()) {
                    inputData.removeItem(de);
                    dataElements.remove(de);
                }
            }
        }
    });
    buttons.addComponent(delButton);
    buttons.setComponentAlignment(delButton, Alignment.TOP_RIGHT);
}

From source file:nl.amc.biolab.nsg.display.component.ProcessingStatusForm.java

License:Open Source License

private void createSubmissionButtons(final VaadinTestApplication app, final SubmissionIO submissionIO,
        final nl.amc.biolab.datamodel.objects.Error error) {
    final Link statusLink = new Link("download", new StreamResource(new StreamSource() {
        private static final long serialVersionUID = 2010850543250392280L;

        public InputStream getStream() {
            String status;/* w  ww  . j a va  2 s . c o m*/
            if (error != null) {
                status = error.getCode() + "\n" + error.getMessage() + "\n" + error.getDescription();
            } else {
                status = "No message";
            }
            return new ByteArrayInputStream(status.getBytes());
        }
    }, "status", getApplication()), "", 400, 300, 2);

    viewStatusButton = new NativeButton("Details");
    viewStatusButton.addListener(new Button.ClickListener() {
        private static final long serialVersionUID = -8337533736203519683L;

        @Override
        public void buttonClick(ClickEvent event) {
            app.getMainWindow().addWindow(new Window() {
                private static final long serialVersionUID = 1520192489661790818L;

                {
                    center();
                    setWidth("700px");
                    setHeight("500px");
                    VerticalLayout vl = new VerticalLayout();
                    vl.addComponent(statusLink);
                    String status;
                    if (error != null) {
                        status = error.getCode() + "\n" + error.getMessage() + "\n" + error.getDescription();
                    } else {
                        status = "No message";
                    }
                    //status += "<img src=\"images/prov.png\"";
                    vl.addComponent(new Label(status, Label.CONTENT_PREFORMATTED));
                    addComponent(vl);
                }
            });
        }
    });

    resubmitButton = new NativeButton("Resume");
    resubmitButton.setData(processingStatusForm);
    resubmitButton.addListener(new Button.ClickListener() {
        private static final long serialVersionUID = -6410875548044234734L;

        @Override
        public void buttonClick(ClickEvent event) {
            long dbId = processingStatus.getProcessing().getDbId();
            long liferayID = app.getLiferayId(processingStatus.getProcessing().getUser().getLiferayID());
            processingService.resubmit(dbId, submissionIO.getSubmission().getDbId(),
                    userDataService.getUserId(), liferayID);
            processingStatusForm.attach();
        }
    });

    markFailButton = new NativeButton("Abort");
    markFailButton.setData(processingStatusForm);
    markFailButton.addListener(new Button.ClickListener() {
        private static final long serialVersionUID = -5019762936706219454L;

        @Override
        public void buttonClick(ClickEvent event) {
            app.getMainWindow().addWindow(new Window() {
                private static final long serialVersionUID = 3852384470521127702L;

                {
                    final Window window = this;
                    center();
                    setWidth("500px");
                    setHeight("300px");
                    VerticalLayout vl = new VerticalLayout();

                    final TextField text = new TextField("Remarks to the user");
                    text.setWidth("97%");
                    text.setHeight("150px");
                    vl.addComponent(text);

                    final Button okButton = new NativeButton();
                    okButton.setCaption("Save");
                    okButton.setImmediate(true);
                    okButton.setWidth("-1px");
                    okButton.setHeight("-1px");
                    okButton.addListener(new Button.ClickListener() {
                        private static final long serialVersionUID = 1754437322024958253L;

                        public void buttonClick(ClickEvent event) {
                            long dbId = processingStatus.getProcessing().getDbId();
                            long userID = processingStatus.getProcessing().getUser().getDbId();
                            long liferayID = app
                                    .getLiferayId(processingStatus.getProcessing().getUser().getLiferayID());
                            processingService.markFailed(submissionIO.getSubmission().getDbId(),
                                    (String) text.getValue());
                            processingStatus = processingService.getProcessingStatus(
                                    userDataService.getProcessing(dbId), userID, liferayID, false);
                            refreshButton.setData(processingStatus);
                            processingStatusForm.fireValueChange(false);//fireEvent(new Event(refreshButton));
                            window.getParent().removeWindow(window);
                        }
                    });
                    vl.addComponent(okButton);
                    addComponent(vl);
                }
            });
        }
    });
    //      }

    remarksButton = new NativeButton("Why?");
    remarksButton.addListener(new Button.ClickListener() {
        private static final long serialVersionUID = -267778012100029422L;

        @Override
        public void buttonClick(ClickEvent event) {
            app.getMainWindow().addWindow(new Window() {
                private static final long serialVersionUID = -5026454769214596711L;

                {
                    List<nl.amc.biolab.datamodel.objects.Error> temp = submissionIO.getSubmission().getErrors();

                    center();
                    setWidth("700px");
                    setHeight("500px");
                    VerticalLayout vl = new VerticalLayout();
                    vl.addComponent(
                            new Label(temp.get(temp.size() - 1).getMessage(), Label.CONTENT_PREFORMATTED));
                    addComponent(vl);
                }
            });
        }
    });
}

From source file:nl.svenvintges.demo.MyVaadinApplication.java

License:Apache License

@Override
public void init() {
    window = new Window("Data centric testcase");
    setMainWindow(window);//from   w  ww. j  av  a  2 s .co  m
    Button button = new Button("Click Me");
    button.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            window.addComponent(new Label("Thank you for clicking"));
        }
    });
    window.addComponent(button);

    PopupDateField startDateField = new PopupDateField();
    startDateField.setCaption("Startdatum:");
    startDateField.setDateFormat("dd-MM-yyyy");
    window.addComponent(startDateField);

    Button searchButton = new Button();
    searchButton.setCaption("Zoeken");
    window.addComponent(searchButton);

    Table messageResultTable = new Table("Resultaten van gevonden berichten op het platform");
    MessageContainer messageContainer = new MessageContainer();
    messageContainer.populateContainer((new MessageDAOImpl()).getMessageByDateRange(new Date(), new Date()));
    messageResultTable.setContainerDataSource(messageContainer);
    window.addComponent(messageResultTable);

}

From source file:nz.co.senanque.vaadinsupport.FieldFactory.java

License:Apache License

public Button createButton(String name, ClickListener listener, ButtonPainter painter, Hints hints) {
    Button ret = hints.getButtonField(name, painter.getMessageSource());
    ret.addListener(listener);
    if (painter != null) {
        getMaduraSessionManager().register(ret, painter);
    }/* w  ww.j av a 2s.  co  m*/
    return ret;
}

From source file:nz.co.senanque.vaadinsupport.viewmanager.TouchLoginForm.java

License:Apache License

public void afterPropertiesSet() throws Exception {
    MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(m_messageSource);
    usernameCaption = messageSourceAccessor.getMessage("username");
    passwordCaption = messageSourceAccessor.getMessage("password");
    submitCaption = messageSourceAccessor.getMessage("login.button");
    welcomeCaption = messageSourceAccessor.getMessage("welcome");
    final TextField userName = new TextField(usernameCaption);
    userName.setImmediate(true);//from  w  w  w  .  j  a  v  a 2s  .com
    addField("userName", userName);
    final PasswordField password = new PasswordField(passwordCaption);
    password.setImmediate(true);
    addField("password", password);
    Button submit = new Button(submitCaption);
    addField("submit", submit);
    submit.addListener(new ClickListener() {

        private static final long serialVersionUID = 5201900702970450254L;

        public void buttonClick(ClickEvent event) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("user", String.valueOf(userName.getValue()));
            map.put("password", String.valueOf(password.getValue()));
            if (getLoginListener() != null) {
                try {
                    getLoginListener().onLogin(map);
                } catch (Exception e) {
                    Throwable cause = e.getCause();
                    if (cause == null || !(cause instanceof LoginException)) {
                        logger.error(e.getMessage(), e);
                    }
                    MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(m_messageSource);
                    String message = messageSourceAccessor.getMessage("Bad.Login", "Bad Login");
                    TouchKitApplication.get().getMainWindow().showNotification(message,
                            Notification.TYPE_ERROR_MESSAGE);
                    return;
                }
            }
            TouchKitApplication.get().setUser(userName.getValue());
        }
    });
}

From source file:org.abstractform.binding.vaadin.internal.VaadinBindingFormInstanceImpl.java

License:Apache License

@Override
public void refreshValidationSummary() {
    validationSummaryComponent.removeAllComponents();
    for (ValidationError error : validationErrosSummaryList) {
        if (error != null) {
            Component errorComponent = null;
            if (error.getFieldId() != null) {
                errorComponent = getComponentById(error.getFieldId());
            }/*from   w ww.  j a va 2 s.  c  o  m*/
            if (errorComponent != null) {
                HorizontalLayout layout = new HorizontalLayout();
                if (errorComponent instanceof AbstractField) {
                    final AbstractField component = (AbstractField) errorComponent;
                    Button but = new Button(errorComponent.getCaption());
                    but.setStyleName(BaseTheme.BUTTON_LINK);

                    but.addListener(new Button.ClickListener() {

                        private static final long serialVersionUID = -635674369175495232L;

                        @Override
                        public void buttonClick(ClickEvent event) {
                            component.focus();
                            if (component instanceof AbstractField) {
                                AbstractTextField field = (AbstractTextField) component;
                                field.selectAll();
                            }
                        }
                    });
                    layout.addComponent(but);
                } else {
                    layout.addComponent(new Label(errorComponent.getCaption()));
                }
                layout.addComponent(new Label(" : " + error.getMessage()));
                validationSummaryComponent.addComponent(layout);

            } else {
                validationSummaryComponent.addComponent(new Label(error.getMessage()));
            }
        }
    }

}

From source file:org.abstractform.vaadin.VaadinFormToolkit.java

License:Apache License

private AbstractComponentContainer buildDrawer(final Drawer drawer,
        Map<String, AbstractComponent> mapComponents, List<String> fieldIdList,
        Map<String, Object> extraObjects) {
    VerticalLayout layout = new VerticalLayout();
    final Button button = new Button();
    // button.setStyleName(BaseTheme.BUTTON_LINK);
    button.setCaption("\u25B6" + drawer.getName());
    final VerticalLayout innerLayout = new VerticalLayout();
    for (Component component : drawer.getChildList()) {
        ComponentContainer container = buildComponent(component, mapComponents, fieldIdList, extraObjects);
        innerLayout.addComponent(container);
    }/*from   w  w w  . j  a  v a  2 s.  c  o m*/
    button.addListener(new Button.ClickListener() {

        private static final long serialVersionUID = 4970466538378502562L;

        @Override
        public void buttonClick(ClickEvent event) {
            innerLayout.setVisible(!innerLayout.isVisible());
            if (innerLayout.isVisible()) {
                button.setCaption("\u25BC" + drawer.getName());
            } else {
                button.setCaption("\u25B6" + drawer.getName());

            }
        }
    });
    layout.addComponent(button);
    layout.addComponent(innerLayout);
    innerLayout.setVisible(false);
    return layout;
}

From source file:org.activiti.editor.ui.ConvertProcessDefinitionPopupWindow.java

License:Apache License

protected void addButtons() {
    // Cancel//from   w ww  .  j  a  va  2  s.c  o  m
    Button cancelButton = new Button(i18nManager.getMessage(Messages.BUTTON_CANCEL));
    cancelButton.addStyleName(Reindeer.BUTTON_SMALL);
    cancelButton.addListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            close();
        }
    });

    // Convert
    Button convertButton = new Button(i18nManager.getMessage(Messages.PROCESS_CONVERT_POPUP_CONVERT_BUTTON));
    convertButton.addStyleName(Reindeer.BUTTON_SMALL);
    convertButton.addListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            try {
                InputStream bpmnStream = repositoryService.getResourceAsStream(
                        processDefinition.getDeploymentId(), processDefinition.getResourceName());
                XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
                InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8");
                XMLStreamReader xtr = xif.createXMLStreamReader(in);
                BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);

                if (bpmnModel.getMainProcess() == null || bpmnModel.getMainProcess().getId() == null) {
                    notificationManager.showErrorNotification(Messages.MODEL_IMPORT_FAILED,
                            i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_BPMN_EXPLANATION));
                } else {

                    if (bpmnModel.getLocationMap().isEmpty()) {
                        notificationManager.showErrorNotification(Messages.MODEL_IMPORT_INVALID_BPMNDI,
                                i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_BPMNDI_EXPLANATION));
                    } else {

                        BpmnJsonConverter converter = new BpmnJsonConverter();
                        ObjectNode modelNode = converter.convertToJson(bpmnModel);
                        Model modelData = repositoryService.newModel();

                        ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
                        modelObjectNode.put(MODEL_NAME, processDefinition.getName());
                        modelObjectNode.put(MODEL_REVISION, 1);
                        modelObjectNode.put(MODEL_DESCRIPTION, processDefinition.getDescription());
                        modelData.setMetaInfo(modelObjectNode.toString());
                        modelData.setName(processDefinition.getName());

                        repositoryService.saveModel(modelData);

                        repositoryService.addModelEditorSource(modelData.getId(),
                                modelNode.toString().getBytes("utf-8"));

                        close();
                        ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(modelData.getId());

                        URL explorerURL = ExplorerApp.get().getURL();
                        URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(),
                                explorerURL.getPort(), explorerURL.getPath().replace("/ui", "")
                                        + "modeler.html?modelId=" + modelData.getId());
                        ExplorerApp.get().getMainWindow().open(new ExternalResource(url));
                    }
                }

            } catch (Exception e) {
                notificationManager.showErrorNotification("error", e);
            }
        }
    });

    // Alignment
    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.addComponent(cancelButton);
    buttonLayout.addComponent(convertButton);
    addComponent(buttonLayout);
    windowLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_RIGHT);
}