GWT has a lazypanel.
As you might realise, that placing a gwt widget within a canvas works but placing a canvas inside a gwt widget usually does not work - so far as my mixing gwt and smartgwt has experienced.
Is there an equivalent for smartgwt canvas?
I couldn't find any, so I stole the code from lazypanel and adapted for canvas. Which seems to work rather well for me. Am I reinventing the lazy wheel which might already exist in smartgwt?
is there any point in writing a lazy loading canvas, or does smartgwt already take care of it by default?
Where, for example, the binding of my tabset hierarchy defined with uibinder is delayed until lazycanvas.show:
So this is my lazycanvas. What I have problem with is:
does canvas.show/canvas.hide perform the same action as canvas.setVisible? So, would placing canvas.setVisible(true) after canvas.show be redundant?
As you might realise, that placing a gwt widget within a canvas works but placing a canvas inside a gwt widget usually does not work - so far as my mixing gwt and smartgwt has experienced.
Is there an equivalent for smartgwt canvas?
I couldn't find any, so I stole the code from lazypanel and adapted for canvas. Which seems to work rather well for me. Am I reinventing the lazy wheel which might already exist in smartgwt?
is there any point in writing a lazy loading canvas, or does smartgwt already take care of it by default?
Where, for example, the binding of my tabset hierarchy defined with uibinder is delayed until lazycanvas.show:
Code:
public class ExampleTabset
extends LazyCanvas<TabSet>{
blah ... blah ...
@Override
protected TabSet createCanvas() {
uiBinder.createAndBindUi(this);
return this.tabset;
}
}
does canvas.show/canvas.hide perform the same action as canvas.setVisible? So, would placing canvas.setVisible(true) after canvas.show be redundant?
Code:
package org.synthful.smartgwt.client;
import com.smartgwt.client.widgets.Canvas;
abstract public class LazyCanvas<W extends Canvas>
extends Canvas {
protected abstract W createCanvas();
/**
* Ensures that the canvas has been created by calling {@link #createCanvas}
* if {@link #getCanvas} returns <code>null</code>. Typically it is not
* necessary to call this directly, as it is called as a side effect of a
* <code>setVisible(true)</code> call.
*/
public void ensureCanvas() {
if (this.canvas == null) {
this.canvas = createCanvas();
this.addChild(this.canvas);
}
}
@Override
/*
* Sets whether this object is visible. If <code>visible</code> is
* <code>true</code>, creates the sole child widget if necessary by calling
* {@link #ensureCanvas}.
*
* @param visible <code>true</code> to show the object, <code>false</code> to
* hide it
*/
public void setVisible(boolean visible) {
if (visible) {
ensureCanvas();
}
super.setVisible(visible);
}
@Override
public void show(){
this.setVisible(true);
super.show();
}
public W getCanvas(){
return canvas;
}
public void setCanvas(W w){
this.canvas = w;
}
private W canvas;
}
Comment