PDA

View Full Version : Programmatically adding portlet into Portal caused auto-size failed



regular
11 Apr 2011, 7:13 PM
Hi all,

I'm using com.extjs.gxt.ui.client.widget.custom.Portal as a desktop page
I need to programmatically add some pages into desktop page.
I noticed that the sample portal just add portlet in onRending method.
And the portlet can autosize to the suitable size, see attachment pictures.
This is the default desktop, with portlets created onRender.


private PortalLayout container = new PortalLayout(.33, .34, .33) {
@Override
protected void onRender(Element parent, int index)
{
super.onRender(parent, index);

ExplorerModel model = Registry.get(Explorer.MODEL);
model.setDesktop(Desktop.this);

addPortlet(Entry.findEntry(CustomerService.CUSTOMER_STOCK), 0);
addPortlet(Entry.findEntry(CustomerService.CUSTOMER_WEATHER), 1);
addPortlet(new Entry(new BogusPort()), 2);
}
// ...

25598
And another portal page with portlets created onRender.


return new PortalLayout(.5, .5) {
@Override
protected void onRender(Element parent, int index)
{
super.onRender(parent, index);

addPortlet(Entry.findEntry(CUSTOMER_STOCK), 0);
addPortlet(Entry.findEntry(CUSTOMER_WEATHER), 1);
addPortlet(Entry.findEntry(CUSTOMER_DASHBOARD), 0);
}
};

25597
The PortalLayout class added a Portal as the center widget:


public abstract class PortalLayout extends LayoutContainer
{
private double[] colWidths;
protected Portal portal;

public PortalLayout(double... colWidths)
{
this.colWidths = Arrays.clone(colWidths);
}

@Override
protected void onRender(Element parent, int index)
{
super.onRender(parent, index);
setLayout(new BorderLayout());

portal = new Portal(colWidths.length);
portal.setBorders(true);
portal.setStyleAttribute("backgroundColor", "white");
for (int i = 0; i < colWidths.length; i++) {
portal.setColumnWidth(i, colWidths[i]);
}

BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
centerData.setMargins(new Margins(5));

add(portal, centerData);
}
// ...

When click "save" button, it will add this entry into the desktop page.


protected void addExtraToolIcon(final ContentPanel panel, final Entry entry)
{
panel.getHeader().addTool(new ToolButton("x-tool-save", new SelectionListener<IconButtonEvent>() {
@Override
public void componentSelected(IconButtonEvent ce)
{
ExplorerModel model = Registry.get(Explorer.MODEL);
model.addPortlet(entry, -1);
MessageBox.info("Information", "&lt;" + entry.getName() + "&gt; has been added into Desktop.", null);
}
}));
}

Please ignore the ExplorerModel, just think it as the Desktop instance is adding a new portlet, as below:


public void addPortlet(Entry entry, int col)
{
ViewPort view = entry.getViewPort();
final Portlet portlet = new Portlet(new FitLayout());
portlet.setData("entry", entry);
portlet.setIcon(view.getIcon());
portlet.setHeading(entry.getName());
addMaximizedIcon(portlet, entry);
addExtraToolIcon(portlet, entry);
portlet.add(view.getPortlet());
if (col >= 0) {
portal.add(portlet, col);
} else {
portal.add(portlet, 2);
}
}

When finished, I got this:
25596
And ...
25600
I got this:
25599

Seems that I didn't do some kind of refresh, or resize, or layout.
Please, anyone knows how to fix this problem?

regular
12 Apr 2011, 12:25 AM
OK, after several * n times testing, the result is as follows:

Try to add a portlet then delay for a while and then move it to a different width column to auto-size it leads to several success and only one fault, when I resist to see the desktop page.

So, it means it's not the reason for not layout it or not repaint it, it's the reason that, the desktop page is hidden.

For proving this assumption, I just delay 5 seconds before add the portlet, and turn to the desktop page, to see it be created. And I found that the portlet is well-formed.

Now, the solution is out. When you want to add a portlet into a "hidden" portal, just like me. U can just queue an operation in list, and when the portal is showing, trigger these operations into handler, and the auto-size layout will work.