Example usage for com.vaadin.ui HorizontalLayout setWidth

List of usage examples for com.vaadin.ui HorizontalLayout setWidth

Introduction

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

Prototype

@Override
    public void setWidth(float width, Unit unit) 

Source Link

Usage

From source file:com.klwork.explorer.ui.task.TaskEventsPanel.java

License:Apache License

protected void addInputField() {
    HorizontalLayout hLayout = new HorizontalLayout();
    hLayout.setSpacing(true);//from w  ww.j a  va 2s.co  m
    hLayout.setWidth(100, Unit.PERCENTAGE);
    pMainContent.addComponent(hLayout);
    //?
    initAddEventInput(hLayout);

    Button addCommentButton = new Button(i18nManager.getMessage(Messages.TASK_ADD_COMMENT));
    hLayout.addComponent(addCommentButton);
    hLayout.setComponentAlignment(addCommentButton, Alignment.MIDDLE_LEFT);
    addCommentButton.addListener(new ClickListener() {
        public void buttonClick(ClickEvent event) {
            addNewComment(commentInputField.getValue().toString());
        }
    });
}

From source file:com.klwork.explorer.ui.task.TaskInvolvedPeopleComponent.java

License:Apache License

protected void initHeader() {
    HorizontalLayout headerLayout = new HorizontalLayout();
    headerLayout.setWidth(100, Unit.PERCENTAGE);
    layout.addComponent(headerLayout);//from  ww w. j  av  a  2 s .  c  om

    initTitle(headerLayout);
    initAddPeopleButton(headerLayout);
}

From source file:com.klwork.explorer.ui.user.ProfilePanel.java

License:Apache License

protected void initAboutSection() {
    // Header/*w  w  w. j a  v a  2 s . c  om*/
    HorizontalLayout header = new HorizontalLayout();
    header.setWidth(100, Unit.PERCENTAGE);
    header.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
    infoPanelLayout.addComponent(header);

    Label aboutLabel = createProfileHeader(i18nManager.getMessage(Messages.PROFILE_ABOUT));
    header.addComponent(aboutLabel);
    header.setExpandRatio(aboutLabel, 1.0f);

    // only show edit/save buttons if current user matches
    if (isCurrentLoggedInUser) {
        Button actionButton = null;
        if (!editable) {
            actionButton = initEditProfileButton();
        } else {
            actionButton = initSaveProfileButton();
        }
        header.addComponent(actionButton);
        header.setComponentAlignment(actionButton, Alignment.MIDDLE_RIGHT);
    }

    // 'About' fields
    GridLayout aboutLayout = createInfoSectionLayout(2, 4);

    // Name
    if (!editable && (isDefined(user.getFirstName()) || isDefined(user.getLastName()))) {
        addProfileEntry(aboutLayout, i18nManager.getMessage(Messages.PROFILE_NAME),
                user.getFirstName() + " " + user.getLastName());
    } else if (editable) {
        firstNameField = new TextField();
        firstNameField.focus();
        addProfileInputField(aboutLayout, i18nManager.getMessage(Messages.PROFILE_FIRST_NAME), firstNameField,
                user.getFirstName());
        lastNameField = new TextField();
        addProfileInputField(aboutLayout, i18nManager.getMessage(Messages.PROFILE_LAST_NAME), lastNameField,
                user.getLastName());
    }

    // Job title
    if (!editable && isDefined(jobTitle)) {
        addProfileEntry(aboutLayout, i18nManager.getMessage(Messages.PROFILE_JOBTITLE), jobTitle);
    } else if (editable) {
        jobTitleField = new TextField();
        addProfileInputField(aboutLayout, i18nManager.getMessage(Messages.PROFILE_JOBTITLE), jobTitleField,
                jobTitle);
    }

    // Birthdate
    if (!editable && isDefined(birthDate)) {
        addProfileEntry(aboutLayout, i18nManager.getMessage(Messages.PROFILE_BIRTHDATE), birthDate);
    } else if (editable) {
        birthDateField = new DateField();
        birthDateField.setDateFormat(Constants.DEFAULT_DATE_FORMAT);
        birthDateField.setResolution(DateField.RESOLUTION_DAY);
        try {
            birthDateField.setValue(new SimpleDateFormat(Constants.DEFAULT_DATE_FORMAT).parse(birthDate));
        } catch (Exception e) {
        } // do nothing
        addProfileInputField(aboutLayout, i18nManager.getMessage(Messages.PROFILE_BIRTHDATE), birthDateField,
                null);
    }

    // Location
    if (!editable && isDefined(location)) {
        addProfileEntry(aboutLayout, i18nManager.getMessage(Messages.PROFILE_LOCATION), location);
    } else if (editable) {
        locationField = new TextField();
        addProfileInputField(aboutLayout, i18nManager.getMessage(Messages.PROFILE_LOCATION), locationField,
                location);
    }
}

From source file:com.lizardtech.expresszip.vaadin.FindLayersViewComponent.java

License:Apache License

public FindLayersViewComponent() {

    treeTable = new ExpressZipTreeTable();
    popupTable = new ExpressZipTreeTable();
    configureTable(treeTable);/*from w w w .j  ava 2s.  co  m*/

    popupSelectionListener = new Property.ValueChangeListener() {
        private static final long serialVersionUID = 625365970493526725L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            // the current popup selection
            Set<ExpressZipLayer> popupSelection = (Set<ExpressZipLayer>) event.getProperty().getValue();

            // get the tree's current selection
            HashSet<ExpressZipLayer> treeSelection = new HashSet<ExpressZipLayer>(
                    (Set<ExpressZipLayer>) treeTable.getValue());

            // remove all items in common with popup
            treeSelection.removeAll(popupTable.getItemIds());

            // set the treeTable selection to the union
            Set<ExpressZipLayer> unionSelection = new HashSet<ExpressZipLayer>();
            unionSelection.addAll(popupSelection);
            unionSelection.addAll(treeSelection);
            treeTable.setValue(unionSelection);
        }
    };
    popupTable.addListener(popupSelectionListener);

    treeTable.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = 6236114836521221107L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            Set<ExpressZipLayer> highlightedLayers = (Set<ExpressZipLayer>) event.getProperty().getValue();
            for (FindLayersViewListener listener : listeners) {
                listener.layerHighlightedEvent(highlightedLayers);
            }

            // reset selection of popup table
            popupTable.removeListener(popupSelectionListener);

            // intersection of treeTable's selection and popupTable items
            Set<ExpressZipLayer> popupSelection = new HashSet<ExpressZipLayer>();
            popupSelection.addAll(highlightedLayers);
            popupSelection.retainAll(popupTable.getItemIds());
            popupTable.setValue(popupSelection);

            popupTable.addListener(popupSelectionListener);
        }
    });
    configureTable(popupTable);

    filter = new Filter(this);
    filterButtonListener = new FilterListeners();
    axisSelectedListener = new AxisSelected();
    listeners = new ArrayList<FindLayersViewListener>();
    btnNext = new ExpressZipButton("Next", Style.STEP);
    btnBack = new ExpressZipButton("Back", Style.STEP);

    btnAddFilter = new ExpressZipButton("Add Filter", Style.ACTION);
    btnAddFilter.addStyleName("filter-flow");

    hshFilterButtons = new HashMap<Button, FilterObject>();
    cssLayers = new CssLayout();

    basemapSelector = new ComboBox();
    basemapSelector.setWidth(100.0f, UNITS_PERCENTAGE);
    basemapSelector.setTextInputAllowed(false);
    basemapSelector.setImmediate(true);
    basemapSelector.setNullSelectionAllowed(false);
    basemapSelector.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = -7358667131762099215L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            ProjectedLayer l = (ProjectedLayer) basemapSelector.getValue();
            boolean enableCheckbox = false;
            if (l instanceof WebMapServiceLayer) {
                for (ExpressZipLayer local : mapModel.getLocalBaseLayers()) {
                    if (l.toString().equals(local.getName())) {
                        enableCheckbox = true;
                        break;
                    }
                }
            }
            includeBasemap.setEnabled(enableCheckbox);
            if (!enableCheckbox) {
                includeBasemap.setValue(false);
            }

            if (mapModel.getBaseLayerTerms(l) != null && !mapModel.getBaseLayerTermsAccepted(l)) {
                final Window modal = new Window("Terms of Use");
                modal.setModal(true);
                modal.setClosable(false);
                modal.setResizable(false);
                modal.getContent().setSizeUndefined(); // trick to size around content
                Button bOK = new ExpressZipButton("OK", Style.ACTION, new ClickListener() {
                    private static final long serialVersionUID = -2872178665349848542L;

                    @Override
                    public void buttonClick(ClickEvent event) {
                        ProjectedLayer l = (ProjectedLayer) basemapSelector.getValue();
                        mapModel.setBaseLayerTermsAccepted(l);
                        for (FindLayersViewListener listener : listeners)
                            listener.baseMapChanged(l);
                        ((ExpressZipWindow) getApplication().getMainWindow()).removeWindow(modal);
                    }
                });
                Button bCancel = new ExpressZipButton("Cancel", Style.ACTION, new ClickListener() {
                    private static final long serialVersionUID = -3044064554876422836L;

                    @Override
                    public void buttonClick(ClickEvent event) {
                        basemapSelector.select(mapModel.getBaseLayers().get(0));
                        ((ExpressZipWindow) getApplication().getMainWindow()).removeWindow(modal);
                    }
                });
                HorizontalLayout buttons = new HorizontalLayout();
                buttons.setSpacing(true);
                buttons.addComponent(bOK);
                buttons.addComponent(bCancel);
                Label termsText = new Label(mapModel.getBaseLayerTerms(l));
                termsText.setContentMode(Label.CONTENT_XHTML);
                VerticalLayout vlay = new VerticalLayout();
                vlay.addComponent(termsText);
                vlay.addComponent(buttons);
                vlay.setComponentAlignment(buttons, Alignment.MIDDLE_RIGHT);
                vlay.setWidth(400, UNITS_PIXELS);
                modal.getContent().addComponent(vlay);
                ((ExpressZipWindow) getApplication().getMainWindow()).addWindow(modal);
            } else {
                for (FindLayersViewListener listener : listeners)
                    listener.baseMapChanged(l);
            }
        }
    });

    includeBasemap = new CheckBox();
    includeBasemap.setDescription("Include this basemap in the exported image.");
    includeBasemap.setWidth(64f, UNITS_PIXELS);

    HorizontalLayout basemapLayout = new HorizontalLayout();
    basemapLayout.setWidth(100f, UNITS_PERCENTAGE);

    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSizeFull();
    setSizeFull();

    Label step = new Label("Step 1: Select Layers");
    step.addStyleName("step");
    layout.addComponent(step);

    layout.addComponent(treeTable);
    layout.setSpacing(true);
    treeTable.setSizeFull();
    layout.setExpandRatio(treeTable, 1f);

    layout.addComponent(new Panel(BASEMAP, basemapLayout));
    basemapLayout.addComponent(basemapSelector);
    basemapLayout.setExpandRatio(basemapSelector, 1f);
    basemapLayout.addComponent(includeBasemap);

    layout.addComponent(cssLayers);
    cssLayers.addComponent(btnAddFilter);

    HorizontalLayout backSubmitLayout = new HorizontalLayout();
    backSubmitLayout.setWidth("100%");
    backSubmitLayout.addComponent(btnBack);
    backSubmitLayout.addComponent(btnNext);
    backSubmitLayout.setComponentAlignment(btnBack, Alignment.BOTTOM_LEFT);
    backSubmitLayout.setComponentAlignment(btnNext, Alignment.BOTTOM_RIGHT);

    VerticalLayout navLayout = new VerticalLayout();
    navLayout.addComponent(backSubmitLayout);
    navLayout.setSpacing(true);

    ThemeResource banner = new ThemeResource("img/ProgressBar1.png");
    navLayout.addComponent(new Embedded(null, banner));

    layout.addComponent(navLayout);
    layout.setComponentAlignment(navLayout, Alignment.BOTTOM_CENTER);

    btnNext.addListener(this);
    btnNext.setEnabled(false);
    btnBack.setEnabled(false); // always disabled
    btnAddFilter.addListener(this);

    layout.addStyleName("findlayers");
    setCompositionRoot(layout);
}

From source file:com.lizardtech.expresszip.vaadin.SetupMapViewComponent.java

License:Apache License

public SetupMapViewComponent() {

    listeners = new ArrayList<SetupMapViewListener>();
    cmbProjection = new ComboBox();
    cmbProjection.setTextInputAllowed(false);
    HorizontalLayout projectionLayout = new HorizontalLayout();
    projectionLayout.addComponent(cmbProjection);
    projectionLayout.setWidth(100f, UNITS_PERCENTAGE);

    setSizeFull();/*from  w  w w  .  java 2  s.  co m*/

    // main layout
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSizeFull();

    // instruction banner
    Label step = new Label("Step 2: Select Export Region");
    step.addStyleName("step");
    layout.addComponent(step);

    //
    // setup tree data source
    //
    treeHier = new HierarchicalContainer();
    treeHier.addContainerProperty(ExpressZipTreeTable.LAYER, ExpressZipLayer.class, null);
    treeHier.addContainerProperty(DRAG_PROPERTY, Embedded.class, null);

    // table holding layers
    treeTable = new ExpressZipTreeTable();
    treeTable.setContainerDataSource(treeHier);

    treeTable.setDragMode(TableDragMode.ROW);
    treeTable.setColumnHeaders(new String[] { ExpressZipTreeTable.LAYER, "" });
    treeTable.setColumnExpandRatio(ExpressZipTreeTable.LAYER, 1);
    treeTable.setColumnWidth(DRAG_PROPERTY, 23);

    // upload shape file
    btnUploadShapeFile.setFieldType(FieldType.BYTE_ARRAY);
    btnUploadShapeFile.setButtonCaption("");
    btnUploadShapeFile.setSizeUndefined();
    btnUploadShapeFile.addStyleName("shapefile");

    // remove shape file
    btnRemoveShapeFile.addListener(this);
    btnRemoveShapeFile.setSizeUndefined();
    btnRemoveShapeFile.setVisible(false);
    btnRemoveShapeFile.setIcon(new ThemeResource("img/RemoveShapefileStandard23px.png"));
    btnRemoveShapeFile.setStyleName(BaseTheme.BUTTON_LINK);
    btnRemoveShapeFile.addStyleName("shapefile");
    HorizontalLayout hznUpload = new HorizontalLayout();

    Panel coordPanel = new Panel("Export Extent");

    layout.addComponent(treeTable);
    layout.addComponent(new Panel(PROJECTION, projectionLayout));
    layout.addComponent(new Panel(SHAPEFILE_UPLOAD, hznUpload));
    layout.addComponent(coordPanel);

    layout.setSpacing(true);

    hznUpload.addComponent(btnUploadShapeFile);
    hznUpload.addComponent(btnRemoveShapeFile);
    hznUpload.addComponent(lblCurrentShapeFile);
    hznUpload.setExpandRatio(lblCurrentShapeFile, 1f);
    hznUpload.setComponentAlignment(lblCurrentShapeFile, Alignment.MIDDLE_LEFT);
    hznUpload.setWidth("100%");

    cmbProjection.setWidth("100%");

    topTextField.setWidth(150, UNITS_PIXELS);
    topTextField.setImmediate(true);
    topTextField.setRequired(true);
    topTextField.addListener(topListener);

    leftTextField.setWidth(150, UNITS_PIXELS);
    leftTextField.setImmediate(true);
    leftTextField.setRequired(true);
    leftTextField.addListener(leftListener);

    bottomTextField.setWidth(150, UNITS_PIXELS);
    bottomTextField.setImmediate(true);
    bottomTextField.setRequired(true);
    bottomTextField.addListener(bottomListener);

    rightTextField.setWidth(150, UNITS_PIXELS);
    rightTextField.setImmediate(true);
    rightTextField.setRequired(true);
    rightTextField.addListener(rightListener);

    VerticalLayout coordLayout = new VerticalLayout();
    coordLayout.setSizeFull();
    coordPanel.setContent(coordLayout);
    coordLayout.addComponent(topTextField);

    HorizontalLayout leftRightLayout = new HorizontalLayout();
    leftRightLayout.setWidth("100%");
    leftRightLayout.addComponent(leftTextField);
    leftRightLayout.addComponent(rightTextField);
    leftRightLayout.setComponentAlignment(leftTextField, Alignment.MIDDLE_LEFT);
    leftRightLayout.setComponentAlignment(rightTextField, Alignment.MIDDLE_RIGHT);
    coordLayout.addComponent(leftRightLayout);

    coordLayout.addComponent(bottomTextField);
    coordLayout.setComponentAlignment(topTextField, Alignment.TOP_CENTER);
    coordLayout.setComponentAlignment(bottomTextField, Alignment.BOTTOM_CENTER);

    btnNext = new ExpressZipButton("Next", Style.STEP, this);
    btnBack = new ExpressZipButton("Back", Style.STEP, this);

    HorizontalLayout backNextLayout = new HorizontalLayout();
    backNextLayout.addComponent(btnBack);
    backNextLayout.addComponent(btnNext);
    btnNext.setEnabled(false);

    backNextLayout.setComponentAlignment(btnBack, Alignment.BOTTOM_LEFT);
    backNextLayout.setComponentAlignment(btnNext, Alignment.BOTTOM_RIGHT);
    backNextLayout.setWidth("100%");

    VerticalLayout navLayout = new VerticalLayout();
    navLayout.addComponent(backNextLayout);
    navLayout.setSpacing(true);

    ThemeResource banner = new ThemeResource("img/ProgressBar2.png");
    navLayout.addComponent(new Embedded(null, banner));

    layout.addComponent(navLayout);
    layout.setComponentAlignment(navLayout, Alignment.BOTTOM_CENTER);

    layout.setExpandRatio(treeTable, 1.0f);
    setCompositionRoot(layout);

    // notify when selection changes
    treeTable.addListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            for (SetupMapViewListener listener : listeners) {
                listener.layersSelectedEvent((Set<ExpressZipLayer>) treeTable.getValue());
            }

        }
    });
    treeTable.addActionHandler(this);
    treeHier.removeAllItems();

    //
    // drag n' drop behavior
    //
    treeTable.setDropHandler(new DropHandler() {
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }

        // Make sure the drag source is the same tree
        public void drop(DragAndDropEvent event) {
            // Wrapper for the object that is dragged
            Transferable t = event.getTransferable();

            // Make sure the drag source is the same tree
            if (t.getSourceComponent() != treeTable)
                return;

            AbstractSelectTargetDetails target = (AbstractSelectTargetDetails) event.getTargetDetails();

            // Get ids of the dragged item and the target item
            Object sourceItemId = t.getData("itemId");
            Object targetItemId = target.getItemIdOver();

            // if we drop on ourselves, ignore
            if (sourceItemId == targetItemId)
                return;

            // On which side of the target the item was dropped
            VerticalDropLocation location = target.getDropLocation();

            // place source after target
            treeHier.moveAfterSibling(sourceItemId, targetItemId);

            // if top, switch them
            if (location == VerticalDropLocation.TOP) {
                treeHier.moveAfterSibling(targetItemId, sourceItemId);
            }

            Collection<ExpressZipLayer> layers = (Collection<ExpressZipLayer>) treeHier.rootItemIds();
            for (SetupMapViewListener listener : listeners)
                listener.layerMovedEvent(layers);
        }
    });

    cmbProjection.setImmediate(true);
    cmbProjection.setNullSelectionAllowed(false);
    cmbProjection.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = -5188369735622627751L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            if (cmbProjection.getValue() != null) {
                selectedEpsg = (String) cmbProjection.getValue();
                String currentProjection = ((ExpressZipWindow) getApplication().getMainWindow())
                        .getExportProps().getMapProjection();
                if (!selectedEpsg.equals(currentProjection))
                    for (SetupMapViewListener listener : new ArrayList<SetupMapViewListener>(listeners))
                        listener.projectionChangedEvent(selectedEpsg);
            }
        }
    });
}

From source file:com.m1kah.ui.TodoComponent.java

License:Open Source License

private void initFooter() {
    itemsLeftLabel = new Label("0 items left");
    filterOptionGroup = new OptionGroup();
    filterOptionGroup.setId("filter-radio");
    for (TodoFilter todoFilter : TodoFilter.values()) {
        filterOptionGroup.addItem(todoFilter);
    }/*  w  w w  . j  ava 2s  . c  om*/
    filterOptionGroup.setValue(filter);
    clearCompletedButton = new Button("Clear completed");

    HorizontalLayout footerLayout = new HorizontalLayout(itemsLeftLabel, filterOptionGroup,
            clearCompletedButton);
    footerLayout.setWidth(100.0f, Unit.PERCENTAGE);
    footerLayout.setComponentAlignment(itemsLeftLabel, Alignment.MIDDLE_LEFT);
    footerLayout.setComponentAlignment(filterOptionGroup, Alignment.MIDDLE_CENTER);
    footerLayout.setComponentAlignment(clearCompletedButton, Alignment.MIDDLE_RIGHT);
    footerLayout.setExpandRatio(itemsLeftLabel, 0.25f);
    footerLayout.setExpandRatio(filterOptionGroup, 0.5f);
    footerLayout.setExpandRatio(clearCompletedButton, 0.25f);
    addComponent(footerLayout);
}

From source file:com.naoset.framework.frontend.view.window.DialogWindow.java

private HorizontalLayout buildFooter() {
    HorizontalLayout layout = new HorizontalLayout();
    layout.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    layout.setWidth(100.0f, Unit.PERCENTAGE);
    return layout;
}

From source file:com.naoset.framework.frontend.view.window.Window.java

private HorizontalLayout buildFooter() {
    HorizontalLayout layout = new HorizontalLayout();
    layout.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    layout.setWidth(100.0f, Unit.PERCENTAGE);

    //Si el objeto a mostrar hereda de Widget, mostraremos su cabecera con el men en la ventana.
    if (Widget.class.isInstance(body)) {
        //if (details.getClass().isInstance(Widget.class)) {
        Widget aux = (Widget) body;/*ww w .j  a  va  2s .co  m*/
        HorizontalLayout header = aux.getHeader();
        header.setWidth(100.0f, Unit.PERCENTAGE);
        layout.addComponent(header);
        //layout.setComponentAlignment(header, Alignment.TOP_LEFT);
        layout.setExpandRatio(header, 1);
    }

    Button ok = new Button("Cerrar");
    ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
    ok.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final Button.ClickEvent event) {
            Boolean canClose = true;
            if (Widget.class.isInstance(body)) {
                Widget aux = (Widget) body;
                canClose = !aux.isModified();
            }
            if (canClose) {
                close();
            } else {

                buildConfirmCloseDialog();

            }

        }
    });
    ok.focus();
    layout.addComponent(ok);
    layout.setComponentAlignment(ok, Alignment.TOP_RIGHT);
    return layout;
}

From source file:com.neatresults.mgnltweaks.neatu2b.ui.form.field.U2BField.java

License:Open Source License

/**
 * Initialize the field. <br>/*from www  .j  av a2  s  . c om*/
 * Create as many configured Field as we have related values already stored.
 */
@Override
protected void initFields(final PropertysetItem newValue) {
    root.removeAllComponents();
    final TextField id = createTextField("Id", newValue);
    root.addComponent(id);
    final TextField title = createTextField("Title", newValue);
    root.addComponent(title);

    final TextFieldDefinition def = new TextFieldBuilder("description").label("Description").rows(3)
            .definition();
    final TextArea description = (TextArea) createLocalField(def, newValue.getItemProperty(def.getName()),
            false);
    newValue.addItemProperty(def.getName(), description.getPropertyDataSource());
    description.setNullRepresentation("");
    description.setWidth("100%");
    description.setNullSettingAllowed(true);
    root.addComponent(description);

    HorizontalLayout ddLine = new HorizontalLayout();
    final TextField publishedAt = createTextField("Published", newValue);
    ddLine.addComponent(publishedAt);
    final TextField duration = createTextField("Duration", newValue);
    ddLine.addComponent(duration);
    ddLine.addComponent(createTextField("Definition", newValue));

    Button fetchButton = new Button("Fetch metadata");
    fetchButton.addStyleName("magnoliabutton");
    fetchButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {

            String idStr = id.getValue();
            // extract id from url when whole url is passed
            if (idStr.startsWith("http")) {
                idStr = StringUtils.substringBefore(StringUtils.substringAfter(idStr, "?v="), "&");
            }

            U2BService service = null;
            try {
                RestEasyClient client = (RestEasyClient) restClientRegistry.getRestClient("youtube");
                service = client.getClientService(U2BService.class);
            } catch (RegistrationException e) {
                log.error("Failed to get a client for [" + U2BService.class.getName() + "] with: "
                        + e.getMessage(), e);
            }
            if (service != null) {
                String key = u2bModule.getGoogleKey();
                JsonNode response = service.meta(idStr, "snippet", key);
                try {
                    if (response.get("items").getElements().hasNext()) {
                        JsonNode videoItem = response.get("items").getElements().next();
                        String descriptionStr = videoItem.get("snippet").get("description").getTextValue();
                        newValue.getItemProperty("description").setValue(descriptionStr);
                        String titleStr = videoItem.get("snippet").get("title").getTextValue();
                        newValue.getItemProperty("title").setValue(titleStr);
                        Iterator<Entry<String, JsonNode>> thumbs = videoItem.get("snippet").get("thumbnails")
                                .getFields();
                        while (thumbs.hasNext()) {
                            Entry<String, JsonNode> entry = thumbs.next();
                            newValue.getItemProperty(entry.getKey() + "Url")
                                    .setValue(entry.getValue().get("url").getTextValue());
                            newValue.getItemProperty(entry.getKey() + "Width")
                                    .setValue("" + entry.getValue().get("width").getLongValue());
                            newValue.getItemProperty(entry.getKey() + "Height")
                                    .setValue("" + entry.getValue().get("height").getLongValue());
                        }
                        String publishedAtStr = videoItem.get("snippet").get("publishedAt").getTextValue();
                        newValue.getItemProperty("published").setValue(publishedAtStr);
                    }
                } catch (Exception e) {
                    log.error("Failed to parse the video metadata.", e);
                }

                response = service.meta(idStr, "contentDetails", key);
                try {
                    if (response.get("items").getElements().hasNext()) {
                        JsonNode videoItem = response.get("items").getElements().next();
                        String durationStr = videoItem.get("contentDetails").get("duration").getTextValue();
                        newValue.getItemProperty("duration").setValue(durationStr);
                        String definition = videoItem.get("contentDetails").get("definition").getTextValue();
                        newValue.getItemProperty("definition").setValue(definition);
                    }
                } catch (Exception e) {
                    log.error("Failed to parse the video duration.", e);
                }
            }
        }
    });

    ddLine.addComponent(fetchButton);
    ddLine.setWidth(100, Unit.PERCENTAGE);
    ddLine.setHeight(-1, Unit.PIXELS);
    ddLine.setComponentAlignment(fetchButton, Alignment.BOTTOM_RIGHT);
    root.addComponent(ddLine);

    PropertysetItem item = (PropertysetItem) getPropertyDataSource().getValue();
    root.addComponent(createEntryComponent("default", item), root.getComponentCount() - 1);
    root.addComponent(createEntryComponent("standard", item), root.getComponentCount() - 1);
    root.addComponent(createEntryComponent("medium", item), root.getComponentCount() - 1);
    root.addComponent(createEntryComponent("high", item), root.getComponentCount() - 1);
    root.addComponent(createEntryComponent("maxres", item), root.getComponentCount() - 1);
}

From source file:com.neatresults.mgnltweaks.neatu2b.ui.form.field.U2BField.java

License:Open Source License

/**
 * Create a single element.<br>/*from   w w w.j a  v  a  2  s  .co  m*/
 * This single element is composed of:<br>
 * - a configured field <br>
 * - a remove Button<br>
 */
private Component createEntryComponent(String propertyId, PropertysetItem newValue) {
    String cappedId = StringUtils.capitalize(propertyId);
    final HorizontalLayout layout = new HorizontalLayout();
    layout.setWidth(100, Unit.PERCENTAGE);
    layout.setHeight(-1, Unit.PIXELS);
    TextField url = createTextField(cappedId + " Thumbnail", newValue, propertyId + "Url");
    layout.addComponent(url);

    TextField width = createTextField("Width", newValue, propertyId + "Width");
    layout.addComponent(width);
    TextField height = createTextField("Height", newValue, propertyId + "Height");
    layout.addComponent(height);
    layout.setExpandRatio(url, .7f);
    layout.setExpandRatio(width, .15f);
    layout.setExpandRatio(height, .15f);

    return layout;
}