PDA

View Full Version : Resizable Portlet



SmallerPlatypus
21 Mar 2011, 3:43 AM
Apologies if this has already been addressed, but I had a need to vertically resize a portlet and if I needed it, I guess others may need it too so here is my extended Portlet class.



import com.extjs.gxt.ui.client.event.ResizeEvent;
import com.extjs.gxt.ui.client.event.ResizeListener;
import com.extjs.gxt.ui.client.fx.Resizable;
import com.extjs.gxt.ui.client.widget.Layout;
import com.extjs.gxt.ui.client.widget.custom.Portlet;

import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;

/**
* A vertically resizable content panel contained in a Portal.
*
* @author Matt Verrinder
*
*/
public class ResizablePortlet extends Portlet {
private Resizable resizer;
private boolean resizable = true;
private boolean resizing = false;
private int minHeight = 100;

/**
* @param fitLayout
*/
public ResizablePortlet(Layout layout) {
super(layout);
setResizable(true);
}

/**
* Returns the min height.
*
* @return the min height
*/
public int getMinHeight() {
return minHeight;
}

/**
* Returns the window's resizable instance.
*
* @return the resizable
*/
public Resizable getResizable() {
if (resizer == null && resizable) {
resizer = new Resizable(this, "s");

resizer.setMinHeight(getMinHeight());
resizer.addResizeListener(new ResizeListener() {

@Override
public void resizeEnd(final ResizeEvent re) {
// end resize after event preview
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
onEndResize(re);
}
});
}

@Override
public void resizeStart(ResizeEvent re) {
onStartResize(re);
}

});
}
return resizer;
}

/**
* The minimum height in pixels allowed for this window (defaults to 100).
* Only applies when resizable = true.
*
* @param minHeight the min height
*/
public void setMinHeight(int minHeight) {
this.minHeight = minHeight;
if (resizer != null) {
resizer.setMinHeight(minHeight);
}
}

/**
* True to allow user resizing at each edge and corner of the window, false to
* disable resizing (defaults to true).
*
* @param resizable true to enabled resizing
*/
public void setResizable(boolean resizable) {
this.resizable = resizable;
if (resizable) {
getResizable();
} else if (resizer != null) {
resizer.release();
resizer = null;
}
}

protected void onEndResize(ResizeEvent re) {
resizing = false;
}

protected void onStartResize(ResizeEvent re) {
resizing = true;
}

sbaramov
13 Nov 2011, 10:45 AM
Thank you very much for sharing the code. It does work nicely. I have one question though: What was the intend for the 'resizing' field?