public class MyLabel<T> extends Label implements ObjectControl<T> {
    public T object;
    private boolean objectText = false;
    private Formatter<T> formatter = new DefaultFormatter();

    public MyLabel() {
    }

    public MyLabel(String text) {
        super(text);
    }

    public MyLabel(String id, String text) {
        super(text);
        id(id);
    }

    public MyLabel(String id, String style, String text) {
        this(id, text);
        setStyleName(style);
    }

    public MyLabel(Element element) {
        super(element);
    }

    public MyLabel<T> style(String style) {
        setStyleName(style);
        return this;
    }

    public MyLabel<T> addStyle(String style, boolean condition) {
        if (condition) {
            addStyle(style);
        } else {
            removeStyleName(style);
        }
        return this;
    }

    public MyLabel<T> addStyle(String style) {
        addStyleName(style);
        return this;
    }

    public MyLabel<T> id(String id) {
        IDUtil.id(this, id);
        return this;
    }

    public MyLabel<T> text(String text) {
        setText(text);
        return this;
    }

    public MyLabel<T> html(String html) {
        DOM.setInnerHTML(getElement(), html);
        return this;
    }

    public MyLabel<T> visible(boolean visible) {
        setVisible(visible);
        return this;
    }

    public String text() {
        return getElement().getInnerText();
    }

    public MyLabel<T> width(String value) {
        setWidth(value);
        return this;
    }

    public String getText() {
        return text();
    }

    public String html() {
        return getElement().getInnerHTML();
    }

    public void setText(String text) {
        super.setText(text);
    }


    public MyLabel<T> object(T object) {
        this.object = object;
        if (objectText) {
            updateObjectText();
        }
        return this;
    }

    public MyLabel<T> objectText() {
        this.objectText = true;
        updateObjectText();
        return this;
    }

    public MyLabel<T> objectText(Formatter<T> formatter) {
        this.formatter = formatter;
        objectText();
        return this;
    }

    private void updateObjectText() {
        text(formatter.toString(object));
    }

    public T object() {
        return object;
    }

    public MyLabel<T> absoluteTopPx(int topPx) {
        Style style = getElement().getStyle();
        style.setProperty("position", "absolute");
        style.setPropertyPx("top", topPx);
        return this;
    }

    public MyLabel<T> heightPx(int height) {
        setHeight(height + "px");
        return this;
    }

    public MyLabel<T> title(String title) {
        setTitle(title);
        return this;
    }
}


On Jul 16, 1:29 pm, Jaroslav Záruba <[email protected]> wrote:
> Could you post your MyLabel class?
>
>
>
> On Fri, Jul 16, 2010 at 12:15 PM, evgenyk <[email protected]> wrote:
> > I do not know where to add such assertion.
> > I think I can't change anything.
> > As far as I understand exception is thrown inside Label constructor.
>
> > On Jul 16, 12:08 pm, Jaroslav Záruba <[email protected]>
> > wrote:
> > > I had the same issue - no problem in hosted mode, "this$static is null"
> > in
> > > compiled. I found out I happen to call a method on null. Putting couple
> > of
> > > not-null assertions into your code might help.
>
> > > On Fri, Jul 16, 2010 at 10:49 AM, evgenyk <[email protected]> wrote:
> > > > Hello friends!
> > > > I periodically get an exception thrown from the following compiled
> > > > code (not obfuscated version):
>
> > > > function $MyLabel(this$static){
> > > >  $setElement(this$static, ($clinit_73() ,
> > > > $doc).createElement('div'));
> > > >  (!!this$static.element || throwAssertionError_Object("This
> > > > UIObject's element is not set; you may be missing a call to either
> > > > Composite.initWidget() or UIObject.setElement()") , this
> > > > $static.element)['className'] = 'gwt-Label';
> > > >  return this$static;
> > > > }
>
> > > > Java version:
> > > > public class MyLabel extends Label {
> > > >    public MyLabel(String text) {
> > > >        super(text);
> > > >    }
> > > >    ... skipped other methods
> > > > }
>
> > > > Exception is thrown time after time in production environment on
> > > > different client browsers with Firefox version 3.0.x on Windows XP.
> > > > It seems to me like a bug in FF. Is there any workaround, or I'm doing
> > > > something wrong?
> > > > GWT version 2.0.3
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "Google Web Toolkit" group.
> > > > To post to this group, send email to
> > [email protected].
> > > > To unsubscribe from this group, send email to
> > > > [email protected]<google-web-toolkit%2Bunsubs
> > > >  [email protected]><google-web-toolkit%2Bunsubs
> > [email protected]>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/google-web-toolkit?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Web Toolkit" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<google-web-toolkit%2Bunsubs 
> > [email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-web-toolkit?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to