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);