Example usage for com.vaadin.ui Window setModal

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

Introduction

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

Prototype

public void setModal(boolean modal) 

Source Link

Document

Sets window modality.

Usage

From source file:eu.lod2.DeleteGraphs.java

License:Apache License

private Button showConfirmDialog(String message) {
    final Window notifier = new Window("Are you sure?");
    notifier.setWidth("400px");
    notifier.setModal(true);

    VerticalLayout layout = (VerticalLayout) notifier.getContent();
    layout.setMargin(true);//  w  w w  .  j av a  2s  . c o  m
    layout.setSpacing(true);

    Label messageLabel = new Label(message);
    notifier.addComponent(messageLabel);

    Button yes = new Button("Yes", new ClickListener() {
        public void buttonClick(ClickEvent event) {
            notifier.getParent().removeWindow(notifier);
        }
    });
    Button no = new Button("No", new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            notifier.getParent().removeWindow(notifier);
        }
    });

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.addComponent(yes);
    buttons.addComponent(no);
    notifier.addComponent(buttons);

    getWindow().addWindow(notifier);

    return yes;
}

From source file:eu.lod2.ExportSelector.java

License:Apache License

public void addNewItem(String newItemCaption) {
    final String newItem = newItemCaption;

    // request the user whether to add it to the list or to reject his choice.
    final Window subwindow = new Window("Create new graph");
    subwindow.setModal(true);

    // Configure the windows layout; by default a VerticalLayout
    VerticalLayout swlayout = (VerticalLayout) subwindow.getContent();

    Label desc = new Label(
            "The graphname " + newItemCaption + " is not a known graph. Shall we create the graph?");
    HorizontalLayout buttons = new HorizontalLayout();

    Button ok = new Button("Create graph", new ClickListener() {
        public void buttonClick(ClickEvent event) {
            createGraph(newItem);//from w  w w.  ja v a2s .c  o m
            (subwindow.getParent()).removeWindow(subwindow);
        }
    });
    ok.setDebugId(this.getClass().getSimpleName() + "_ok");
    Button cancel = new Button("Cancel", new ClickListener() {
        public void buttonClick(ClickEvent event) {
            (subwindow.getParent()).removeWindow(subwindow);
        }
    });
    cancel.setDebugId(this.getClass().getSimpleName() + "_cancel");

    swlayout.addComponent(desc);
    swlayout.addComponent(buttons);
    buttons.addComponent(ok);
    buttons.addComponent(cancel);
    buttons.setComponentAlignment(ok, Alignment.BOTTOM_RIGHT);
    buttons.setComponentAlignment(cancel, Alignment.BOTTOM_RIGHT);
    getWindow().addWindow(subwindow);
    subwindow.setWidth("300px");

}

From source file:eu.lod2.ExportSelector3.java

License:Apache License

public void addNewItem(String newItemCaption) {
    final String newItem = newItemCaption;

    // request the user whether to add it to the list or to reject his choice.
    final Window subwindow = new Window("Create new graph");
    subwindow.setModal(true);

    // Configure the windows layout; by default a VerticalLayout
    VerticalLayout swlayout = (VerticalLayout) subwindow.getContent();

    Label desc = new Label(
            "The graphname " + newItemCaption + " is not a known graph. Shall we create the graph?");
    HorizontalLayout buttons = new HorizontalLayout();

    Button ok = new Button("Create graph", new ClickListener() {
        public void buttonClick(ClickEvent event) {
            createGraph(newItem);/*from www  . j  a  va  2 s . co m*/
            (subwindow.getParent()).removeWindow(subwindow);
        }
    });
    ok.setDebugId(this.getClass().getSimpleName() + "_ok");
    Button cancel = new Button("Cancel", new ClickListener() {
        public void buttonClick(ClickEvent event) {
            (subwindow.getParent()).removeWindow(subwindow);
        }
    });
    cancel.setDebugId(this.getClass().getSimpleName() + "_cancel");
    swlayout.addComponent(desc);
    swlayout.addComponent(buttons);
    buttons.addComponent(ok);
    buttons.addComponent(cancel);
    buttons.setComponentAlignment(ok, Alignment.BOTTOM_RIGHT);
    buttons.setComponentAlignment(cancel, Alignment.BOTTOM_RIGHT);
    getWindow().addWindow(subwindow);
    subwindow.setWidth("300px");

}

From source file:facs.components.Settings.java

License:Open Source License

private void addNewDevice() {
    final Window subWindow = new Window("Add Device");
    FormLayout form = new FormLayout();
    form.setMargin(true);/*w w w.  j a  va2 s  .  com*/
    final TextField name = new TextField();
    name.setImmediate(true);
    name.addValidator(new StringLengthValidator("The name must be 1-85 letters long (Was {0}).", 1, 85, true));
    name.setCaption("Name of new device");
    form.addComponent(name);
    final TextArea description = new TextArea();
    description.setImmediate(true);
    description.addValidator(
            new StringLengthValidator("The name must be 1-255 letters long (Was {0}).", 1, 255, true));
    description.setCaption("Description");
    form.addComponent(description);
    final OptionGroup restricted = new OptionGroup("Is Device restricted by operators?");
    restricted.addItem("yes");
    restricted.setMultiSelect(true);
    form.addComponent(restricted);
    HorizontalLayout buttons = new HorizontalLayout();
    Button save = new Button("save");
    buttons.addComponent(save);
    Button discard = new Button("discard");
    discard.setDescription("discarding will abort the process of adding a new device into the databse.");
    buttons.addComponent(discard);
    buttons.setSpacing(true);
    form.addComponent(buttons);
    subWindow.setContent(form);

    form.setMargin(true);
    form.setSpacing(true);
    buttons.setMargin(true);
    buttons.setSpacing(true);

    // Center it in the browser window
    subWindow.center();
    subWindow.setModal(true);
    subWindow.setWidth("50%");
    // Open it in the UI
    UI.getCurrent().addWindow(subWindow);

    discard.addClickListener(new ClickListener() {
        /**
         * 
         */
        private static final long serialVersionUID = -5808910314649620731L;

        @Override
        public void buttonClick(ClickEvent event) {
            subWindow.close();
        }
    });
    save.addClickListener(new ClickListener() {
        /**
         * 
         */
        private static final long serialVersionUID = 3748395242651585005L;

        @Override
        public void buttonClick(ClickEvent event) {
            if (name.isValid() && description.isValid()) {
                Set<String> restr = (Set<String>) restricted.getValue();
                int deviceId = DBManager.getDatabaseInstance().addDevice(name.getValue(),
                        description.getValue(), (restr.size() == 1));
                DeviceBean bean = new DeviceBean(deviceId, name.getValue(), description.getValue(),
                        (restr.size() == 1));
                devicesGrid.addRow(bean);
            } else {
                Notification.show("Failed to add device to database.");
            }
        }
    });

    // DeviceBean db = new DeviceBean(0, "Device 1","some description1", false);
    // TODO
    // add to database
    /*
     * boolean added = false;//DBManager.getDatabaseInstance().addDevice(db); //TODO test //add to
     * grid if(added){ devicesGrid.addRow(db); }else{ //TODO log failed operation
     * Notification.show("Failed to add device to database.", Type.ERROR_MESSAGE); }
     */
}

From source file:fi.pss.cleanbeach.standalone.map.MapComponent.java

public void addPoint(final fi.pss.cleanbeach.data.Event e) {

    Location l = e.getLocation();

    LMarker m = new LMarker(l.getLatitude(), l.getLongitude());
    m.setData(l);//from  w  ww .  jav  a 2s.  c  o m
    addComponent(m);

    setIcon(m, l);
    m.setIconAnchor(new Point(16, 32));

    m.addClickListener(new LeafletClickListener() {

        @Override
        public void onClick(LeafletClickEvent event) {
            details.update(e);
            Window pop = new Window(null, details);
            pop.setResizable(false);
            pop.addStyleName("detailpop");
            pop.setModal(true);
            getUI().addWindow(pop);

            setCenter(e.getLocation().getLatitude(), e.getLocation().getLongitude() + getDetailsPosOffset());
        }

    });
    markers.put(l, m);
}

From source file:fi.semantum.strategia.Utils.java

License:Open Source License

public static void setUserMeter(final Main main, final Base base, final Meter m) {

    final Database database = main.getDatabase();

    final Window subwindow = new Window("Aseta mittarin arvo", new VerticalLayout());
    subwindow.setModal(true);
    subwindow.setWidth("350px");
    subwindow.setResizable(false);//w  w  w .  ja va 2  s.  c o m

    final VerticalLayout winLayout = (VerticalLayout) subwindow.getContent();
    winLayout.setMargin(true);
    winLayout.setSpacing(true);

    String caption = m.getCaption(database);
    if (caption != null && !caption.isEmpty()) {
        final Label header = new Label(caption);
        header.addStyleName(ValoTheme.LABEL_LARGE);
        winLayout.addComponent(header);
    }

    final Indicator indicator = m.getPossibleIndicator(database);
    if (indicator == null)
        return;

    Datatype dt = indicator.getDatatype(database);
    if (!(dt instanceof EnumerationDatatype))
        return;

    final Label l = new Label("Selite: " + indicator.getValueShortComment());

    AbstractField<?> forecastField = dt.getEditor(main, base, indicator, true, new CommentCallback() {

        @Override
        public void runWithComment(String shortComment, String comment) {
            l.setValue("Selite: " + indicator.getValueShortComment());
        }

        @Override
        public void canceled() {
        }

    });
    forecastField.setWidth("100%");
    forecastField.setCaption("Ennuste");
    winLayout.addComponent(forecastField);

    AbstractField<?> currentField = dt.getEditor(main, base, indicator, false, new CommentCallback() {

        @Override
        public void runWithComment(String shortComment, String comment) {
            l.setValue("Selite: " + indicator.getValueShortComment());
        }

        @Override
        public void canceled() {
        }

    });
    currentField.setWidth("100%");
    currentField.setCaption("Toteuma");
    winLayout.addComponent(currentField);

    winLayout.addComponent(l);

    l.setWidth("100%");
    winLayout.setComponentAlignment(l, Alignment.BOTTOM_CENTER);

    HorizontalLayout hl = new HorizontalLayout();
    winLayout.addComponent(hl);
    winLayout.setComponentAlignment(hl, Alignment.BOTTOM_CENTER);

    Button ok = new Button("Sulje", new Button.ClickListener() {

        private static final long serialVersionUID = 1364802814012491490L;

        public void buttonClick(ClickEvent event) {
            main.removeWindow(subwindow);
        }

    });

    Button define = new Button("Mrit", new Button.ClickListener() {

        private static final long serialVersionUID = 1364802814012491490L;

        public void buttonClick(ClickEvent event) {
            Meter.editMeter(main, base, m);
        }

    });

    hl.addComponent(ok);
    hl.setComponentAlignment(ok, Alignment.BOTTOM_LEFT);
    hl.addComponent(define);
    hl.setComponentAlignment(define, Alignment.BOTTOM_LEFT);

    main.addWindow(subwindow);

}

From source file:fi.semantum.strategia.Utils.java

License:Open Source License

public static void editTextAndId(final Main main, String title, final Base container) {

    final Database database = main.getDatabase();

    final Window subwindow = new Window(title, new VerticalLayout());
    subwindow.setModal(true);
    subwindow.setWidth("400px");
    subwindow.setHeight("500px");
    subwindow.setResizable(false);//from   w w w  .  ja v a2  s  .  c om

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

    final TextField tf = new TextField();
    tf.setCaption("Lyhytnimi:");
    tf.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    tf.setValue(container.getId(database));
    tf.setWidth("100%");
    winLayout.addComponent(tf);

    final TextArea ta = new TextArea();
    ta.setCaption("Teksti:");
    ta.setValue(container.getText(database));
    ta.setWidth("100%");
    ta.setHeight("290px");
    winLayout.addComponent(ta);

    Button save = new Button("Tallenna", new Button.ClickListener() {

        private static final long serialVersionUID = 6641880870005364983L;

        public void buttonClick(ClickEvent event) {
            String idValue = tf.getValue();
            String value = ta.getValue();
            main.removeWindow(subwindow);
            container.modifyId(main, idValue);
            container.modifyText(main, value);
            Collection<String> tags = Tag.extractTags(value);
            database.assertTags(tags);
            ArrayList<Tag> tagObjects = new ArrayList<Tag>();
            for (String s : tags)
                tagObjects.add(database.getOrCreateTag(s));
            container.assertRelatedTags(database, tagObjects);
            Updates.update(main, true);
            Property emails = Property.find(database, Property.EMAIL);
            String addr = emails.getPropertyValue(container);
            if (addr != null && !addr.isEmpty()) {
                String[] addrs = addr.split(",");
                if (addrs.length > 0) {
                    try {
                        Email.send(addrs, "Muutos strategiakartassa: " + container.getId(database),
                                "Kyttj " + main.account.getId(database)
                                        + " on muuttanut strategiakarttaa.<br/><br/>Lyhytnimi: "
                                        + container.getId(database) + "<br/><br/>Teksti: "
                                        + container.getText(database));
                    } catch (MessagingException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

    });

    Button discard = new Button("Peru muutokset", new Button.ClickListener() {

        private static final long serialVersionUID = -784522457615993823L;

        public void buttonClick(ClickEvent event) {
            Updates.update(main, true);
            main.removeWindow(subwindow);
        }

    });

    HorizontalLayout hl2 = new HorizontalLayout();
    hl2.setSpacing(true);
    hl2.addComponent(save);
    hl2.addComponent(discard);
    winLayout.addComponent(hl2);
    winLayout.setComponentAlignment(hl2, Alignment.MIDDLE_CENTER);
    main.addWindow(subwindow);

    ta.setCursorPosition(ta.getValue().length());

}

From source file:fi.semantum.strategia.Utils.java

License:Open Source License

public static void editTags(final Main main, String title, final Base container) {

    final Database database = main.getDatabase();

    final Window subwindow = new Window(title, new VerticalLayout());
    subwindow.setModal(true);
    subwindow.setWidth("400px");
    subwindow.setHeight("360px");
    subwindow.setResizable(true);//  ww w  .ja v a 2  s . c  om

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

    // Add some content; a label and a close-button
    final List<String> tags = new ArrayList<String>();
    for (Tag t : container.getRelatedTags(database))
        tags.add(t.getId(database));

    final CssLayout vl = new CssLayout();
    vl.setCaption("Kytss olevat aihetunnisteet:");
    fillTagEditor(database, vl, tags, Account.canWrite(main, container));
    winLayout.addComponent(vl);

    HorizontalLayout hl = new HorizontalLayout();
    hl.setWidth("100%");
    hl.setSpacing(true);

    final TagCombo combo = new TagCombo();
    final CustomLazyContainer comboContainer = new CustomLazyContainer(database, combo,
            Tag.enumerate(database));
    combo.setWidth("100%");
    combo.setCaption("Uusi aihetunniste:");
    combo.setInputPrompt("valitse listasta tai kirjoita");
    combo.setFilteringMode(FilteringMode.STARTSWITH);
    combo.setTextInputAllowed(true);
    combo.setImmediate(true);
    combo.setNullSelectionAllowed(false);
    combo.setInvalidAllowed(true);
    combo.setInvalidCommitted(true);
    combo.setItemCaptionMode(ItemCaptionMode.PROPERTY);
    combo.setItemCaptionPropertyId("id"); //should set
    combo.setContainerDataSource(comboContainer);

    hl.addComponent(combo);
    hl.setExpandRatio(combo, 1.0f);

    Button add = new Button("Lis", new Button.ClickListener() {

        private static final long serialVersionUID = -2848576385076605664L;

        public void buttonClick(ClickEvent event) {
            String filter = (String) combo.getValue();
            if (filter != null && filter.length() > 0) {
                Tag t = database.getOrCreateTag(filter);
                if (tags.contains(t.getId(database)))
                    return;
                tags.add(t.getId(database));
                fillTagEditor(database, vl, tags, main.account != null);
                combo.clear();
            }
        }
    });
    hl.addComponent(add);
    hl.setComponentAlignment(add, Alignment.BOTTOM_LEFT);
    hl.setExpandRatio(add, 0.0f);

    winLayout.addComponent(hl);

    Button close = new Button("Tallenna", new Button.ClickListener() {

        private static final long serialVersionUID = -451523776456589591L;

        public void buttonClick(ClickEvent event) {
            main.removeWindow(subwindow);
            List<Tag> newTags = new ArrayList<Tag>();
            for (String s : tags)
                newTags.add(database.getOrCreateTag(s));
            container.setRelatedTags(database, newTags);
            Updates.update(main, true);
        }
    });
    Button discard = new Button("Peru muutokset", new Button.ClickListener() {

        private static final long serialVersionUID = -2387057110951581993L;

        public void buttonClick(ClickEvent event) {
            main.removeWindow(subwindow);
        }
    });

    HorizontalLayout hl2 = new HorizontalLayout();
    hl2.setSpacing(true);
    hl2.addComponent(close);
    hl2.addComponent(discard);
    winLayout.addComponent(hl2);
    winLayout.setComponentAlignment(hl2, Alignment.MIDDLE_CENTER);

    main.addWindow(subwindow);

}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

public void showInWindow(String caption, Component vaadinComponent, Window.CloseListener closeListener) {

    // Create a sub-window and set the content
    Window subWindow = new Window(caption);

    subWindow.setContent(vaadinComponent);

    if (closeListener != null)
        subWindow.addCloseListener(closeListener);

    // Center it in the browser window
    subWindow.center();//from  ww w  .jav  a2  s . c om

    subWindow.setModal(true);

    // Open it in the UI
    UI.getCurrent().addWindow(subWindow);

}

From source file:io.mateu.ui.vaadin.framework.MyUI.java

License:Apache License

/**
 * abre una vista. La colocar en el lado derecho
 *
 * @param ui// w ww  .  ja v a2  s  .c  om
 * @param view
 */
public static void addView(MyUI ui, AbstractView view) {

    if (view == null) {
        System.out.println("abriendo vista null");
        ui.getViewDisplay().removeAllComponents();
    } else {

        System.out.println("abriendo vista " + view.getClass().getName() + "::" + view.getViewId());

        ViewLayout v = new ViewLayout(view);
        if (view instanceof AbstractDialog) {

            AbstractDialog d = (AbstractDialog) view;

            // Create a sub-window and set the content
            Window subWindow = new Window(((AbstractDialog) view).getTitle());

            HorizontalLayout footer = new HorizontalLayout();
            footer.setWidth("100%");
            footer.setSpacing(true);
            footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);

            Label footerText = new Label("");
            footerText.setSizeUndefined();

            Button ok;
            if (d instanceof AbstractAddRecordDialog) {
                ok = new Button("Add record", e -> {
                    List<String> errors = v.getView().getForm().validate();
                    if (errors.size() > 0) {
                        io.mateu.ui.core.client.app.MateuUI.notifyErrors(errors);
                    } else {
                        //if (d.isCloseOnOk()) subWindow.close();
                        ((AbstractAddRecordDialog) view).addAndClean(v.getView().getForm().getData());
                    }
                });
            } else {
                ok = new Button(d.getOkText(), e -> {
                    List<String> errors = v.getView().getForm().validate();
                    if (errors.size() > 0) {
                        io.mateu.ui.core.client.app.MateuUI.notifyErrors(errors);
                    } else {
                        if (d.isCloseOnOk())
                            subWindow.close();
                        ((AbstractDialog) view).onOk(v.getView().getForm().getData());
                    }
                });
            }
            ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
            ok.setClickShortcut(ShortcutAction.KeyCode.ENTER);

            footer.addComponents(footerText);

            for (AbstractAction a : d.getActions()) {
                Button b = new Button(a.getName(), e -> {
                    a.run();
                });
                //b.addStyleName(ValoTheme.BUTTON_);
                //b.setClickShortcut(ShortcutAction.KeyCode.ENTER);
                if ("previous".equalsIgnoreCase(a.getName())) {
                    b.setIcon(VaadinIcons.ANGLE_LEFT);
                } else if ("next".equalsIgnoreCase(a.getName())) {
                    b.setIcon(VaadinIcons.ANGLE_RIGHT);
                }
                footer.addComponent(b);
            }

            if (d instanceof AbstractListEditorDialog) {
                AbstractListEditorDialog lv = (AbstractListEditorDialog) d;

                Property<Integer> pos = new SimpleObjectProperty<>();

                pos.setValue(lv.getInitialPos());

                Button prev = new Button("Previous", e -> {
                    List<String> errors = v.getView().getForm().validate();
                    if (errors.size() > 0) {
                        io.mateu.ui.core.client.app.MateuUI.notifyErrors(errors);
                    } else {

                        if (pos.getValue() > 0) {
                            lv.setData(pos.getValue(), view.getForm().getData());
                            pos.setValue(pos.getValue() - 1);
                            view.getForm().setData(lv.getData(pos.getValue()));
                        }

                    }
                });
                prev.setIcon(VaadinIcons.ANGLE_LEFT);
                footer.addComponent(prev);

                Button next = new Button("Next", e -> {
                    List<String> errors = v.getView().getForm().validate();
                    if (errors.size() > 0) {
                        io.mateu.ui.core.client.app.MateuUI.notifyErrors(errors);
                    } else {

                        if (pos.getValue() < lv.getListSize() - 1) {
                            lv.setData(pos.getValue(), view.getForm().getData());
                            pos.setValue(pos.getValue() + 1);
                            view.getForm().setData(lv.getData(pos.getValue()));
                        }

                    }
                });
                next.setIcon(VaadinIcons.ANGLE_RIGHT);
                footer.addComponent(next);

                pos.addListener(new ChangeListener<Integer>() {
                    @Override
                    public void changed(ObservableValue<? extends Integer> observable, Integer oldValue,
                            Integer newValue) {
                        if (newValue <= 0) {
                            prev.setEnabled(false);
                        } else {
                            prev.setEnabled(true);
                        }
                        if (newValue < lv.getListSize() - 1) {
                            next.setEnabled(true);
                        } else {
                            next.setEnabled(false);
                        }
                    }
                });

            }

            footer.addComponents(ok); //, cancel);
            footer.setExpandRatio(footerText, 1);

            v.addComponent(footer);

            subWindow.setContent(v);

            // Center it in the browser window
            subWindow.center();

            subWindow.setModal(true);

            // Open it in the UI
            ui.addWindow(subWindow);

        } else {

            System.out.println("aadiendo vista al contenedor de vistas");

            ui.getViewDisplay().removeAllComponents();
            ui.getViewDisplay().addComponent(v);

            ui.refreshMenu(v.getArea(), v.getMenu());

        }

    }

}