- Start Workflow Wizard now shows resources list and allows items to be added and removed

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3629 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2006-08-29 21:16:07 +00:00
parent 7878ecd144
commit 3c1a2ff549
2 changed files with 319 additions and 12 deletions

View File

@@ -1,14 +1,18 @@
package org.alfresco.web.bean.workflow; package org.alfresco.web.bean.workflow;
import java.io.Serializable; import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem; import javax.faces.model.SelectItem;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.workflow.WorkflowModel; import org.alfresco.repo.workflow.WorkflowModel;
@@ -23,10 +27,14 @@ import org.alfresco.service.cmr.workflow.WorkflowTaskState;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application; import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.MapNode;
import org.alfresco.web.bean.repository.Node; import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.repository.TransientNode; import org.alfresco.web.bean.repository.TransientNode;
import org.alfresco.web.bean.wizard.BaseWizardBean; import org.alfresco.web.bean.wizard.BaseWizardBean;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.UIActionLink;
import org.alfresco.web.ui.common.component.data.UIRichList;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@@ -42,6 +50,11 @@ public class StartWorkflowWizard extends BaseWizardBean
protected Map<String, WorkflowDefinition> workflows; protected Map<String, WorkflowDefinition> workflows;
protected WorkflowService workflowService; protected WorkflowService workflowService;
protected Node startTaskNode; protected Node startTaskNode;
protected List<Node> resources;
protected List<String> packageItemsToAdd;
protected UIRichList packageItemsRichList;
protected String[] itemsToAdd;
protected boolean isItemBeingAdded = false;
protected boolean nextButtonDisabled = false; protected boolean nextButtonDisabled = false;
private static final Log logger = LogFactory.getLog(StartWorkflowWizard.class); private static final Log logger = LogFactory.getLog(StartWorkflowWizard.class);
@@ -65,6 +78,31 @@ public class StartWorkflowWizard extends BaseWizardBean
} }
this.startTaskNode = null; this.startTaskNode = null;
this.resources = null;
this.itemsToAdd = null;
this.packageItemsToAdd = new ArrayList<String>();
this.isItemBeingAdded = false;
if (this.packageItemsRichList != null)
{
this.packageItemsRichList.setValue(null);
}
// TODO: Does this need to be in a read-only transaction??
// add the item the workflow wizard was started on to the list of resources
String itemToWorkflowId = this.parameters.get("item-to-workflow");
if (itemToWorkflowId != null && itemToWorkflowId.length() > 0)
{
// create the node ref for the item and determine its type
NodeRef itemToWorkflow = new NodeRef(Repository.getStoreRef(), itemToWorkflowId);
QName type = this.nodeService.getType(itemToWorkflow);
if (this.dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT) ||
this.dictionaryService.isSubClass(type, ContentModel.TYPE_FILELINK))
{
this.packageItemsToAdd.add(itemToWorkflow.toString());
}
}
} }
@Override @Override
@@ -80,23 +118,17 @@ public class StartWorkflowWizard extends BaseWizardBean
Map<QName, Serializable> params = WorkflowBean.prepareWorkItemParams(this.startTaskNode); Map<QName, Serializable> params = WorkflowBean.prepareWorkItemParams(this.startTaskNode);
// create a workflow package for the attached items and add them // create a workflow package for the attached items and add them
String itemToWorkflowId = this.parameters.get("item-to-workflow"); if (this.packageItemsToAdd.size() > 0)
if (itemToWorkflowId != null && itemToWorkflowId.length() > 0)
{ {
// create the node ref for the item and determine its type NodeRef workflowPackage = this.workflowService.createPackage(null);
NodeRef itemToWorkflow = new NodeRef(Repository.getStoreRef(), itemToWorkflowId);
QName type = this.nodeService.getType(itemToWorkflow);
NodeRef workflowPackage = null; for (String addedItem : this.packageItemsToAdd)
if (this.dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT) ||
this.dictionaryService.isSubClass(type, ContentModel.TYPE_FILELINK))
{ {
// create a workflow package and add the given item to workflow as a child NodeRef addedNodeRef = new NodeRef(addedItem);
workflowPackage = this.workflowService.createPackage(null); this.nodeService.addChild(workflowPackage, addedNodeRef,
this.nodeService.addChild(workflowPackage, itemToWorkflow,
ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
QName.createValidLocalName((String)this.nodeService.getProperty( QName.createValidLocalName((String)this.nodeService.getProperty(
itemToWorkflow, ContentModel.PROP_NAME)))); addedNodeRef, ContentModel.PROP_NAME))));
} }
// add the workflow package to the parameter map // add the workflow package to the parameter map
@@ -175,9 +207,131 @@ public class StartWorkflowWizard extends BaseWizardBean
return this.nextButtonDisabled; return this.nextButtonDisabled;
} }
// ------------------------------------------------------------------------------
// Event Handlers
/**
* Prepares the dialog to allow the user to add an item to the workflow package
*
* @param event The event
*/
public void prepareForAdd(ActionEvent event)
{
this.isItemBeingAdded = true;
}
/**
* Cancels the adding of an item to the workflow package
*
* @param event The event
*/
public void cancelAddPackageItems(ActionEvent event)
{
this.isItemBeingAdded = false;
}
/**
* Adds items to the workflow package
*
* @param event The event
*/
public void addPackageItems(ActionEvent event)
{
if (this.itemsToAdd != null)
{
for (String item : this.itemsToAdd)
{
this.packageItemsToAdd.add(item);
if (logger.isDebugEnabled())
logger.debug("Added item to the added list: " + item);
}
// reset the rich list so it re-renders
this.packageItemsRichList.setValue(null);
}
this.isItemBeingAdded = false;
this.itemsToAdd = null;
}
/**
* Removes an item from the workflow package
*
* @param event The event containing a reference to the item to remove
*/
public void removePackageItem(ActionEvent event)
{
UIActionLink link = (UIActionLink)event.getComponent();
Map<String, String> params = link.getParameterMap();
String nodeRef = new NodeRef(Repository.getStoreRef(), params.get("id")).toString();
if (this.packageItemsToAdd.contains(nodeRef))
{
// remove the item from the added list if it was added in this dialog session
this.packageItemsToAdd.remove(nodeRef);
if (logger.isDebugEnabled())
logger.debug("Removed item from the added list: " + nodeRef);
}
// reset the rich list so it re-renders
this.packageItemsRichList.setValue(null);
}
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// Bean Getters and Setters // Bean Getters and Setters
/**
* Returns a String array of NodeRef's that are being added to the workflow package
*
* @return String array of NodeRef's
*/
public String[] getItemsToAdd()
{
return this.itemsToAdd;
}
/**
* Sets the NodeRef's to add as items to the workflow package
*
* @param itemsToAdd NodeRef's to add to the workflow package
*/
public void setItemsToAdd(String[] itemsToAdd)
{
this.itemsToAdd = itemsToAdd;
}
/**
* Determines whether an item is currently being added to the workflow package
*
* @return true if an item is being added
*/
public boolean isItemBeingAdded()
{
return this.isItemBeingAdded;
}
/**
* Sets the rich list being used for the workflow package items
*
* @param richList The rich list instance
*/
public void setPackageItemsRichList(UIRichList richList)
{
this.packageItemsRichList = richList;
}
/**
* Returns the rich list being used for the workflow package items
*
* @return The rich list instance
*/
public UIRichList getPackageItemsRichList()
{
return this.packageItemsRichList;
}
/** /**
* Returns the workflow selected by the user * Returns the workflow selected by the user
* *
@@ -317,6 +471,59 @@ public class StartWorkflowWizard extends BaseWizardBean
return availableWorkflows; return availableWorkflows;
} }
/**
* Returns a list of resources associated with this work item
* i.e. the children of the workflow package
*
* @return The list of nodes
*/
public List<Node> getResources()
{
this.resources = new ArrayList<Node>(4);
UserTransaction tx = null;
try
{
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context, true);
tx.begin();
for (String newItem : this.packageItemsToAdd)
{
NodeRef nodeRef = new NodeRef(newItem);
if (this.nodeService.exists(nodeRef))
{
// create our Node representation
MapNode node = new MapNode(nodeRef, this.nodeService, true);
this.browseBean.setupCommonBindingProperties(node);
// add property resolvers to show path information
node.addPropertyResolver("path", this.browseBean.resolverPath);
node.addPropertyResolver("displayPath", this.browseBean.resolverDisplayPath);
this.resources.add(node);
}
else
{
if (logger.isDebugEnabled())
logger.debug("Ignoring " + nodeRef + " as it has been removed from the repository");
}
}
// commit the transaction
tx.commit();
}
catch (Throwable err)
{
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
this.resources = Collections.<Node>emptyList();
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
}
return this.resources;
}
/** /**
* Sets the workflow service to use * Sets the workflow service to use
* *

View File

@@ -44,7 +44,107 @@
<r:propertySheetGrid id="task-props" value="#{WizardManager.bean.taskMetadataNode}" <r:propertySheetGrid id="task-props" value="#{WizardManager.bean.taskMetadataNode}"
var="taskProps" columns="1" externalConfig="true" /> var="taskProps" columns="1" externalConfig="true" />
</a:panel> </a:panel>
<h:outputText styleClass="paddingRow" value="&nbsp;" escape="false" />
<a:panel id="resources-panel" label="#{msg.resources}"
border="white" bgcolor="white" titleBorder="blue" titleBgcolor="#D3E6FE" styleClass="mainSubTitle">
<a:richList id="resources-list" viewMode="details" value="#{WizardManager.bean.resources}" var="r"
binding="#{WizardManager.bean.packageItemsRichList}"
styleClass="recordSet" headerStyleClass="recordSetHeader" rowStyleClass="recordSetRow"
altRowStyleClass="recordSetRowAlt" width="100%" pageSize="10"
initialSortColumn="name" initialSortDescending="true">
<%-- Name column --%>
<a:column primary="true" width="200" style="padding:2px; text-align:left">
<f:facet name="header">
<a:sortLink label="#{msg.name}" value="name" mode="case-insensitive" styleClass="header"/>
</f:facet>
<f:facet name="small-icon">
<a:actionLink value="#{r.name}" href="#{r.url}" target="new" image="#{r.fileType16}"
showLink="false" styleClass="inlineAction" />
</f:facet>
<a:actionLink value="#{r.name}" href="#{r.url}" target="new" />
</a:column>
<%-- Description column --%>
<a:column style="text-align:left">
<f:facet name="header">
<a:sortLink label="#{msg.description}" value="description" styleClass="header"/>
</f:facet>
<h:outputText value="#{r.description}" />
</a:column>
<%-- Path column --%>
<a:column style="text-align:left">
<f:facet name="header">
<a:sortLink label="#{msg.path}" value="path" styleClass="header"/>
</f:facet>
<r:nodePath value="#{r.path}" />
</a:column>
<%-- Created Date column --%>
<a:column style="text-align:left">
<f:facet name="header">
<a:sortLink label="#{msg.created}" value="created" styleClass="header"/>
</f:facet>
<h:outputText value="#{r.created}">
<a:convertXMLDate type="both" pattern="#{msg.date_time_pattern}" />
</h:outputText>
</a:column>
<%-- Modified Date column --%>
<a:column style="text-align:left">
<f:facet name="header">
<a:sortLink label="#{msg.modified}" value="modified" styleClass="header"/>
</f:facet>
<h:outputText value="#{r.modified}">
<a:convertXMLDate type="both" pattern="#{msg.date_time_pattern}" />
</h:outputText>
</a:column>
<%-- Actions column --%>
<a:column actions="true" style="text-align:left">
<f:facet name="header">
<h:outputText value="#{msg.actions}"/>
</f:facet>
<%-- TODO: need to drive this dynamically from the model - need support for #{CurrentContainer....}
<r:actions id="actions-col-actions" value="#{WizardManager.bean.packageItemActionGroup}"
context="#{r}" showLink="false" styleClass="inlineAction" />
--%>
<a:actionLink value="#{msg.view_details}" action="dialog:showDocDetails" image="/images/icons/View_details.gif"
showLink="false" actionListener="#{BrowseBean.setupContentAction}" styleClass="inlineAction">
<f:param name="id" value="#{r.id}" />
</a:actionLink>
<a:actionLink value="#{msg.remove}" image="/images/icons/remove_item.gif" styleClass="inlineAction"
showLink="false" actionListener="#{WizardManager.bean.removePackageItem}">
<f:param name="id" value="#{r.id}" />
</a:actionLink>
</a:column>
</a:richList>
<h:panelGrid columns="1" styleClass="paddingRow">
<%-- TODO: need to drive this dynamically from the model - need support for #{CurrentContainer....}
<r:actions context="#{WizardManager.bean.taskMetadataNode}" value="#{WizardManager.bean.packageActionGroup}" />
--%>
<a:actionLink value="#{msg.add_resource}" image="/images/icons/add_item.gif"
actionListener="#{WizardManager.bean.prepareForAdd}" styleClass="inlineAction">
<f:param name="id" value="#{r.id}" />
</a:actionLink>
</h:panelGrid>
<h:panelGrid columns="1" rendered="#{WizardManager.bean.itemBeingAdded}" styleClass="selector" style="margin-top: 6px;">
<r:contentSelector value="#{WizardManager.bean.itemsToAdd}" styleClass="" />
<h:panelGrid columns="2">
<h:commandButton value="#{msg.add_to_list_button}" actionListener="#{WizardManager.bean.addPackageItems}" />
<h:commandButton value="#{msg.cancel}" actionListener="#{WizardManager.bean.cancelAddPackageItems}" />
</h:panelGrid>
</h:panelGrid>
</a:panel>
</h:panelGroup> </h:panelGroup>