Edit space is now done with a property sheet

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2671 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2006-04-20 10:30:43 +00:00
parent 819bf188d8
commit 4a0fefc4bd
15 changed files with 356 additions and 234 deletions

View File

@@ -5,7 +5,9 @@ import java.text.MessageFormat;
import javax.faces.context.FacesContext;
import javax.transaction.UserTransaction;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.NodeService;
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;
@@ -27,6 +29,8 @@ public abstract class BaseDialogBean implements IDialogBean
protected BrowseBean browseBean;
protected NavigationBean navigator;
protected NodeService nodeService;
protected FileFolderService fileFolderService;
protected SearchService searchService;
public void init()
{
@@ -54,7 +58,12 @@ public abstract class BaseDialogBean implements IDialogBean
// call the actual implementation
outcome = finishImpl(context, outcome);
// persist the changes
tx.commit();
// allow any subclasses to perform post commit processing
// i.e. resetting state or setting status messages
outcome = doPostCommitProcessing(context, outcome);
}
catch (Throwable e)
{
@@ -106,6 +115,22 @@ public abstract class BaseDialogBean implements IDialogBean
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;
}
/**
* Returns the default cancel outcome
*
@@ -138,6 +163,20 @@ public abstract class BaseDialogBean implements IDialogBean
protected abstract String finishImpl(FacesContext context, String outcome)
throws Exception;
/**
* Performs any post commit processing subclasses may want to provide
*
* @param context FacesContext
* @param outcome The default outcome
* @return The outcome
*/
protected String doPostCommitProcessing(FacesContext context, String outcome)
{
// do nothing by default, subclasses can override if necessary
return outcome;
}
/**
* Returns a formatted exception string for the given exception
*

View File

@@ -63,7 +63,7 @@ public class SpaceIconPickerGenerator extends BaseComponentGenerator
ValueBinding binding = propertySheet.getValueBinding("value");
String expression = binding.getExpressionString();
String beanName = expression.substring(2, expression.indexOf(".")+1);
if (beanName.equals("DialogManager") || beanName.equals("WizardManager"))
if (beanName.equals("DialogManager.") || beanName.equals("WizardManager."))
{
// deal with the special dialog and wizard manager beans by
// adding .bean

View File

@@ -0,0 +1,260 @@
package org.alfresco.web.bean.spaces;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.config.Config;
import org.alfresco.config.ConfigElement;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.ui.common.component.UIListItem;
/**
* Dialog bean to edit an existing space.
*
* @author gavinc
*/
public class EditSpaceDialog extends BaseDialogBean
{
protected Node editableNode;
protected DictionaryService dictionaryService;
protected NamespaceService namespaceService;
@Override
public void init()
{
super.init();
// setup the space being edited
this.editableNode = this.browseBean.getActionSpace();
}
/**
* Returns the editable node
*
* @return The editable node
*/
public Node getEditableNode()
{
return this.editableNode;
}
/**
* Sets the dictionary service
*
* @param dictionaryService the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @param namespaceService The NamespaceService
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* 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()
{
List<UIListItem> icons = null;
QName type = QName.createQName(this.editableNode.getType().toString());
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)
{
icons = new ArrayList<UIListItem>(iconsCfg.getChildCount());
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);
UIListItem item = new UIListItem();
item.setValue("space-icon-default");
item.getAttributes().put("image", "/images/icons/space-icon-default.gif");
icons.add(item);
}
return icons;
}
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception
{
// update the existing node in the repository
NodeRef nodeRef = this.editableNode.getNodeRef();
Map<String, Object> editedProps = this.editableNode.getProperties();
// handle the name property separately, perform a rename in case it changed
String name = (String)editedProps.get(ContentModel.PROP_NAME);
if (name != null)
{
this.fileFolderService.rename(nodeRef, name);
}
// get the current set of properties from the repository
Map<QName, Serializable> repoProps = this.nodeService.getProperties(nodeRef);
// overwrite the current properties with the edited ones
Iterator<String> iterProps = editedProps.keySet().iterator();
while (iterProps.hasNext())
{
String propName = iterProps.next();
QName qname = QName.createQName(propName);
// make sure the property is represented correctly
Serializable propValue = (Serializable)editedProps.get(propName);
// check for empty strings when using number types, set to null in this case
if ((propValue != null) && (propValue instanceof String) &&
(propValue.toString().length() == 0))
{
PropertyDefinition propDef = this.dictionaryService.getProperty(qname);
if (propDef != null)
{
if (propDef.getDataType().getName().equals(DataTypeDefinition.DOUBLE) ||
propDef.getDataType().getName().equals(DataTypeDefinition.FLOAT) ||
propDef.getDataType().getName().equals(DataTypeDefinition.INT) ||
propDef.getDataType().getName().equals(DataTypeDefinition.LONG))
{
propValue = null;
}
}
}
repoProps.put(qname, propValue);
}
// send the properties back to the repository
this.nodeService.setProperties(nodeRef, repoProps);
// we also need to persist any association changes that may have been made
// add any associations added in the UI
Map<String, Map<String, AssociationRef>> addedAssocs = this.editableNode.getAddedAssociations();
for (Map<String, AssociationRef> typedAssoc : addedAssocs.values())
{
for (AssociationRef assoc : typedAssoc.values())
{
this.nodeService.createAssociation(assoc.getSourceRef(), assoc.getTargetRef(), assoc.getTypeQName());
}
}
// remove any association removed in the UI
Map<String, Map<String, AssociationRef>> removedAssocs = this.editableNode.getRemovedAssociations();
for (Map<String, AssociationRef> typedAssoc : removedAssocs.values())
{
for (AssociationRef assoc : typedAssoc.values())
{
this.nodeService.removeAssociation(assoc.getSourceRef(), assoc.getTargetRef(), assoc.getTypeQName());
}
}
// add any child associations added in the UI
Map<String, Map<String, ChildAssociationRef>> addedChildAssocs = this.editableNode.getAddedChildAssociations();
for (Map<String, ChildAssociationRef> typedAssoc : addedChildAssocs.values())
{
for (ChildAssociationRef assoc : typedAssoc.values())
{
this.nodeService.addChild(assoc.getParentRef(), assoc.getChildRef(), assoc.getTypeQName(), assoc.getTypeQName());
}
}
// remove any child association removed in the UI
Map<String, Map<String, ChildAssociationRef>> removedChildAssocs = this.editableNode.getRemovedChildAssociations();
for (Map<String, ChildAssociationRef> typedAssoc : removedChildAssocs.values())
{
for (ChildAssociationRef assoc : typedAssoc.values())
{
this.nodeService.removeChild(assoc.getParentRef(), assoc.getChildRef());
}
}
return outcome;
}
@Override
protected String doPostCommitProcessing(FacesContext context, String outcome)
{
this.editableNode.reset();
return outcome;
}
/**
* 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

@@ -17,10 +17,6 @@ public abstract class BaseWizardBean extends BaseDialogBean implements IWizardBe
{
private static final String MSG_NOT_SET = "value_not_set";
// services common to most wizards
protected FileFolderService fileFolderService;
protected SearchService searchService;
public boolean getNextButtonDisabled()
{
return false;
@@ -40,22 +36,6 @@ public abstract class BaseWizardBean extends BaseDialogBean implements IWizardBe
{
return Application.getMessage(FacesContext.getCurrentInstance(), "finish_button");
}
/**
* @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;
}
/**
* Build summary table from the specified list of Labels and Values