Files
alfresco-community-repo/source/java/org/alfresco/web/bean/SpaceDetailsBean.java
Kevin Roast 9c9a0d3d1b . Dashboard views (templates) can now be applied to Documents through the Document Details View
- refactored DocumentDetailsBean and SpaceDetailsBean common code into BaseDetailsBase
. Fixed a couple of minor errors in example templates
. Preview in Template actions now launched as dialog actions

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2586 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2006-03-29 10:50:07 +00:00

245 lines
7.5 KiB
Java

/*
* 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.
*/
package org.alfresco.web.bean;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.TemplateImageResolver;
import org.alfresco.service.cmr.repository.TemplateNode;
import org.alfresco.service.cmr.security.OwnableService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.Utils.URLMode;
import org.alfresco.web.ui.common.component.UIActionLink;
import org.alfresco.web.ui.common.component.UIPanel.ExpandedEvent;
/**
* Backing bean provided access to the details of a Space
*
* @author Kevin Roast
*/
public class SpaceDetailsBean extends BaseDetailsBean
{
private static final String OUTCOME_RETURN = "showSpaceDetails";
/** PermissionService bean reference */
protected PermissionService permissionService;
// ------------------------------------------------------------------------------
// Construction
/**
* Default constructor
*/
public SpaceDetailsBean()
{
// initial state of some panels that don't use the default
panels.put("rules-panel", false);
}
// ------------------------------------------------------------------------------
// Bean property getters and setters
/**
* @param permissionService The PermissionService to set.
*/
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
/**
* Returns the Node this bean is currently representing
*
* @return The Node
*/
public Node getNode()
{
return this.browseBean.getActionSpace();
}
/**
* Returns the Space this bean is currently representing
*
* @return The Space Node
*/
public Node getSpace()
{
return getNode();
}
/**
* Resolve the actual document Node from any Link object that may be proxying it
*
* @return current document Node or document Node resolved from any Link object
*/
protected Node getLinkResolvedNode()
{
Node space = getSpace();
if (ContentModel.TYPE_FOLDERLINK.equals(space.getType()))
{
NodeRef destRef = (NodeRef)space.getProperties().get(ContentModel.PROP_LINK_DESTINATION);
space = new Node(destRef);
}
return space;
}
/**
* Returns a model for use by a template on the Space Details page.
*
* @return model containing current current space info.
*/
@SuppressWarnings("unchecked")
public Map getTemplateModel()
{
HashMap model = new HashMap(1, 1.0f);
FacesContext fc = FacesContext.getCurrentInstance();
TemplateNode spaceNode = new TemplateNode(getSpace().getNodeRef(),
Repository.getServiceRegistry(fc), imageResolver);
model.put("space", spaceNode);
return model;
}
/**
* @see org.alfresco.web.bean.BaseDetailsBean#getPropertiesPanelId()
*/
protected String getPropertiesPanelId()
{
return "space-props";
}
/**
* @see org.alfresco.web.bean.BaseDetailsBean#getReturnOutcome()
*/
protected String getReturnOutcome()
{
return OUTCOME_RETURN;
}
// ------------------------------------------------------------------------------
// Action event handlers
/**
* Navigates to next item in the list of Spaces
*/
public void nextItem(ActionEvent event)
{
UIActionLink link = (UIActionLink)event.getComponent();
Map<String, String> params = link.getParameterMap();
String id = params.get("id");
if (id != null && id.length() != 0)
{
List<Node> nodes = this.browseBean.getNodes();
if (nodes.size() > 1)
{
// perform a linear search - this is slow but stateless
// otherwise we would have to manage state of last selected node
// this gets very tricky as this bean is instantiated once and never
// reset - it does not know when the document has changed etc.
for (int i=0; i<nodes.size(); i++)
{
if (id.equals(nodes.get(i).getId()) == true)
{
Node next;
// found our item - navigate to next
if (i != nodes.size() - 1)
{
next = nodes.get(i + 1);
}
else
{
// handle wrapping case
next = nodes.get(0);
}
// prepare for showing details for this node
this.browseBean.setupSpaceAction(next.getId(), false);
}
}
}
}
}
/**
* Navigates to the previous item in the list Spaces
*/
public void previousItem(ActionEvent event)
{
UIActionLink link = (UIActionLink)event.getComponent();
Map<String, String> params = link.getParameterMap();
String id = params.get("id");
if (id != null && id.length() != 0)
{
List<Node> nodes = this.browseBean.getNodes();
if (nodes.size() > 1)
{
// see above
for (int i=0; i<nodes.size(); i++)
{
if (id.equals(nodes.get(i).getId()) == true)
{
Node previous;
// found our item - navigate to previous
if (i != 0)
{
previous = nodes.get(i - 1);
}
else
{
// handle wrapping case
previous = nodes.get(nodes.size() - 1);
}
// show details for this node
this.browseBean.setupSpaceAction(previous.getId(), false);
}
}
}
}
}
/**
* Action handler to clear the current Space properties before returning to the browse screen,
* as the user may have modified the properties!
*/
public String closeDialog()
{
this.navigator.resetCurrentNodeProperties();
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
}