use of org.alfresco.web.bean.NavigationBean in project acs-community-packaging by Alfresco.
the class WorkspaceClipboardItem method paste.
/**
* @see org.alfresco.web.bean.clipboard.ClipboardItem#paste(javax.faces.context.FacesContext, java.lang.String, int)
*/
public boolean paste(final FacesContext fc, String viewId, final int action) {
final ServiceRegistry serviceRegistry = getServiceRegistry();
final RetryingTransactionHelper retryingTransactionHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
if (super.canCopyToViewId(viewId) || WORKSPACE_PASTE_VIEW_ID.equals(viewId) || FORUMS_PASTE_VIEW_ID.equals(viewId) || FORUM_PASTE_VIEW_ID.equals(viewId)) {
NavigationBean navigator = (NavigationBean) FacesHelper.getManagedBean(fc, NavigationBean.BEAN_NAME);
final NodeRef destRef = new NodeRef(Repository.getStoreRef(), navigator.getCurrentNodeId());
final DictionaryService dd = serviceRegistry.getDictionaryService();
final NodeService nodeService = serviceRegistry.getNodeService();
final FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
final CopyService copyService = serviceRegistry.getCopyService();
final MultilingualContentService multilingualContentService = serviceRegistry.getMultilingualContentService();
final boolean isPrimaryParent;
final ChildAssociationRef assocRef;
if (getParent() == null) {
assocRef = nodeService.getPrimaryParent(getNodeRef());
isPrimaryParent = true;
} else {
NodeRef parentNodeRef = getParent();
List<ChildAssociationRef> assocList = nodeService.getParentAssocs(getNodeRef());
ChildAssociationRef foundRef = null;
if (assocList != null) {
for (ChildAssociationRef assocListEntry : assocList) {
if (parentNodeRef.equals(assocListEntry.getParentRef())) {
foundRef = assocListEntry;
break;
}
}
}
assocRef = foundRef;
isPrimaryParent = parentNodeRef.equals(nodeService.getPrimaryParent(getNodeRef()).getParentRef());
}
// initial name to attempt the copy of the item with
String name = getName();
String translationPrefix = "";
if (action == UIClipboardShelfItem.ACTION_PASTE_LINK) {
// copy as link was specifically requested by the user
String linkTo = Application.getMessage(fc, MSG_LINK_TO);
name = linkTo + ' ' + name;
}
// Loop until we find a target name that doesn't exist
for (; ; ) {
try {
final String currentTranslationPrefix = translationPrefix;
final String currentName = name;
// attempt each copy/paste in its own transaction
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
if (getMode() == ClipboardStatus.COPY) {
if (action == UIClipboardShelfItem.ACTION_PASTE_LINK) {
// LINK operation
if (logger.isDebugEnabled())
logger.debug("Attempting to link node ID: " + getNodeRef() + " into node: " + destRef.toString());
// create the node using the nodeService (can only use FileFolderService for content)
if (checkExists(currentName + LINK_NODE_EXTENSION, destRef) == false) {
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2, 1.0f);
String newName = currentName + LINK_NODE_EXTENSION;
props.put(ContentModel.PROP_NAME, newName);
props.put(ContentModel.PROP_LINK_DESTINATION, getNodeRef());
if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT)) {
// create File Link node
ChildAssociationRef childRef = nodeService.createNode(destRef, ContentModel.ASSOC_CONTAINS, QName.createQName(assocRef.getQName().getNamespaceURI(), newName), ApplicationModel.TYPE_FILELINK, props);
// apply the titled aspect - title and description
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(2, 1.0f);
titledProps.put(ContentModel.PROP_TITLE, currentName);
titledProps.put(ContentModel.PROP_DESCRIPTION, currentName);
nodeService.addAspect(childRef.getChildRef(), ContentModel.ASPECT_TITLED, titledProps);
} else {
// create Folder link node
ChildAssociationRef childRef = nodeService.createNode(destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName(), ApplicationModel.TYPE_FOLDERLINK, props);
// apply the uifacets aspect - icon, title and description props
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(4, 1.0f);
uiFacetsProps.put(ApplicationModel.PROP_ICON, "space-icon-link");
uiFacetsProps.put(ContentModel.PROP_TITLE, currentName);
uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, currentName);
nodeService.addAspect(childRef.getChildRef(), ApplicationModel.ASPECT_UIFACETS, uiFacetsProps);
}
}
} else {
// COPY operation
if (logger.isDebugEnabled())
logger.debug("Attempting to copy node: " + getNodeRef() + " into node ID: " + destRef.toString());
// first check that we are not attempting to copy a duplicate into the same parent
if (destRef.equals(assocRef.getParentRef()) && currentName.equals(getName())) {
// manually change the name if this occurs
throw new FileExistsException(destRef, currentName);
}
if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT) || dd.isSubClass(getType(), ContentModel.TYPE_FOLDER)) {
// copy the file/folder
fileFolderService.copy(getNodeRef(), destRef, currentName);
} else if (dd.isSubClass(getType(), ContentModel.TYPE_MULTILINGUAL_CONTAINER)) {
// copy the mlContainer and its translations
multilingualContentService.copyTranslationContainer(getNodeRef(), destRef, currentTranslationPrefix);
} else {
// copy the node
if (checkExists(currentName, destRef) == false) {
copyService.copyAndRename(getNodeRef(), destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName(), true);
}
}
}
} else {
// MOVE operation
if (logger.isDebugEnabled())
logger.debug("Attempting to move node: " + getNodeRef() + " into node ID: " + destRef.toString());
if (dd.isSubClass(getType(), ContentModel.TYPE_CONTENT) || dd.isSubClass(getType(), ContentModel.TYPE_FOLDER)) {
// move the file/folder
fileFolderService.moveFrom(getNodeRef(), getParent(), destRef, currentName);
} else if (dd.isSubClass(getType(), ContentModel.TYPE_MULTILINGUAL_CONTAINER)) {
// copy the mlContainer and its translations
multilingualContentService.moveTranslationContainer(getNodeRef(), destRef);
} else {
if (isPrimaryParent) {
// move the node
nodeService.moveNode(getNodeRef(), destRef, ContentModel.ASSOC_CONTAINS, assocRef.getQName());
} else {
nodeService.removeChild(getParent(), getNodeRef());
nodeService.addChild(destRef, getNodeRef(), assocRef.getTypeQName(), assocRef.getQName());
}
}
}
return null;
}
});
// We got here without error, so no need to loop with a new name
break;
} catch (FileExistsException fileExistsErr) {
// If mode is COPY, have another go around the loop with a new name
if (getMode() == ClipboardStatus.COPY) {
String copyOf = Application.getMessage(fc, MSG_COPY_OF);
name = copyOf + ' ' + name;
translationPrefix = copyOf + ' ' + translationPrefix;
} else {
// we should not rename an item when it is being moved - so exit
throw fileExistsErr;
}
}
}
return true;
} else {
return false;
}
}
use of org.alfresco.web.bean.NavigationBean in project acs-community-packaging by Alfresco.
the class UINavigator method broadcast.
/**
* @see javax.faces.component.UIInput#broadcast(javax.faces.event.FacesEvent)
*/
public void broadcast(FacesEvent event) throws AbortProcessingException {
if (event instanceof NavigatorEvent) {
FacesContext context = FacesContext.getCurrentInstance();
NavigatorEvent navEvent = (NavigatorEvent) event;
// node or panel selected?
switch(navEvent.getMode()) {
case PANEL_SELECTED:
{
String panelSelected = navEvent.getItem();
// a panel was selected, setup the context to make the panel
// the focus
NavigationBean nb = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
if (nb != null) {
try {
if (logger.isDebugEnabled())
logger.debug("Selecting panel: " + panelSelected);
nb.processToolbarLocation(panelSelected, true);
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NOHOME), Application.getCurrentUser(context).getHomeSpaceId()), refErr);
} catch (Exception err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
}
}
break;
}
case NODE_SELECTED:
{
// a node was clicked in the tree
boolean nodeExists = true;
NodeRef nodeClicked = new NodeRef(navEvent.getItem());
// make sure the node exists still before navigating to it
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(context, true);
tx.begin();
NodeService nodeSvc = Repository.getServiceRegistry(context).getNodeService();
nodeExists = nodeSvc.exists(nodeClicked);
tx.commit();
} catch (Throwable err) {
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
if (nodeExists) {
// setup the context to make the node the current node
BrowseBean bb = (BrowseBean) FacesHelper.getManagedBean(context, BrowseBean.BEAN_NAME);
if (bb != null) {
if (logger.isDebugEnabled())
logger.debug("Selected node: " + nodeClicked);
bb.clickSpace(nodeClicked);
}
} else {
String msg = Application.getMessage(context, "navigator_node_deleted");
Utils.addErrorMessage(msg);
}
break;
}
}
} else {
super.broadcast(event);
}
}
use of org.alfresco.web.bean.NavigationBean in project acs-community-packaging by Alfresco.
the class UINavigator method encodeBegin.
@Override
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException {
if (!isRendered())
return;
// TODO: pull width and height from user preferences and/or the main config,
// if present override below using the style attribute
ResponseWriter out = context.getResponseWriter();
NavigationBean navBean = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
NavigatorPluginBean navPluginBean = (NavigatorPluginBean) FacesHelper.getManagedBean(context, NavigatorPluginBean.BEAN_NAME);
List<TreeNode> rootNodesForArea = null;
String area = this.getActiveArea();
String areaTitle = null;
boolean treePanel = true;
if (NavigationBean.LOCATION_COMPANY.equals(area)) {
rootNodesForArea = navPluginBean.getCompanyHomeRootNodes();
areaTitle = Application.getMessage(context, NavigationBean.MSG_COMPANYHOME);
} else if (NavigationBean.LOCATION_HOME.equals(area)) {
rootNodesForArea = navPluginBean.getMyHomeRootNodes();
areaTitle = Application.getMessage(context, NavigationBean.MSG_MYHOME);
} else if (NavigationBean.LOCATION_GUEST.equals(area)) {
rootNodesForArea = navPluginBean.getGuestHomeRootNodes();
areaTitle = Application.getMessage(context, NavigationBean.MSG_GUESTHOME);
} else {
treePanel = false;
areaTitle = Application.getMessage(context, NavigationBean.MSG_MYALFRESCO);
}
// order the root nodes by the tree label
if (rootNodesForArea != null && rootNodesForArea.size() > 1) {
QuickSort sorter = new QuickSort(rootNodesForArea, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
// main container div
out.write("<div id=\"navigator\" class=\"navigator\">");
// generate the active panel title
String cxPath = context.getExternalContext().getRequestContextPath();
out.write("<div class=\"sidebarButtonSelected\" style=\"background-image: url(" + cxPath + "/images/parts/navigator_blue_gradient_bg.gif)\">");
out.write("<a class='sidebarButtonSelectedLink' onclick=\"");
out.write(Utils.generateFormSubmit(context, this, getClientId(context), PANEL_ACTION + area));
out.write("\" href=\"#\">");
out.write(Utils.encode(areaTitle));
out.write("</a></div>");
// generate the javascript method to capture the tree node click events
if (treePanel) {
out.write("<script type=\"text/javascript\">");
out.write("function treeNodeSelected(nodeRef) {");
out.write(Utils.generateFormSubmit(context, this, getClientId(context), "nodeRef", true, null));
out.write("}</script>");
// generate the active panel containing the tree
out.write("<div class=\"navigatorPanelBody\">");
UITree tree = (UITree) context.getApplication().createComponent(UITree.COMPONENT_TYPE);
tree.setId("tree");
tree.setRootNodes(rootNodesForArea);
tree.setRetrieveChildrenUrl(AJAX_URL_START + ".retrieveChildren?area=" + area);
tree.setNodeCollapsedUrl(AJAX_URL_START + ".nodeCollapsed?area=" + area);
tree.setNodeSelectedCallback("treeNodeSelected");
tree.setNodeCollapsedCallback("informOfCollapse");
Utils.encodeRecursive(context, tree);
out.write("</div>");
}
// generate the closed panel title areas
String sideBarStyle = "style=\"background-image: url(" + cxPath + "/images/parts/navigator_grey_gradient_bg.gif)\"";
if (NavigationBean.LOCATION_COMPANY.equals(area) == false && navBean.getCompanyHomeVisible()) {
encodeSidebarButton(context, out, sideBarStyle, NavigationBean.LOCATION_COMPANY, NavigationBean.MSG_COMPANYHOME);
}
if (NavigationBean.LOCATION_HOME.equals(area) == false) {
encodeSidebarButton(context, out, sideBarStyle, NavigationBean.LOCATION_HOME, NavigationBean.MSG_MYHOME);
}
if (NavigationBean.LOCATION_GUEST.equals(area) == false && navBean.getIsGuest() == false && navBean.getGuestHomeVisible()) {
encodeSidebarButton(context, out, sideBarStyle, NavigationBean.LOCATION_GUEST, NavigationBean.MSG_GUESTHOME);
}
if (NavigationBean.LOCATION_MYALFRESCO.equals(area) == false) {
encodeSidebarButton(context, out, sideBarStyle, NavigationBean.LOCATION_MYALFRESCO, NavigationBean.MSG_MYALFRESCO);
}
out.write("</div>");
}
use of org.alfresco.web.bean.NavigationBean in project acs-community-packaging by Alfresco.
the class UICategoryBrowser method broadcast.
/*
* (non-Javadoc)
*
* @see org.alfresco.extension.web.ui.repo.component.UINavigator#broadcast(javax.faces.event.FacesEvent)
*/
@Override
public void broadcast(FacesEvent event) throws AbortProcessingException {
if (event instanceof CategoryBrowserEvent) {
FacesContext context = FacesContext.getCurrentInstance();
CategoryBrowserEvent categoryBrowseEvent = (CategoryBrowserEvent) event;
NodeRef nodeClicked = new NodeRef(categoryBrowseEvent.getItem());
boolean subcategories = categoryBrowseEvent.isIncludeSubcategories();
if (logger.isDebugEnabled())
logger.debug("Selected category: " + nodeClicked + " subcategories? " + subcategories);
CategoryBrowserBean categoryBrowserBean = (CategoryBrowserBean) FacesHelper.getManagedBean(context, CategoryBrowserBean.BEAN_NAME);
categoryBrowserBean.setCurrentCategory(nodeClicked);
categoryBrowserBean.setIncludeSubcategories(subcategories);
SearchContext categorySearch = categoryBrowserBean.generateCategorySearchContext();
NavigationBean nb = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
nb.setSearchContext(categorySearch);
context.getApplication().getNavigationHandler().handleNavigation(context, null, "category-browse");
} else {
super.broadcast(event);
}
}
use of org.alfresco.web.bean.NavigationBean in project acs-community-packaging by Alfresco.
the class UserMembersBean method inheritPermissionsValueChanged.
/**
* Inherit parent Space permissions value changed by the user
*/
public void inheritPermissionsValueChanged(ValueChangeEvent event) {
try {
// change the value to the new selected value
boolean inheritPermissions = (Boolean) event.getNewValue();
this.getPermissionService().setInheritParentPermissions(getNode().getNodeRef(), inheritPermissions);
// inform the user that the change occured
FacesContext context = FacesContext.getCurrentInstance();
String msg;
if (inheritPermissions) {
msg = Application.getMessage(context, MSG_SUCCESS_INHERIT);
} else {
msg = Application.getMessage(context, MSG_SUCCESS_INHERIT_NOT);
}
// pressing the top level navigation button i.e. My Home
if (this.getPermissionService().hasPermission(getNode().getNodeRef(), PermissionService.CHANGE_PERMISSIONS) == AccessStatus.ALLOWED) {
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
context.addMessage(event.getComponent().getClientId(context), facesMsg);
} else {
NavigationBean nb = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
if (nb != null) {
try {
nb.processToolbarLocation(nb.getToolbarLocation(), true);
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NOHOME), Application.getCurrentUser(context).getHomeSpaceId()), refErr);
} catch (Exception err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
}
}
}
} catch (Throwable e) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), e.getMessage()), e);
}
}
Aggregations