Combined edit categories dialog for content and spaces into one dialog and separated it from Document/SpaceDetailsBean

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6866 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2007-09-25 22:02:07 +00:00
parent 2418955ed2
commit 2a5a949275
9 changed files with 212 additions and 448 deletions

View File

@@ -60,13 +60,10 @@ import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.servlet.DownloadContentServlet;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.alfresco.web.bean.dialog.IDialogBean;
import org.alfresco.web.bean.ml.MultilingualUtils;
import org.alfresco.web.bean.repository.MapNode;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.Utils.URLMode;
import org.alfresco.web.ui.common.component.UIActionLink;
@@ -76,7 +73,7 @@ import org.alfresco.web.ui.common.component.UIActionLink;
*
* @author gavinc
*/
public class DocumentDetailsBean extends BaseDetailsBean implements IDialogBean
public class DocumentDetailsBean extends BaseDetailsBean
{
private static final String OUTCOME_RETURN = "showDocDetails";
@@ -87,8 +84,7 @@ public class DocumentDetailsBean extends BaseDetailsBean implements IDialogBean
private static final String MSG_ERROR_ASPECT_INLINEEDITABLE = "error_aspect_inlineeditable";
private static final String MSG_ERROR_ASPECT_VERSIONING = "error_aspect_versioning";
private static final String MSG_ERROR_ASPECT_CLASSIFY = "error_aspect_classify";
private static final String MSG_ERROR_UPDATE_CATEGORY = "error_update_category";
private static final String MSG_MODIFY_CATEGORIES_OF = "modify_categories_of";
private static final String ML_VERSION_PANEL_ID = "ml-versions-panel";
@@ -99,21 +95,7 @@ public class DocumentDetailsBean extends BaseDetailsBean implements IDialogBean
protected ContentFilterLanguagesService contentFilterLanguagesService;
protected EditionService editionService;
private NodeRef addedCategory;
private List categories;
private Node translationDocument;
private BaseDialogBean baseDialogBean = new BaseDialogBeanImpl();
private class BaseDialogBeanImpl extends BaseDialogBean
{
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
return saveCategories(context, outcome);
}
}
// ------------------------------------------------------------------------------
// Construction
@@ -142,10 +124,6 @@ public class DocumentDetailsBean extends BaseDetailsBean implements IDialogBean
{
// reset the workflow cache
this.workflowProperties = null;
// reset the category caches
this.categories = null;
this.addedCategory = null;
}
/**
@@ -576,99 +554,6 @@ public class DocumentDetailsBean extends BaseDetailsBean implements IDialogBean
return html;
}
/**
* Event handler called to setup the categories for editing
*
* @param event The event
*/
public void setupCategoriesForEdit(ActionEvent event)
{
this.categories = (List)this.nodeService.getProperty(getDocument().getNodeRef(),
ContentModel.PROP_CATEGORIES);
}
/**
* Returns a Map of the initial categories on the node keyed by the NodeRef
*
* @return Map of initial categories
*/
public List getCategories()
{
return this.categories;
}
/**
* Sets the categories Map
*
* @param categories
*/
public void setCategories(List categories)
{
this.categories = categories;
}
/**
* Returns the last category added from the multi value editor
*
* @return The last category added
*/
public NodeRef getAddedCategory()
{
return this.addedCategory;
}
/**
* Sets the category added from the multi value editor
*
* @param addedCategory The added category
*/
public void setAddedCategory(NodeRef addedCategory)
{
this.addedCategory = addedCategory;
}
/**
* Updates the categories for the current document
*
* @return The outcome
*/
public String saveCategories(FacesContext newContext, String newOutcome)
{
String outcome = newOutcome;
try
{
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>()
{
public Object execute() throws Throwable
{
// firstly retrieve all the properties for the current node
Map<QName, Serializable> updateProps = nodeService.getProperties(getDocument().getNodeRef());
// create a node ref representation of the selected id and set the new properties
updateProps.put(ContentModel.PROP_CATEGORIES, (Serializable) categories);
// set the properties on the node
nodeService.setProperties(getDocument().getNodeRef(), updateProps);
return null;
}
};
txnHelper.doInTransaction(callback);
// reset the state of the current document so it reflects the changes just made
getDocument().reset();
}
catch (Throwable e)
{
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), MSG_ERROR_UPDATE_CATEGORY), e.getMessage()), e);
}
return outcome;
}
/**
* Applies the classifiable aspect to the current document
*/
@@ -1097,78 +982,4 @@ public class DocumentDetailsBean extends BaseDetailsBean implements IDialogBean
{
this.editionService = editionService;
}
// ------------------------------------------------------------------------------
// IDialogBean implementation
public String cancel()
{
return baseDialogBean.cancel();
}
public String finish()
{
return baseDialogBean.finish();
}
public List<DialogButtonConfig> getAdditionalButtons()
{
return baseDialogBean.getAdditionalButtons();
}
public String getCancelButtonLabel()
{
return baseDialogBean.getCancelButtonLabel();
}
public String getContainerDescription()
{
return baseDialogBean.getContainerDescription();
}
public String getContainerTitle()
{
return Application.getMessage(FacesContext.getCurrentInstance(), MSG_MODIFY_CATEGORIES_OF) +
" '" + getDocument().getName() + "'";
}
public String getContainerSubTitle()
{
return baseDialogBean.getContainerSubTitle();
}
public boolean getFinishButtonDisabled()
{
return false;
}
public String getFinishButtonLabel()
{
return baseDialogBean.getFinishButtonLabel();
}
public void init(Map<String, String> parameters)
{
baseDialogBean.init(parameters);
}
public void restored()
{
baseDialogBean.restored();
}
public Object getActionsContext()
{
return baseDialogBean.getActionsContext();
}
public String getActionsConfigId()
{
return baseDialogBean.getActionsConfigId();
}
public String getMoreActionsConfigId()
{
return baseDialogBean.getMoreActionsConfigId();
}
}

View File

@@ -24,7 +24,6 @@
*/
package org.alfresco.web.bean;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.HashMap;
@@ -39,15 +38,11 @@ import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.TemplateService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.servlet.GuestTemplateContentServlet;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.alfresco.web.bean.dialog.IDialogBean;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.config.DialogsConfigElement.DialogButtonConfig;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.Utils.URLMode;
import org.alfresco.web.ui.common.component.UIActionLink;
@@ -57,31 +52,15 @@ import org.alfresco.web.ui.common.component.UIActionLink;
*
* @author Kevin Roast
*/
public class SpaceDetailsBean extends BaseDetailsBean implements IDialogBean
public class SpaceDetailsBean extends BaseDetailsBean
{
private static final String MSG_HAS_FOLLOWING_CATEGORIES = "has_following_categories_space";
private static final String MSG_NO_CATEGORIES_APPLIED = "no_categories_applied_space";
private static final String MSG_ERROR_UPDATE_CATEGORY = "error_update_category";
private static final String MSG_ERROR_ASPECT_CLASSIFY = "error_aspect_classify_space";
private static final String MSG_MODIFY_CATEGORIES_OF = "modify_categories_of";
/** Category details */
private NodeRef addedCategory;
private List categories;
private BaseDialogBean baseDialogBean = new BaseDialogBeanImpl();
/** RSS Template ID */
private String rssTemplate;
private class BaseDialogBeanImpl extends BaseDialogBean
{
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
return saveCategories(context, outcome);
}
}
// ------------------------------------------------------------------------------
// Construction
@@ -352,99 +331,6 @@ public class SpaceDetailsBean extends BaseDetailsBean implements IDialogBean
return html;
}
/**
* Event handler called to setup the categories for editing
*
* @param event The event
*/
public void setupCategoriesForEdit(ActionEvent event)
{
this.categories = (List)this.nodeService.getProperty(getSpace().getNodeRef(),
ContentModel.PROP_CATEGORIES);
}
/**
* Returns a Map of the initial categories on the node keyed by the NodeRef
*
* @return Map of initial categories
*/
public List getCategories()
{
return this.categories;
}
/**
* Sets the categories Map
*
* @param categories
*/
public void setCategories(List categories)
{
this.categories = categories;
}
/**
* Returns the last category added from the multi value editor
*
* @return The last category added
*/
public NodeRef getAddedCategory()
{
return this.addedCategory;
}
/**
* Sets the category added from the multi value editor
*
* @param addedCategory The added category
*/
public void setAddedCategory(NodeRef addedCategory)
{
this.addedCategory = addedCategory;
}
/**
* Updates the categories for the current document
*
* @return The outcome
*/
public String saveCategories(FacesContext newContext, String newOutcome)
{
String outcome = newOutcome;
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance());
tx.begin();
// firstly retrieve all the properties for the current node
Map<QName, Serializable> updateProps = this.nodeService.getProperties(
getSpace().getNodeRef());
// create a node ref representation of the selected id and set the new properties
updateProps.put(ContentModel.PROP_CATEGORIES, (Serializable)this.categories);
// set the properties on the node
this.nodeService.setProperties(getSpace().getNodeRef(), updateProps);
// commit the transaction
tx.commit();
// reset the state of the current document so it reflects the changes just made
getSpace().reset();
}
catch (Throwable e)
{
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), MSG_ERROR_UPDATE_CATEGORY), e.getMessage()), e);
}
return outcome;
}
/**
* Applies the classifiable aspect to the current document
@@ -598,78 +484,4 @@ public class SpaceDetailsBean extends BaseDetailsBean implements IDialogBean
FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), e.getMessage()), e);
}
}
// ------------------------------------------------------------------------------
// dialog implementation
public String cancel()
{
return baseDialogBean.cancel();
}
public String finish()
{
return baseDialogBean.finish();
}
public List<DialogButtonConfig> getAdditionalButtons()
{
return baseDialogBean.getAdditionalButtons();
}
public String getCancelButtonLabel()
{
return baseDialogBean.getCancelButtonLabel();
}
public String getContainerDescription()
{
return baseDialogBean.getContainerDescription();
}
public String getContainerTitle()
{
return Application.getMessage(FacesContext.getCurrentInstance(), MSG_MODIFY_CATEGORIES_OF) +
" '" + getSpace().getName() + "'";
}
public String getContainerSubTitle()
{
return baseDialogBean.getContainerSubTitle();
}
public boolean getFinishButtonDisabled()
{
return false;
}
public String getFinishButtonLabel()
{
return baseDialogBean.getFinishButtonLabel();
}
public void init(Map<String, String> parameters)
{
baseDialogBean.init(parameters);
}
public void restored()
{
baseDialogBean.restored();
}
public Object getActionsContext()
{
return baseDialogBean.getActionsContext();
}
public String getActionsConfigId()
{
return baseDialogBean.getActionsConfigId();
}
public String getMoreActionsConfigId()
{
return baseDialogBean.getMoreActionsConfigId();
}
}

View File

@@ -0,0 +1,179 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.web.bean.categories;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ParameterCheck;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
/**
* Implementation for the edit node categories dialog.
*
* @author gavinc
*/
public class EditNodeCategoriesDialog extends BaseDialogBean
{
protected Node node;
protected NodeRef addedCategory;
protected List categories;
protected String description;
private static final String MSG_ERROR_UPDATE_CATEGORY = "error_update_category";
private static final String MSG_MODIFY_CATEGORIES_OF = "modify_categories_of";
// ------------------------------------------------------------------------------
// Dialog implementation
@Override
public void init(Map<String, String> parameters)
{
super.init(parameters);
// reset variables
this.categories = null;
this.addedCategory = null;
// retrieve parameters
String id = parameters.get("id");
// make sure id was supplied
ParameterCheck.mandatoryString("id", id);
// create the node
this.node = new Node(new NodeRef(Repository.getStoreRef(), id));
// determine description for dialog
FacesContext context = FacesContext.getCurrentInstance();
if (this.dictionaryService.isSubClass(this.node.getType(), ContentModel.TYPE_FOLDER))
{
this.description = Application.getMessage(context, "editcategory_space_description");
}
else
{
this.description = Application.getMessage(context, "editcategory_description");
}
}
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
// firstly retrieve all the properties for the current node
Map<QName, Serializable> updateProps = this.nodeService.getProperties(this.node.getNodeRef());
// create a node ref representation of the selected id and set the new properties
updateProps.put(ContentModel.PROP_CATEGORIES, (Serializable) categories);
// set the properties on the node
this.nodeService.setProperties(this.node.getNodeRef(), updateProps);
return outcome;
}
@Override
public boolean getFinishButtonDisabled()
{
return false;
}
@Override
public String getContainerTitle()
{
return Application.getMessage(FacesContext.getCurrentInstance(), MSG_MODIFY_CATEGORIES_OF) +
" '" + this.node.getName() + "'";
}
@Override
public String getContainerDescription()
{
return this.description;
}
@Override
protected String getErrorMessageId()
{
return MSG_ERROR_UPDATE_CATEGORY;
}
// ------------------------------------------------------------------------------
// Bean property getters and setters
/**
* Returns a Map of the initial categories on the node keyed by the NodeRef
*
* @return Map of initial categories
*/
public List getCategories()
{
if (this.categories == null)
{
// get the list of categories
this.categories = (List)this.nodeService.getProperty(this.node.getNodeRef(),
ContentModel.PROP_CATEGORIES);
}
return this.categories;
}
/**
* Sets the categories Map
*
* @param categories
*/
public void setCategories(List categories)
{
this.categories = categories;
}
/**
* Returns the last category added from the multi value editor
*
* @return The last category added
*/
public NodeRef getAddedCategory()
{
return this.addedCategory;
}
/**
* Sets the category added from the multi value editor
*
* @param addedCategory The added category
*/
public void setAddedCategory(NodeRef addedCategory)
{
this.addedCategory = addedCategory;
}
}