Example usage for com.vaadin.ui Button Button

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

Introduction

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

Prototype

public Button(Resource icon, ClickListener listener) 

Source Link

Document

Creates a new push button with a click listener.

Usage

From source file:at.jku.ce.adaptivetesting.vaadin.ui.topic.accounting.AccountingQuestionManager.java

License:LGPL

public void displayCompanyInfo(Component[] components) {
    // Create second page
    VerticalLayout layout = new VerticalLayout();

    addComponent(layout);/*w w w .ja  v  a 2s. c o m*/
    Label label = new Label(
            "Stelle dir vor, du hast dich mit dem Handel von Tablet-PCs aller Art selbstndig gemacht und dazu das Einzelunternehmen World of Tabs e. U. vor zwei Jahren gegrndet. Da du dich in Rechnungswesen schon gut auskennst, beschliet du selbst die Buchhaltung zu fhren.<p/>",
            ContentMode.HTML);
    Label companyData = new Label(
            "<table><tr><td>Firmenname:</td><td>World of Tabs</td></tr><tr><td>Adresse:</td><td>Unterfeld 15</td></tr><tr><td></td><td>4541 Adlwang</td></tr><tr><td>E-mail:</td><td>office@worldtabs.at</td></tr><tr><td>Internet:</td><td>www.worldtabs.at</td></tr><tr><td>UID-Nummer:</td><td>ATU32589716</td></tr></table><p/>",
            ContentMode.HTML);
    Label descr = new Label(
            "<i>World of Tabs dient im Folgenden als Modellunternehmen, <b>aus dessen Sicht</b> du die Aufgabenstellungen bearbeiten sollst. Wir bitten dich die Aufgaben <b>alleine, ohne Hilfe</b> von Mitschler/inne/n oder Lehrer/inne/n zu lsen. Du kannst den Kontenplan und einen Taschenrechner verwenden.</i><p/>",
            ContentMode.HTML);
    Label disclaimer = new Label(
            "<b>Wichtig ist, dass du im Folgenden bei der Angabe der Kontennummer und des Kontennamens die genaue Nummer bzw. Bezeichnung verwendest. Bspw. wird eine Aufgabe falsch gewertet, wenn du die Nummer 30 anstatt 33 fr das Lieferverbindlichkeiten whlst oder du den Kontennamen \"Lieferverbindlichkeiten\" anstatt \"AATech\" (bei personifiziertem Lieferantenkonto) fr den Lieferanten whlst.<b>",
            ContentMode.HTML);
    Button cont = new Button("Weiter", e -> {
        removeAllComponents();
        for (Component c : components) {
            addComponent(c);
        }
        super.startQuiz(student);
    });
    //      layout.addComponent(components[0]);// Title of the quiz
    layout.addComponent(HtmlLabel.getCenteredLabel("h1", "Unternehmensbeschreibung"));// Title of the quiz
    layout.addComponent(companyData);
    layout.addComponent(label);
    layout.addComponent(descr);
    layout.addComponent(disclaimer);
    layout.addComponent(cont);
    layout.setComponentAlignment(components[0], Alignment.MIDDLE_CENTER);

}

From source file:at.jku.ce.adaptivetesting.vaadin.ui.VaadinResultView.java

License:LGPL

public VaadinResultView(ResultFiredArgs args, String title) {
    setSpacing(true);/*from   ww  w  .  j a v a  2s .c  o m*/
    addComponent(new HtmlLabel(title));
    //addComponent(HtmlLabel.getCenteredLabel("h2", "Test abgeschlossen"));
    addComponent(HtmlLabel.getCenteredLabel(
            "Der Test wurde beendet, da " + (args.outOfQuestions ? "keine weiteren Fragen verfgbar sind."
                    : "dein Kompetenzniveau bestimmt wurde.")));
    addComponent(HtmlLabel.getCenteredLabel(
            "Im Folgenden siehst du die Fragen und die gegebenen Antworten in zeitlich absteigender Reihenfolge."));
    addComponent(HtmlLabel.getCenteredLabel(
            "Die Zahl in der ersten Spalte bezieht sich auf die Schwierigkeit der jeweiligen Frage. Negative Zahlen stehen fr leichtere Fragen, positive Zahlen kennzeichnen schwierigere Fragen."));

    // Create HTML table of the history
    Table table = new Table();
    final String solution = "Korrekte Antwort", userAnswer = "Ihre Antwort";
    table.addContainerProperty("Schwierigkeitsgrad", Float.class, null);
    table.addContainerProperty("Resultat", String.class, null);
    table.addContainerProperty(userAnswer, Button.class, null);
    table.addContainerProperty(solution, Button.class, null);
    //List<HistoryEntry> entries = Lists.reverse(args.history);
    List<HistoryEntry> entries = new ArrayList<HistoryEntry>(args.history);
    Collections.reverse(entries);

    for (HistoryEntry entry : entries) {
        Button qAnswer = null, qSolution = null;
        if (entry.question instanceof Component && entry.question != null) {
            try {
                Class<? extends AnswerStorage> dataStorageClass = entry.question.getSolution().getClass();
                Constructor<? extends IQuestion> constructor = entry.question.getClass()
                        .getConstructor(dataStorageClass, dataStorageClass, float.class, String.class);
                // The following casts can not fail, because the question is
                // a component as well
                Component iQuestionSolution = (Component) constructor.newInstance(entry.question.getSolution(),
                        entry.question.getSolution(), entry.question.getDifficulty(),
                        entry.question.getQuestionText());
                Component iQuestionUser = (Component) constructor.newInstance(entry.question.getSolution(),
                        entry.question.getUserAnswer(), entry.question.getDifficulty(),
                        entry.question.getQuestionText());
                // Create the 2 needed click listeners
                ClickListener clickListenerSol = event -> {
                    Window window = new Window(solution);
                    event.getButton().setEnabled(false);
                    window.addCloseListener(e -> event.getButton().setEnabled(true));
                    window.setContent(iQuestionSolution);
                    window.center();
                    window.setWidth("90%");
                    window.setHeight("50%");
                    if (iQuestionSolution instanceof Sizeable) {
                        Sizeable sizeable = iQuestionSolution;
                        sizeable.setSizeFull();
                    }
                    getUI().addWindow(window);
                };

                ClickListener clickListenerUA = event -> {
                    Window window = new Window(userAnswer);
                    event.getButton().setEnabled(false);
                    window.addCloseListener(e -> event.getButton().setEnabled(true));
                    window.setContent(iQuestionUser);
                    window.center();
                    window.setWidth("90%");
                    window.setHeight("50%");
                    if (iQuestionUser instanceof Sizeable) {
                        Sizeable sizeable = iQuestionUser;
                        sizeable.setSizeFull();
                    }
                    getUI().addWindow(window);
                };

                // Create the two buttons
                qAnswer = new Button(userAnswer, clickListenerUA);
                qSolution = new Button(solution, clickListenerSol);

            } catch (Exception e) {
                // Ignore this line in the table
                LogHelper.logInfo("1 entry's solution/ user answer are missing on the final screen."
                        + entry.question.getClass().getName()
                        + " does not implement the constructors required by" + IQuestion.class.getName());
            }
        }

        table.addItem(new Object[] { entry.question.getDifficulty(),
                isCorrect(entry.points, entry.question.getMaxPoints()), qAnswer, qSolution }, null);
    }
    int size = table.size();
    if (size > 10) {
        size = 10;
    }
    table.setPageLength(size);
    addComponent(table);
    setComponentAlignment(table, Alignment.MIDDLE_CENTER);

    addComponent(HtmlLabel.getCenteredLabel("h3", "Dein Kompetenzniveau ist: <b>" + args.skillLevel + "</b>"));
    addComponent(HtmlLabel.getCenteredLabel("Delta:  " + args.delta));
    storeResults(args);
}

From source file:at.peppol.webgui.app.components.InvoiceLineWindow.java

License:Mozilla Public License

public InvoiceLineWindow(final TabInvoiceLine parent) {
    this.parent = parent;
    invln = new InvoiceLineAdapter();

    //    line = new Line();    
    //    BeanItem<InvoiceLineAdapter> invoiceLine = new BeanItem<InvoiceLineAdapter>(invln);
    //    parent.setItemDataSource(invoiceLine);
    //    BeanItem<Line> invoiceLine = new BeanItem<Line>(line);
    //    parent.setItemDataSource(invoiceLine);

    subwindow = new Window("Invoice Line");
    subwindow.setModal(true);//w  w  w  . ja  va2s . c  o m

    VerticalLayout layout = (VerticalLayout) subwindow.getContent();
    layout.setMargin(true);
    layout.setSpacing(true);

    Button btnClose = new Button("Close", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            (subwindow.getParent()).removeWindow(subwindow);
        }
    });

    Button btnSave = new Button("Save", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            //update GUI table !!
            ///parent.getTable().addInvoiceLine (invln);
            //update actual invoice line item
            ///parent.items.add (invln);

            //close popup
            (subwindow.getParent()).removeWindow(subwindow);
        }
    });

    try {
        layout.addComponent(createInvoiceLineForm());
    } catch (Exception e) {
        e.printStackTrace();
    }
    layout.addComponent(btnSave);
    layout.addComponent(btnClose);
    layout.setComponentAlignment(btnClose, Alignment.BOTTOM_RIGHT);
}

From source file:at.peppol.webgui.app.components.InvoiceTabForm.java

License:Mozilla Public License

private void initElements() {
    supplierForm = new PartyDetailForm("Supplier", supplier.getParty());
    supplierForm.setImmediate(true);//from ww  w .  j  av  a2s .  c  o  m
    customerForm = new PartyDetailForm("Customer", customer.getParty());
    customerForm.setImmediate(true);
    //supplierForm.setSizeFull ();
    //customerForm.setSizeFull ();

    final HorizontalLayout footerLayout = new HorizontalLayout();
    footerLayout.setSpacing(true);
    footerLayout.setMargin(true);
    footerLayout.addComponent(new Button("Save Invoice", new Button.ClickListener() {

        @Override
        public void buttonClick(final Button.ClickEvent event) {
            SetCommonCurrency();
            ValidatorHandler vh = new ValidatorHandler(footerLayout);
            AbstractUBLDocumentMarshaller.setGlobalValidationEventHandler(vh);
            vh.clearErrors();
            clearTabErrorStyles();
            boolean invoiceHasErrors = false;

            List<ValidationError> errors = GlobalValidationsRegistry.runAll();
            if (errors.size() > 0) {
                invoiceHasErrors = true;
                Window errorWindow = new Window("Errors");
                //position and size of the window
                errorWindow.setPositionX(200);
                errorWindow.setPositionY(200);
                errorWindow.setWidth("600px");
                errorWindow.setHeight("300px");

                //add the error messages
                String errorMessage = "<ol>";
                for (int i = 0; i < errors.size(); i++) {
                    errorMessage += "<li style=\"margin-top: 4px;\"><b>" + errors.get(i).getRuleID() + "</b>: "
                            + errors.get(i).getErrorInfo() + "</li>";
                    //mark the appropriate Tab as error
                    Tab tab = invTabSheet.getTab(errors.get(i).getMainComponent());
                    if (tab != null)
                        tab.setStyleName("test111");
                }
                errorMessage += "</ol>";
                errorWindow.addComponent(new Label(errorMessage, Label.CONTENT_XHTML));

                //show the error window
                getParent().getWindow().addWindow(errorWindow);
                errors.clear();
            }

            ValidatorsList.validateListenersNotify();
            if (ValidatorsList.validateListeners() == false) {
                invoiceHasErrors = true;
            }

            if (invoiceHasErrors) {
                getWindow().showNotification("Validation error. Could not save invoice",
                        Notification.TYPE_TRAY_NOTIFICATION);
            } else {
                try {
                    if (invoiceFilePath.equals("")) {
                        UBL20DocumentMarshaller.writeInvoice(invoice,
                                new StreamResult(new File(um.getDrafts().getFolder().toString()
                                        + System.getProperty("file.separator") + "invoice"
                                        + System.currentTimeMillis() + ".xml")));
                        invoiceFilePath = um.getDrafts().getFolder().toString()
                                + System.getProperty("file.separator") + "invoice" + System.currentTimeMillis()
                                + ".xml";
                    } else {
                        UBL20DocumentMarshaller.writeInvoice(invoice,
                                new StreamResult(new File(invoiceFilePath)));
                    }
                    getWindow()
                            .showNotification(
                                    "Validation passed. Invoice saved in "
                                            + um.getDrafts().getName().toUpperCase() + " folder",
                                    Notification.TYPE_TRAY_NOTIFICATION);
                } catch (Exception e) {
                    getWindow().showNotification("Disk access error. Could not save invoice",
                            Notification.TYPE_ERROR_MESSAGE);
                }
            }

            /*PEPPOL validation
             * final ValidationPyramid vp = new ValidationPyramid (EValidationDocumentType.INVOICE,
                    ValidationTransaction.createUBLTransaction (ETransaction.T10));
             final List <ValidationPyramidResultLayer> aResults = vp.applyValidation (new FileSystemResource ("invoice.xml"))
                   .getAllValidationResultLayers ();
             if (aResults.isEmpty ())
               System.out.println ("  The document is valid!");
             else
               for (final ValidationPyramidResultLayer aResultLayer : aResults)
                 for (final IResourceError aError : aResultLayer.getValidationErrors ())
                   System.out.println ("  " + aResultLayer.getValidationLevel () + " " + aError.getAsString (Locale.US));
            */
            /*ValidatorsList.validateListenersNotify();
            if (ValidatorsList.validateListeners() == false) {
               getParent().getWindow().showNotification("Validation error... ",Notification.TYPE_TRAY_NOTIFICATION);
            }
            else
               getParent().getWindow().showNotification("Validation passed! ",Notification.TYPE_TRAY_NOTIFICATION);
            */

        }
    }));

    /*    footerLayout.addComponent (new Button ("Save Invoice", new Button.ClickListener () {
            
          @Override
          public void buttonClick (final Button.ClickEvent event) {
            try {
              SetCommonCurrency ();          
              System.out.println (invoice.getDelivery ().get (0).getDeliveryAddress ().getStreetName ().getValue ());
            }
            catch (final Exception ex) {
              LOGGER.error ("Error creating files. ", ex);
            }
          }
        }));
    */
    footerLayout.addComponent(new Button("Read Invoice from disk", new Button.ClickListener() {

        @Override
        public void buttonClick(final Button.ClickEvent event) {
            try {
                SetCommonCurrency();
                InvoiceType inv = UBL20DocumentMarshaller
                        .readInvoice(new StreamSource(new FileInputStream(new File("invoice.xml"))));
            } catch (final Exception ex) {
                LOGGER.error("Error creating files. ", ex);
            }
        }
    }));

    getFooter().addComponent(footerLayout);

}

From source file:at.reisisoft.jku.ce.adaptivelearning.vaadin.ui.core.VaadinUI.java

License:LGPL

public VaadinUI() {
    // Set up the Navigator
    navigator = new Navigator(this, this);

    // Create Welcome Screen
    MainUI mainScreen = new MainUI();
    mainScreen.setMargin(true);/*  w  w  w .  j  a v  a  2 s . c  o  m*/
    Button start = new Button("Start", e -> {
        navigator.navigateTo(Views.TEST.toString());
    });
    start.setWidth("40%");
    start.setHeight("40%");
    mainScreen.addComponent(new HtmlLabel(HtmlUtils.center("h1", "Welcome to " + productData)));
    mainScreen.addComponent(new HtmlLabel(
            HtmlUtils.center("h2", "Click the <b>" + start.getCaption() + "</b> Button to start!")));
    mainScreen.addComponent(start);
    mainScreen.setComponentAlignment(start, Alignment.MIDDLE_CENTER);

    navigator.addView(Views.DEFAULT.toString(), mainScreen);
    // Question view
    // Change this to the questionManager you like
    final QuestionManager manager = new AccountingQuestionManager("Accounting Quiz");
    navigator.addView(Views.TEST.toString(), manager);
    navigator.addView(Views.Log.toString(), new LogView(new File(Servlet.getLogFileName())));
    navigator.setErrorView(mainScreen);
    LogHelper.logInfo("Startup completed");
}

From source file:at.reisisoft.jku.ce.adaptivelearning.vaadin.ui.topic.accounting.AccountingQuestionManager.java

License:LGPL

@Override
public void startQuiz() {
    // Remove everything from the layout, save it for displaying after
    // clicking OK
    final Component[] components = new Component[getComponentCount()];
    for (int i = 0; i < components.length; i++) {
        components[i] = getComponent(i);
    }//from www.  j  a  v a2  s.c o  m
    removeAllComponents();
    // Create first page
    VerticalLayout layout = new VerticalLayout();

    addComponent(layout);
    Label label = new Label("Answer all the questions like you were working for \"Unternehmen XY\"",
            ContentMode.HTML);
    Button cont = new Button("Continue", e -> {
        removeAllComponents();
        for (Component c : components) {
            addComponent(c);
        }
        super.startQuiz();
    });
    layout.addComponent(components[0]);// Title of the quiz
    layout.addComponent(label);
    layout.addComponent(cont);
    layout.setComponentAlignment(components[0], Alignment.MIDDLE_CENTER);

}

From source file:at.reisisoft.jku.ce.adaptivelearning.vaadin.ui.VaadinResultView.java

License:LGPL

public VaadinResultView(ResultFiredArgs args, String title) {
    setSpacing(true);/* www  . j  a va 2s  .com*/
    addComponent(new HtmlLabel(title));
    addComponent(HtmlLabel.getCenteredLabel("h2", "Finished test"));
    addComponent(HtmlLabel.getCenteredLabel("The test ended, because we "
            + (args.outOfQuestions ? "did not have any more questions" : "determined your skill level")));
    addComponent(HtmlLabel.getCenteredLabel(
            "This are the difficulties and your answers. On top are your last answers. The first column indicates the difficulty."));
    addComponent(HtmlLabel.getCenteredLabel(
            "Closer to -INF means easy question, to +INF dificult questions. This also applies to your skill level!"));

    // Create HTML table of the history
    Table table = new Table();
    final String solution = "Solution", userAnswewr = "Yourt answer";
    table.addContainerProperty("Question difficulty", Float.class, null);
    table.addContainerProperty("Result", String.class, null);
    table.addContainerProperty(userAnswewr, Button.class, null);
    table.addContainerProperty(solution, Button.class, null);
    List<HistoryEntry> entries = Lists.reverse(args.history);

    for (HistoryEntry entry : entries) {
        Button qAnswer = null, qSolution = null;
        if (entry.question instanceof Component && entry.question != null) {
            try {
                Class<? extends AnswerStorage> dataStorageClass = entry.question.getSolution().getClass();
                Constructor<? extends IQuestion> constructor = entry.question.getClass()
                        .getConstructor(dataStorageClass, dataStorageClass, float.class, String.class);
                // The following casts can not fail, because the question is
                // a component as well
                Component iQuestionSolution = (Component) constructor.newInstance(entry.question.getSolution(),
                        entry.question.getSolution(), entry.question.getDifficulty(),
                        entry.question.getQuestionText());
                Component iQuestionUser = (Component) constructor.newInstance(entry.question.getSolution(),
                        entry.question.getUserAnswer(), entry.question.getDifficulty(),
                        entry.question.getQuestionText());
                // Create the 2 needed click listeners
                ClickListener clickListenerSol = event -> {
                    Window window = new Window(solution);
                    event.getButton().setEnabled(false);
                    window.addCloseListener(e -> event.getButton().setEnabled(true));
                    window.setContent(iQuestionSolution);
                    window.center();
                    window.setWidth("90%");
                    window.setHeight("50%");
                    if (iQuestionSolution instanceof Sizeable) {
                        Sizeable sizeable = iQuestionSolution;
                        sizeable.setSizeFull();
                    }
                    getUI().addWindow(window);
                };

                ClickListener clickListenerUA = event -> {
                    Window window = new Window(userAnswewr);
                    event.getButton().setEnabled(false);
                    window.addCloseListener(e -> event.getButton().setEnabled(true));
                    window.setContent(iQuestionUser);
                    window.center();
                    window.setWidth("90%");
                    window.setHeight("50%");
                    if (iQuestionUser instanceof Sizeable) {
                        Sizeable sizeable = iQuestionUser;
                        sizeable.setSizeFull();
                    }
                    getUI().addWindow(window);
                };

                // Create the two buttons
                qAnswer = new Button(userAnswewr, clickListenerUA);
                qSolution = new Button(solution, clickListenerSol);

            } catch (Exception e) {
                // Ignore this line in the table
                LogHelper.logInfo("1 entry's solution/ user answer are missing on the final screen."
                        + entry.question.getClass().getName()
                        + " does not implement the constructors required by" + IQuestion.class.getName());
            }
        }

        table.addItem(new Object[] { entry.question.getDifficulty(),
                isCorrect(entry.points, entry.question.getMaxPoints()), qAnswer, qSolution }, null);
    }
    int size = table.size();
    if (size > 10) {
        size = 10;
    }
    table.setPageLength(size);
    addComponent(table);
    setComponentAlignment(table, Alignment.MIDDLE_CENTER);

    addComponent(HtmlLabel.getCenteredLabel("h3", "Your skill level is: <b>" + args.skillLevel + "</b>"));
    addComponent(HtmlLabel.getCenteredLabel("Delta (Valus close to 0 are best):  " + args.delta));
}

From source file:br.com.anteros.mobileserver.app.form.ActionForm.java

License:Apache License

private void createButtons() {
    buttons = new HorizontalLayout();
    buttons.setSpacing(true);//from  w w w.ja  v a  2  s .  c  o  m
    buttons.setWidth("715px");

    btnOk = new Button("Ok", this);
    btnOk.addStyleName("default");
    btnOk.setIcon(new ThemeResource("icons/16/ok.png"));
    buttons.addComponent(btnOk);
    buttons.setComponentAlignment(btnOk, Alignment.MIDDLE_RIGHT);
    buttons.setExpandRatio(btnOk, 1);

    btnCancel = new Button("Cancela", this);
    btnCancel.setIcon(new ThemeResource("icons/16/cancel.png"));
    buttons.addComponent(btnCancel);
    buttons.setComponentAlignment(btnCancel, Alignment.MIDDLE_RIGHT);

    actionForm.getFooter().addComponent(buttons);
}

From source file:br.com.anteros.mobileserver.app.form.ApplicationForm.java

License:Apache License

private void createButtons() {
    buttons = new HorizontalLayout();
    buttons.setSpacing(true);/*from  w  w  w .  j a v a2 s  .  c o  m*/
    buttons.setWidth("640px");

    btnOk = new Button("Ok", this);
    btnOk.addStyleName("default");
    btnOk.setIcon(new ThemeResource("icons/16/ok.png"));
    buttons.addComponent(btnOk);
    buttons.setComponentAlignment(btnOk, Alignment.MIDDLE_RIGHT);
    buttons.setExpandRatio(btnOk, 1);

    btnCancel = new Button("Cancela", this);
    btnCancel.setIcon(new ThemeResource("icons/16/cancel.png"));
    buttons.addComponent(btnCancel);
    buttons.setComponentAlignment(btnCancel, Alignment.MIDDLE_RIGHT);

    applicationForm.getFooter().addComponent(buttons);
}

From source file:br.com.anteros.mobileserver.app.form.FieldForm.java

License:Apache License

private void createButtons() {
    buttons = new HorizontalLayout();
    buttons.setSpacing(true);/*from  ww  w .j a v a  2 s .  com*/
    buttons.setWidth("640px");

    btnOk = new Button("Ok", this);
    btnOk.addStyleName("default");
    btnOk.setIcon(new ThemeResource("icons/16/ok.png"));
    buttons.addComponent(btnOk);
    buttons.setComponentAlignment(btnOk, Alignment.MIDDLE_RIGHT);
    buttons.setExpandRatio(btnOk, 1);

    btnCancel = new Button("Cancela", this);
    btnCancel.setIcon(new ThemeResource("icons/16/cancel.png"));
    buttons.addComponent(btnCancel);
    buttons.setComponentAlignment(btnCancel, Alignment.MIDDLE_RIGHT);
    fieldForm.getFooter().addComponent(buttons);
}