Example usage for com.google.gwt.user.client.ui Label Label

List of usage examples for com.google.gwt.user.client.ui Label Label

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Label Label.

Prototype

protected Label(Element element) 

Source Link

Document

This constructor may be used by subclasses to explicitly use an existing element.

Usage

From source file:burrito.client.crud.input.ReadOnlyTextCrudInputField.java

License:Apache License

public ReadOnlyTextCrudInputField(CrudField field) {
    this.field = field;

    String value = null;/* w w  w  .  j  a v a2s  .  c  o  m*/

    //Perhaps add a getReadOnlyHTML() method on CrudField? 
    //That way we would get better outputs than just toString()

    Object objectValue = field.getValue();
    if (objectValue != null) {
        value = objectValue.toString();
    }

    label = new Label(value != null ? value : "(Not set)");
    label.addStyleName("k5-ReadOnlyTextCrudInputField");
    label.addStyleName("readOnly");
}

From source file:burrito.client.crud.widgets.EmbeddedListWidget.java

License:Apache License

public EmbeddedListWidget(String embeddedClassName, boolean required) {
    this.embeddedClassNameUnderscore = embeddedClassName.replace('.', '_');
    this.embeddedClassName = embeddedClassName;
    this.required = required;
    validationError.addStyleName("validationError");
    validationError.setVisible(false);//from  w ww .  j  a v  a 2  s.  com
    wrapper.add(validationError);
    wrapper.add(tablePlaceHolder);
    tablePlaceHolder.setWidget(new Label(
            labels.noEmbeddedItemsAdded(CrudLabelHelper.getString(embeddedClassNameUnderscore + "_plural"))));
    add = new Anchor(CrudLabelHelper.getString(embeddedClassNameUnderscore + "_new"));
    add.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            showPopup();
        }
    });
    wrapper.add(add);
    initWidget(wrapper);
}

From source file:burrito.client.crud.widgets.EmbeddedListWidget.java

License:Apache License

private void reloadTable() {
    // Check if value is empty
    if (currentValue == null || currentValue.isEmpty()) {
        tablePlaceHolder.setWidget(new Label(labels
                .noEmbeddedItemsAdded(CrudLabelHelper.getString(embeddedClassNameUnderscore + "_plural"))));
        return;// w  ww.  j  a v a2s . com
    }

    tablePlaceHolder.setWidget(new Label(labels.loading()));

    // Fetch the first row to figure out how to create the table
    CrudEntityDescription nr1 = currentValue.get(0);

    Table<CrudEntityDescription> table = new Table<CrudEntityDescription>(nr1.getFields().size(), true, true,
            true) {

        @Override
        protected void doLoad(PageMetaData<String> p,
                final Table.LoadedCallback<CrudEntityDescription> callback) {
            // nevermind the page info, display all values
            ItemCollection<CrudEntityDescription> coll = new ItemCollection<CrudEntityDescription>(currentValue,
                    false, p.getPage(), p.getItemsPerPage());
            callback.onReady(coll);
        }
    };
    for (CrudField field : nr1.getFields()) {
        String header = CrudLabelHelper.getString(nr1.getEntityName().replace('.', '_') + "_" + field.getName(),
                field.getName());
        table.addHeader(new Header(header));
    }
    for (int i = 0; i < nr1.getFields().size(); i++) {
        final int indexInside = i;
        table.addCellRenderer(new CellRenderer<CrudEntityDescription>() {

            public Widget render(CrudEntityDescription modelObj) {
                CrudField cf = modelObj.getFields().get(indexInside);
                if (cf.getValue() == null) {
                    return new Label();
                }
                if (cf instanceof ImageField) {
                    ImageField imgField = (ImageField) cf;
                    Image image = new Image(
                            imgField.getValue().toString().replace("/images/view/", "/images/view/thumb_"));
                    image.setWidth("100px");
                    return image;
                }
                return new Label(String.valueOf(cf.getValue()));
            }
        });
    }
    table.addBatchAction(new BatchAction<CrudEntityDescription>(labels.delete(), labels.deleteEmbeddedItem()) {

        public void performAction(List<CrudEntityDescription> selected, AsyncCallback<Void> callback) {
            currentValue.removeAll(selected);
            reloadTable();
        }

        public String getSuccessText(List<CrudEntityDescription> removed) {
            return labels.embeddedItemsDeleted(
                    CrudLabelHelper.getString(embeddedClassNameUnderscore + "_plural"), removed.size());
        }
    });
    table.setRowOrderHandler(new RowOrderHandler<CrudEntityDescription>() {

        public void onRowsReordered(List<CrudEntityDescription> newOrder) {
            currentValue = newOrder;
        }
    });
    table.setRowEditHandler(new RowEditHandler<CrudEntityDescription>() {

        public void onRowEditClicked(CrudEntityDescription obj) {
            final CrudEntityEdit panel = new CrudEntityEdit(obj) {
                @Override
                public void doSave(SaveCallback saveCallback) {
                    saveCallback.success();
                }
            };
            panel.setSaveCancelListener(new EditForm.SaveCancelListener() {

                public void onSave() {
                    // values are saved in the original description
                    panel.getValue();
                    editPopup.hide();
                    reloadTable();
                }

                public void onPartialSave(String warning) {
                    throw new UnsupportedOperationException();
                }

                public void onCancel() {
                    editPopup.hide();
                }
            });
            editPopup.setWidget(panel);
            editPopup.setText(CrudLabelHelper.getString(embeddedClassNameUnderscore + "_editing"));
            editPopup.center();
            editPopup.show();
        }
    });
    table.render();
    tablePlaceHolder.setWidget(table);

}

From source file:burrito.client.crud.widgets.ImagePicker.java

License:Apache License

public ImagePicker(boolean required, String value, int width, int height) {
    setValue(value);/*from   ww w .  j  a  v  a  2 s  .c  om*/
    this.required = required;
    validationError.addStyleName("validationError");
    validationError.setVisible(false);
    popup = new ImagePickerPopup(width, height);
    previewThumbnail.setSize("120px", "67px");
    previewThumbnail.addStyleName("k5-ImagePicker-thumb");
    previewThumbnail.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (currentImage != null) {
                Window.open(currentImage, "_blank", null);
            }
        }
    });
    popup.addSaveHandler(new ImagePickerPopup.SaveHandler() {

        public void saved(String value) {
            setValue("/images/view/" + value);
        }
    });
    chooseImage.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            popup.center();
            popup.show();
        }
    });
    chooseImage.addStyleName("k5-ImagePicker-choose");

    removeImage.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            setValue(null);
        }
    });

    Label label = new Label(
            height == 0 ? labels.requiredImageWidth(width) : labels.requiredImageSize(width, height));
    label.addStyleName("k5-ImagePicker-description");
    wrapper.add(label);
    wrapper.add(validationError);
    wrapper.add(previewThumbnail);
    wrapper.add(chooseImage);
    wrapper.add(removeImage);
    initWidget(wrapper);
    addStyleName("k5-ImagePicker");
}

From source file:burrito.client.crud.widgets.ImagePickerPopup.java

License:Apache License

/**
 * Creates an {@link ImagePickerPopup} that validates uploaded images
 * against a required width and height. If strict is true then the uploaded
 * image will be validated at exactly that size. If strict is false, then
 * the uploaded image will be validated against a maximum size instead.
 * /*from w  w  w .j a va  2 s  .co  m*/
 * @param width
 * @param height
 * @param strict
 *            whether or not the uploaded image size must strictly be width
 *            x height
 */
public ImagePickerPopup(int width, int height, boolean strict) {
    super(true);
    setText(labels.uploadImage());
    BlobStoreUploader form = new BlobStoreUploader(new AsyncCallback<String>() {

        @Override
        public void onSuccess(String result) {
            saved(result);
        }

        @Override
        public void onFailure(Throwable caught) {
            Window.alert("Failed to store image. Reason: " + caught.getMessage());
            throw new RuntimeException(caught);
        }
    });

    if (strict) {
        wrapper.add(new Label(
                height == 0 ? labels.requiredImageWidth(width) : labels.requiredImageSize(width, height)));
    } else {
        wrapper.add(new Label(labels.maximumImageSize(width, height)));
    }
    wrapper.add(form);
    setWidget(wrapper);
}

From source file:burrito.client.crud.widgets.LinkedEntityWidgetPopup.java

License:Apache License

public LinkedEntityWidgetPopup(final SaveHandler saveHandler) {
    super(false, true);
    setText(labels.createNewLink());//w  w  w  .  java2 s . c o  m
    type.setLabelCreator(new SelectionListLabelCreator<String>() {

        @Override
        public String createLabel(String typeClassName) {
            return CrudLabelHelper.getString(typeClassName.replace('.', '_') + "_singular");
        }
    });
    type.setNullSelectLabel(labels.chooseLinkType());
    type.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            handleTypeChange();
        }
    });

    wrapper.add(new Label(labels.linkText()));
    wrapper.add(linkText);
    wrapper.add(new Label(labels.selectLinkTo()));
    wrapper.add(type);
    wrapper.add(valuesWrapper);

    urlWrapper.setVisible(false);
    urlWrapper.add(new Label(labels.writeOrPasteLink()));
    urlWrapper.add(url);
    wrapper.add(urlWrapper);

    HorizontalPanel hp = new HorizontalPanel();

    hp.add(new Button(labels.save(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            doSave(saveHandler);
        }
    }));
    hp.add(new Button(labels.cancel(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            removeFromParent();
        }
    }));
    wrapper.add(new VerticalSpacer(10));
    wrapper.add(hp);
    setWidget(wrapper);
    addStyleName("k5-LinkedEntityWidget");

    init();
}

From source file:burrito.client.crud.widgets.LinkedEntityWidgetPopup.java

License:Apache License

protected void handleTypeChange() {
    valuesWrapper.clear();//w  w  w. j a  v a  2  s  . co m
    urlWrapper.setVisible(false);
    relationSelectionList = null;
    if (type.getValue() == null) {
        return;
    }
    String typeClassName = type.getValue();
    if (TYPE_ABSOLUTE_URL.equals(typeClassName)) {
        urlWrapper.setVisible(true);
        return;
    }
    relationSelectionList = new RelationSelectionList(false, typeClassName);
    relationSelectionList.setValue(typeIdWaitingToBeSet);
    typeIdWaitingToBeSet = null;
    VerticalPanel vp = new VerticalPanel();
    vp.add(new Label(labels
            .selectLinkToEntity(CrudLabelHelper.getString(typeClassName.replace('.', '_') + "_singular"))));
    vp.add(relationSelectionList);
    valuesWrapper.setWidget(vp);

}

From source file:burrito.client.sitelet.SiteletDragAndDropPanel.java

License:Apache License

public SiteletDragAndDropPanel(final String containerName) {
    super();//from w w w.jav  a  2 s.  c  om
    widgetCreator.setContainerName(containerName);
    Hyperlink addSitelet = new Hyperlink(labels.addSitelet(), "-1");

    wrapper.add(addSitelet);

    saveOrderButton = new Button(labels.saveOrder(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            service.saveSiteletOrder(containerName, currentOrder, new AsyncCallback<Void>() {

                @Override
                public void onSuccess(Void result) {
                    InfoMessagePopup popup = new InfoMessagePopup();
                    popup.setTextAndShow(labels.orderSaved());
                    orderChangedPanel.setVisible(false);
                }

                @Override
                public void onFailure(Throwable caught) {
                    throw new RuntimeException("Failed to save order", caught);
                }
            });

        }
    });
    orderChangedPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    orderChangedPanel.add(new Label(labels.orderChanged()));
    orderChangedPanel.add(new HTML("&nbsp;"));
    orderChangedPanel.add(saveOrderButton);
    orderChangedPanel.setVisible(false);

    service.getSitelets(containerName, new AsyncCallback<List<SiteletDescription>>() {

        @Override
        public void onSuccess(final List<SiteletDescription> result) {
            currentModel = result;
            render();
        }

        @Override
        public void onFailure(Throwable caught) {
            throw new RuntimeException("Failed to load sitelets for container " + containerName, caught);
        }
    });
    wrapper.add(siteletsContainer);
    wrapper.add(orderChangedPanel);
    initWidget(wrapper);
}

From source file:burrito.client.sitelet.SiteletDragAndDropPanel.java

License:Apache License

protected void render() {
    if (currentModel == null || currentModel.isEmpty()) {
        siteletsContainer.setWidget(new Label(labels.noSiteletsHaveBeenAdded()));
    } else {//  ww w.j a  v a  2 s . c o m
        currentOrder = convertToLongList(currentModel);

        sortingPanel = new DragAndDropPanel<SiteletDescription>(currentModel, widgetCreator) {
            @Override
            public void onOrderChanged(List<SiteletDescription> newOrder) {
                List<Long> newLongList = convertToLongList(newOrder);
                if (!currentOrder.equals(newLongList)) {
                    currentOrder = newLongList;
                    orderChangedPanel.setVisible(true);
                }
            }
        };
        siteletsContainer.setWidget(sortingPanel);
    }
}

From source file:burrito.client.sitelet.SiteletDraggableWidgetCreator.java

License:Apache License

@Override
public Widget createWidget(final SiteletDescription modelObj) {
    SimplePanel wrapper = new SimplePanel();
    wrapper.addStyleName("k5-SiteLetDraggableWidget-Wrapper");

    FlowPanel inner = new FlowPanel();

    String headerText = CrudLabelHelper.getString(modelObj.getEntityName().replace('.', '_'));
    Label header = new Label(headerText);
    header.addStyleName("k5-SiteLetDraggableWidget-Header");
    inner.add(header);/*from  www  .  j  a  v a2s . co m*/

    Label desc = new Label(modelObj.getDescription());
    desc.addStyleName("k5-SiteLetDraggableWidget-Desc");
    inner.add(desc);

    FlowPanel actionsPanel = new FlowPanel();
    actionsPanel.addStyleName("k5-SiteLetDraggableWidget-Actions");

    Hyperlink editAnchor = new Hyperlink(labels.edit(), String.valueOf(modelObj.getEntityId()));
    editAnchor.addStyleName("k5-SiteLetDraggableWidget-EditAnchor");
    editAnchor.addStyleName("k5-SiteLetDraggableWidget-Action");

    final Anchor deleteAnchor = new Anchor(labels.delete());
    final Label progress = new Label(labels.deleting());
    deleteAnchor.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            List<Long> idList = new ArrayList<Long>();
            idList.add(modelObj.getEntityId());
            if (!Window.confirm(labels.confirmDeleteSitelet())) {
                return;
            }
            progress.setVisible(true);
            deleteAnchor.setVisible(false);
            service.deleteSitelets(containerName, idList, new AsyncCallback<Void>() {

                @Override
                public void onSuccess(Void result) {
                    progress.setVisible(false);
                    deleteAnchor.setVisible(true);
                    deleteCallback.onSuccess(modelObj);
                }

                @Override
                public void onFailure(Throwable caught) {
                    progress.setVisible(false);
                    deleteAnchor.setVisible(true);
                    deleteCallback.onFailure(caught);
                    throw new RuntimeException("Failed when trying to delete sitelet with id "
                            + modelObj.getEntityId() + " from container " + containerName, caught);
                }
            });
            event.preventDefault();
        }
    });
    progress.addStyleName("k5-SiteLetDraggableWidget-Action");
    progress.addStyleName("burrito-progress-text");
    deleteAnchor.addStyleName("k5-SiteLetDraggableWidget-DeleteAnchor");
    deleteAnchor.addStyleName("k5-SiteLetDraggableWidget-Action");

    actionsPanel.add(editAnchor);
    actionsPanel.add(deleteAnchor);
    progress.setVisible(false);
    actionsPanel.add(progress);

    inner.add(actionsPanel);
    HTML clearFloats = new HTML();
    clearFloats.addStyleName("burrito-clear-floats");
    inner.add(clearFloats);
    wrapper.setWidget(inner);
    return wrapper;
}