Completion of dialog and wizard frameworks also converted advanced space wizard and create space dialog to the new frameworks.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2615 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2006-04-04 12:12:58 +00:00
parent 4f3e44c1d3
commit 48e2691f6a
34 changed files with 2448 additions and 759 deletions

View File

@@ -1,9 +1,18 @@
package org.alfresco.web.bean.dialog;
import javax.faces.context.FacesContext;
import java.text.MessageFormat;
import javax.faces.context.FacesContext;
import javax.transaction.UserTransaction;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.bean.BrowseBean;
import org.alfresco.web.bean.NavigationBean;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
/**
* Base class for all dialog beans providing common functionality
@@ -12,9 +21,12 @@ import org.alfresco.web.app.context.UIContextService;
*/
public abstract class BaseDialogBean implements IDialogBean
{
protected static final String DIALOG_CLOSE = "dialog:close";
public abstract String finish();
protected static final String ERROR_ID = "error_generic";
// services common to most dialogs
protected BrowseBean browseBean;
protected NavigationBean navigator;
protected NodeService nodeService;
public void init()
{
@@ -24,16 +36,118 @@ public abstract class BaseDialogBean implements IDialogBean
public String cancel()
{
return DIALOG_CLOSE;
return getDefaultCancelOutcome();
}
public String finish()
{
String outcome = getDefaultFinishOutcome();
UserTransaction tx = null;
try
{
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context);
tx.begin();
// call the actual implementation
outcome = finishImpl(context, outcome);
tx.commit();
}
catch (Throwable e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
Utils.addErrorMessage(formatErrorMessage(e));
outcome = null;
}
return outcome;
}
public boolean getFinishButtonDisabled()
public String getCancelButtonLabel()
{
return true;
return Application.getMessage(FacesContext.getCurrentInstance(), "cancel");
}
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "ok");
}
public boolean getFinishButtonDisabled()
{
return true;
}
/**
* @param browseBean The BrowseBean to set.
*/
public void setBrowseBean(BrowseBean browseBean)
{
this.browseBean = browseBean;
}
/**
* @param navigator The NavigationBean to set.
*/
public void setNavigator(NavigationBean navigator)
{
this.navigator = navigator;
}
/**
* @param nodeService The nodeService to set.
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Returns the default cancel outcome
*
* @return Default close outcome, dialog:close by default
*/
protected String getDefaultCancelOutcome()
{
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
/**
* Returns the default finish outcome
*
* @return Default finish outcome, dialog:close by default
*/
protected String getDefaultFinishOutcome()
{
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
/**
* Performs the actual processing for the wizard.
* NOTE: This method is called within the context of a transaction
* so no transaction handling is required
*
* @param context FacesContext
* @param outcome The default outcome
* @return The outcome
*/
protected abstract String finishImpl(FacesContext context, String outcome)
throws Exception;
/**
* Returns a formatted exception string for the given exception
*
* @param exception The exception that got thrown
* @return The formatted message
*/
protected String formatErrorMessage(Throwable exception)
{
return MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), ERROR_ID),
exception.getMessage());
}
}

View File

@@ -39,6 +39,16 @@ public class DialogManager
this.currentDialog.init();
}
/**
* Returns the config for the current dialog
*
* @return The current dialog config
*/
public DialogConfig getCurrentDialog()
{
return this.currentDialogConfig;
}
/**
* Returns the current dialog bean being managed
*
@@ -111,6 +121,16 @@ public class DialogManager
return this.currentDialogConfig.getPage();
}
/**
* Returns the label to use for the cancel button
*
* @return The cancel button label
*/
public String getCancelButtonLabel()
{
return this.currentDialog.getCancelButtonLabel();
}
/**
* Returns the label to use for the finish button
*

View File

@@ -12,19 +12,26 @@ public interface IDialogBean
*/
public void init();
/**
* Method handler called when the cancel button of the dialog is pressed
*
* @return The outcome to return
*/
public String cancel();
/**
* Method handler called when the finish button of the dialog is pressed
*
* @return The outcome to return (normally dialog:close)
* @return The outcome to return
*/
public String finish();
/**
* Method handler called when the cancel button of the dialog is pressed
* Returns the label to use for the cancel button
*
* @return The outcome to return (normally dialog:close)
* @return The cancel button label
*/
public String cancel();
public String getCancelButtonLabel();
/**
* Returns the label to use for the finish button

View File

@@ -1,328 +0,0 @@
package org.alfresco.web.bean.dialog;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.transaction.UserTransaction;
import org.alfresco.config.Config;
import org.alfresco.config.ConfigElement;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.BrowseBean;
import org.alfresco.web.bean.NavigationBean;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.UIListItem;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Dialog bean to create a space
*
* @author gavinc
*/
public class SpaceDialog extends BaseDialogBean
{
protected static final String ERROR = "error_space";
private static final String SPACE_ICON_DEFAULT = "space-icon-default";
// private static final String DEFAULT_SPACE_TYPE_ICON = "/images/icons/space.gif";
private static final String ICONS_LOOKUP_KEY = " icons";
protected NodeService nodeService;
protected FileFolderService fileFolderService;
protected NamespaceService namespaceService;
protected SearchService searchService;
protected NavigationBean navigator;
protected BrowseBean browseBean;
protected String spaceType;
protected String icon;
protected String name;
protected String description;
private static Log logger = LogFactory.getLog(SpaceDialog.class);
/**
* @param nodeService The nodeService to set.
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param fileFolderService used to manipulate folder/folder model nodes
*/
public void setFileFolderService(FileFolderService fileFolderService)
{
this.fileFolderService = fileFolderService;
}
/**
* @param searchService the service used to find nodes
*/
public void setSearchService(SearchService searchService)
{
this.searchService = searchService;
}
/**
* @param namespaceService The NamespaceService
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* @param navigator The NavigationBean to set.
*/
public void setNavigator(NavigationBean navigator)
{
this.navigator = navigator;
}
/**
* @param browseBean The BrowseBean to set.
*/
public void setBrowseBean(BrowseBean browseBean)
{
this.browseBean = browseBean;
}
/**
* @return Returns the description.
*/
public String getDescription()
{
return description;
}
/**
* @param description The description to set.
*/
public void setDescription(String description)
{
this.description = description;
}
/**
* @return Returns the icon.
*/
public String getIcon()
{
return icon;
}
/**
* @param icon The icon to set.
*/
public void setIcon(String icon)
{
this.icon = icon;
}
/**
* @return Returns the name.
*/
public String getName()
{
return name;
}
/**
* @param name The name to set.
*/
public void setName(String name)
{
this.name = name;
}
/**
* @return Returns the spaceType.
*/
public String getSpaceType()
{
return spaceType;
}
/**
* @param spaceType The spaceType to set.
*/
public void setSpaceType(String spaceType)
{
this.spaceType = spaceType;
}
/**
* Returns a list of icons to allow the user to select from.
* The list can change according to the type of space being created.
*
* @return A list of icons
*/
@SuppressWarnings("unchecked")
public List<UIListItem> getIcons()
{
// NOTE: we can't cache this list as it depends on the space type
// which the user can change during the advanced space wizard
List<UIListItem> icons = null;
QName type = QName.createQName(this.spaceType);
String typePrefixForm = type.toPrefixString(this.namespaceService);
Config config = Application.getConfigService(FacesContext.getCurrentInstance()).
getConfig(typePrefixForm + ICONS_LOOKUP_KEY);
if (config != null)
{
ConfigElement iconsCfg = config.getConfigElement("icons");
if (iconsCfg != null)
{
boolean first = true;
for (ConfigElement icon : iconsCfg.getChildren())
{
String iconName = icon.getAttribute("name");
String iconPath = icon.getAttribute("path");
if (iconName != null && iconPath != null)
{
if (first)
{
// if this is the first icon create the list and make
// the first icon in the list the default
icons = new ArrayList<UIListItem>(iconsCfg.getChildCount());
if (this.icon == null)
{
// set the default if it is not already
this.icon = iconName;
}
first = false;
}
UIListItem item = new UIListItem();
item.setValue(iconName);
item.getAttributes().put("image", iconPath);
icons.add(item);
}
}
}
}
// if we didn't find any icons display one default choice
if (icons == null)
{
icons = new ArrayList<UIListItem>(1);
this.icon = SPACE_ICON_DEFAULT;
UIListItem item = new UIListItem();
item.setValue("space-icon-default");
item.getAttributes().put("image", "/images/icons/space-icon-default.gif");
icons.add(item);
}
return icons;
}
/**
* Initialises the wizard
*/
public void init()
{
super.init();
// reset all variables
this.spaceType = ContentModel.TYPE_FOLDER.toString();
this.icon = null;
this.name = null;
this.description = "";
}
@Override
public String finish()
{
String outcome = DIALOG_CLOSE;
UserTransaction tx = null;
try
{
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context);
tx.begin();
// create the space (just create a folder for now)
NodeRef parentNodeRef;
String nodeId = this.navigator.getCurrentNodeId();
if (nodeId == null)
{
parentNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
}
else
{
parentNodeRef = new NodeRef(Repository.getStoreRef(), nodeId);
}
FileInfo fileInfo = fileFolderService.create(
parentNodeRef,
this.name,
Repository.resolveToQName(this.spaceType));
NodeRef nodeRef = fileInfo.getNodeRef();
if (logger.isDebugEnabled())
logger.debug("Created folder node with name: " + this.name);
// apply the uifacets aspect - icon, title and description props
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(5);
uiFacetsProps.put(ContentModel.PROP_ICON, this.icon);
uiFacetsProps.put(ContentModel.PROP_TITLE, this.name);
uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, this.description);
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_UIFACETS, uiFacetsProps);
if (logger.isDebugEnabled())
logger.debug("Added uifacets aspect with properties: " + uiFacetsProps);
// commit the transaction
tx.commit();
}
catch (FileExistsException e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
// print status message
String statusMsg = MessageFormat.format(
Application.getMessage(
FacesContext.getCurrentInstance(), "error_exists"),
e.getExisting().getName());
Utils.addErrorMessage(statusMsg);
// no outcome
outcome = null;
}
catch (Throwable e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), ERROR), e.getMessage()), e);
outcome = null;
}
return outcome;
}
}

View File

@@ -0,0 +1,34 @@
package org.alfresco.web.bean.spaces;
import javax.faces.context.FacesContext;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
/**
* Dialog bean to create a space.
* Uses the CreateSpaceWizard and just overrides the finish button label
* and the default outcomes.
*
* @author gavinc
*/
public class CreateSpaceDialog extends CreateSpaceWizard
{
@Override
public String getFinishButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "new_space");
}
@Override
protected String getDefaultCancelOutcome()
{
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
@Override
protected String getDefaultFinishOutcome()
{
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
}

View File

@@ -0,0 +1,696 @@
package org.alfresco.web.bean.spaces;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import org.alfresco.config.Config;
import org.alfresco.config.ConfigElement;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.DynamicNamespacePrefixResolver;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.wizard.BaseWizardBean;
import org.alfresco.web.data.IDataContainer;
import org.alfresco.web.data.QuickSort;
import org.alfresco.web.ui.common.component.UIListItem;
import org.alfresco.web.ui.common.component.description.UIDescription;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean responsible for the create space wizard
*
* @author gavinc
*/
public class CreateSpaceWizard extends BaseWizardBean
{
public static final String DEFAULT_SPACE_ICON_NAME = "space-icon-default";
public static final String DEFAULT_SPACE_ICON_PATH = "";
public static final String DEFAULT_SPACE_TYPE_ICON_PATH = "/images/icons/space.gif";
private static Log logger = LogFactory.getLog(CreateSpaceWizard.class);
protected NamespaceService namespaceService;
protected DictionaryService dictionaryService;
protected String spaceType;
protected String icon;
protected String createFrom;
protected NodeRef existingSpaceId;
protected String templateSpaceId;
protected String copyPolicy;
protected String name;
protected String description;
protected String templateName;
protected boolean saveAsTemplate;
protected List<SelectItem> templates;
protected List<UIListItem> folderTypes;
protected List<UIDescription> folderTypeDescriptions;
// the NodeRef of the node created during finish
protected NodeRef createdNode;
/**
* Initialises the wizard
*/
public void init()
{
super.init();
// clear the cached query results
if (this.templates != null)
{
this.templates.clear();
this.templates = null;
}
// reset all variables
this.createFrom = "scratch";
this.spaceType = ContentModel.TYPE_FOLDER.toString();
this.icon = null;
this.copyPolicy = "contents";
this.existingSpaceId = null;
this.templateSpaceId = null;
this.name = null;
this.description = "";
this.templateName = null;
this.saveAsTemplate = false;
}
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
String newSpaceId = null;
if (this.createFrom.equals("scratch"))
{
// create the space (just create a folder for now)
NodeRef parentNodeRef;
String nodeId = this.navigator.getCurrentNodeId();
if (nodeId == null)
{
parentNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
}
else
{
parentNodeRef = new NodeRef(Repository.getStoreRef(), nodeId);
}
FileInfo fileInfo = fileFolderService.create(
parentNodeRef,
this.name,
Repository.resolveToQName(this.spaceType));
NodeRef nodeRef = fileInfo.getNodeRef();
newSpaceId = nodeRef.getId();
if (logger.isDebugEnabled())
logger.debug("Created folder node with name: " + this.name);
// apply the uifacets aspect - icon, title and description props
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(5);
uiFacetsProps.put(ContentModel.PROP_ICON, this.icon);
uiFacetsProps.put(ContentModel.PROP_TITLE, this.name);
uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, this.description);
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_UIFACETS, uiFacetsProps);
if (logger.isDebugEnabled())
logger.debug("Added uifacets aspect with properties: " + uiFacetsProps);
// remember the created node
this.createdNode = nodeRef;
}
else if (this.createFrom.equals("existing"))
{
// copy the selected space and update the name, description and icon
NodeRef sourceNode = this.existingSpaceId;
NodeRef parentSpace = new NodeRef(Repository.getStoreRef(), this.navigator.getCurrentNodeId());
// copy from existing
NodeRef copiedNode = this.fileFolderService.copy(sourceNode, parentSpace, this.name).getNodeRef();
// also need to set the new description and icon properties
this.nodeService.setProperty(copiedNode, ContentModel.PROP_DESCRIPTION, this.description);
this.nodeService.setProperty(copiedNode, ContentModel.PROP_ICON, this.icon);
newSpaceId = copiedNode.getId();
if (logger.isDebugEnabled())
logger.debug("Copied space with id of " + sourceNode.getId() + " to " + this.name);
// remember the created node
this.createdNode = copiedNode;
}
else if (this.createFrom.equals("template"))
{
// copy the selected space and update the name, description and icon
NodeRef sourceNode = new NodeRef(Repository.getStoreRef(), this.templateSpaceId);
NodeRef parentSpace = new NodeRef(Repository.getStoreRef(), this.navigator.getCurrentNodeId());
// copy from the template
NodeRef copiedNode = this.fileFolderService.copy(sourceNode, parentSpace, this.name).getNodeRef();
// also need to set the new description and icon properties
this.nodeService.setProperty(copiedNode, ContentModel.PROP_DESCRIPTION, this.description);
this.nodeService.setProperty(copiedNode, ContentModel.PROP_ICON, this.icon);
newSpaceId = copiedNode.getId();
if (logger.isDebugEnabled())
logger.debug("Copied template space with id of " + sourceNode.getId() + " to " + this.name);
// remember the created node
this.createdNode = copiedNode;
}
// if the user selected to save the space as a template space copy the new
// space to the templates folder
if (this.saveAsTemplate)
{
// get hold of the Templates node
DynamicNamespacePrefixResolver namespacePrefixResolver = new DynamicNamespacePrefixResolver(null);
namespacePrefixResolver.registerNamespace(NamespaceService.APP_MODEL_PREFIX, NamespaceService.APP_MODEL_1_0_URI);
String xpath = Application.getRootPath(FacesContext.getCurrentInstance()) + "/" +
Application.getGlossaryFolderName(FacesContext.getCurrentInstance()) + "/" +
Application.getSpaceTemplatesFolderName(FacesContext.getCurrentInstance());
NodeRef rootNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
List<NodeRef> templateNodeList = this.searchService.selectNodes(
rootNodeRef,
xpath, null, namespacePrefixResolver, false);
if (templateNodeList.size() == 1)
{
// get the first item in the list as we from test above there is only one!
NodeRef templateNode = templateNodeList.get(0);
NodeRef sourceNode = new NodeRef(Repository.getStoreRef(), newSpaceId);
// copy this to the template location
fileFolderService.copy(sourceNode, templateNode, this.templateName);
}
}
return outcome;
}
/**
* @return Returns the copyPolicy.
*/
public String getCopyPolicy()
{
return copyPolicy;
}
/**
* @param copyPolicy The copyPolicy to set.
*/
public void setCopyPolicy(String copyPolicy)
{
this.copyPolicy = copyPolicy;
}
/**
* @return Returns the createFrom.
*/
public String getCreateFrom()
{
return createFrom;
}
/**
* @param createFrom The createFrom to set.
*/
public void setCreateFrom(String createFrom)
{
this.createFrom = createFrom;
}
/**
* @return Returns the description.
*/
public String getDescription()
{
return description;
}
/**
* @param description The description to set.
*/
public void setDescription(String description)
{
this.description = description;
}
/**
* @return Returns the existingSpaceId.
*/
public NodeRef getExistingSpaceId()
{
return existingSpaceId;
}
/**
* @param existingSpaceId The existingSpaceId to set.
*/
public void setExistingSpaceId(NodeRef existingSpaceId)
{
this.existingSpaceId = existingSpaceId;
}
/**
* @return Returns the icon.
*/
public String getIcon()
{
return icon;
}
/**
* @param icon The icon to set.
*/
public void setIcon(String icon)
{
this.icon = icon;
}
/**
* @return Returns the name.
*/
public String getName()
{
return name;
}
/**
* @param name The name to set.
*/
public void setName(String name)
{
this.name = name;
}
/**
* @return Returns the saveAsTemplate.
*/
public boolean isSaveAsTemplate()
{
return saveAsTemplate;
}
/**
* @param saveAsTemplate The saveAsTemplate to set.
*/
public void setSaveAsTemplate(boolean saveAsTemplate)
{
this.saveAsTemplate = saveAsTemplate;
}
/**
* @return Returns the spaceType.
*/
public String getSpaceType()
{
return spaceType;
}
/**
* @param spaceType The spaceType to set.
*/
public void setSpaceType(String spaceType)
{
this.spaceType = spaceType;
}
/**
* @return Returns the templateName.
*/
public String getTemplateName()
{
return templateName;
}
/**
* @param templateName The templateName to set.
*/
public void setTemplateName(String templateName)
{
this.templateName = templateName;
}
/**
* @return Returns the templateSpaceId.
*/
public String getTemplateSpaceId()
{
return templateSpaceId;
}
/**
* @param templateSpaceId The templateSpaceId to set.
*/
public void setTemplateSpaceId(String templateSpaceId)
{
this.templateSpaceId = templateSpaceId;
}
/**
* @return Returns the summary data for the wizard.
*/
public String getSummary()
{
String summaryCreateType = null;
ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance());
if (this.createFrom.equals("scratch"))
{
summaryCreateType = bundle.getString("scratch");
}
else if (this.createFrom.equals("existing"))
{
summaryCreateType = bundle.getString("an_existing_space");
}
else if (this.createFrom.equals("template"))
{
summaryCreateType = bundle.getString("a_template");
}
// String summarySaveAsTemplate = this.saveAsTemplate ? bundle.getString("yes") : bundle.getString("no");
// bundle.getString("save_as_template"), bundle.getString("template_name")},
// summarySaveAsTemplate, this.templateName
String spaceTypeLabel = null;
for (UIListItem item : this.getFolderTypes())
{
if (item.getValue().equals(this.spaceType))
{
spaceTypeLabel = item.getLabel();
break;
}
}
return buildSummary(
new String[] {bundle.getString("space_type"), bundle.getString("name"),
bundle.getString("description"), bundle.getString("creating_from")},
new String[] {spaceTypeLabel, this.name, this.description, summaryCreateType});
}
/**
* @return Returns a list of template spaces currently in the system
*/
public List<SelectItem> getTemplateSpaces()
{
if (this.templates == null)
{
this.templates = new ArrayList<SelectItem>();
FacesContext context = FacesContext.getCurrentInstance();
String xpath = Application.getRootPath(context) + "/" + Application.getGlossaryFolderName(context) +
"/" + Application.getSpaceTemplatesFolderName(context) + "/*";
NodeRef rootNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
NamespaceService resolver = Repository.getServiceRegistry(context).getNamespaceService();
List<NodeRef> results = this.searchService.selectNodes(rootNodeRef, xpath, null, resolver, false);
if (results.size() > 0)
{
for (NodeRef assocRef : results)
{
Node childNode = new Node(assocRef);
this.templates.add(new SelectItem(childNode.getId(), childNode.getName()));
}
// make sure the list is sorted by the label
QuickSort sorter = new QuickSort(this.templates, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
// add an entry (at the start) to instruct the user to select a template
this.templates.add(0, new SelectItem("none", Application.getMessage(FacesContext.getCurrentInstance(), "select_a_template")));
}
return this.templates;
}
/**
* Returns a list of UIListItem objects representing the folder types
* and also constructs the list of descriptions for each type
*
* @return List of UIListItem components
*/
@SuppressWarnings("unchecked")
public List<UIListItem> getFolderTypes()
{
if (this.folderTypes == null)
{
FacesContext context = FacesContext.getCurrentInstance();
this.folderTypes = new ArrayList<UIListItem>(2);
this.folderTypeDescriptions = new ArrayList<UIDescription>(2);
// add the well known 'container space' type to start with
UIListItem defaultItem = new UIListItem();
String defaultLabel = Application.getMessage(context, "container");
defaultItem.setValue(ContentModel.TYPE_FOLDER.toString());
defaultItem.setLabel(defaultLabel);
defaultItem.setTooltip(defaultLabel);
defaultItem.getAttributes().put("image", DEFAULT_SPACE_TYPE_ICON_PATH);
this.folderTypes.add(defaultItem);
UIDescription defaultDesc = new UIDescription();
defaultDesc.setControlValue(ContentModel.TYPE_FOLDER.toString());
defaultDesc.setText(Application.getMessage(context, "container_desc"));
this.folderTypeDescriptions.add(defaultDesc);
// add any configured content sub-types to the list
Config wizardCfg = Application.getConfigService(FacesContext.getCurrentInstance()).
getConfig("Custom Folder Types");
if (wizardCfg != null)
{
ConfigElement typesCfg = wizardCfg.getConfigElement("folder-types");
if (typesCfg != null)
{
for (ConfigElement child : typesCfg.getChildren())
{
QName idQName = Repository.resolveToQName(child.getAttribute("name"));
TypeDefinition typeDef = this.dictionaryService.getType(idQName);
if (typeDef != null &&
this.dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_FOLDER))
{
// look for a client localized string
String label = null;
String msgId = child.getAttribute("displayLabelId");
if (msgId != null)
{
label = Application.getMessage(context, msgId);
}
// if there wasn't an externalized string look for one in the config
if (label == null)
{
label = child.getAttribute("displayLabel");
}
// if there wasn't a client based label try and get it from the dictionary
if (label == null)
{
label = typeDef.getTitle();
}
// finally use the localname if we still haven't found a label
if (label == null)
{
label = idQName.getLocalName();
}
// resolve a description string for the type
String description = null;
msgId = child.getAttribute("descriptionMsgId");
if (msgId != null)
{
description = Application.getMessage(context, msgId);
}
if (description == null)
{
description = child.getAttribute("description");
}
// if we don't have a local description just use the label
if (description == null)
{
description = label;
}
// extract the icon to use from the config
String icon = child.getAttribute("icon");
if (icon == null || icon.length() == 0)
{
icon = DEFAULT_SPACE_TYPE_ICON_PATH;
}
UIListItem item = new UIListItem();
item.getAttributes().put("value", idQName.toString());
item.getAttributes().put("label", label);
item.getAttributes().put("tooltip", label);
item.getAttributes().put("image", icon);
this.folderTypes.add(item);
UIDescription desc = new UIDescription();
desc.setControlValue(idQName.toString());
desc.setText(description);
this.folderTypeDescriptions.add(desc);
}
}
}
else
{
logger.warn("Could not find 'folder-types' configuration element");
}
}
else
{
logger.warn("Could not find 'Custom Folder Types' configuration section");
}
}
return this.folderTypes;
}
/**
* Returns a list of UIDescription objects for the folder types
*
* @return A list of UIDescription objects
*/
public List<UIDescription> getFolderTypeDescriptions()
{
if (this.folderTypeDescriptions == null)
{
// call the getFolderType method to construct the list
getFolderTypes();
}
return this.folderTypeDescriptions;
}
/**
* Returns a list of icons to allow the user to select from.
* The list can change according to the type of space being created.
*
* @return A list of icons
*/
@SuppressWarnings("unchecked")
public List<UIListItem> getIcons()
{
// NOTE: we can't cache this list as it depends on the space type
// which the user can change during the advanced space wizard
List<UIListItem> icons = null;
QName type = QName.createQName(this.spaceType);
String typePrefixForm = type.toPrefixString(this.namespaceService);
Config config = Application.getConfigService(FacesContext.getCurrentInstance()).
getConfig(typePrefixForm + " icons");
if (config != null)
{
ConfigElement iconsCfg = config.getConfigElement("icons");
if (iconsCfg != null)
{
boolean first = true;
for (ConfigElement icon : iconsCfg.getChildren())
{
String iconName = icon.getAttribute("name");
String iconPath = icon.getAttribute("path");
if (iconName != null && iconPath != null)
{
if (first)
{
// if this is the first icon create the list and make
// the first icon in the list the default
icons = new ArrayList<UIListItem>(iconsCfg.getChildCount());
if (this.icon == null)
{
// set the default if it is not already
this.icon = iconName;
}
first = false;
}
UIListItem item = new UIListItem();
item.setValue(iconName);
item.getAttributes().put("image", iconPath);
icons.add(item);
}
}
}
}
// if we didn't find any icons display one default choice
if (icons == null)
{
icons = new ArrayList<UIListItem>(1);
this.icon = DEFAULT_SPACE_ICON_NAME;
UIListItem item = new UIListItem();
item.setValue("space-icon-default");
item.getAttributes().put("image", "/images/icons/space-icon-default.gif");
icons.add(item);
}
return icons;
}
/**
* @param namespaceService The NamespaceService
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* Sets the dictionary service
*
* @param dictionaryService the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Formats the error message to display if an error occurs during finish processing
*
* @param The exception
* @return The formatted message
*/
@Override
protected String formatErrorMessage(Throwable exception)
{
if (exception instanceof FileExistsException)
{
return MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), "error_exists"),
((FileExistsException)exception).getExisting().getName());
}
else
{
return MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), "error_space"),
((FileExistsException)exception).getExisting().getName());
}
}
}

View File

@@ -2,47 +2,35 @@ package org.alfresco.web.bean.wizard;
import javax.faces.context.FacesContext;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.bean.dialog.BaseDialogBean;
/**
* Base class for all wizard beans providing common functionality
*
* @author gavinc
*/
public abstract class BaseWizardBean implements IWizardBean
public abstract class BaseWizardBean extends BaseDialogBean implements IWizardBean
{
protected static final String WIZARD_CLOSE = "wizard:close";
private static final String MSG_NOT_SET = "value_not_set";
public abstract String finish();
// services common to most wizards
protected FileFolderService fileFolderService;
protected SearchService searchService;
public void init()
{
// tell any beans to update themselves so the UI gets refreshed
UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
}
public boolean getNextButtonDisabled()
{
return true;
}
public boolean getBackButtonDisabled()
{
return true;
}
public boolean getFinishButtonDisabled()
{
return true;
return false;
}
public String getNextButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "next_button");
}
public String getBackButtonLabel()
{
return Application.getMessage(FacesContext.getCurrentInstance(), "back_button");
@@ -52,9 +40,67 @@ public abstract class BaseWizardBean implements IWizardBean
{
return Application.getMessage(FacesContext.getCurrentInstance(), "finish_button");
}
public String cancel()
/**
* @param fileFolderService used to manipulate folder/folder model nodes
*/
public void setFileFolderService(FileFolderService fileFolderService)
{
return WIZARD_CLOSE;
this.fileFolderService = fileFolderService;
}
/**
* @param searchService the service used to find nodes
*/
public void setSearchService(SearchService searchService)
{
this.searchService = searchService;
}
/**
* Build summary table from the specified list of Labels and Values
*
* @param labels Array of labels to display
* @param values Array of values to display
*
* @return summary table HTML
*/
protected String buildSummary(String[] labels, String[] values)
{
if (labels == null || values == null || labels.length != values.length)
{
throw new IllegalArgumentException("Labels and Values passed to summary must be valid and of equal length.");
}
String msg = Application.getMessage(FacesContext.getCurrentInstance(), MSG_NOT_SET);
String notSetMsg = "&lt;" + msg + "&gt;";
StringBuilder buf = new StringBuilder(256);
buf.append("<table cellspacing='4' cellpadding='2' border='0' class='summary'>");
for (int i=0; i<labels.length; i++)
{
String value = values[i];
buf.append("<tr><td valign='top'><b>");
buf.append(labels[i]);
buf.append(":</b></td><td>");
buf.append(value != null ? value : notSetMsg);
buf.append("</td></tr>");
}
buf.append("</table>");
return buf.toString();
}
@Override
protected String getDefaultCancelOutcome()
{
return AlfrescoNavigationHandler.CLOSE_WIZARD_OUTCOME;
}
@Override
protected String getDefaultFinishOutcome()
{
return AlfrescoNavigationHandler.CLOSE_WIZARD_OUTCOME;
}
}

View File

@@ -9,34 +9,6 @@ import org.alfresco.web.bean.dialog.IDialogBean;
*/
public interface IWizardBean extends IDialogBean
{
/**
* Method handler called when the next button of the wizard is pressed
*
* @return The outcome to return
*/
// public String next();
/**
* Method handler called when the back button of the wizard is pressed
*
* @return The outcome to return
*/
// public String back();
/**
* Determines whether the next button on the wizard should be disabled
*
* @return true if the button should be disabled
*/
public boolean getNextButtonDisabled();
/**
* Determines whether the back button on the wizard should be disabled
*
* @return true if the button should be disabled
*/
public boolean getBackButtonDisabled();
/**
* Returns the label to use for the next button
*
@@ -50,4 +22,11 @@ public interface IWizardBean extends IDialogBean
* @return The back button label
*/
public String getBackButtonLabel();
/**
* Determines whether the next button on the wizard should be disabled
*
* @return true if the button should be disabled
*/
public boolean getNextButtonDisabled();
}

View File

@@ -1,10 +1,21 @@
package org.alfresco.web.bean.wizard;
import java.util.ArrayList;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.servlet.FacesHelper;
import org.alfresco.web.config.WizardsConfigElement.ConditionalPageConfig;
import org.alfresco.web.config.WizardsConfigElement.PageConfig;
import org.alfresco.web.config.WizardsConfigElement.StepConfig;
import org.alfresco.web.config.WizardsConfigElement.WizardConfig;
import org.alfresco.web.ui.common.component.UIListItem;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean that manages the wizard framework
@@ -13,8 +24,13 @@ import org.alfresco.web.config.WizardsConfigElement.WizardConfig;
*/
public class WizardManager
{
private static Log logger = LogFactory.getLog(WizardManager.class);
protected int currentStep = 1;
protected PageConfig currentPageCfg;
protected WizardConfig currentWizardConfig;
protected IWizardBean currentWizard;
protected List<StepConfig> steps;
/**
* Sets the current wizard
@@ -23,6 +39,7 @@ public class WizardManager
*/
public void setCurrentWizard(WizardConfig config)
{
this.currentStep = 1;
this.currentWizardConfig = config;
String beanName = this.currentWizardConfig.getManagedBean();
@@ -36,6 +53,22 @@ public class WizardManager
// initialise the managed bean
this.currentWizard.init();
// get the steps for the wizard
this.steps = this.currentWizardConfig.getStepsAsList();
// setup the first step
determineCurrentPage();
}
/**
* Returns the config for the current wizard
*
* @return The current wizard config
*/
public WizardConfig getCurrentWizard()
{
return this.currentWizardConfig;
}
/**
@@ -47,4 +80,395 @@ public class WizardManager
{
return this.currentWizard;
}
/**
* Returns the icon to use for the current wizard
*
* @return The icon
*/
public String getIcon()
{
return this.currentWizardConfig.getIcon();
}
/**
* Returns the resolved title to use for the wizard
*
* @return The title
*/
public String getTitle()
{
String title = this.currentWizardConfig.getTitleId();
if (title != null)
{
title = Application.getMessage(FacesContext.getCurrentInstance(), title);
}
else
{
title = this.currentWizardConfig.getTitle();
}
return title;
}
/**
* Returns the resolved description to use for the wizard
*
* @return The description
*/
public String getDescription()
{
String desc = this.currentWizardConfig.getDescriptionId();
if (desc != null)
{
desc = Application.getMessage(FacesContext.getCurrentInstance(), desc);
}
else
{
desc = this.currentWizardConfig.getDescription();
}
return desc;
}
/**
* Returns the current step position
*
* @return Current step position
*/
public int getCurrentStep()
{
return this.currentStep;
}
/**
* Returns the current step position as a string for use in the UI
*
* @return Current step position as a string
*/
public String getCurrentStepAsString()
{
return Integer.toString(this.currentStep);
}
/**
* Returns a list of UIListItems representing the steps of the wizard
*
* @return List of steps to display in UI
*/
public List<UIListItem> getStepItems()
{
List<UIListItem> items = new ArrayList<UIListItem>(this.steps.size());
for (int x = 0; x < this.steps.size(); x++)
{
String uiStepNumber = Integer.toString(x + 1);
StepConfig stepCfg = this.steps.get(x);
UIListItem item = new UIListItem();
item.setValue(uiStepNumber);
// get the title for the step
String stepTitle = stepCfg.getTitleId();
if (stepTitle != null)
{
stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), stepTitle);
}
else
{
stepTitle = stepCfg.getTitle();
}
// get the tooltip for the step
String stepTooltip = stepCfg.getDescriptionId();
if (stepTooltip != null)
{
stepTooltip = Application.getMessage(FacesContext.getCurrentInstance(), stepTooltip);
}
else
{
stepTooltip = stepCfg.getDescription();
}
// set the label and tooltip
item.setLabel(uiStepNumber + ". " + stepTitle);
item.setTooltip(stepTooltip);
items.add(item);
}
return items;
}
/**
* Returns the current page of the wizard (depends on the current step position)
*
* @return The page
*/
public String getPage()
{
return this.currentPageCfg.getPath();
}
/**
* Returns the title of the current step
*
* @return The step title
*/
public String getStepTitle()
{
String title = this.currentPageCfg.getTitleId();
if (title != null)
{
title = Application.getMessage(FacesContext.getCurrentInstance(), title);
}
else
{
title = this.currentPageCfg.getTitle();
}
return title;
}
/**
* Returns the description of the current step
*
* @return The step description
*/
public String getStepDescription()
{
String desc = this.currentPageCfg.getDescriptionId();
if (desc != null)
{
desc = Application.getMessage(FacesContext.getCurrentInstance(), desc);
}
else
{
desc = this.currentPageCfg.getDescription();
}
return desc;
}
/**
* Returns the instructions for the current step
*
* @return The step instructions
*/
public String getStepInstructions()
{
String instruction = this.currentPageCfg.getInstructionId();
if (instruction != null)
{
instruction = Application.getMessage(FacesContext.getCurrentInstance(), instruction);
}
else
{
instruction = this.currentPageCfg.getInstruction();
}
return instruction;
}
/**
* Returns the label to use for the next button
*
* @return The next button label
*/
public String getNextButtonLabel()
{
return this.currentWizard.getNextButtonLabel();
}
/**
* Determines whether the next button on the wizard should be disabled
*
* @return true if the button should be disabled
*/
public boolean getNextButtonDisabled()
{
if (this.currentStep == this.steps.size())
{
return true;
}
else
{
return this.currentWizard.getNextButtonDisabled();
}
}
/**
* Returns the label to use for the back button
*
* @return The back button label
*/
public String getBackButtonLabel()
{
return this.currentWizard.getBackButtonLabel();
}
/**
* Determines whether the back button on the wizard should be disabled
*
* @return true if the button should be disabled
*/
public boolean getBackButtonDisabled()
{
if (this.currentStep == 1)
{
return true;
}
else
{
return false;
}
}
/**
* Returns the label to use for the cancel button
*
* @return The cancel button label
*/
public String getCancelButtonLabel()
{
return this.currentWizard.getCancelButtonLabel();
}
/**
* Returns the label to use for the finish button
*
* @return The finish button label
*/
public String getFinishButtonLabel()
{
return this.currentWizard.getFinishButtonLabel();
}
/**
* Determines whether the finish button on the wizard should be disabled
*
* @return true if the button should be disabled
*/
public boolean getFinishButtonDisabled()
{
if (this.currentStep == this.steps.size())
{
return false;
}
else
{
return this.currentWizard.getFinishButtonDisabled();
}
}
/**
* Method handler called when the next button of the wizard is pressed
*
* @return The outcome
*/
public void next()
{
this.currentStep++;
if (logger.isDebugEnabled())
logger.debug("next called, current step is now: " + this.currentStep);
// TODO: place a hook in here to call the wizard bean so it can override
// what step comes next thus overrriding the wizard manager
determineCurrentPage();
}
/**
* Method handler called when the back button of the wizard is pressed
*
* @return The outcome
*/
public void back()
{
this.currentStep--;
if (logger.isDebugEnabled())
logger.debug("back called, current step is now: " + this.currentStep);
// TODO: place a hook in here to call the wizard bean so it can override
// what step comes next thus overrriding the wizard manager
determineCurrentPage();
}
/**
* Method handler called when the finish button of the wizard is pressed
*
* @return The outcome
*/
public String finish()
{
return this.currentWizard.finish();
}
/**
* Method handler called when the cancel button of the wizard is pressed
*
* @return The outcome
*/
public String cancel()
{
return this.currentWizard.cancel();
}
/**
* Sets up the current page to show in the wizard
*/
protected void determineCurrentPage()
{
this.currentPageCfg = null;
// get the config for the current step position
StepConfig stepCfg = this.steps.get(this.currentStep-1);
// is the step conditional?
if (stepCfg.hasConditionalPages())
{
FacesContext context = FacesContext.getCurrentInstance();
// test each conditional page in turn
List<ConditionalPageConfig> pages = stepCfg.getConditionalPages();
for (ConditionalPageConfig pageCfg : pages)
{
String condition = pageCfg.getCondition();
if (logger.isDebugEnabled())
logger.debug("Evaluating condition: " + condition);
ValueBinding vb = context.getApplication().createValueBinding(condition);
Object obj = vb.getValue(context);
if (obj instanceof Boolean && ((Boolean)obj).booleanValue())
{
this.currentPageCfg = pageCfg;
break;
}
}
}
// if none of the conditions passed use the default page
if (this.currentPageCfg == null)
{
this.currentPageCfg = stepCfg.getDefaultPage();
}
if (this.currentPageCfg == null)
{
throw new AlfrescoRuntimeException("Failed to determine page for step '" + stepCfg.getName() +
"'. Make sure a default page is configured.");
}
if (logger.isDebugEnabled())
logger.debug("Config for current page: " + this.currentPageCfg);
}
}