Example usage for com.vaadin.ui Panel setContent

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

Introduction

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

Prototype

@Override
public void setContent(Component content) 

Source Link

Document

Sets the content of this container.

Usage

From source file:fi.jasoft.dragdroplayouts.demo.views.DragdropCaptionModeDemo.java

License:Apache License

@Override
public Component getLayout() {
    // start-source
    // Create layout
    DDAbsoluteLayout layout = new DDAbsoluteLayout();

    // Enable dragging components by their caption
    layout.setDragMode(LayoutDragMode.CAPTION);

    // Enable dropping components
    layout.setDropHandler(new DefaultAbsoluteLayoutDropHandler());

    // Add some content to the layout
    layout.addComponent(new Label("This layout uses the LayoutDragMode.CAPTION "
            + "drag mode for dragging the components. This mode is useful "
            + "when you only want users to drag items by their captions. The Panels below are only draggable by their captions (<< Move >>).",
            ContentMode.HTML));/*  www .j a  va  2  s  .  c  om*/

    Panel chapter1 = new Panel("<< Move >>");
    chapter1.setWidth("300px");
    Label chapter1Content = new Label(new LoremIpsum().getParagraphs(1), ContentMode.TEXT);
    chapter1Content.setCaption("===== Chapter 1 - The beginning ======");
    chapter1.setContent(chapter1Content);
    layout.addComponent(chapter1, "top:50px;left:10px");

    Panel chapter2 = new Panel("<< Move >>");
    chapter2.setWidth("300px");
    Label chapter2Content = new Label(new LoremIpsum().getParagraphs(1), ContentMode.TEXT);
    chapter2Content.setCaption("===== Chapter 2 - The finale ======");
    chapter2.setContent(chapter2Content);
    layout.addComponent(chapter2, "top:50px; left:320px");

    // end-source
    return layout;
}

From source file:fi.jasoft.dragdroplayouts.demo.views.DragdropDragGrabFilterDemo.java

License:Apache License

private Panel createCompositeChild(String caption) {
    Panel compositePanel = new Panel();
    compositePanel.setWidthUndefined();/*from  w ww  . j a  va  2  s.com*/
    compositePanel.setCaption("Composite Widget " + caption);

    VerticalLayout content = new VerticalLayout();
    content.setWidthUndefined();
    compositePanel.setContent(content);

    content.addComponent(new Label("Grab me to drag Panel"));
    content.addComponent(new Button("Cannot be grabbed"));
    content.addComponent(new TextField("Cannot be grabbed TextField"));
    content.addComponent(new Label("Grab me too!"));

    for (int i = 0; i < content.getComponentCount(); i++) {
        content.getComponent(i).setWidth(100, Unit.PERCENTAGE);
    }

    return compositePanel;
}

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

License:Open Source License

public static void manage(final Main main) {

    final Database database = main.getDatabase();

    VerticalLayout content = new VerticalLayout();
    content.setSizeFull();/*from ww  w  .j  ava  2s. c  o m*/
    content.setSpacing(true);

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

    final ComboBox users = new ComboBox();
    users.setWidth("100%");
    users.setNullSelectionAllowed(false);
    users.addStyleName(ValoTheme.COMBOBOX_SMALL);
    users.setCaption("Valitse kyttj:");

    final Map<String, Account> accountMap = new HashMap<String, Account>();
    makeAccountCombo(main, accountMap, users);

    for (Account a : Account.enumerate(database)) {
        accountMap.put(a.getId(database), a);
        users.addItem(a.getId(database));
        users.select(a.getId(database));
    }

    final Table table = new Table();
    table.setSelectable(true);
    table.setMultiSelect(true);
    table.addStyleName(ValoTheme.TABLE_SMALL);
    table.addStyleName(ValoTheme.TABLE_SMALL);
    table.addStyleName(ValoTheme.TABLE_COMPACT);

    users.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 5036991262418844060L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            users.removeValueChangeListener(this);
            makeAccountCombo(main, accountMap, users);
            makeAccountTable(database, users, accountMap, table);
            users.addValueChangeListener(this);
        }

    });

    final TextField tf = new TextField();

    Validator nameValidator = new Validator() {

        private static final long serialVersionUID = -4779239111120669168L;

        @Override
        public void validate(Object value) throws InvalidValueException {
            String s = (String) value;
            if (s.isEmpty())
                throw new InvalidValueException("Nimi ei saa olla tyhj");
            if (accountMap.containsKey(s))
                throw new InvalidValueException("Nimi on jo kytss");
        }

    };

    final Button save = new Button("Luo", new Button.ClickListener() {

        private static final long serialVersionUID = -6053708137324681886L;

        public void buttonClick(ClickEvent event) {

            if (!tf.isValid())
                return;

            String pass = Long.toString(Math.abs(UUID.randomUUID().getLeastSignificantBits()), 36);
            Account.create(database, tf.getValue(), "", Utils.hash(pass));

            Updates.update(main, true);

            makeAccountCombo(main, accountMap, users);
            makeAccountTable(database, users, accountMap, table);

            Dialogs.infoDialog(main, "Uusi kyttj '" + tf.getValue() + "' luotu",
                    "Kyttjn salasana on " + pass + "", null);

        }

    });
    save.addStyleName(ValoTheme.BUTTON_SMALL);

    final Button remove = new Button("Poista", new Button.ClickListener() {

        private static final long serialVersionUID = -5359199320445328801L;

        public void buttonClick(ClickEvent event) {

            Object selection = users.getValue();
            Account state = accountMap.get(selection);

            // System cannot be removed
            if ("System".equals(state.getId(database)))
                return;

            state.remove(database);

            Updates.update(main, true);

            makeAccountCombo(main, accountMap, users);
            makeAccountTable(database, users, accountMap, table);

        }

    });
    remove.addStyleName(ValoTheme.BUTTON_SMALL);

    tf.setWidth("100%");
    tf.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    tf.setCaption("Luo uusi kyttj nimell:");
    tf.setValue(findFreshUserName(nameValidator));
    tf.setCursorPosition(tf.getValue().length());
    tf.setValidationVisible(true);
    tf.setInvalidCommitted(true);
    tf.setImmediate(true);
    tf.addTextChangeListener(new TextChangeListener() {

        private static final long serialVersionUID = -8274588731607481635L;

        @Override
        public void textChange(TextChangeEvent event) {
            tf.setValue(event.getText());
            try {
                tf.validate();
            } catch (InvalidValueException e) {
                save.setEnabled(false);
                return;
            }
            save.setEnabled(true);
        }

    });
    tf.addValidator(nameValidator);
    if (!tf.isValid())
        save.setEnabled(false);

    hl1.addComponent(users);
    hl1.setExpandRatio(users, 1.0f);
    hl1.setComponentAlignment(users, Alignment.BOTTOM_CENTER);

    hl1.addComponent(tf);
    hl1.setExpandRatio(tf, 1.0f);
    hl1.setComponentAlignment(tf, Alignment.BOTTOM_CENTER);

    hl1.addComponent(save);
    hl1.setExpandRatio(save, 0.0f);
    hl1.setComponentAlignment(save, Alignment.BOTTOM_CENTER);

    hl1.addComponent(remove);
    hl1.setExpandRatio(remove, 0.0f);
    hl1.setComponentAlignment(remove, Alignment.BOTTOM_CENTER);

    content.addComponent(hl1);
    content.setExpandRatio(hl1, 0.0f);

    table.addContainerProperty("Kartta", String.class, null);
    table.addContainerProperty("Oikeus", String.class, null);
    table.addContainerProperty("Laajuus", String.class, null);

    table.setWidth("100%");
    table.setHeight("100%");
    table.setNullSelectionAllowed(true);
    table.setMultiSelect(true);
    table.setCaption("Kyttjn oikeudet");

    makeAccountTable(database, users, accountMap, table);

    content.addComponent(table);
    content.setExpandRatio(table, 1.0f);

    final Button removeRights = new Button("Poista valitut rivit", new Button.ClickListener() {

        private static final long serialVersionUID = 4699670345358079045L;

        public void buttonClick(ClickEvent event) {

            Object user = users.getValue();
            Account state = accountMap.get(user);

            Object selection = table.getValue();
            Collection<?> sel = (Collection<?>) selection;

            List<Right> toRemove = new ArrayList<Right>();

            for (Object s : sel) {
                Integer index = (Integer) s;
                toRemove.add(state.rights.get(index - 1));
            }

            for (Right r : toRemove)
                state.rights.remove(r);

            Updates.update(main, true);

            makeAccountTable(database, users, accountMap, table);

        }

    });
    removeRights.addStyleName(ValoTheme.BUTTON_SMALL);

    table.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1188285609779556446L;

        @Override
        public void valueChange(ValueChangeEvent event) {

            Object selection = table.getValue();
            Collection<?> sel = (Collection<?>) selection;
            if (sel.isEmpty())
                removeRights.setEnabled(false);
            else
                removeRights.setEnabled(true);

        }

    });

    final ComboBox mapSelect = new ComboBox();
    mapSelect.setWidth("100%");
    mapSelect.setNullSelectionAllowed(false);
    mapSelect.addStyleName(ValoTheme.COMBOBOX_SMALL);
    mapSelect.setCaption("Valitse kartta:");
    for (Strategiakartta a : Strategiakartta.enumerate(database)) {
        mapSelect.addItem(a.uuid);
        mapSelect.setItemCaption(a.uuid, a.getText(database));
        mapSelect.select(a.uuid);
    }

    final ComboBox rightSelect = new ComboBox();
    rightSelect.setWidth("100px");
    rightSelect.setNullSelectionAllowed(false);
    rightSelect.addStyleName(ValoTheme.COMBOBOX_SMALL);
    rightSelect.setCaption("Valitse oikeus:");
    rightSelect.addItem("Muokkaus");
    rightSelect.addItem("Luku");
    rightSelect.select("Luku");

    final ComboBox propagateSelect = new ComboBox();
    propagateSelect.setWidth("130px");
    propagateSelect.setNullSelectionAllowed(false);
    propagateSelect.addStyleName(ValoTheme.COMBOBOX_SMALL);
    propagateSelect.setCaption("Valitse laajuus:");
    propagateSelect.addItem(VALITTU_KARTTA);
    propagateSelect.addItem(ALATASON_KARTAT);
    propagateSelect.select(VALITTU_KARTTA);

    final Button addRight = new Button("Lis rivi", new Button.ClickListener() {

        private static final long serialVersionUID = -4841787792917761055L;

        public void buttonClick(ClickEvent event) {

            Object user = users.getValue();
            Account state = accountMap.get(user);

            String mapUUID = (String) mapSelect.getValue();
            Strategiakartta map = database.find(mapUUID);
            String right = (String) rightSelect.getValue();
            String propagate = (String) propagateSelect.getValue();

            Right r = new Right(map, right.equals("Muokkaus"), propagate.equals(ALATASON_KARTAT));
            state.rights.add(r);

            Updates.update(main, true);

            makeAccountTable(database, users, accountMap, table);

        }

    });
    addRight.addStyleName(ValoTheme.BUTTON_SMALL);

    table.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 6439090862804667322L;

        @Override
        public void valueChange(ValueChangeEvent event) {

            Object selection = table.getValue();
            Collection<?> selected = (Collection<?>) selection;
            if (!selected.isEmpty()) {
                removeRights.setEnabled(true);
            } else {
                removeRights.setEnabled(false);
            }

        }

    });

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

    hl2.addComponent(removeRights);
    hl2.setComponentAlignment(removeRights, Alignment.TOP_LEFT);
    hl2.setExpandRatio(removeRights, 0.0f);

    hl2.addComponent(addRight);
    hl2.setComponentAlignment(addRight, Alignment.BOTTOM_LEFT);
    hl2.setExpandRatio(addRight, 0.0f);

    hl2.addComponent(mapSelect);
    hl2.setComponentAlignment(mapSelect, Alignment.BOTTOM_LEFT);
    hl2.setExpandRatio(mapSelect, 1.0f);

    hl2.addComponent(rightSelect);
    hl2.setComponentAlignment(rightSelect, Alignment.BOTTOM_LEFT);
    hl2.setExpandRatio(rightSelect, 0.0f);

    hl2.addComponent(propagateSelect);
    hl2.setComponentAlignment(propagateSelect, Alignment.BOTTOM_LEFT);
    hl2.setExpandRatio(propagateSelect, 0.0f);

    content.addComponent(hl2);
    content.setComponentAlignment(hl2, Alignment.BOTTOM_LEFT);
    content.setExpandRatio(hl2, 0.0f);

    final VerticalLayout vl = new VerticalLayout();

    final Panel p = new Panel();
    p.setWidth("100%");
    p.setHeight("200px");
    p.setContent(vl);

    final TimeConfiguration tc = TimeConfiguration.getInstance(database);

    final TextField tf2 = new TextField();
    tf2.setWidth("200px");
    tf2.addStyleName(ValoTheme.TEXTFIELD_SMALL);
    tf2.setCaption("Strategiakartan mritysaika:");
    tf2.setValue(tc.getRange());
    tf2.setCursorPosition(tf.getValue().length());
    tf2.setValidationVisible(true);
    tf2.setInvalidCommitted(true);
    tf2.setImmediate(true);
    tf2.addTextChangeListener(new TextChangeListener() {

        private static final long serialVersionUID = -8274588731607481635L;

        @Override
        public void textChange(TextChangeEvent event) {
            tf2.setValue(event.getText());
            try {
                tf2.validate();
                tc.setRange(event.getText());
                updateYears(database, vl);
                Updates.update(main, true);
            } catch (InvalidValueException e) {
                return;
            }
        }

    });
    tf2.addValidator(new Validator() {

        private static final long serialVersionUID = -4779239111120669168L;

        @Override
        public void validate(Object value) throws InvalidValueException {
            String s = (String) value;
            TimeInterval ti = TimeInterval.parse(s);
            long start = ti.startYear;
            long end = ti.endYear;
            if (start < 2015)
                throw new InvalidValueException("Alkuvuosi ei voi olla aikaisempi kuin 2015.");
            if (end > 2025)
                throw new InvalidValueException("Pttymisvuosi ei voi olla myhisempi kuin 2025.");
            if (end - start > 9)
                throw new InvalidValueException("Strategiakartta ei tue yli 10 vuoden tarkasteluja.");
        }

    });

    content.addComponent(tf2);
    content.setComponentAlignment(tf2, Alignment.BOTTOM_LEFT);
    content.setExpandRatio(tf2, 0.0f);

    updateYears(database, vl);

    content.addComponent(p);
    content.setComponentAlignment(p, Alignment.BOTTOM_LEFT);
    content.setExpandRatio(p, 0.0f);

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    buttons.setMargin(false);

    Dialogs.makeDialog(main, main.dialogWidth(), main.dialogHeight(0.8), "Hallinnoi strategiakarttaa", "Sulje",
            content, buttons);

}

From source file:foo.MyVaadinApplication.java

License:Apache License

/**
 * Initializes the middle banner// ww w  .  j a v a2s.  co m
 * 
 * @return initialized middle banner
 */
private Panel initMiddlePanel() {
    HorizontalLayout h = new HorizontalLayout();
    SidePanel sidePanel = new SidePanel(this);
    h.addComponent(sidePanel);
    h.setComponentAlignment(sidePanel, Alignment.MIDDLE_LEFT);

    contentPanel = new ContentPanel(this);
    h.addComponent(contentPanel);
    h.setComponentAlignment(contentPanel, Alignment.TOP_CENTER);

    Panel middlePanel = new Panel();
    middlePanel.setContent(h);

    return middlePanel;
}

From source file:foo.MyVaadinApplication.java

License:Apache License

/**
 * Initializes the top banner//  w  w w .ja  va  2  s  .  c  o m
 * 
 * @return initialized top banner
 */
private Panel initTopBanner() {
    Panel topBanner = new Panel();
    topBanner.setWidth("100%");

    String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();

    FileResource resource = new FileResource(new File(basepath + "/WEB-INF/images/topBannerPlaceholder.png"));

    Embedded image = new Embedded("", resource);

    VerticalLayout v = new VerticalLayout();
    v.addComponent(image);
    topBanner.setContent(v);

    return topBanner;
}

From source file:foo.MyVaadinApplication.java

License:Apache License

/**
 * Initializes the bottom banner/*from   w w w  .j ava 2  s  .  c o m*/
 * 
 * @return initialized bottom banner
 */
private Panel initBottomBanner() {
    Panel bottomBanner = new Panel();
    bottomBanner.setWidth("100%");

    String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();

    FileResource resource = new FileResource(
            new File(basepath + "/WEB-INF/images/bottomBannerPlaceholder.png"));

    Embedded image = new Embedded("", resource);

    VerticalLayout v = new VerticalLayout();
    v.addComponent(image);
    bottomBanner.setContent(v);

    return bottomBanner;
}

From source file:fr.amapj.view.engine.tools.BaseUiTools.java

License:Open Source License

/**
 * Cre un Panel avec un VerticalLayout  l'intrieur 
 * /*ww  w  . j  ava 2  s . c o m*/
 * @param layout
 * @param styleName
 * @return
 */
static public VerticalLayout addPanel(Layout layout, String styleName) {
    Panel p0 = new Panel();
    p0.setWidth("100%");
    p0.addStyleName(styleName);

    VerticalLayout vl1 = new VerticalLayout();
    vl1.setMargin(true);
    p0.setContent(vl1);
    layout.addComponent(p0);

    return vl1;
}

From source file:fr.amapj.view.engine.tools.BaseUiTools.java

License:Open Source License

/**
 * Permet de crer un bandeau, c'est  dire avec un texte avec un fond, et ceci sur toute la longueur 
 * //w w w.j  av  a2s.c o  m
 */
static public Label addBandeau(Layout layout, String content, String styleName) {
    Label l = new Label(content);
    l.setWidth("100%");

    Panel p1 = new Panel();
    p1.setContent(l);
    p1.addStyleName("bandeau-" + styleName);

    layout.addComponent(p1);

    return l;
}

From source file:fr.amapj.view.views.advanced.devtools.DevToolsView.java

License:Open Source License

@Override
public void enterIn(ViewChangeEvent event) {
    boolean allowTimeControl = AppConfiguration.getConf().isAllowTimeControl();
    boolean allowMailControl = AppConfiguration.getConf().isAllowMailControl();

    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");

    addLabel(this, "Outils pour le developpement", "titre");

    // Partie date 
    HorizontalLayout hl = new HorizontalLayout();
    hl.addComponent(new Label("Date et heure courante :"));
    String valDate = df.format(DateUtils.getDate());
    labelDateHeure = new Label(valDate);
    hl.addComponent(labelDateHeure);//  ww w  . j  a  va2  s.  co m
    if (allowTimeControl == true) {

        textDateHeure = new TextField();
        textDateHeure.setWidth("200px");
        textDateHeure.setValue(valDate);
        hl.addComponent(textDateHeure);

        Button b = new Button("Control time");
        hl.addComponent(b);
        b.addClickListener(e -> controlTime());
    }

    addComponent(hl);

    //
    addLabel(this, "Nombre d'emails envoys aujourd'hui : " + MailerCounter.getNbMails());

    if (allowMailControl == true) {

        Button b = new Button("Visualiser tous les mails locaux");
        this.addComponent(b);
        b.addClickListener(e -> controlMail());
    }

    Panel devToolsPanel = new Panel("Outils de dveloppement");
    devToolsPanel.addStyleName("action");
    devToolsPanel.setContent(getDevToolsPanel());

    addComponent(devToolsPanel);

}

From source file:fr.amapj.view.views.advanced.maintenance.MaintenanceView.java

License:Open Source License

@Override
public void enterIn(ViewChangeEvent event) {
    boolean adminFull = SessionManager.getSessionParameters().isAdminFull();

    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");

    addLabel(this, "Maintenance du systme", "titre");

    // Partie date 
    addLabel(this, "Date et heure courante :" + df.format(DateUtils.getDate()));
    addLabel(this, "Version de l'application : " + new MaintenanceService().getVersion());
    addLabel(this, "Nombre d'emails envoys aujourd'hui : " + MailerCounter.getNbMails());

    Panel backupPanel = new Panel("Sauvegarde de la base et envoi par e mail");
    backupPanel.addStyleName("action");
    backupPanel.setContent(getBackupPanel());

    Panel diversPanel = new Panel("Outils d'admin");
    diversPanel.addStyleName("action");
    diversPanel.setContent(getDiversPanel());

    addComponent(backupPanel);/*w ww  .  j  ava  2s . c om*/
    addEmptyLine(this);

    //
    if (adminFull) {
        addComponent(diversPanel);
    }

}