Example usage for com.vaadin.ui Window setContent

List of usage examples for com.vaadin.ui Window setContent

Introduction

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

Prototype

@Override
public void setContent(Component content) 

Source Link

Document

Sets the content of this container.

Usage

From source file:ac.uk.icl.dell.vaadin.glycanbuilder.VaadinGlycanCanvas.java

License:Open Source License

public void appendImportMenu(CustomMenuBar.MenuItem parent, CustomMenuBar.MenuItem beforeItem) {
    final Window importWindow = new Window() {
        private static final long serialVersionUID = -397373017493034496L;

        @Override/*from   ww w . j a  v  a2 s .  c  om*/
        public void close() {
            setVisible(false);
        }
    };
    importWindow.setCaption("Import from sequence");
    importWindow.setResizable(false);

    final CanvasImport canvasImport = new CanvasImport();
    importWindow.getContent().addComponent(canvasImport);
    importWindow.center();
    importWindow.setVisible(false);

    @SuppressWarnings("unused")
    CustomMenuBar.MenuItem importMenu = parent.addItemBefore("Import", null, new CustomMenuBar.Command() {
        private static final long serialVersionUID = -6735134306275926140L;

        @Override
        public void menuSelected(CustomMenuBar.MenuItem selectedItem) {
            if (!importWindow.isVisible()) {
                if (getWindow().getChildWindows().contains(importWindow) == false) {
                    getWindow().addWindow(importWindow);
                }

                importWindow.setVisible(true);
            }
        }
    }, beforeItem);

    importWindow.setSizeUndefined();
    importWindow.getContent().setSizeUndefined();

    final Window importFromStringWindow = new Window() {
        private static final long serialVersionUID = 7035248961169308096L;

        @Override
        public void close() {
            setVisible(false);
        }
    };

    importFromStringWindow.setCaption("Import sequence from string");
    importFromStringWindow.setWidth("400px");

    final ImportStructureFromStringDialog importStructureStringDialog = new ImportStructureFromStringDialog(
            theCanvas);

    importStructureStringDialog.addListener(new UserInputEndedListener() {
        @Override
        public void done(boolean cancelled) {
            if (!cancelled) {
                if (!theCanvas.theDoc.importFromString(importStructureStringDialog.getSequenceString(),
                        theCanvas
                                .getImportFormatShortFormat(importStructureStringDialog.getSequenceFormat()))) {
                    IGGApplication.reportMessage(LogUtils.getLastError());

                    LogUtils.clearLastError();
                }
            }
        }
    });

    WeeLayout layout = new WeeLayout(Direction.VERTICAL);
    layout.setSizeFull();
    importFromStringWindow.setContent(layout);
    layout.addComponent(importStructureStringDialog, Alignment.MIDDLE_CENTER);

    importFromStringWindow.center();
    importFromStringWindow.setVisible(false);

    @SuppressWarnings("unused")
    CustomMenuBar.MenuItem importFromStringMenu = parent.addItemBefore("Import from string", null,
            new CustomMenuBar.Command() {
                private static final long serialVersionUID = 1586089744665899803L;

                @Override
                public void menuSelected(CustomMenuBar.MenuItem selectedItem) {
                    if (!importFromStringWindow.isVisible()) {
                        if (getWindow().getChildWindows().contains(importFromStringWindow) == false) {
                            getWindow().addWindow(importFromStringWindow);
                        }

                        importFromStringWindow.setVisible(true);
                    }
                }
            }, beforeItem);
}

From source file:annis.gui.admin.GroupManagementPanel.java

License:Apache License

public GroupManagementPanel() {
    groupsContainer.setBeanIdProperty("name");

    progress = new ProgressBar();
    progress.setCaption("Loading group list");
    progress.setIndeterminate(true);//  www .j  a  v  a2s. c  om
    progress.setVisible(false);

    GeneratedPropertyContainer generated = new GeneratedPropertyContainer(groupsContainer);
    generated.addGeneratedProperty("edit", new PropertyValueGenerator<String>() {

        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            return "Edit";
        }

        @Override
        public Class<String> getType() {
            return String.class;
        }
    });
    groupsGrid.setContainerDataSource(generated);
    groupsGrid.setSelectionMode(Grid.SelectionMode.MULTI);
    groupsGrid.setSizeFull();
    groupsGrid.setColumns("name", "edit", "corpora");

    Grid.HeaderRow filterRow = groupsGrid.appendHeaderRow();
    TextField groupFilterField = new TextField();
    groupFilterField.setInputPrompt("Filter");
    groupFilterField.addTextChangeListener(new FieldEvents.TextChangeListener() {

        @Override
        public void textChange(FieldEvents.TextChangeEvent event) {
            groupsContainer.removeContainerFilters("name");
            if (!event.getText().isEmpty()) {
                groupsContainer
                        .addContainerFilter(new SimpleStringFilter("name", event.getText(), true, false));
            }
        }
    });
    filterRow.getCell("name").setComponent(groupFilterField);

    TextField corpusFilterField = new TextField();
    corpusFilterField.setInputPrompt("Filter by corpus");
    corpusFilterField.addTextChangeListener(new FieldEvents.TextChangeListener() {

        @Override
        public void textChange(FieldEvents.TextChangeEvent event) {
            groupsContainer.removeContainerFilters("corpora");
            if (!event.getText().isEmpty()) {
                groupsContainer.addContainerFilter(new StringPatternInSetFilter("corpora", event.getText()));
            }
        }
    });
    filterRow.getCell("corpora").setComponent(corpusFilterField);

    Grid.Column editColumn = groupsGrid.getColumn("edit");
    editColumn.setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() {

        @Override
        public void click(ClickableRenderer.RendererClickEvent event) {
            Group g = groupsContainer.getItem(event.getItemId()).getBean();

            FieldGroup fields = new FieldGroup(groupsContainer.getItem(event.getItemId()));
            fields.addCommitHandler(new GroupCommitHandler(g.getName()));

            EditSingleGroup edit = new EditSingleGroup(fields, corpusContainer);

            Window w = new Window("Edit group \"" + g.getName() + "\"");
            w.setContent(edit);
            w.setModal(true);
            w.setWidth("500px");
            w.setHeight("250px");
            UI.getCurrent().addWindow(w);
        }
    }));

    Grid.Column corporaColumn = groupsGrid.getColumn("corpora");
    ;
    corporaColumn.setConverter(new CommaSeperatedStringConverterSet());

    txtGroupName = new TextField();
    txtGroupName.setInputPrompt("New group name");

    Button btAddNewGroup = new Button("Add new group");
    btAddNewGroup.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            handleAdd();
        }
    });
    btAddNewGroup.addStyleName(ChameleonTheme.BUTTON_DEFAULT);

    Button btDeleteGroup = new Button("Delete selected group(s)");
    btDeleteGroup.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            // get selected groups
            Set<String> selectedGroups = new TreeSet<>();
            for (Object id : groupsGrid.getSelectedRows()) {
                selectedGroups.add((String) id);
            }
            groupsGrid.getSelectionModel().reset();
            for (GroupListView.Listener l : listeners) {
                l.deleteGroups(selectedGroups);
            }
        }
    });

    actionLayout = new HorizontalLayout(txtGroupName, btAddNewGroup, btDeleteGroup);

    VerticalLayout layout = new VerticalLayout(actionLayout, progress, groupsGrid);
    layout.setSizeFull();
    layout.setExpandRatio(groupsGrid, 1.0f);
    layout.setExpandRatio(progress, 1.0f);
    layout.setSpacing(true);
    layout.setMargin(new MarginInfo(true, false, false, false));

    layout.setComponentAlignment(actionLayout, Alignment.MIDDLE_CENTER);
    layout.setComponentAlignment(progress, Alignment.TOP_CENTER);

    setContent(layout);
    setSizeFull();

    addActionHandler(new AddGroupHandler(txtGroupName));
}

From source file:annis.gui.admin.UserManagementPanel.java

License:Apache License

public UserManagementPanel() {

    userContainer = new BeanContainer<>(User.class);
    userContainer.setBeanIdProperty("name");

    progress = new ProgressBar();
    progress.setCaption("Loading user list");
    progress.setIndeterminate(true);/* w  w w . j a v  a  2s. c  o  m*/
    progress.setVisible(false);

    GeneratedPropertyContainer generated = new GeneratedPropertyContainer(userContainer);
    generated.addGeneratedProperty("edit", new PropertyValueGenerator<String>() {

        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            return "Edit";
        }

        @Override
        public Class<String> getType() {
            return String.class;
        }
    });
    generated.addGeneratedProperty("changePassword", new PropertyValueGenerator<String>() {

        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            return "Change password";
        }

        @Override
        public Class<String> getType() {
            return String.class;
        }
    });

    userList = new Grid(generated);
    userList.setSizeFull();
    userList.setSelectionMode(Grid.SelectionMode.MULTI);
    userList.setColumns("name", "edit", "changePassword", "expires", "groups", "permissions");

    HeaderRow filterRow = userList.appendHeaderRow();
    TextField userFilterField = new TextField();
    userFilterField.setInputPrompt("Filter");
    userFilterField.addTextChangeListener(new FieldEvents.TextChangeListener() {

        @Override
        public void textChange(FieldEvents.TextChangeEvent event) {
            userContainer.removeContainerFilters("name");
            if (!event.getText().isEmpty()) {
                userContainer.addContainerFilter(new SimpleStringFilter("name", event.getText(), true, false));
            }
        }
    });
    filterRow.getCell("name").setComponent(userFilterField);

    CheckBox expiredFilterField = new CheckBox("has expired");
    expiredFilterField.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            userContainer.removeContainerFilters("expires");
            if ((Boolean) event.getProperty().getValue() == true) {
                userContainer.addContainerFilter(new ExpiredUserFilter("expires"));
            }
        }
    });
    filterRow.getCell("expires").setComponent(expiredFilterField);

    TextField groupFilterField = new TextField();
    groupFilterField.setInputPrompt("Filter by groups");
    groupFilterField.addTextChangeListener(new FieldEvents.TextChangeListener() {

        @Override
        public void textChange(FieldEvents.TextChangeEvent event) {
            userContainer.removeContainerFilters("groups");
            if (!event.getText().isEmpty()) {
                userContainer.addContainerFilter(
                        new GroupManagementPanel.StringPatternInSetFilter("groups", event.getText()));
            }
        }
    });
    filterRow.getCell("groups").setComponent(groupFilterField);

    Grid.Column editColum = userList.getColumn("edit");
    editColum.setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() {

        @Override
        public void click(ClickableRenderer.RendererClickEvent event) {

            User u = userContainer.getItem(event.getItemId()).getBean();

            FieldGroup group = new FieldGroup(userContainer.getItem(event.getItemId()));
            group.addCommitHandler(new UserCommitHandler(u.getName()));

            EditSingleUser edit = new EditSingleUser(group, groupsContainer, permissionsContainer);

            Window w = new Window("Edit user \"" + u.getName() + "\"");
            w.setContent(edit);
            w.setModal(true);
            w.setWidth("500px");
            w.setHeight("400px");
            UI.getCurrent().addWindow(w);
        }
    }));
    editColum.setHeaderCaption("");
    editColum.setExpandRatio(0);

    Grid.Column passwordColumn = userList.getColumn("changePassword");
    passwordColumn.setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() {

        @Override
        public void click(ClickableRenderer.RendererClickEvent event) {
            UserManagementPanel.this.askForPasswordChange((String) event.getItemId());
        }
    }));
    passwordColumn.setHeaderCaption("");
    passwordColumn.setExpandRatio(0);

    userList.getColumn("name").setHeaderCaption("Username");

    Grid.Column groupsColumm = userList.getColumn("groups");
    groupsColumm.setHeaderCaption("Groups");
    groupsColumm.setConverter(new CommaSeperatedStringConverterSet());
    groupsColumm.setExpandRatio(1);

    Grid.Column permissionsColumn = userList.getColumn("permissions");
    permissionsColumn.setHeaderCaption("Additional permissions");
    permissionsColumn.setConverter(new CommaSeperatedStringConverterSet());

    Grid.Column expiresColumn = userList.getColumn("expires");
    expiresColumn.setHeaderCaption("Expiration Date");
    expiresColumn.setConverter(new DateTimeStringConverter());

    txtUserName = new TextField();
    txtUserName.setInputPrompt("New user name");

    Button btAddNewUser = new Button("Add new user");
    btAddNewUser.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            handleAdd();
        }
    });
    btAddNewUser.addStyleName(ChameleonTheme.BUTTON_DEFAULT);

    Button btDeleteUser = new Button("Delete selected user(s)");
    btDeleteUser.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            // get selected users
            Set<String> selectedUsers = new TreeSet<>();
            for (Object id : userList.getSelectedRows()) {
                selectedUsers.add((String) id);
            }
            userList.getSelectionModel().reset();
            for (UserListView.Listener l : listeners) {
                l.deleteUsers(selectedUsers);
            }
        }
    });

    actionLayout = new HorizontalLayout(txtUserName, btAddNewUser, btDeleteUser);

    layout = new VerticalLayout(actionLayout, progress, userList);
    layout.setSizeFull();
    layout.setExpandRatio(userList, 1.0f);
    layout.setExpandRatio(progress, 1.0f);
    layout.setSpacing(true);
    layout.setMargin(new MarginInfo(true, false, false, false));

    layout.setComponentAlignment(actionLayout, Alignment.MIDDLE_CENTER);
    layout.setComponentAlignment(progress, Alignment.TOP_CENTER);

    setContent(layout);
    setSizeFull();

    addActionHandler(new AddUserHandler(txtUserName));

}

From source file:annis.gui.docbrowser.DocBrowserTable.java

License:Apache License

public Button generateInfoButtonCell(final String docName) {
    Button btn = new Button();
    btn.setStyleName(ChameleonTheme.BUTTON_BORDERLESS);
    btn.setIcon(INFO_ICON);/* w  ww .  j av a  2 s  .  c o m*/
    btn.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            try {

                List<Annotation> annos = getDocMetaData(docName);

                /**
                 * Transforms to a list of key value pairs. The values concates the
                 * namespace and ordinary value. Namespaces "NULL" are ignored.
                 */
                // create datasource and bind it to a table
                BeanItemContainer<Annotation> metaContainer = new BeanItemContainer<>(Annotation.class);
                metaContainer.addAll(annos);
                metaContainer.sort(new Object[] { "namespace", "name" }, new boolean[] { true, true });

                Table metaTable = new Table();
                metaTable.setContainerDataSource(metaContainer);
                metaTable.addGeneratedColumn("genname",
                        new MetaDataPanel.MetaTableNameGenerator(metaContainer));
                metaTable.addGeneratedColumn("genvalue",
                        new MetaDataPanel.MetaTableValueGenerator(metaContainer));

                metaTable.setVisibleColumns("genname", "genvalue");

                metaTable.setColumnHeaders(new String[] { "Name", "Value" });
                metaTable.setSizeFull();
                metaTable.setColumnWidth("genname", -1);
                metaTable.setColumnExpandRatio("genvalue", 1.0f);
                metaTable.addStyleName(ChameleonTheme.TABLE_STRIPED);

                // create and style the extra window for the metadata table
                Window metaWin = new Window();
                metaWin.setContent(metaTable);
                metaWin.setCaption("metadata doc " + docName);
                metaWin.center();
                metaWin.setWidth(400, Unit.PIXELS);
                metaWin.setHeight(400, Unit.PIXELS);

                // paint the window
                docBrowserPanel.getUI().addWindow(metaWin);
            } catch (UniformInterfaceException ex) {
                log.error("can not retrieve metadata for document " + docName, ex);
            }

        }
    });
    return btn;
}

From source file:annis.gui.resultview.SingleResultPanel.java

License:Apache License

@Override
public void buttonClick(ClickEvent event) {
    if (event.getButton() == btInfo && result != null) {
        Window infoWindow = new Window("Info for " + result.getId());

        infoWindow.setModal(false);/*from   w ww.  ja va  2  s .  co m*/
        MetaDataPanel meta = new MetaDataPanel(path.get(0), path.get(path.size() - 1));
        infoWindow.setContent(meta);
        infoWindow.setWidth("400px");
        infoWindow.setHeight("400px");

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

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

License:LGPL

public MockQuestion(Question question) {
    this.question = question;

    TextArea textArea = new TextArea("Question text");
    textArea.setSizeFull();//from  w  ww. ja  v a2 s  . c o m

    // Download the result
    Button button = new Button("Display current user's solution");

    button.setSizeFull();
    button.addClickListener(e -> {
        Window window = new Window("Current user solution");
        VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        window.setContent(layout);
        // Update questionText
        textArea.addTextChangeListener(ev -> questionText = ev.getText());
        textArea.setTextChangeEventMode(TextChangeEventMode.EAGER);
        Label label;
        try {
            label = new Label(toXML());
        } catch (Exception e1) {
            label = new Label(
                    "<h1>Error parsing XML</h1><p>" + e1.getMessage() + Arrays.toString(e1.getStackTrace()),
                    ContentMode.HTML);
            LogHelper.logThrowable(e1);
        }
        layout.addComponent(label);
        window.center();
        getUI().addWindow(window);
    });
    // Add components to the UI
    addComponent(textArea);
    addComponent(question);
    addComponent(button);
}

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

License:LGPL

public AccountingQuestionManager(String quizName) {
    super(quizName);
    Button openKontenplan = new Button("Kontenplan ffnen");
    openKontenplan.addClickListener(e -> {
        openKontenplan.setEnabled(false);
        // Create Window with layout
        Window window = new Window("Kontenplan");
        GridLayout layout = new GridLayout(1, 1);
        layout.addComponent(AccountingDataProvider.getInstance().toHtmlTable());
        layout.setSizeFull();//from w  ww  .  j a  v  a 2s .c  o  m
        window.setContent(layout);
        window.center();
        window.setWidth("60%");
        window.setHeight("80%");
        window.setResizable(false);
        window.addCloseListener(e1 -> openKontenplan.setEnabled(true));
        getUI().addWindow(window);

    });
    addHelpButton(openKontenplan);
}

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

License:LGPL

public VaadinResultView(ResultFiredArgs args, String title) {
    setSpacing(true);/*from  w w  w  .j  a  v a2 s  . 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.reisisoft.jku.ce.adaptivelearning.vaadin.ui.topic.accounting.AccountingQuestionManager.java

License:LGPL

public AccountingQuestionManager(String quizName) {
    super(quizName);
    Button openKontenplan = new Button("Open Kontenplan");
    openKontenplan.addClickListener(e -> {
        openKontenplan.setEnabled(false);
        // Create Window with layout
        Window window = new Window("Kontenplan");
        GridLayout layout = new GridLayout(1, 1);
        layout.addComponent(AccountingDataProvider.getInstance().toHtmlTable());
        layout.setSizeFull();//from   w  ww .j av  a 2s . c  o  m
        window.setContent(layout);
        window.center();
        window.setWidth("60%");
        window.setHeight("80%");
        window.setResizable(false);
        window.addCloseListener(e1 -> openKontenplan.setEnabled(true));
        getUI().addWindow(window);

    });
    addHelpButton(openKontenplan);
}

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

License:LGPL

public VaadinResultView(ResultFiredArgs args, String title) {
    setSpacing(true);//from  w  w  w. ja  v a2 s .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));
}