From 4a0fefc4bdc31f2b1adad92fbce7b59aa18bc73e Mon Sep 17 00:00:00 2001 From: Gavin Cornwell Date: Thu, 20 Apr 2006 10:30:43 +0000 Subject: [PATCH] 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 --- config/alfresco/messages/webclient.properties | 1 + config/alfresco/web-client-config-dialogs.xml | 4 + .../alfresco/web-client-config-properties.xml | 2 + .../web/bean/dialog/BaseDialogBean.java | 39 +++ .../generator/SpaceIconPickerGenerator.java | 2 +- .../web/bean/spaces/EditSpaceDialog.java | 260 ++++++++++++++++++ .../web/bean/wizard/BaseWizardBean.java | 20 -- source/web/WEB-INF/faces-config-beans.xml | 6 +- .../web/WEB-INF/faces-config-navigation.xml | 16 -- source/web/jsp/dialog/container.jsp | 2 + source/web/jsp/dialog/edit-space.jsp | 189 ------------- source/web/jsp/dialog/space-details.jsp | 2 +- source/web/jsp/spaces/create-space-dialog.jsp | 9 +- source/web/jsp/spaces/edit-space-dialog.jsp | 36 +++ source/web/jsp/wizard/container.jsp | 2 + 15 files changed, 356 insertions(+), 234 deletions(-) create mode 100644 source/java/org/alfresco/web/bean/spaces/EditSpaceDialog.java delete mode 100644 source/web/jsp/dialog/edit-space.jsp create mode 100644 source/web/jsp/spaces/edit-space-dialog.jsp diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index f0c90c704c..d1d145a65f 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -487,6 +487,7 @@ undo_checkout_info=If you undo the check out of a document, the associated worki details_of=Details of preview_of=Preview of modify_props_of=Modify Properties of +modify_space_properties=Modify Space Properties preview=Preview in Template dashboard_view=Dashboard View dashboard=Dashboard diff --git a/config/alfresco/web-client-config-dialogs.xml b/config/alfresco/web-client-config-dialogs.xml index ec24ec9ba8..16d27f0b88 100644 --- a/config/alfresco/web-client-config-dialogs.xml +++ b/config/alfresco/web-client-config-dialogs.xml @@ -7,6 +7,10 @@ + + diff --git a/config/alfresco/web-client-config-properties.xml b/config/alfresco/web-client-config-properties.xml index 3fcb116616..95cc11676a 100644 --- a/config/alfresco/web-client-config-properties.xml +++ b/config/alfresco/web-client-config-properties.xml @@ -14,6 +14,8 @@ + diff --git a/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java b/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java index cd6a543487..adc41bcaaa 100644 --- a/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java +++ b/source/java/org/alfresco/web/bean/dialog/BaseDialogBean.java @@ -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 * diff --git a/source/java/org/alfresco/web/bean/generator/SpaceIconPickerGenerator.java b/source/java/org/alfresco/web/bean/generator/SpaceIconPickerGenerator.java index b7c63f25fe..e61f3a4f28 100644 --- a/source/java/org/alfresco/web/bean/generator/SpaceIconPickerGenerator.java +++ b/source/java/org/alfresco/web/bean/generator/SpaceIconPickerGenerator.java @@ -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 diff --git a/source/java/org/alfresco/web/bean/spaces/EditSpaceDialog.java b/source/java/org/alfresco/web/bean/spaces/EditSpaceDialog.java new file mode 100644 index 0000000000..c424d8014a --- /dev/null +++ b/source/java/org/alfresco/web/bean/spaces/EditSpaceDialog.java @@ -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 getIcons() + { + List 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(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(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 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 repoProps = this.nodeService.getProperties(nodeRef); + + // overwrite the current properties with the edited ones + Iterator 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> addedAssocs = this.editableNode.getAddedAssociations(); + for (Map 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> removedAssocs = this.editableNode.getRemovedAssociations(); + for (Map 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> addedChildAssocs = this.editableNode.getAddedChildAssociations(); + for (Map 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> removedChildAssocs = this.editableNode.getRemovedChildAssociations(); + for (Map 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()); + } + } +} diff --git a/source/java/org/alfresco/web/bean/wizard/BaseWizardBean.java b/source/java/org/alfresco/web/bean/wizard/BaseWizardBean.java index af13529c04..5b74b6bdf3 100644 --- a/source/java/org/alfresco/web/bean/wizard/BaseWizardBean.java +++ b/source/java/org/alfresco/web/bean/wizard/BaseWizardBean.java @@ -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 diff --git a/source/web/WEB-INF/faces-config-beans.xml b/source/web/WEB-INF/faces-config-beans.xml index cbe8d7ef6f..e80288e5d2 100644 --- a/source/web/WEB-INF/faces-config-beans.xml +++ b/source/web/WEB-INF/faces-config-beans.xml @@ -318,7 +318,7 @@ The bean that backs up the Edit Space Dialog EditSpaceDialog - org.alfresco.web.bean.wizard.NewSpaceWizard + org.alfresco.web.bean.spaces.EditSpaceDialog session nodeService @@ -340,6 +340,10 @@ searchService #{SearchService} + + dictionaryService + #{DictionaryService} + namespaceService #{NamespaceService} diff --git a/source/web/WEB-INF/faces-config-navigation.xml b/source/web/WEB-INF/faces-config-navigation.xml index 0618fc6f4e..a484145a45 100644 --- a/source/web/WEB-INF/faces-config-navigation.xml +++ b/source/web/WEB-INF/faces-config-navigation.xml @@ -239,10 +239,6 @@ /jsp/dialog/space-details.jsp - - editSpaceProperties - /jsp/dialog/edit-space.jsp - manageInvitedUsers /jsp/roles/manage-invited-users.jsp @@ -277,18 +273,6 @@ - - /jsp/dialog/edit-space.jsp - - cancel - /jsp/dialog/space-details.jsp - - - finish - /jsp/dialog/space-details.jsp - - - /jsp/dialog/document-details.jsp diff --git a/source/web/jsp/dialog/container.jsp b/source/web/jsp/dialog/container.jsp index 564275a0f9..8a061b41fd 100644 --- a/source/web/jsp/dialog/container.jsp +++ b/source/web/jsp/dialog/container.jsp @@ -94,9 +94,11 @@
+ <% PanelGenerator.generatePanelStart(out, request.getContextPath(), "white", "white"); %> + <% PanelGenerator.generatePanelEnd(out, request.getContextPath(), "white"); %> diff --git a/source/web/jsp/dialog/edit-space.jsp b/source/web/jsp/dialog/edit-space.jsp deleted file mode 100644 index 4971ed4cfb..0000000000 --- a/source/web/jsp/dialog/edit-space.jsp +++ /dev/null @@ -1,189 +0,0 @@ -<%-- - Copyright (C) 2005 Alfresco, Inc. - - Licensed under the Mozilla Public License version 1.1 - with a permitted attribution clause. You may obtain a - copy of the License at - - http://www.alfresco.org/legal/license.txt - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - either express or implied. See the License for the specific - language governing permissions and limitations under the - License. ---%> -<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> -<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> -<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %> -<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %> - -<%@ page buffer="32kb" contentType="text/html;charset=UTF-8" %> -<%@ page isELIgnored="false" %> -<%@ page import="org.alfresco.web.ui.common.PanelGenerator" %> - - - - - - - - <%-- load a bundle of properties with I18N strings --%> - - - - - <%-- Main outer table --%> - - - <%-- Title bar --%> - - - - - <%-- Main area --%> - - <%-- Shelf --%> - - - <%-- Work Area --%> - - -
- <%@ include file="../parts/titlebar.jsp" %> -
- <%@ include file="../parts/shelf.jsp" %> - - - <%-- Breadcrumb --%> - <%@ include file="../parts/breadcrumb.jsp" %> - - <%-- Status and Actions --%> - - - - - - - <%-- separator row with gradient shadow --%> - - - - - - - <%-- Details --%> - - - - - - - <%-- separator row with bottom panel graphics --%> - - - - - - -
- - <%-- Status and Actions inner contents table --%> - <%-- Generally this consists of an icon, textual summary and actions for the current object --%> - - - - - -
- -
''
-
-
- -
- - - - - - -
- - - - <% PanelGenerator.generatePanelStart(out, request.getContextPath(), "white", "white"); %> - - - - - - - - - - - - - - - - - - - - -
: -  * -
: - -
 
: -
- <% PanelGenerator.generatePanelStart(out, request.getContextPath(), "blue", "#D3E6FE"); %> - - - - <% PanelGenerator.generatePanelEnd(out, request.getContextPath(), "blue"); %> -
-
- <% PanelGenerator.generatePanelEnd(out, request.getContextPath(), "white"); %> -
- <% PanelGenerator.generatePanelStart(out, request.getContextPath(), "blue", "#D3E6FE"); %> - - - - - - - -
- -
- -
- <% PanelGenerator.generatePanelEnd(out, request.getContextPath(), "blue"); %> -
-
-
- -
- -
- -
\ No newline at end of file diff --git a/source/web/jsp/dialog/space-details.jsp b/source/web/jsp/dialog/space-details.jsp index b8f51cad60..3aad33d109 100644 --- a/source/web/jsp/dialog/space-details.jsp +++ b/source/web/jsp/dialog/space-details.jsp @@ -163,7 +163,7 @@ + action="dialog:editSpace" /> diff --git a/source/web/jsp/spaces/create-space-dialog.jsp b/source/web/jsp/spaces/create-space-dialog.jsp index 20710d699e..a4229d133c 100644 --- a/source/web/jsp/spaces/create-space-dialog.jsp +++ b/source/web/jsp/spaces/create-space-dialog.jsp @@ -20,9 +20,7 @@ <%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %> <%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %> -<%@ page import="org.alfresco.web.ui.common.PanelGenerator" %> - -