// try explicit entry position
for(int i=0; i < set.getEntryCount(); i++)
{
if ((targetLayout!=null) && (baseLayout!=null)) break;
Entry p = set.getEntry(i);
Layout layout = p.getLayout();
if ((layout!=null)&&(layout.getPosition()!=-1))
{
int lpos = (int)layout.getPosition();
if ((baseLayout == null) && (lpos==position))
{
baseLayout = layout;
}
if ((targetLayout == null) && (lpos==target))
{
targetLayout = layout;
}
}
}
//else use implicit position
if (baseLayout == null)
{
if (position < set.getPortletsCount())
{
Portlets p = set.getPortlets(position);
if (p.getLayout()==null)
{
p.setLayout(new PsmlLayout());
}
baseLayout=p.getLayout();
}
if (position < set.getEntryCount())
{
Entry p = set.getEntry(position);
if (p.getLayout()==null)
{
p.setLayout(new PsmlLayout());
}
baseLayout=p.getLayout();
}
}
if (targetLayout == null)
{
if (target < set.getPortletsCount())
{
Portlets p = set.getPortlets(target);
if (p.getLayout()==null)
{
p.setLayout(new PsmlLayout());
}
targetLayout=p.getLayout();
}
if (target < set.getEntryCount())
{
Entry p = set.getEntry(target);
if (p.getLayout()==null)
{
p.setLayout(new PsmlLayout());
}
targetLayout=p.getLayout();
}
}
//we should now have found both baseLayout and targetLayout, swap
//their positions using explicit positioning