}
String sourceId = pcontext.getRequestParameter("srcID");
UIComponent uiSource = uiWorking.findComponentById(sourceId);
UIContainer uiTarget = uiWorking.findComponentById(pcontext.getRequestParameter("targetID"));
if (position < 0 && uiTarget.getChildren().size() > 0)
{
position = uiTarget.getChildren().size();
}
else if (position < 0)
{
position = 0;
}
if (uiSource == null)
{
UITabPane subTabPane = portalComposer.getChild(UITabPane.class);
UIContainerList uiContainerConfig = subTabPane.getChild(UIContainerList.class);
if (uiContainerConfig != null && subTabPane.getSelectedTabId().equals(uiContainerConfig.getId()))
{
org.exoplatform.portal.webui.container.UIContainer uiContainer =
uiTarget.createUIComponent(org.exoplatform.portal.webui.container.UIContainer.class, null, null);
Container container = uiContainerConfig.getContainer(sourceId);
container.setId(String.valueOf(container.hashCode()));
uiContainer.setStorageId(container.getStorageId());
PortalDataMapper.toUIContainer(uiContainer, container);
String[] accessPers = uiContainer.getAccessPermissions();
for (String accessPer : accessPers)
{
if (accessPer.equals(""))
accessPer = null;
}
if (accessPers == null || accessPers.length == 0)
accessPers = new String[]{UserACL.EVERYONE};
uiContainer.setAccessPermissions(accessPers);
uiSource = uiContainer;
}
else
{
Application app = null;
UIApplicationList appList = uiApp.findFirstComponentOfType(UIApplicationList.class);
app = appList.getApplication(sourceId);
ApplicationType applicationType = app.getType();
//
UIPortlet uiPortlet = uiTarget.createUIComponent(UIPortlet.class, null, null);
if (app.getDisplayName() != null)
{
uiPortlet.setTitle(app.getDisplayName());
}
else if (app.getApplicationName() != null)
{
uiPortlet.setTitle(app.getApplicationName());
}
uiPortlet.setDescription(app.getDescription());
List<String> accessPersList = app.getAccessPermissions();
String[] accessPers = accessPersList.toArray(new String[accessPersList.size()]);
for (String accessPer : accessPers)
{
if (accessPer.equals(""))
accessPers = null;
}
if (accessPers == null || accessPers.length == 0)
accessPers = new String[]{UserACL.EVERYONE};
uiPortlet.setAccessPermissions(accessPers);
UIPage uiPage = uiTarget.getAncestorOfType(UIPage.class);
// Hardcode on state to fix error while drag/drop Dashboard
if ("dashboard/DashboardPortlet".equals(app.getContentId()))
{
TransientApplicationState state = new TransientApplicationState<Object>(app.getContentId());
uiPortlet.setState(new PortletState(state, applicationType));
}
else
{
CloneApplicationState state = new CloneApplicationState<Object>(app.getStorageId());
uiPortlet.setState(new PortletState(state, applicationType));
}
uiPortlet.setPortletInPortal(uiTarget instanceof UIPortal);
uiPortlet.setShowEditControl(true);
uiSource = uiPortlet;
}
List<UIComponent> children = uiTarget.getChildren();
uiSource.setParent(uiTarget);
children.add(position, uiSource);
return;
}
UIContainer uiParent = uiSource.getParent();
if (uiParent == uiTarget)
{
int currentIdx = uiTarget.getChildren().indexOf(uiSource);
if (position <= currentIdx)
{
uiTarget.getChildren().add(position, uiSource);
currentIdx++;
uiTarget.getChildren().remove(currentIdx);
return;
}
uiTarget.getChildren().remove(currentIdx);
if (position >= uiTarget.getChildren().size())
{
position = uiTarget.getChildren().size();
}
uiTarget.getChildren().add(position, uiSource);
return;
}
uiParent.getChildren().remove(uiSource);
uiTarget.getChildren().add(position, uiSource);
uiSource.setParent(uiTarget);
}