Example usage for com.vaadin.ui Window addCloseListener

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

Introduction

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

Prototype

public Registration addCloseListener(CloseListener listener) 

Source Link

Document

Adds a CloseListener to the window.

Usage

From source file:annis.gui.controlpanel.CorpusListPanel.java

License:Apache License

public void initCorpusBrowser(String topLevelCorpusName, final Button l) {

    AnnisCorpus c = ui.getQueryState().getAvailableCorpora().getItem(topLevelCorpusName).getBean();
    MetaDataPanel meta = new MetaDataPanel(c.getName());

    CorpusBrowserPanel browse = new CorpusBrowserPanel(c, ui.getQueryController());
    GridLayout infoLayout = new GridLayout(2, 2);
    infoLayout.setSizeFull();/*from ww w  .j  a v  a 2s  .com*/

    String corpusURL = Helper.generateCorpusLink(Sets.newHashSet(topLevelCorpusName));
    Label lblLink = new Label("Link to corpus: <a href=\"" + corpusURL + "\">" + corpusURL + "</a>",
            ContentMode.HTML);
    lblLink.setHeight("-1px");
    lblLink.setWidth("-1px");

    infoLayout.addComponent(meta, 0, 0);
    infoLayout.addComponent(browse, 1, 0);
    infoLayout.addComponent(lblLink, 0, 1, 1, 1);

    infoLayout.setRowExpandRatio(0, 1.0f);
    infoLayout.setColumnExpandRatio(0, 0.5f);
    infoLayout.setColumnExpandRatio(1, 0.5f);
    infoLayout.setComponentAlignment(lblLink, Alignment.MIDDLE_CENTER);

    Window window = new Window("Corpus information for " + c.getName() + " (ID: " + c.getId() + ")",
            infoLayout);
    window.setWidth(70, UNITS_EM);
    window.setHeight(45, UNITS_EM);
    window.setResizable(true);
    window.setModal(false);
    window.setResizeLazy(true);

    window.addCloseListener(new Window.CloseListener() {

        @Override
        public void windowClose(Window.CloseEvent e) {
            l.setEnabled(true);
        }
    });

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

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

License:Apache License

private void showShareSingleMatchGenerator() {
    // select the current match
    if (ui != null) {
        ui.getQueryState().getSelectedMatches().getValue().clear();
        ui.getQueryState().getSelectedMatches().getValue().add(resultNumber);
        ui.getSearchView().updateFragment(ui.getQueryController().getSearchQuery());
    }//from  w  w w  . j a  v a2s . co  m

    Window window = new ShareSingleMatchGenerator(resolverEntries, match, query, segmentationName, ps);
    window.setWidth(790, Unit.PIXELS);
    window.setHeight(580, Unit.PIXELS);
    window.setResizable(true);
    window.setModal(true);

    window.addCloseListener(new Window.CloseListener() {

        @Override
        public void windowClose(Window.CloseEvent e) {
            btLink.setEnabled(true);
        }
    });
    window.setCaption("Match reference link");

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

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.  ja  va 2 s. 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  av a  2 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   ww w .ja va2 s. c om*/
        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  ww w .j a v a  2s . c  o m*/
    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:com.cavisson.gui.dashboard.components.calender.BeanItemContainerTestUI.java

License:Apache License

/**
 * Opens up a modal dialog window where an event can be modified
 * //ww w.j a  va  2  s  . c om
 * @param event
 *            The event to modify
 */
private void editEvent(final BasicEvent event) {
    Window modal = new Window("Add event");
    modal.setModal(true);
    modal.setResizable(false);
    modal.setDraggable(false);
    modal.setWidth("300px");
    final FieldGroup fieldGroup = new FieldGroup();

    FormLayout formLayout = new FormLayout();
    TextField captionField = new TextField("Caption");
    captionField.setImmediate(true);
    TextField descriptionField = new TextField("Description");
    descriptionField.setImmediate(true);
    DateField startField = new DateField("Start");
    startField.setResolution(Resolution.MINUTE);
    startField.setImmediate(true);
    DateField endField = new DateField("End");
    endField.setImmediate(true);
    endField.setResolution(Resolution.MINUTE);

    formLayout.addComponent(captionField);
    formLayout.addComponent(descriptionField);
    formLayout.addComponent(startField);
    formLayout.addComponent(endField);

    fieldGroup.bind(captionField, ContainerEventProvider.CAPTION_PROPERTY);
    fieldGroup.bind(descriptionField, ContainerEventProvider.DESCRIPTION_PROPERTY);
    fieldGroup.bind(startField, ContainerEventProvider.STARTDATE_PROPERTY);
    fieldGroup.bind(endField, ContainerEventProvider.ENDDATE_PROPERTY);

    fieldGroup.setItemDataSource(new BeanItem<BasicEvent>(event,
            Arrays.asList(ContainerEventProvider.CAPTION_PROPERTY, ContainerEventProvider.DESCRIPTION_PROPERTY,
                    ContainerEventProvider.STARTDATE_PROPERTY, ContainerEventProvider.ENDDATE_PROPERTY)));
    modal.setContent(formLayout);
    modal.addCloseListener(new Window.CloseListener() {
        @Override
        public void windowClose(CloseEvent e) {
            // Commit changes to bean
            try {
                fieldGroup.commit();
            } catch (CommitException e1) {
                e1.printStackTrace();
            }

            if (events.containsId(event)) {
                /*
                 * BeanItemContainer does not notify container listeners
                 * when the bean changes so we need to trigger a
                 * ItemSetChange event
                 */
                BasicEvent dummy = new BasicEvent();
                events.addBean(dummy);
                events.removeItem(dummy);

            } else {
                events.addBean(event);
            }
        }
    });
    getUI().addWindow(modal);
}

From source file:com.etest.view.testbank.CellCaseMainUI.java

HorizontalLayout getHlayout() {
    HorizontalLayout hlayout = new HorizontalLayout();
    hlayout.setSpacing(true);//  w  ww  . j  av a  2  s  .c  o m

    subject.setWidth("200px");
    subject.addValueChangeListener((new CurriculumPropertyChangeListener(topic)));
    hlayout.addComponent(subject);
    hlayout.setComponentAlignment(subject, Alignment.MIDDLE_LEFT);

    topic.setInputPrompt("Select a Topic..");
    topic.addStyleName(ValoTheme.COMBOBOX_SMALL);
    topic.setWidth("500px");
    topic.addValueChangeListener((Property.ValueChangeEvent event) -> {
        if (event.getProperty().getValue() == null) {
        } else {
            syllabusId = (int) event.getProperty().getValue();
            populateDataTable();
        }
    });
    hlayout.addComponent(topic);
    hlayout.setComponentAlignment(topic, Alignment.MIDDLE_LEFT);

    Button createCellBtn = new Button("CREATE");
    createCellBtn.setWidthUndefined();
    createCellBtn.setIcon(FontAwesome.OPENID);
    createCellBtn.addStyleName(ValoTheme.BUTTON_PRIMARY);
    createCellBtn.addStyleName(ValoTheme.BUTTON_SMALL);
    createCellBtn.addClickListener((Button.ClickEvent event) -> {
        Window sub = new CellCaseWindow(0);
        if (sub.getParent() == null) {
            UI.getCurrent().addWindow(sub);
        }
        sub.addCloseListener((Window.CloseEvent e) -> {
            populateDataTable();
        });
    });
    hlayout.addComponent(createCellBtn);
    hlayout.setComponentAlignment(createCellBtn, Alignment.MIDDLE_LEFT);

    return hlayout;
}

From source file:com.etest.view.tq.TQCoverageUI.java

public TQCoverageUI() {
    setSizeFull();//from w  ww  .ja  v  a 2  s  .c o m

    addComponent(buildTQCoverageForms());
    addComponent(grid);

    footer = grid.appendFooterRow();

    grid.addItemClickListener((ItemClickEvent event) -> {
        Object itemId = event.getItemId();
        Item item = grid.getContainerDataSource().getItem(itemId);

        if (event.getPropertyId().toString().equals("Topic")) {
            Window sub = getTopicWindow(item);
            if (sub.getParent() == null) {
                UI.getCurrent().addWindow(sub);
            }
        }

        Window sub;
        if (event.getPropertyId().toString().contains("Pick")) {
            boolean isValueInTBNotZero = tq.isValueInTBNotZero(item,
                    CommonUtilities.replaceStringPickToTB(event.getPropertyId()));
            if (!isValueInTBNotZero) {
                Notification.show("There are no Items in Test Bank!", Notification.Type.ERROR_MESSAGE);
                return;
            } else {
                sub = getPickWindow(item, CommonUtilities.replaceStringPickToTB(event.getPropertyId()));
                if (sub.getParent() == null) {
                    UI.getCurrent().addWindow(sub);
                }
                sub.addCloseListener((Window.CloseEvent e) -> {
                    if (tq.calculateTotalPickItemsPerTopic(grid, itemId) > CommonUtilities
                            .convertStringToDouble(item.getItemProperty("Max Items").getValue().toString())) {
                        item.getItemProperty(event.getPropertyId()).setValue(0);
                        ShowErrorNotification.error("Running Total is greater than Max Items");
                    } else {
                        item.getItemProperty("Running Total")
                                .setValue(tq.calculateTotalPickItemsPerTopic(grid, itemId));
                        footer.getCell("Running Total").setText(String.valueOf(tq.calculateRunningTotal(grid)));
                    }
                });
            }
        }

        if (event.getPropertyId().toString().equals("Max Items")) {
            double value = (double) item.getItemProperty("Max Items").getValue();
            sub = getMaxItemsWindow(item, value);
            if (sub.getParent() == null) {
                UI.getCurrent().addWindow(sub);
            }
        }
    });

    grid.getColumn("remove")
            .setRenderer(new DeleteButtonValueRenderer((ClickableRenderer.RendererClickEvent event) -> {
                grid.getContainerDataSource().removeItem(event.getItemId());
                populateGridFooter();
                footer.getCell("Running Total").setText(String.valueOf(tq.calculateRunningTotal(grid)));
            })).setWidth(100);

    footer.getCell("Topic").setText("Total");
    footer.setStyleName("align-center");

    Button generateTQ = new Button("Generate TQ");
    generateTQ.setWidth("300px");
    generateTQ.addClickListener(buttonClickListener);

    addComponent(new Label("\n"));
    addComponent(generateTQ);
    setComponentAlignment(generateTQ, Alignment.MIDDLE_RIGHT);
}

From source file:com.garyclayburg.vconsole.TargetWindows.java

License:Open Source License

void showTargetWindow(User selectedUser, final String entitledTarget) {
    Window window = targetWindows.get(entitledTarget);
    if (window == null) { //only generate new window if user clicked on it - no new windows from policy update
        UI ui = UI.getCurrent();/*  w ww  .j  av  a2  s  . c om*/
        if (ui != null) {
            window = new Window(entitledTarget);
            window.setWidth("300px");
            targetWindows.put(entitledTarget, window);
            window.addCloseListener(new Window.CloseListener() {
                @Override
                public void windowClose(Window.CloseEvent e) {
                    targetWindows.remove(entitledTarget);
                }
            });
            ui.addWindow(window);
        } else {
            return;
        }
    }
    populateTarget(selectedUser, entitledTarget);
}