use of org.alfresco.web.ui.common.component.UIActionLink in project acs-community-packaging by Alfresco.
the class UIActions method buildActionGroup.
/**
* Build an action group as reusable UIActionLink components.
*
* @param context FacesContext
* @param config ActionsConfigElement
* @param actionGroup ActionGroup
* @param contextId String
* @throws IOException
*/
@SuppressWarnings("unchecked")
private void buildActionGroup(FacesContext context, ActionsConfigElement config, ActionGroup actionGroup, String contextId) throws IOException {
javax.faces.application.Application facesApp = context.getApplication();
ResourceBundle messages = Application.getBundle(context);
// get overriding display attributes
String style = (String) getAttributes().get(ATTR_STYLE);
String styleClass = (String) getAttributes().get(ATTR_STYLECLASS);
Boolean showLink = null;
if (getAttributes().get(ATTR_SHOWLINK) != null) {
showLink = (Boolean) getAttributes().get(ATTR_SHOWLINK);
}
// build parent wrapper component
HtmlPanelGroup wrapper = (HtmlPanelGroup) facesApp.createComponent(ComponentConstants.JAVAX_FACES_PANELGROUP);
wrapper.setId(createUniqueId());
wrapper.getAttributes().put("contextId", contextId);
this.getChildren().add(wrapper);
if (logger.isDebugEnabled())
logger.debug("UIActions id: " + this.getId() + " Children() structure size: " + this.getChildren().size());
this.groups.add(contextId);
// process each ActionDefinition in the order they were defined
for (String actionId : actionGroup) {
if (logger.isDebugEnabled())
logger.debug("---processing ActionDefinition: " + actionId);
ActionDefinition actionDef = config.getActionDefinition(actionId);
if (actionDef == null) {
throw new AlfrescoRuntimeException("Unable to find configured ActionDefinition Id: " + actionId);
}
UIComponent currentParent = wrapper;
// build a permissions evaluator component to wrap the actionlink
PermissionEvaluator permEval = null;
List<String> allow = actionDef.getAllowPermissions();
if (allow != null && allow.size() != 0) {
// found some permissions to test
permEval = (PermissionEvaluator) facesApp.createComponent(COMPONENT_PERMISSIONEVAL);
String condition = allow.get(0);
if (allow.size() != 1) {
for (int i = 1; i < allow.size(); i++) {
condition += "," + allow.get(i);
}
}
permEval.setAllow(condition);
}
List<String> deny = actionDef.getDenyPermissions();
if (deny != null && deny.size() != 0) {
if (permEval == null) {
permEval = (PermissionEvaluator) facesApp.createComponent(COMPONENT_PERMISSIONEVAL);
}
String condition = deny.get(0);
if (deny.size() != 1) {
for (int i = 1; i < deny.size(); i++) {
condition += "," + deny.get(i);
}
}
permEval.setDeny(condition);
}
if (permEval != null) {
// add the permission evaluator component and walk down the hierarchy
permEval.setId(createUniqueId());
permEval.setValueBinding(ATTR_VALUE, facesApp.createValueBinding("#{" + ACTION_CONTEXT + "}"));
if (logger.isDebugEnabled())
logger.debug("-----adding PermissionEvaluator to action");
currentParent.getChildren().add(permEval);
currentParent = permEval;
}
// now prepare any code based evaluators that may be present
if (actionDef.Evaluator != null) {
ActionInstanceEvaluator evaluator = (ActionInstanceEvaluator) facesApp.createComponent(COMPONENT_ACTIONEVAL);
evaluator.setId(createUniqueId());
evaluator.setEvaluator(actionDef.Evaluator);
evaluator.setValueBinding(ATTR_VALUE, facesApp.createValueBinding("#{" + ACTION_CONTEXT + "}"));
// add the action evaluator component and walk down the hiearchy
if (logger.isDebugEnabled())
logger.debug("-----adding ActionEvaluator to action");
currentParent.getChildren().add(evaluator);
currentParent = evaluator;
}
// now build the UIActionLink component for this action
UIActionLink control = (UIActionLink) facesApp.createComponent(COMPONENT_ACTIONLINK);
control.setRendererType(RENDERER_ACTIONLINK);
control.setId(actionDef.getId() + createUniqueId());
if (actionDef.Action != null) {
if (UIComponentTagUtils.isValueReference(actionDef.Action)) {
control.setAction(facesApp.createMethodBinding(actionDef.Action, null));
} else {
control.setAction(new ConstantMethodBinding(actionDef.Action));
}
}
if (actionDef.ActionListener != null) {
control.setActionListener(facesApp.createMethodBinding(actionDef.ActionListener, ACTION_CLASS_ARGS));
}
if (style != null) {
control.getAttributes().put(ATTR_STYLE, style);
} else if (actionDef.Style != null) {
control.getAttributes().put(ATTR_STYLE, actionDef.Style);
}
if (styleClass != null) {
control.getAttributes().put(ATTR_STYLECLASS, styleClass);
} else if (actionDef.StyleClass != null) {
control.getAttributes().put(ATTR_STYLECLASS, actionDef.StyleClass);
}
if (showLink != null) {
control.setShowLink(showLink.booleanValue());
} else {
control.setShowLink(actionDef.ShowLink);
}
if (actionDef.Onclick != null) {
if (UIComponentTagUtils.isValueReference(actionDef.Onclick)) {
control.setValueBinding("onclick", facesApp.createValueBinding(actionDef.Onclick));
} else {
control.setOnclick(actionDef.Onclick);
}
}
if (actionDef.Href != null) {
if (UIComponentTagUtils.isValueReference(actionDef.Href)) {
control.setValueBinding("href", facesApp.createValueBinding(actionDef.Href));
} else {
control.setHref(actionDef.Href);
}
} else if (actionDef.Script != null && actionDef.Script.length() != 0) {
// found a script reference - may be a Path or a NodeRef
StringBuilder scriptHref = new StringBuilder(100);
scriptHref.append("/command/script/execute");
if (actionDef.Script.charAt(0) == '/') {
// found a Path - encode it as a URL argument
scriptHref.append("?scriptPath=");
scriptHref.append(URLEncoder.encode(actionDef.Script));
} else {
// found a NodeRef string, encode as URL elements
NodeRef ref = new NodeRef(actionDef.Script);
scriptHref.append('/').append(ref.getStoreRef().getProtocol()).append('/').append(ref.getStoreRef().getIdentifier()).append('/').append(ref.getId());
}
// set the full script execution URL as the href for the control
control.setHref(scriptHref.toString());
}
control.setTarget(actionDef.Target);
control.setImage(actionDef.Image);
if (actionDef.TooltipMsg != null) {
control.setTooltip(messages.getString(actionDef.TooltipMsg));
} else if (actionDef.Tooltip != null) {
if (UIComponentTagUtils.isValueReference(actionDef.Tooltip)) {
control.setValueBinding("tooltip", facesApp.createValueBinding(actionDef.Tooltip));
} else {
control.setValue(actionDef.Tooltip);
}
}
if (actionDef.LabelMsg != null) {
control.setValue(messages.getString(actionDef.LabelMsg));
} else if (actionDef.Label != null) {
if (UIComponentTagUtils.isValueReference(actionDef.Label)) {
control.setValueBinding("value", facesApp.createValueBinding(actionDef.Label));
} else {
control.setValue(actionDef.Label);
}
}
// build any child params <f:param> components that are needed.
Map<String, String> params = actionDef.getParams();
if (params != null) {
for (String name : params.keySet()) {
UIParameter param = (UIParameter) facesApp.createComponent(ComponentConstants.JAVAX_FACES_PARAMETER);
param.setId(createUniqueId());
param.setName(name);
String value = params.get(name);
if (UIComponentTagUtils.isValueReference(value)) {
param.setValueBinding(ATTR_VALUE, facesApp.createValueBinding(value));
} else {
param.setValue(value);
}
control.getChildren().add(param);
}
}
if (logger.isDebugEnabled())
logger.debug("-----adding UIActionLink component for: " + actionId);
currentParent.getChildren().add(control);
}
}
use of org.alfresco.web.ui.common.component.UIActionLink in project acs-community-packaging by Alfresco.
the class UsersDialog method setupUserAction.
/**
* Action event called by all actions that need to setup a Person context on
* the Users bean before an action page is called. The context will be a
* Person Node in setPerson() which can be retrieved on the action page from
* UsersDialog.getPerson().
*/
public void setupUserAction(ActionEvent event) {
UIActionLink link = (UIActionLink) event.getComponent();
Map<String, String> params = link.getParameterMap();
setupUserAction(params.get("id"));
}
use of org.alfresco.web.ui.common.component.UIActionLink in project acs-community-packaging by Alfresco.
the class UserMembersBean method setupUserAction.
/**
* Action event called by all actions that need to setup a Person context on
* the UserMembers bean before an action page is called. The context will be a
* Authority in setPersonAuthority() which can be retrieved on the action page from
* UserMembersBean.setPersonAuthority().
*/
public void setupUserAction(ActionEvent event) {
FacesContext context = FacesContext.getCurrentInstance();
UIActionLink link = (UIActionLink) event.getComponent();
Map<String, String> params = link.getParameterMap();
String authority = params.get("userName");
if (authority != null && authority.length() != 0) {
try {
if (this.getPersonService().personExists(authority)) {
// create the node ref, then our node representation
NodeRef ref = getPersonService().getPerson(authority);
Node node = new Node(ref);
// setup convience function for current user full name
String firstName = (String) node.getProperties().get(ContentModel.PROP_FIRSTNAME);
String lastName = (String) node.getProperties().get(ContentModel.PROP_LASTNAME);
setPersonName((firstName != null ? firstName : "") + ' ' + (lastName != null ? lastName : ""));
} else {
String label = params.get("userNameLabel");
if (label == null || label.length() == 0) {
label = authority;
}
setPersonName(label);
}
// setup roles for this Authority
List<PermissionWrapper> userPermissions = new ArrayList<PermissionWrapper>(4);
Set<AccessPermission> permissions = getPermissionService().getAllSetPermissions(getNode().getNodeRef());
if (permissions != null) {
for (AccessPermission permission : permissions) {
// we are only interested in Allow permissions
if (permission.getAccessStatus() == AccessStatus.ALLOWED) {
if (authority.equals(permission.getAuthority())) {
// found a permission for this user authentiaction
PermissionWrapper wrapper = new PermissionWrapper(permission.getPermission(), Application.getMessage(context, permission.getPermission()));
userPermissions.add(wrapper);
}
}
}
}
// action context setup
this.personRolesDataModel = null;
this.personRoles = userPermissions;
setPersonAuthority(authority);
} catch (Exception err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), new Object[] { err.getMessage() }));
}
} else {
setPersonAuthority(null);
}
// force refresh on return to this page
contextUpdated();
}
use of org.alfresco.web.ui.common.component.UIActionLink in project acs-community-packaging by Alfresco.
the class StartWorkflowWizard method removePackageItem.
/**
* 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);
}
use of org.alfresco.web.ui.common.component.UIActionLink in project acs-community-packaging by Alfresco.
the class RulesDialog method setupRuleAction.
/**
* Handles a rule being clicked ready for an action i.e. edit or delete
*
* @param event The event representing the click
*/
public void setupRuleAction(ActionEvent event) {
UIActionLink link = (UIActionLink) event.getComponent();
Map<String, String> params = link.getParameterMap();
String id = params.get("id");
if (id != null && id.length() != 0) {
if (logger.isDebugEnabled())
logger.debug("Rule clicked, it's id is: " + id);
this.currentRule = this.getRuleService().getRule(new NodeRef(id));
// refresh list
contextUpdated();
}
}
Aggregations