* @throws ModelException
*/
public ListingDescriptor createListingDescriptor(ModelRequest request)
throws ConfigurationException, PersistenceException, ModelException
{
ListingDescriptor listing = (ListingDescriptor) UserTools.getContextObject(request, id);
if (listing != null)
{
return listing;
}
listing = de.iritgo.aktera.ui.listing.Listing.createListingFromConfig(getConfiguration(), getDerivationPath());
listing.setNg(true);
listing.setCommandStyle(commandStyle);
listing.setTitle(title);
listing.setTitleBundle(titleBundle);
if (header != null)
{
listing.setHeader(header);
}
listing.setIcon(icon);
listing.setEmbedded(embedded);
listing.setSingleSelection(singleSelection);
listing.setSelectable(selectable);
listing.setKeyName(keyName);
listing.setId(listId);
listing.setListModel(listModel);
listing.setCommand(ListingDescriptor.COMMAND_VIEW, cmdView);
listing.setCommand(ListingDescriptor.COMMAND_SEARCH, cmdSearch);
listing.setCommand(ListingDescriptor.COMMAND_NEW, cmdNew);
listing.setCommand(ListingDescriptor.COMMAND_BACK, cmdBack);
listing.setCommand(ListingDescriptor.COMMAND_EXECUTE, cmdExecute);
if (commandConfig.size() > 0)
{
CommandDescriptor cmdDescriptor = new CommandDescriptor();
for (Iterator i = commandConfig.iterator(); i.hasNext();)
{
Configuration aCommandConfig = (Configuration) i.next();
String permission = aCommandConfig.getAttribute("permission", null);
if (permission != null && ! UserTools.currentUserHasPermission(request, permission))
{
continue;
}
String role = aCommandConfig.getAttribute("role", null);
if (role != null && ! UserTools.currentUserIsInGroup(request, role))
{
continue;
}
CommandInfo cmdInfo = new CommandInfo(aCommandConfig.getAttribute("model"), aCommandConfig
.getAttribute("id"), aCommandConfig.getAttribute("label"), aCommandConfig.getAttribute(
"icon", null));
cmdInfo.setBundle(aCommandConfig.getAttribute("bundle", "Aktera"));
Configuration[] params = aCommandConfig.getChildren("param");
setParameters(cmdInfo, params);
cmdDescriptor.add(cmdInfo);
}
listing.setListCommands(cmdDescriptor);
}
if (! overview && itemCommandConfig.size() > 0)
{
CommandDescriptor cmdDescriptor = new CommandDescriptor("selectedItems");
for (Iterator i = itemCommandConfig.iterator(); i.hasNext();)
{
Configuration aItemCommandConfig = (Configuration) i.next();
if (! NumberTools.toBool(aItemCommandConfig.getAttribute("visible", "true"), true))
{
continue;
}
if (cmdDescriptor.hasCommand(aItemCommandConfig.getAttribute("id")))
{
continue;
}
CommandInfo cmdInfo = new CommandInfo(aItemCommandConfig.getAttribute("model", aItemCommandConfig
.getAttribute("bean", null)), aItemCommandConfig.getAttribute("id"), aItemCommandConfig
.getAttribute("label"), aItemCommandConfig.getAttribute("icon", null));
cmdInfo.setStyle(aItemCommandConfig.getAttribute("style", null));
cmdInfo.setBundle(aItemCommandConfig.getAttribute("bundle", "Aktera"));
if (aItemCommandConfig.getAttribute("bean", null) != null)
{
cmdInfo.setBean(true);
}
Configuration[] params = aItemCommandConfig.getChildren("param");
setParameters(cmdInfo, params);
cmdDescriptor.add(cmdInfo);
}
listing.setItemCommands(cmdDescriptor);
}
PersistentDescriptor persistents = new PersistentDescriptor();
PersistentFactory persistentManager = null;
try
{
persistentManager = (PersistentFactory) KeelTools.getService(PersistentFactory.ROLE);
if (persistentConfig.size() > 0)
{
Iterator persistentConfigIterator = persistentConfig.iterator();
Configuration aPersistentConfig = (Configuration) persistentConfigIterator.next();
Persistent persistent = persistentManager.create(aPersistentConfig.getAttribute("name"));
persistents.put(aPersistentConfig.getAttribute("id"), persistent);
for (; persistentConfigIterator.hasNext();)
{
aPersistentConfig = (Configuration) persistentConfigIterator.next();
persistent = persistentManager.create(aPersistentConfig.getAttribute("name"));
String join = aPersistentConfig.getAttribute("join", null);
if (join != null)
{
persistents.put(aPersistentConfig.getAttribute("id"), persistent).join(join,
aPersistentConfig.getAttribute("otherKey"),
aPersistentConfig.getAttribute("myKey"),
aPersistentConfig.getAttribute("condition", null));
}
else
{
persistents.put(aPersistentConfig.getAttribute("id"), persistent);
}
}
}
}
catch (ServiceException x)
{
}
finally
{
KeelTools.releaseService(persistentManager);
}
listing.setPersistents(persistents);
if (queryConfig != null)
{
QueryDescriptor qd = new QueryDescriptor();
listing.setQuery(qd);
qd.setName(queryConfig.getAttribute("name", null));
qd.setDaoName(queryConfig.getAttribute("dao", null));
qd.setDaoMethodName(queryConfig.getAttribute("method", null));
qd.setQuery(queryConfig.getChild("find").getValue(queryConfig.getChild("expression").getValue(null)));
qd.setCountQuery(queryConfig.getChild("count").getValue(null));
for (Configuration paramConfig : queryConfig.getChildren("param"))
{
String value = paramConfig.getAttribute("value", null);
if (value == null)
{
value = paramConfig.getValue();
}
qd.setParam(paramConfig.getAttribute("name"), value);
}
}
listing.setCondition(condition != null ? condition : "");
UserTools.setContextObject(request, id, listing);
return listing;
}