Removed depcreated package com.arsdigita.cms.ui.contentcenter
parent
f0069cba93
commit
c9eb1bb20b
|
|
@ -34,7 +34,6 @@ import org.librecms.contentsection.ContentItem;
|
|||
import org.librecms.contentsection.ContentSection;
|
||||
|
||||
import com.arsdigita.cms.dispatcher.CMSPage;
|
||||
import com.arsdigita.cms.ui.workflow.WorkflowAdminPane;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.util.Assert;
|
||||
|
||||
|
|
@ -125,8 +124,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
|||
|
||||
private ItemSearch m_searchPane;
|
||||
|
||||
private WorkflowAdminPane m_workflowPane;
|
||||
|
||||
/**
|
||||
* Creates the content section index page containing - a Navigaton bar for
|
||||
* the various tasks (items, search, images, ....) - a breadcrumb - ....
|
||||
|
|
@ -142,7 +139,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
|||
// Initialize the individual panes
|
||||
m_browsePane = getBrowsePane();
|
||||
m_searchPane = getSearchPane();
|
||||
m_workflowPane = getWorkflowAdminPane();
|
||||
|
||||
// The panes
|
||||
m_tabbedPane = createTabbedPane();
|
||||
|
|
@ -167,11 +163,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
|||
.createCdiUtil().findBean(PermissionChecker.class);
|
||||
|
||||
if (CMSConfig.getConfig().isHideAdminTabs()) {
|
||||
m_tabbedPane.setTabVisible(
|
||||
state,
|
||||
m_workflowPane,
|
||||
permissionChecker.isPermitted(
|
||||
AdminPrivileges.ADMINISTER_WORKFLOWS));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -208,17 +199,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
|||
return m_searchPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates, and then caches, the workflow administration pane. Overriding
|
||||
* this method to return null will prevent this tab from appearing.
|
||||
*/
|
||||
protected WorkflowAdminPane getWorkflowAdminPane() {
|
||||
if (m_workflowPane == null) {
|
||||
m_workflowPane = new WorkflowAdminPane();
|
||||
}
|
||||
return m_workflowPane;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified component, with the specified tab name, to the tabbed
|
||||
* pane only if it is not null.
|
||||
|
|
@ -262,7 +242,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
|||
|
||||
tab(pane, "cms.ui.browse", getBrowsePane());
|
||||
tab(pane, "cms.ui.search", getSearchPane());
|
||||
tab(pane, "cms.ui.workflows", getWorkflowAdminPane());
|
||||
|
||||
return pane;
|
||||
}
|
||||
|
|
@ -293,15 +272,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
|||
final PageState state = event.getPageState();
|
||||
|
||||
final Component pane = m_tabbedPane.getCurrentPane(state);
|
||||
|
||||
//ToDo NG if (pane == m_searchPane) {
|
||||
// m_searchPane.reset(state);
|
||||
// } else if (pane == m_imagesPane) {
|
||||
// m_imagesPane.reset(state);
|
||||
// } else
|
||||
if (pane == m_workflowPane) {
|
||||
m_workflowPane.reset(state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,637 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
package com.arsdigita.cms.ui.contentcenter;
|
||||
|
||||
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.Embedded;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.Link;
|
||||
import com.arsdigita.bebop.Page;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.Table;
|
||||
import com.arsdigita.bebop.parameters.BigDecimalParameter;
|
||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
||||
import com.arsdigita.bebop.table.TableColumn;
|
||||
import com.arsdigita.bebop.table.TableColumnModel;
|
||||
import com.arsdigita.bebop.table.TableModel;
|
||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
||||
import com.arsdigita.cms.PageLocations;
|
||||
import com.arsdigita.cms.ui.CMSContainer;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.util.LockableImpl;
|
||||
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentSectionRepository;
|
||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* Displays all the content sections in table, with links to the admin (and in
|
||||
* legacy mode to legacy public pages as well). Also displays a form for each
|
||||
* content section to create an object of a given type (configurable). The list
|
||||
* of available types retrieved for each content section.
|
||||
*
|
||||
* <p>
|
||||
* This class is a container for two other components: a form and a table. The
|
||||
* form represents the drop down list of the content types available in a
|
||||
* particular content section. It is an extension of the
|
||||
* {@link com.arsdigita.cms.ui.authoring.NewItemForm}. The table displays each
|
||||
* content section in one row, along with the specified form. The same form is
|
||||
* reused in every row of the table.
|
||||
*
|
||||
* @author <a href="mailto:mbryzek@arsdigita.com">Michael Bryzek</a>
|
||||
* @version $Id: ContentSectionContainer.java 287 2005-02-22 00:29:02Z sskracic$
|
||||
*/
|
||||
public class ContentSectionContainer extends CMSContainer {
|
||||
|
||||
private static final String CONTENT_SECTION_CLASS = "contentSections";
|
||||
|
||||
private final ContentSectionTable m_table;
|
||||
private final FormContainer m_formContainer;
|
||||
private final SingleSelectionModel m_typeSel;
|
||||
private final SingleSelectionModel m_sectionSel;
|
||||
|
||||
/**
|
||||
* Constructs a new ContentSectionContainer which containts:
|
||||
*
|
||||
* <ul>
|
||||
* <li> SimpleContainer (to contain the form)
|
||||
* <ul>
|
||||
* <li> Form (for creating a new content item in each section)
|
||||
* </ul>
|
||||
* <li> Table (Displays all content sections)
|
||||
* </ul>
|
||||
*
|
||||
* @param typeSel passthrough to {@link NewItemForm}
|
||||
* @param sectionSel passthrough to {@link NewItemForm}
|
||||
*/
|
||||
public ContentSectionContainer(SingleSelectionModel typeSel,
|
||||
SingleSelectionModel sectionSel) {
|
||||
super();
|
||||
setClassAttr(CONTENT_SECTION_CLASS);
|
||||
|
||||
m_typeSel = typeSel;
|
||||
m_sectionSel = sectionSel;
|
||||
|
||||
m_formContainer = new FormContainer();
|
||||
add(m_formContainer);
|
||||
m_table = new ContentSectionTable();
|
||||
add(m_table);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param p
|
||||
*/
|
||||
@Override
|
||||
public void register(Page p) {
|
||||
super.register(p);
|
||||
p.setVisibleDefault(m_formContainer, false);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private class FormContainer extends CMSContainer {
|
||||
|
||||
// private final StaticNewItemForm m_form;
|
||||
private final BigDecimalParameter m_sectionIdParam;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
private FormContainer() {
|
||||
super();
|
||||
m_sectionIdParam = new BigDecimalParameter("sectionId");
|
||||
// m_form = new StaticNewItemForm(m_sectionIdParam);
|
||||
|
||||
// m_form.addSubmissionListener(new FormSubmissionListener() {
|
||||
//
|
||||
// /**
|
||||
// * Cancels the form if the user lacks the "create new items"
|
||||
// * privilege.
|
||||
// */
|
||||
// @Override
|
||||
// public void submitted(FormSectionEvent event)
|
||||
// throws FormProcessException {
|
||||
// PageState state = event.getPageState();
|
||||
// StaticNewItemForm form = (StaticNewItemForm) event
|
||||
// .getSource();
|
||||
//
|
||||
// ContentSection section = form.getContentSection(state);
|
||||
// final PermissionChecker permissionChecker = CdiUtil
|
||||
// .createCdiUtil().findBean(PermissionChecker.class);
|
||||
// Category folder = null;
|
||||
// //ToDo
|
||||
//// User user = Web.getWebContext().getUser();
|
||||
//// if (user != null) {
|
||||
//// folder = Folder.getUserHomeFolder(user, section);
|
||||
//// }
|
||||
//// if (folder == null) {
|
||||
//// folder = section.getRootFolder();
|
||||
//// }
|
||||
////ToDo End
|
||||
// folder = section.getRootDocumentsFolder();
|
||||
//
|
||||
// if (!permissionChecker.isPermitted(
|
||||
// ItemPrivileges.CREATE_NEW, folder)) {
|
||||
// throw new FormProcessException(
|
||||
// (GlobalizationUtil.globalize(
|
||||
// "cms.ui.insufficient_privileges")));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// });
|
||||
//
|
||||
// m_form.addProcessListener(new FormProcessListener() {
|
||||
//
|
||||
// /**
|
||||
// * Process listener: redirects to the authoring kit to create a
|
||||
// * new item.
|
||||
// */
|
||||
// @Override
|
||||
// public void process(FormSectionEvent e) throws
|
||||
// FormProcessException {
|
||||
// StaticNewItemForm form = (StaticNewItemForm) e.getSource();
|
||||
// PageState state = e.getPageState();
|
||||
//
|
||||
// BigDecimal typeId = form.getTypeID(state);
|
||||
// if (typeId != null) {
|
||||
// Long sectionId = form.getContentSectionID(state);
|
||||
// m_sectionSel.setSelectedKey(state, sectionId);
|
||||
// m_typeSel.setSelectedKey(state, typeId);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// });
|
||||
//
|
||||
// add(m_form);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(Page p) {
|
||||
super.register(p);
|
||||
p.addComponentStateParam(this, m_sectionIdParam);
|
||||
}
|
||||
|
||||
// public StaticNewItemForm getNewItemForm() {
|
||||
//// return m_form;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
// private static class StaticNewItemForm extends NewItemForm {
|
||||
//
|
||||
// private final Hidden m_sectionIDParamWidget;
|
||||
//
|
||||
// public StaticNewItemForm(BigDecimalParameter sectionParam) {
|
||||
// super("StaticNewItemForm", BoxPanel.VERTICAL);
|
||||
// setClassAttr("static-new-item-form");
|
||||
// m_sectionIDParamWidget = new Hidden(sectionParam);
|
||||
// add(m_sectionIDParamWidget);
|
||||
// setProcessInvisible(true);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Sets the id of the content section in this form. This ID is used to
|
||||
// * generate a list of available content types in the section.
|
||||
// *
|
||||
// * @param state The current page state.
|
||||
// * @param id The id of the ContentSection for which this form should
|
||||
// * display a list of content types
|
||||
// *
|
||||
// * @pre ( state != null && id != null )
|
||||
// */
|
||||
// public void setSectionId(PageState state, BigDecimal id) {
|
||||
// Assert.exists(id);
|
||||
// m_sectionIDParamWidget.setValue(state, id);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Retrieves the content section for this form given the specified page
|
||||
// * state. This method will return null if there is no content section.
|
||||
// *
|
||||
// * @param state The current page state.
|
||||
// *
|
||||
// * @return The current content section or null if the section does not
|
||||
// * exist
|
||||
// *
|
||||
// * @pre ( state != null )
|
||||
// */
|
||||
// @Override
|
||||
// public ContentSection getContentSection(PageState state) {
|
||||
// Long id = getContentSectionID(state);
|
||||
// Assert.exists(id);
|
||||
// ContentSection section;
|
||||
// section = CdiUtil.createCdiUtil().findBean(
|
||||
// ContentSectionRepository.class).findById(id);
|
||||
// return section;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Retrieves the ID of the content section for this form given the
|
||||
// * specified page state. This method will return null if no content
|
||||
// * section id has been set.
|
||||
// *
|
||||
// * @param state The current page state.
|
||||
// *
|
||||
// * @return The id of the content section or null if it has not been set.
|
||||
// *
|
||||
// * @pre ( state != null )
|
||||
// */
|
||||
// private Long getContentSectionID(PageState state) {
|
||||
// return (Long) Long.parseLong((String) m_sectionIDParamWidget
|
||||
// .getValue(state));
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* A table that displays all content sections, with links to their locations
|
||||
* and admin pages and a {@link NewItemForm} next to each section.
|
||||
*
|
||||
* @author <a href="mailto:mbryzek@arsdigita.com">Michael Bryzek</a>
|
||||
* @version $Revision$ $DateTime: 2004/08/17 23:15:09 $
|
||||
*
|
||||
*/
|
||||
private class ContentSectionTable extends Table {
|
||||
|
||||
// We will use a (symboloc) headerKey to match columns. Because the
|
||||
// number of columns depends on configuration for the llocation column,
|
||||
// the index varies and con not be used.
|
||||
private static final String COLUMN_SECTION = "Section";
|
||||
private static final String COLUMN_LOCATION = "Public Site";
|
||||
private static final String COLUMN_ACTION = "Action";
|
||||
|
||||
/**
|
||||
* Constructs a new ContentSectionTable, using a default table model
|
||||
* builder.
|
||||
*/
|
||||
private ContentSectionTable() {
|
||||
super();
|
||||
|
||||
// we must use symbolic keys (instead of symbolic column index as
|
||||
// usual) to identify a column because their number is dynamic
|
||||
// depending on configuration of the location column!
|
||||
Integer colNo = 0;
|
||||
|
||||
Label emptyView = new Label(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.section", CmsConstants.CMS_BUNDLE));
|
||||
emptyView.setFontWeight(Label.ITALIC);
|
||||
setEmptyView(emptyView);
|
||||
|
||||
setClassAttr("dataTable");
|
||||
|
||||
// add columns to the table
|
||||
TableColumnModel columnModel = getColumnModel();
|
||||
|
||||
// prepare column headers
|
||||
Label sectionHead = new Label(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.section", CmsConstants.CMS_BUNDLE));
|
||||
sectionHead.setHint(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.section_hint", CmsConstants.CMS_BUNDLE));
|
||||
Label locationHead = new Label(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.location", CmsConstants.CMS_BUNDLE));
|
||||
locationHead.setHint(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.location_hint", CmsConstants.CMS_BUNDLE));
|
||||
Label actionHead = new Label(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.action", CmsConstants.CMS_BUNDLE));
|
||||
actionHead.setHint(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.action_hint", CmsConstants.CMS_BUNDLE));
|
||||
|
||||
//TableColumn contentSectionColumn = new TableColumn(colNo, COLUMN_SECTION);
|
||||
TableColumn contentSectionColumn = new TableColumn(
|
||||
colNo,
|
||||
sectionHead,
|
||||
COLUMN_SECTION);
|
||||
contentSectionColumn
|
||||
.setCellRenderer(new AdminURLTableCellRenderer());
|
||||
columnModel.add(contentSectionColumn);
|
||||
|
||||
TableColumn actionColumn = new TableColumn(
|
||||
colNo++,
|
||||
actionHead,
|
||||
COLUMN_ACTION);
|
||||
actionColumn.setCellRenderer(new ActionTableCellRenderer());
|
||||
columnModel.add(actionColumn);
|
||||
|
||||
setModelBuilder(new ContentSectionTableModelBuilder());
|
||||
}
|
||||
|
||||
/**
|
||||
* An ContentSections table model builder
|
||||
*
|
||||
* @author <a href="mailto:mbryzek@arsdigita.com">Michael Bryzek</a>
|
||||
*
|
||||
*/
|
||||
private class ContentSectionTableModelBuilder extends LockableImpl
|
||||
implements TableModelBuilder {
|
||||
|
||||
@Override
|
||||
public TableModel makeModel(Table table, PageState state) {
|
||||
table.getRowSelectionModel().clearSelection(state);
|
||||
return new ContentSectionTableModel((ContentSectionTable) table,
|
||||
state);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An ContentSections table model
|
||||
*
|
||||
* @author <a href="mailto:mbryzek@arsdigita.com">Michael Bryzek</a>
|
||||
*
|
||||
*/
|
||||
private class ContentSectionTableModel implements TableModel {
|
||||
|
||||
private final ContentSectionTable m_table;
|
||||
private final TableColumnModel m_columnModel;
|
||||
private final PageState m_state;
|
||||
private final List<ContentSection> m_contentSections;
|
||||
private ContentSection m_section;
|
||||
private int index = -1;
|
||||
|
||||
private ContentSectionTableModel(ContentSectionTable table,
|
||||
PageState state) {
|
||||
m_table = table;
|
||||
m_columnModel = table.getColumnModel();
|
||||
m_state = state;
|
||||
|
||||
// retrieve all Content Sections
|
||||
m_contentSections = getContentSectionCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of ContentSections to display in this table.
|
||||
* This implementation orders the content sections by
|
||||
* <code>lower(label)</code>. They are also already filtered for the
|
||||
* sections to which the current user has no access.
|
||||
*
|
||||
*/
|
||||
private List<ContentSection> getContentSectionCollection() {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
||||
PermissionChecker.class);
|
||||
final List<ContentSection> allSections = cdiUtil.findBean(
|
||||
ContentSectionRepository.class).findAll();
|
||||
return allSections
|
||||
.stream()
|
||||
.filter(section -> permissionChecker
|
||||
.isPermitted(ItemPrivileges.VIEW_PUBLISHED,
|
||||
section))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return m_columnModel.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextRow() {
|
||||
index++;
|
||||
if (index < m_contentSections.size()) {
|
||||
m_section = m_contentSections.get(index);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, we return null. For the section, location, and action
|
||||
* columns, we return the current Content Section if there is one.
|
||||
*
|
||||
* @param columnIndex The index of the current column
|
||||
*/
|
||||
@Override
|
||||
public Object getElementAt(int columnIndex) {
|
||||
if (m_columnModel == null || m_section == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TableColumn tc = m_columnModel.get(columnIndex);
|
||||
String columnKey = (String) tc.getHeaderKey();
|
||||
|
||||
Object result = m_section;
|
||||
if (columnKey.equals(COLUMN_SECTION)
|
||||
|| columnKey.equals(COLUMN_LOCATION)
|
||||
|| columnKey.equals(
|
||||
COLUMN_ACTION)) {
|
||||
result = m_section;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getKeyAt(int columnIndex) {
|
||||
return m_section.getObjectId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the table associated with this table model.
|
||||
*
|
||||
*/
|
||||
protected Table getTable() {
|
||||
return m_table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current page state
|
||||
*
|
||||
*/
|
||||
protected PageState getPageState() {
|
||||
return m_state;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hidden parameter in the form containers form to the id of
|
||||
* the current section. Then returns the form for display, but only if
|
||||
* the user has permission to create new items in the current section.
|
||||
*
|
||||
* @author <a href="mailto:mbryzek@arsdigita.com">Michael Bryzek</a>
|
||||
*
|
||||
*/
|
||||
private class ActionTableCellRenderer implements TableCellRenderer {
|
||||
|
||||
@Override
|
||||
public Component getComponent(Table table, PageState state,
|
||||
Object value,
|
||||
boolean isSelected, Object key,
|
||||
int row, int column) {
|
||||
ContentSection section = (ContentSection) value;
|
||||
Category folder = null;
|
||||
//ToDo
|
||||
// User user = Web.getWebContext().getUser();
|
||||
// if (user != null) {
|
||||
// folder = Folder.getUserHomeFolder(user, section);
|
||||
// }
|
||||
// if (folder == null) {
|
||||
// folder = section.getRootFolder();
|
||||
// }
|
||||
|
||||
folder = section.getRootDocumentsFolder();
|
||||
// If the user has no access, return an empty Label
|
||||
|
||||
//
|
||||
// SecurityManager sm = new SecurityManager(section);
|
||||
//
|
||||
// if (!sm.canAccess(state.getRequest(), SecurityManager.NEW_ITEM,
|
||||
// folder)
|
||||
// || !ContentSection.getConfig()
|
||||
// .getAllowContentCreateInSectionListing()) {
|
||||
// // return null; // produces NPE here but works somewhere else.
|
||||
// // It's a kind of a hack. Label is supposed not to accept
|
||||
// // not-gloabalized data. Usually aou will return null here
|
||||
// // and xmlgenerator takes care of it. Doesn't work here.
|
||||
// return new Embedded(
|
||||
// " - - ");
|
||||
// } else {
|
||||
// // set the value of the sectionIdParameter in the form
|
||||
// // to this section
|
||||
// m_formContainer.getNewItemForm().setSectionId(state, section
|
||||
// .getID());
|
||||
// return m_formContainer.getNewItemForm();
|
||||
// }
|
||||
//ToDo End
|
||||
return new Embedded(
|
||||
" - - ");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the correct URL to the public pages for a content section.
|
||||
*
|
||||
* @author <a href="mailto:mbryzek@arsdigita.com">Michael Bryzek</a>
|
||||
*
|
||||
*/
|
||||
public static class URLTableCellRenderer implements TableCellRenderer {
|
||||
|
||||
/**
|
||||
* The object passed in is the current content section. This returns a
|
||||
* Link whose name and target are the url to the public pages.
|
||||
*
|
||||
* @return Link whose name and target are the url to the public pages of
|
||||
* the current (passed in) content section or a Label if current
|
||||
* use does not habe acces priviledge for the content section
|
||||
*/
|
||||
@Override
|
||||
public Component getComponent(Table table,
|
||||
PageState state,
|
||||
Object value,
|
||||
boolean isSelected,
|
||||
Object key,
|
||||
int row,
|
||||
int column) {
|
||||
|
||||
/* cast to ContentSection for further processing */
|
||||
ContentSection section = (ContentSection) value;
|
||||
String name = section.getLabel();
|
||||
String path = section.getPrimaryUrl(); // from Application
|
||||
|
||||
// If the user has no access, return a Label instead of a Link
|
||||
// Kind of a hack because Label is supposed not to accept
|
||||
// "un-globalized" display data. Label had been abused here to
|
||||
// to display a DataValue
|
||||
return new Embedded("/" + name + "/", false);
|
||||
// return null; // produces NPE here
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the correct URL to the admin pages for a content section.
|
||||
*
|
||||
* @author <a href="mailto:mbryzek@arsdigita.com">Michael Bryzek</a>
|
||||
*
|
||||
*/
|
||||
public static class AdminURLTableCellRenderer extends URLTableCellRenderer {
|
||||
|
||||
/**
|
||||
* The object passed in is the current content section
|
||||
*
|
||||
* @param table
|
||||
* @param state
|
||||
* @param row
|
||||
* @param value
|
||||
* @param column
|
||||
* @param isSelected
|
||||
* @param key
|
||||
*
|
||||
* @return
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public Component getComponent(Table table, PageState state, Object value,
|
||||
boolean isSelected, Object key,
|
||||
int row, int column) {
|
||||
ContentSection section = (ContentSection) value;
|
||||
|
||||
final PermissionChecker permissionChecker = CdiUtil.createCdiUtil()
|
||||
.findBean(PermissionChecker.class);
|
||||
|
||||
// If the user has no access, return a Label instead of a Link
|
||||
if (permissionChecker.isPermitted(
|
||||
ItemPrivileges.EDIT,
|
||||
section.getRootDocumentsFolder())) {
|
||||
|
||||
return new Link(section.getLabel(),
|
||||
generateURL(section.getPrimaryUrl()));
|
||||
} else {
|
||||
//return new Label(section.getName(), false);
|
||||
// return null; // Produces a NPE although it shouldn't and
|
||||
// indeed doesn't elsewhere
|
||||
// Kind of a hack because Label is supposed not to accept
|
||||
// "un-globalized" display data. Label had been abused here to
|
||||
// to display a DataValue
|
||||
return new Embedded(section.getLabel(), false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the admin url for the specified prefix. Always returns
|
||||
* something that does not start with a forward slash.
|
||||
*
|
||||
* @param prefix The prefix of the URL
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected String generateURL(String prefix) {
|
||||
return prefix + PageLocations.SECTION_PAGE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,260 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
package com.arsdigita.cms.ui.contentcenter;
|
||||
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SimpleContainer;
|
||||
import com.arsdigita.bebop.TabbedPane;
|
||||
import com.arsdigita.bebop.event.ActionEvent;
|
||||
import com.arsdigita.bebop.event.ActionListener;
|
||||
import com.arsdigita.bebop.parameters.LongParameter;
|
||||
import com.arsdigita.cms.ui.CMSApplicationPage;
|
||||
import com.arsdigita.cms.ui.GlobalNavigation;
|
||||
import com.arsdigita.cms.ui.WorkspaceContextBar;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.ui.CcmObjectSelectionModel;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentType;
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Developer's Note:
|
||||
// Replaces the (old) Dispatcher based Code cms.ui.CMSPageWorkspacePage
|
||||
// Note should be removed as soon as the migration process is competed (in-
|
||||
// cluding content section pages).
|
||||
//
|
||||
// ////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* <p>
|
||||
* The Content Center main page. </p>
|
||||
*
|
||||
* The page contains the general header and footer, the breadcrumb, and the
|
||||
* complete content page including the tab bar, the sections/tasks page, the
|
||||
* search page, and the listener to switch between the tabs.
|
||||
*
|
||||
* @author Jack Chung (flattop@arsdigita.com)
|
||||
* @author Michael Pih (pihman@arsdigita.com)
|
||||
* @author Peter Boy (pboy@barkhof.uni-bremen.de)
|
||||
*/
|
||||
public class MainPage extends CMSApplicationPage implements ActionListener {
|
||||
|
||||
private final static String XSL_CLASS = "CMS Admin";
|
||||
|
||||
public static final String CONTENT_TYPE = "type_id";
|
||||
public static final String CONTENT_SECTION = "section_id";
|
||||
|
||||
private final CcmObjectSelectionModel<ContentType> typeSelection;
|
||||
private final CcmObjectSelectionModel<ContentSection> sectionSelection;
|
||||
|
||||
private final TabbedPane tabbedPane;
|
||||
|
||||
private TasksPane tasksPanel;
|
||||
// private ItemSearch m_search;
|
||||
// private IdSearchTab m_IdSearch;
|
||||
|
||||
/**
|
||||
* Construct a new MainPage.
|
||||
*
|
||||
* Creates the complete page ready to be included in the page cache of
|
||||
* ContentCenterServlet.
|
||||
*/
|
||||
public MainPage() {
|
||||
|
||||
super(new Label(new GlobalizedMessage("cms.ui.content_center",
|
||||
CmsConstants.CMS_BUNDLE)),
|
||||
new SimpleContainer());
|
||||
|
||||
|
||||
/* Set the class attribute value (down in SimpleComponent). */
|
||||
super.setClassAttr("cms-admin");
|
||||
|
||||
final LongParameter typeId = new LongParameter(CONTENT_TYPE);
|
||||
super.addGlobalStateParam(typeId);
|
||||
typeSelection = new CcmObjectSelectionModel<>(ContentType.class, typeId);
|
||||
|
||||
final LongParameter sectionId = new LongParameter(CONTENT_SECTION);
|
||||
super.addGlobalStateParam(sectionId);
|
||||
sectionSelection = new CcmObjectSelectionModel<>(ContentSection.class,
|
||||
sectionId
|
||||
);
|
||||
|
||||
super.add(new WorkspaceContextBar());
|
||||
super.add(new GlobalNavigation());
|
||||
|
||||
tasksPanel = getTasksPane(typeSelection, sectionSelection);
|
||||
// m_search = getSearchPane();
|
||||
// m_IdSearch = getIdSearchPane();
|
||||
|
||||
tabbedPane = createTabbedPane();
|
||||
tabbedPane.setIdAttr("page-body");
|
||||
super.add(tabbedPane);
|
||||
|
||||
// add(new DebugPanel());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates, and then caches, the Tasks pane. Overriding this method to
|
||||
* return null will prevent this tab from appearing.
|
||||
*
|
||||
* @param typeModel
|
||||
* @param sectionModel
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected TasksPane getTasksPane(
|
||||
final CcmObjectSelectionModel<ContentType> typeModel,
|
||||
final CcmObjectSelectionModel<ContentSection> sectionModel) {
|
||||
|
||||
if (tasksPanel == null) {
|
||||
tasksPanel = new TasksPane(typeModel, sectionModel);
|
||||
}
|
||||
return tasksPanel;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Creates, and then caches, the Search pane. Overriding this method to
|
||||
// * return null will prevent this tab from appearing.
|
||||
// *
|
||||
// */
|
||||
// protected ItemSearch getSearchPane() {
|
||||
// if (m_search == null) {
|
||||
// m_search = new ItemSearch(ContentItem.DRAFT);
|
||||
// }
|
||||
//
|
||||
// return m_search;
|
||||
// }
|
||||
//
|
||||
// protected IdSearchTab getIdSearchPane() {
|
||||
// if (m_IdSearch == null) {
|
||||
// m_IdSearch = new IdSearchTab("idsearch");
|
||||
// }
|
||||
//
|
||||
// return m_IdSearch;
|
||||
// }
|
||||
/**
|
||||
* Created the TabbedPane to use for this page. Sets the class attribute for
|
||||
* this tabbed pane. The default implementation uses a
|
||||
* {@link com.arsdigita.bebop.TabbedPane} and sets the class attribute to
|
||||
* "CMS Admin." This implementation also adds tasks, content sections, and
|
||||
* search panes.
|
||||
*
|
||||
* Developers can override this method to add only the tabs they want, or to
|
||||
* add additional tabs after the default CMS tabs are added.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected TabbedPane createTabbedPane() {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PermissionChecker permissionChecker = cdiUtil
|
||||
.findBean(PermissionChecker.class);
|
||||
|
||||
final TabbedPane pane = new TabbedPane();
|
||||
pane.setClassAttr(XSL_CLASS);
|
||||
Label taskLabel = new Label(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.mainpage.taskssections",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
Label pagesLabel = new Label(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.mainpage.pages",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
Label searchLabel = new Label(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.mainpage.search", CmsConstants.CMS_BUNDLE));
|
||||
Label IdsearchLabel = new Label("ID Search");
|
||||
|
||||
addToPane(pane,
|
||||
taskLabel,
|
||||
getTasksPane(typeSelection, sectionSelection));
|
||||
|
||||
// if (permissionChecker.isPermitted(PagesPrivileges.ADMINISTER_PAGES)) {
|
||||
addToPane(pane,
|
||||
pagesLabel,
|
||||
new PagesPane());
|
||||
// }
|
||||
// addToPane(tabbedPane,
|
||||
// new Label(new GlobalizedMessage(
|
||||
// "cms.ui.contentcenter.mainpage.search",
|
||||
// CmsConstants.CMS_BUNDLE)),
|
||||
// getSearchPane());
|
||||
// addToPane(tabbedPane,
|
||||
// IdsearchLabel,
|
||||
// getIdSearchPane());
|
||||
|
||||
pane.addActionListener(this);
|
||||
return pane;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Adds the specified component, with the specified tab name, to the
|
||||
// * tabbed pane only if it is not null.
|
||||
// *
|
||||
// * @param pane The pane to which to add the tab
|
||||
// * @param tabName The name of the tab if it's added
|
||||
// * @param comp The component to add to the pane
|
||||
// * @deprecated refactor to use addToPane(Label, Component) instead to
|
||||
// * enable localized tab strips.
|
||||
// */
|
||||
// protected void addToPane(TabbedPane pane, String tabName, Component comp) {
|
||||
// if (comp != null) {
|
||||
// pane.addTab(tabName, comp);
|
||||
// }
|
||||
// }
|
||||
/**
|
||||
* Adds the specified component, with the specified Label as tab name, to
|
||||
* the tabbed pane only if it is not null.
|
||||
*
|
||||
* @param pane The pane to which to add the tab
|
||||
* @param tabName The name of the tab if it's added
|
||||
* @param component The component to add to the pane
|
||||
*/
|
||||
protected void addToPane(final TabbedPane pane,
|
||||
final Label tabName,
|
||||
final Component component) {
|
||||
if (component != null) {
|
||||
pane.addTab(tabName, component);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When a new tab is selected, reset the state of the formerly-selected
|
||||
* pane.
|
||||
*
|
||||
* @param event The event fired by selecting a tab
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent event) {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
final Component pane = tabbedPane.getCurrentPane(state);
|
||||
|
||||
if (pane == tasksPanel) {
|
||||
tasksPanel.reset(state);
|
||||
}
|
||||
// else if (pane == m_search) {
|
||||
// m_search.reset(state);
|
||||
// } else if (pane == m_IdSearch) {
|
||||
// m_IdSearch.reset(state);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,279 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.contentcenter;
|
||||
|
||||
import com.arsdigita.bebop.Form;
|
||||
import com.arsdigita.bebop.FormData;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.bebop.SaveCancelSection;
|
||||
import com.arsdigita.bebop.Text;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.event.PrintEvent;
|
||||
import com.arsdigita.bebop.form.Option;
|
||||
import com.arsdigita.bebop.form.SingleSelect;
|
||||
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
import org.libreccm.categorization.Domain;
|
||||
import org.libreccm.categorization.DomainRepository;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.core.UnexpectedErrorException;
|
||||
import org.libreccm.sites.Site;
|
||||
import org.libreccm.sites.SiteRepository;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.pages.Pages;
|
||||
import org.librecms.pages.PagesRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.TooManyListenersException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
class PagesForm extends Form {
|
||||
|
||||
private final static String PRIMARY_URL_FIELD = "primaryUrl";
|
||||
private final static String SITE_SELECT = "site";
|
||||
private final static String CATEGORY_DOMAIN_SELECT = "categoryDomain";
|
||||
|
||||
private final PagesPane pagesPane;
|
||||
private final ParameterSingleSelectionModel<String> selectedPages;
|
||||
|
||||
private final TextField primaryUrlField;
|
||||
private final SingleSelect siteSelect;
|
||||
private final SingleSelect categoryDomainSelect;
|
||||
private final SaveCancelSection saveCancelSection;
|
||||
|
||||
PagesForm(final PagesPane pagesPane,
|
||||
final ParameterSingleSelectionModel<String> selectedPages) {
|
||||
|
||||
super("pagesForm");
|
||||
|
||||
this.pagesPane = pagesPane;
|
||||
this.selectedPages = selectedPages;
|
||||
|
||||
primaryUrlField = new TextField(PRIMARY_URL_FIELD);
|
||||
primaryUrlField.setLabel(new GlobalizedMessage(
|
||||
"cms.ui.pages.form.primary_url_field.label",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
super.add(primaryUrlField);
|
||||
|
||||
siteSelect = new SingleSelect(SITE_SELECT);
|
||||
try {
|
||||
siteSelect.addPrintListener(this::populateSiteSelect);
|
||||
} catch (TooManyListenersException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
siteSelect.setLabel(new GlobalizedMessage(
|
||||
"cms.ui.pages.form.site_select.label",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
super.add(siteSelect);
|
||||
|
||||
categoryDomainSelect = new SingleSelect(CATEGORY_DOMAIN_SELECT);
|
||||
try {
|
||||
categoryDomainSelect
|
||||
.addPrintListener(this::populateCategoryDomainSelect);
|
||||
} catch (TooManyListenersException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
categoryDomainSelect.setLabel(new GlobalizedMessage(
|
||||
"cms.ui.pages.form.category_domain_select.label",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
super.add(categoryDomainSelect);
|
||||
|
||||
saveCancelSection = new SaveCancelSection();
|
||||
super.add(saveCancelSection);
|
||||
|
||||
super.addInitListener(this::init);
|
||||
super.addValidationListener(this::validate);
|
||||
super.addProcessListener(this::process);
|
||||
}
|
||||
|
||||
private void populateSiteSelect(final PrintEvent event) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final SiteRepository siteRepository = cdiUtil
|
||||
.findBean(SiteRepository.class);
|
||||
|
||||
final List<Site> sites = siteRepository.findAll();
|
||||
|
||||
final SingleSelect target = (SingleSelect) event.getTarget();
|
||||
target.clearOptions();
|
||||
|
||||
for (final Site site : sites) {
|
||||
final Text label;
|
||||
if (site.isDefaultSite()) {
|
||||
label = new Text(String.format("%s *", site.getDomainOfSite()));
|
||||
} else {
|
||||
label = new Text(site.getDomainOfSite());
|
||||
}
|
||||
|
||||
target.addOption(new Option(Long.toString(site.getObjectId()),
|
||||
label));
|
||||
}
|
||||
|
||||
if (selectedPages.getSelectedKey(event.getPageState()) != null) {
|
||||
target.setDisabled();
|
||||
}
|
||||
}
|
||||
|
||||
private void populateCategoryDomainSelect(final PrintEvent event) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final DomainRepository domainRepo = cdiUtil
|
||||
.findBean(DomainRepository.class);
|
||||
|
||||
final List<Domain> categoryDomains = domainRepo.findAll();
|
||||
|
||||
final SingleSelect target = (SingleSelect) event.getTarget();
|
||||
target.clearOptions();
|
||||
|
||||
for (final Domain domain : categoryDomains) {
|
||||
|
||||
target.addOption(new Option(Long.toString(domain.getObjectId()),
|
||||
new Text(domain.getDomainKey())));
|
||||
}
|
||||
|
||||
if (selectedPages.getSelectedKey(event.getPageState()) != null) {
|
||||
target.setDisabled();
|
||||
}
|
||||
}
|
||||
|
||||
private void init(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
if (selectedPages.getSelectedKey(state) != null) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PagesRepository pagesRepo = cdiUtil
|
||||
.findBean(PagesRepository.class);
|
||||
|
||||
final Pages pages = pagesRepo
|
||||
.findById(Long.parseLong(selectedPages.getSelectedKey(state)))
|
||||
.orElseThrow(() -> new UnexpectedErrorException(String
|
||||
.format("No Pages with ID %s in the database.",
|
||||
selectedPages.getSelectedKey(state))));
|
||||
|
||||
primaryUrlField.setValue(state, pages.getPrimaryUrl());
|
||||
|
||||
siteSelect.setValue(state,
|
||||
Long.toString(pages.getSite().getObjectId()));
|
||||
|
||||
categoryDomainSelect
|
||||
.setValue(state,
|
||||
Long.toString(pages.getCategoryDomain().getObjectId()));
|
||||
}
|
||||
}
|
||||
|
||||
private void validate(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
||||
|
||||
final FormData data = event.getFormData();
|
||||
|
||||
final String primaryUrl = data.getString(PRIMARY_URL_FIELD);
|
||||
if (primaryUrl == null
|
||||
|| primaryUrl.isEmpty()
|
||||
|| primaryUrl.matches("\\s*")) {
|
||||
|
||||
data.addError(PRIMARY_URL_FIELD,
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.pages.form.primary_url_field.error",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
}
|
||||
|
||||
final String selectedSite = data.getString(SITE_SELECT);
|
||||
if (selectedSite == null
|
||||
|| selectedSite.isEmpty()) {
|
||||
|
||||
data.addError(PRIMARY_URL_FIELD,
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.pages.form.site_select.error",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
}
|
||||
|
||||
final String selectedDomain = data.getString(CATEGORY_DOMAIN_SELECT);
|
||||
if (selectedDomain == null
|
||||
|| selectedDomain.isEmpty()) {
|
||||
|
||||
data.addError(PRIMARY_URL_FIELD,
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.pages.form.category_domain_select.error",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void process(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PagesPaneController controller = cdiUtil
|
||||
.findBean(PagesPaneController.class);
|
||||
|
||||
final FormData data = event.getFormData();
|
||||
|
||||
final String primaryUrl;
|
||||
if (data.getString(PRIMARY_URL_FIELD).startsWith("/")
|
||||
&& data.getString(PRIMARY_URL_FIELD).endsWith("/")) {
|
||||
primaryUrl = data.getString(PRIMARY_URL_FIELD);
|
||||
} else if(data.getString(PRIMARY_URL_FIELD).startsWith("/")) {
|
||||
primaryUrl = String.format("%s/",
|
||||
data.getString(PRIMARY_URL_FIELD));
|
||||
} else if(data.getString(PRIMARY_URL_FIELD).endsWith("/")) {
|
||||
primaryUrl = String.format("/%s",
|
||||
data.getString(PRIMARY_URL_FIELD));
|
||||
} else {
|
||||
primaryUrl = String.format("/%s/",
|
||||
data.getString(PRIMARY_URL_FIELD));
|
||||
}
|
||||
final String selectedSiteId = data.getString(SITE_SELECT);
|
||||
final String selectedDomainId = data.getString(
|
||||
CATEGORY_DOMAIN_SELECT);
|
||||
|
||||
if (selectedPages.getSelectedKey(state) == null) {
|
||||
controller.createPages(primaryUrl,
|
||||
Long.parseLong(selectedSiteId),
|
||||
Long.parseLong(selectedDomainId));
|
||||
} else {
|
||||
controller
|
||||
.updatePages(
|
||||
Long.parseLong(selectedPages.getSelectedKey(state)),
|
||||
primaryUrl);
|
||||
}
|
||||
}
|
||||
|
||||
pagesPane.showPagesTable(state);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,398 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.contentcenter;
|
||||
|
||||
import com.arsdigita.bebop.ActionLink;
|
||||
import com.arsdigita.bebop.BoxPanel;
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.ControlLink;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.Link;
|
||||
import com.arsdigita.bebop.Page;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.bebop.Table;
|
||||
import com.arsdigita.bebop.Text;
|
||||
import com.arsdigita.bebop.event.TableActionEvent;
|
||||
import com.arsdigita.bebop.event.TableActionListener;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
||||
import com.arsdigita.bebop.table.TableColumn;
|
||||
import com.arsdigita.bebop.table.TableColumnModel;
|
||||
import com.arsdigita.bebop.table.TableModel;
|
||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
||||
import com.arsdigita.cms.ui.CMSContainer;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.util.LockableImpl;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.core.UnexpectedErrorException;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.pages.Pages;
|
||||
import org.librecms.pages.PagesPrivileges;
|
||||
import org.librecms.pages.PagesRepository;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
class PagesPane extends CMSContainer {
|
||||
|
||||
private final ParameterSingleSelectionModel<String> selectedPages;
|
||||
|
||||
private final ActionLink addPagesLink;
|
||||
private final PagesTable pagesTable;
|
||||
private final PagesForm pagesForm;
|
||||
|
||||
PagesPane() {
|
||||
|
||||
super();
|
||||
|
||||
selectedPages = new ParameterSingleSelectionModel<>(
|
||||
new StringParameter("selectedPages"));
|
||||
|
||||
addPagesLink = new ActionLink(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.pages.add_link",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
addPagesLink.addActionListener(event -> {
|
||||
showPagesForm(event.getPageState());
|
||||
});
|
||||
pagesTable = new PagesTable();
|
||||
pagesForm = new PagesForm(this, selectedPages);
|
||||
|
||||
final BoxPanel panel = new BoxPanel(BoxPanel.VERTICAL);
|
||||
panel.add(addPagesLink);
|
||||
panel.add(pagesTable);
|
||||
panel.add(pagesForm);
|
||||
|
||||
super.add(panel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(final Page page) {
|
||||
super.register(page);
|
||||
|
||||
page.addGlobalStateParam(selectedPages.getStateParameter());
|
||||
|
||||
page.setVisibleDefault(addPagesLink, true);
|
||||
page.setVisibleDefault(pagesTable, true);
|
||||
page.setVisibleDefault(pagesForm, false);
|
||||
}
|
||||
|
||||
protected void showPagesForm(final PageState state) {
|
||||
|
||||
addPagesLink.setVisible(state, false);
|
||||
pagesTable.setVisible(state, false);
|
||||
pagesForm.setVisible(state, true);
|
||||
}
|
||||
|
||||
protected void showPagesTable(final PageState state) {
|
||||
|
||||
addPagesLink.setVisible(state, true);
|
||||
pagesTable.setVisible(state, true);
|
||||
pagesForm.setVisible(state, false);
|
||||
|
||||
selectedPages.clearSelection(state);
|
||||
}
|
||||
|
||||
private class PagesTable extends Table {
|
||||
|
||||
public static final int COL_SITE = 0;
|
||||
public static final int COL_PAGES_INSTANCE = 1;
|
||||
public static final int COL_EDIT = 2;
|
||||
public static final int COL_DELETE = 3;
|
||||
|
||||
public PagesTable() {
|
||||
|
||||
super();
|
||||
|
||||
final TableColumnModel columnModel = super.getColumnModel();
|
||||
|
||||
columnModel
|
||||
.add(new TableColumn(
|
||||
COL_SITE,
|
||||
new Label(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.pagestable.columns.site.header",
|
||||
CmsConstants.CMS_BUNDLE))));
|
||||
columnModel
|
||||
.add(new TableColumn(
|
||||
COL_SITE,
|
||||
new Label(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.pagestable.columns.pages_instance.header",
|
||||
CmsConstants.CMS_BUNDLE))));
|
||||
columnModel
|
||||
.add(new TableColumn(
|
||||
COL_EDIT,
|
||||
new Label(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.pagestable.columns.edit.header",
|
||||
CmsConstants.CMS_BUNDLE))));
|
||||
columnModel
|
||||
.add(new TableColumn(
|
||||
COL_DELETE,
|
||||
new Label(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.pagestable.columns.delete.header",
|
||||
CmsConstants.CMS_BUNDLE))));
|
||||
|
||||
columnModel
|
||||
.get(COL_SITE)
|
||||
.setCellRenderer(new TableCellRenderer() {
|
||||
|
||||
@Override
|
||||
public Component getComponent(final Table table,
|
||||
final PageState state,
|
||||
final Object value,
|
||||
final boolean isSelected,
|
||||
final Object key,
|
||||
final int row,
|
||||
final int column) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PermissionChecker permissionChecker = cdiUtil
|
||||
.findBean(PermissionChecker.class);
|
||||
|
||||
// return new ControlLink((String) value);
|
||||
final Pages pages = (Pages) value;
|
||||
if (permissionChecker.isPermitted(
|
||||
PagesPrivileges.ADMINISTER_PAGES)) {
|
||||
return new Link(pages.getSite().getDomainOfSite(),
|
||||
pages.getPrimaryUrl());
|
||||
} else {
|
||||
return new Text(pages.getSite().getDomainOfSite());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
columnModel
|
||||
.get(COL_PAGES_INSTANCE)
|
||||
.setCellRenderer(new TableCellRenderer() {
|
||||
|
||||
@Override
|
||||
public Component getComponent(final Table table,
|
||||
final PageState state,
|
||||
final Object value,
|
||||
final boolean isSelected,
|
||||
final Object key,
|
||||
final int row,
|
||||
final int column) {
|
||||
|
||||
final Pages pages = (Pages) value;
|
||||
return new Text(pages.getPrimaryUrl());
|
||||
}
|
||||
});
|
||||
|
||||
columnModel
|
||||
.get(COL_EDIT)
|
||||
.setCellRenderer(new TableCellRenderer() {
|
||||
|
||||
@Override
|
||||
public Component getComponent(final Table table,
|
||||
final PageState state,
|
||||
final Object value,
|
||||
final boolean isSelected,
|
||||
final Object key,
|
||||
final int row,
|
||||
final int column) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PermissionChecker permissionChecker = cdiUtil
|
||||
.findBean(PermissionChecker.class);
|
||||
|
||||
if (permissionChecker.isPermitted(
|
||||
PagesPrivileges.ADMINISTER_PAGES)) {
|
||||
|
||||
final ControlLink link = new ControlLink(
|
||||
(Component) value);
|
||||
return link;
|
||||
} else {
|
||||
return new Text("");
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
columnModel
|
||||
.get(COL_DELETE)
|
||||
.setCellRenderer(new TableCellRenderer() {
|
||||
|
||||
@Override
|
||||
public Component getComponent(final Table table,
|
||||
final PageState state,
|
||||
final Object value,
|
||||
final boolean isSelected,
|
||||
final Object key,
|
||||
final int row,
|
||||
final int column) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PermissionChecker permissionChecker = cdiUtil
|
||||
.findBean(PermissionChecker.class);
|
||||
|
||||
if (permissionChecker.isPermitted(
|
||||
PagesPrivileges.ADMINISTER_PAGES)) {
|
||||
|
||||
final ControlLink link = new ControlLink(
|
||||
(Component) value);
|
||||
link.setConfirmation(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.pages.delete.confirm",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
return link;
|
||||
} else {
|
||||
return new Text("");
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
super.addTableActionListener(new TableActionListener() {
|
||||
|
||||
@Override
|
||||
public void cellSelected(final TableActionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final int column = event.getColumn();
|
||||
final String key = (String) event.getRowKey();
|
||||
|
||||
switch (column) {
|
||||
case COL_EDIT:
|
||||
selectedPages.setSelectedKey(state, key);
|
||||
showPagesForm(state);
|
||||
break;
|
||||
case COL_DELETE: {
|
||||
deletePages(key);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new UnexpectedErrorException(
|
||||
"Illegal column index.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void headSelected(final TableActionEvent event) {
|
||||
|
||||
//Nothing
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
super.setModelBuilder(new PagesTableModelBuilder());
|
||||
|
||||
super.setEmptyView(new Label(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.pages.none", CmsConstants.CMS_BUNDLE)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void deletePages(final String pagesId) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PagesRepository pagesRepo = cdiUtil
|
||||
.findBean(PagesRepository.class);
|
||||
|
||||
final Pages pages = pagesRepo
|
||||
.findById(Long.parseLong(pagesId))
|
||||
.orElseThrow(() -> new UnexpectedErrorException(String
|
||||
.format("No Pages with ID %d in the database.",
|
||||
pagesId)));
|
||||
|
||||
pagesRepo.delete(pages);
|
||||
}
|
||||
|
||||
private class PagesTableModelBuilder
|
||||
extends LockableImpl
|
||||
implements TableModelBuilder {
|
||||
|
||||
@Override
|
||||
public TableModel makeModel(final Table table, final PageState state) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PagesRepository pagesRepo = cdiUtil
|
||||
.findBean(PagesRepository.class);
|
||||
|
||||
final List<Pages> pages = pagesRepo.findAll();
|
||||
return new PagesTableModel(pages);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class PagesTableModel implements TableModel {
|
||||
|
||||
private final Iterator<Pages> iterator;
|
||||
private Pages current;
|
||||
|
||||
public PagesTableModel(final List<Pages> pages) {
|
||||
|
||||
iterator = pages.iterator();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextRow() {
|
||||
|
||||
if (iterator.hasNext()) {
|
||||
current = iterator.next();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getElementAt(final int columnIndex) {
|
||||
|
||||
switch (columnIndex) {
|
||||
case PagesTable.COL_SITE:
|
||||
return current;
|
||||
case PagesTable.COL_PAGES_INSTANCE:
|
||||
return current;
|
||||
case PagesTable.COL_EDIT:
|
||||
return new Label(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.pages.edit.label",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
case PagesTable.COL_DELETE:
|
||||
return new Label(new GlobalizedMessage(
|
||||
"cms.ui.contentcenter.pages.delete.label",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
default:
|
||||
throw new IllegalArgumentException("Illegal column index.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getKeyAt(final int columnIndex) {
|
||||
|
||||
return current.getObjectId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.contentcenter;
|
||||
|
||||
import org.libreccm.categorization.Domain;
|
||||
import org.libreccm.categorization.DomainRepository;
|
||||
import org.libreccm.core.UnexpectedErrorException;
|
||||
import org.libreccm.sites.Site;
|
||||
import org.libreccm.sites.SiteManager;
|
||||
import org.libreccm.sites.SiteRepository;
|
||||
import org.librecms.pages.Pages;
|
||||
import org.librecms.pages.PagesManager;
|
||||
import org.librecms.pages.PagesRepository;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
class PagesPaneController {
|
||||
|
||||
@Inject
|
||||
private DomainRepository domainRepo;
|
||||
|
||||
@Inject
|
||||
private PagesRepository pagesRepo;
|
||||
|
||||
@Inject
|
||||
private PagesManager pagesManager;
|
||||
|
||||
@Inject
|
||||
private SiteManager siteManager;
|
||||
|
||||
@Inject
|
||||
private SiteRepository siteRepo;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void createPages(final String primaryUrl,
|
||||
final long siteId,
|
||||
final long categoryDomainId) {
|
||||
|
||||
final Site site = siteRepo
|
||||
.findById(siteId)
|
||||
.orElseThrow(() -> new UnexpectedErrorException(String
|
||||
.format("No Site with ID %d in the database.",
|
||||
siteId)));
|
||||
|
||||
final Domain domain = domainRepo
|
||||
.findById(categoryDomainId)
|
||||
.orElseThrow(() -> new UnexpectedErrorException(String
|
||||
.format("No (Category) Domain with ID %d in the database.",
|
||||
categoryDomainId)));
|
||||
|
||||
final Pages pages = pagesManager.createPages(primaryUrl, site, domain);
|
||||
pages.setPrimaryUrl(primaryUrl);
|
||||
|
||||
pagesRepo.save(pages);
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void updatePages(final long pagesId,
|
||||
final String primaryUrl) {
|
||||
|
||||
final Pages pages = pagesRepo
|
||||
.findById(pagesId)
|
||||
.orElseThrow(() -> new UnexpectedErrorException(String
|
||||
.format("No Pages with ID %d in the database.",
|
||||
pagesId)));
|
||||
|
||||
pages.setPrimaryUrl(primaryUrl);
|
||||
|
||||
pagesRepo.save(pages);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,762 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
package com.arsdigita.cms.ui.contentcenter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import com.arsdigita.bebop.ActionLink;
|
||||
import com.arsdigita.bebop.BoxPanel;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.Page;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.PaginationModelBuilder;
|
||||
import com.arsdigita.bebop.Paginator;
|
||||
import com.arsdigita.bebop.RequestLocal;
|
||||
import com.arsdigita.bebop.SimpleComponent;
|
||||
import com.arsdigita.bebop.event.ActionEvent;
|
||||
import com.arsdigita.bebop.event.ActionListener;
|
||||
import com.arsdigita.bebop.event.ChangeEvent;
|
||||
import com.arsdigita.bebop.event.ChangeListener;
|
||||
import com.arsdigita.bebop.event.PrintEvent;
|
||||
import com.arsdigita.bebop.event.PrintListener;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.cms.CMS;
|
||||
import com.arsdigita.cms.ui.CMSContainer;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.ui.CcmObjectSelectionModel;
|
||||
import com.arsdigita.xml.Element;
|
||||
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentType;
|
||||
|
||||
public class TasksPane extends CMSContainer {
|
||||
|
||||
// The default number of rows to show
|
||||
private static final int DEFAULT_MAX_ROWS = 15;
|
||||
// Number of tasks to show
|
||||
private final int m_maxRows;
|
||||
private TaskList m_taskList;
|
||||
// private ActionLink m_viewAllLink;
|
||||
// private ActionLink m_viewShortLink;
|
||||
private Paginator m_paginator;
|
||||
private ActionLink m_viewLockLink;
|
||||
private ActionLink m_viewUnlockLink;
|
||||
private ActionLink m_viewAllLockLink;
|
||||
private Label m_viewLockLabel;
|
||||
private Label m_viewUnlockLabel;
|
||||
private Label m_viewAllLockLabel;
|
||||
private StringParameter m_sortDirectionParam;
|
||||
private StringParameter m_sortTypeParam;
|
||||
private StringParameter m_lockFilterParam;
|
||||
// control link variable
|
||||
private static final String TASK_PANEL_CLASS = "taskPanel";
|
||||
private static final String TASK_ACTION = "taskAction";
|
||||
private static final String SORT_DOWN = "sortActionUp";
|
||||
private static final String SORT_UP = "sortActionDown";
|
||||
private static final String LOCK_FILTER_TYPE = "lockFilterType";
|
||||
private static final String SORT_TYPE = "sortType";
|
||||
private static final String SORT_DIRECTION = "sortDirection";
|
||||
private static final String SORT_ACTION = "action";
|
||||
private static final String SORT_DATE = "date";
|
||||
private static final String SORT_STATUS = "status";
|
||||
private static final String SORT_TITLE = "title";
|
||||
private static final String SORT_USER = "user";
|
||||
private static final String SORT_WORKFLOW = "workflow";
|
||||
// IMAGES
|
||||
public static final String UP_ARROW_IMAGE
|
||||
= "/themes/heirfloom/images/gray-triangle-up.gif";
|
||||
public static final String DOWN_ARROW_IMAGE
|
||||
= "/themes/heirfloom/images/gray-triangle-down.gif";
|
||||
// CREATION PANE CONSTANTS
|
||||
private Label m_selectorLabel;
|
||||
//ToDo
|
||||
// private CreationSelector m_selector;
|
||||
private ContentSectionContainer m_sections;
|
||||
// ToDo End
|
||||
private CcmObjectSelectionModel m_sectionSel;
|
||||
private CcmObjectSelectionModel m_typeSel;
|
||||
|
||||
// private RootFolderSelectionModel m_folderSel;
|
||||
private BoxPanel m_creationPane;
|
||||
|
||||
/**
|
||||
* Constructs a new task panel that shows no more than 15 enabled tasks by
|
||||
* default.
|
||||
*
|
||||
* @param typeModel
|
||||
* @param sectionModel
|
||||
*
|
||||
*/
|
||||
public TasksPane(CcmObjectSelectionModel typeModel,
|
||||
CcmObjectSelectionModel sectionModel) {
|
||||
this(DEFAULT_MAX_ROWS, typeModel, sectionModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new task panel that shows a specified number enabled tasks.
|
||||
*
|
||||
* @param maxRows the maximum number of rows to show by default
|
||||
* @param typeModel
|
||||
* @param sectionModel
|
||||
*
|
||||
* @pre maxRows != null
|
||||
*
|
||||
*/
|
||||
public TasksPane(int maxRows,
|
||||
CcmObjectSelectionModel typeModel,
|
||||
CcmObjectSelectionModel sectionModel) {
|
||||
super();
|
||||
|
||||
// Set class attribute
|
||||
setClassAttr(TASK_PANEL_CLASS);
|
||||
|
||||
m_maxRows = maxRows;
|
||||
|
||||
m_typeSel = typeModel;
|
||||
m_sectionSel = sectionModel;
|
||||
|
||||
m_sortDirectionParam = new StringParameter(SORT_DIRECTION);
|
||||
m_sortTypeParam = new StringParameter(SORT_TYPE);
|
||||
m_lockFilterParam = new StringParameter(LOCK_FILTER_TYPE);
|
||||
addComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the components to this tasks panel
|
||||
*/
|
||||
private void addComponents() {
|
||||
m_creationPane = new BoxPanel(BoxPanel.VERTICAL);
|
||||
|
||||
// A label that says "Create $content_type in $section"
|
||||
m_selectorLabel = new Label(new PrintListener() {
|
||||
|
||||
@Override
|
||||
public void prepare(PrintEvent e) {
|
||||
PageState s = e.getPageState();
|
||||
Label t = (Label) e.getTarget();
|
||||
|
||||
ContentType type = (ContentType) m_typeSel.getSelectedObject(s);
|
||||
ContentSection sec = (ContentSection) m_sectionSel
|
||||
.getSelectedObject(s);
|
||||
|
||||
StringBuilder buf = new StringBuilder(
|
||||
new GlobalizedMessage("cms.ui.create",
|
||||
CmsConstants.CMS_BUNDLE).localize()
|
||||
+ " ");
|
||||
buf.append(type.getLabel());
|
||||
buf.append(" in ");
|
||||
buf.append(sec.getLabel());
|
||||
|
||||
t.setLabel(buf.toString());
|
||||
t.setFontWeight(Label.BOLD);
|
||||
t.setClassAttr("creationLabel");
|
||||
}
|
||||
|
||||
});
|
||||
m_selectorLabel.setClassAttr("creationLabel");
|
||||
m_creationPane.add(m_selectorLabel);
|
||||
|
||||
//ToDo
|
||||
// m_folderSel = new RootFolderSelectionModel(m_sectionSel);
|
||||
// m_selector = new CreationSelector(m_typeSel, m_folderSel);
|
||||
// m_creationPane.add(m_selector);
|
||||
//ToDo End
|
||||
m_creationPane.setClassAttr("itemCreationPane");
|
||||
add(m_creationPane);
|
||||
|
||||
// The section list UIx
|
||||
//ToDo
|
||||
m_sections = new ContentSectionContainer(m_typeSel, m_sectionSel);
|
||||
add(m_sections);
|
||||
//ToDo End
|
||||
// When a new type is selected, show the creation UI.
|
||||
// When the selection is cleared, return to section list
|
||||
m_typeSel.addChangeListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
PageState s = e.getPageState();
|
||||
boolean isSelected = m_typeSel.isSelected(s);
|
||||
|
||||
//ToDo
|
||||
// m_sections.setVisible(s, !isSelected);
|
||||
//ToDo End
|
||||
m_creationPane.setVisible(s, isSelected);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
m_viewLockLink = new ActionLink(new Label(new GlobalizedMessage(
|
||||
"cms.ui.workflow.task.view_locked", CmsConstants.CMS_BUNDLE)));
|
||||
m_viewLockLink.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
PageState ps = e.getPageState();
|
||||
ps.setValue(m_lockFilterParam, "lock");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
m_viewUnlockLink = new ActionLink(new Label(new GlobalizedMessage(
|
||||
"cms.ui.workflow.task.view_unlocked", CmsConstants.CMS_BUNDLE)));
|
||||
m_viewUnlockLink.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
PageState ps = e.getPageState();
|
||||
ps.setValue(m_lockFilterParam, "unlock");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
m_viewAllLockLink = new ActionLink(new Label(new GlobalizedMessage(
|
||||
"cms.ui.workflow.task.view_all", CmsConstants.CMS_BUNDLE)));
|
||||
m_viewAllLockLink.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
PageState ps = e.getPageState();
|
||||
ps.setValue(m_lockFilterParam, "all");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
m_viewLockLabel = new Label(new GlobalizedMessage(
|
||||
"cms.ui.workflow.task.view_locked", CmsConstants.CMS_BUNDLE));
|
||||
m_viewLockLabel.setFontWeight(Label.BOLD);
|
||||
m_viewUnlockLabel = new Label(new GlobalizedMessage(
|
||||
"cms.ui.workflow.task.view_unlocked", CmsConstants.CMS_BUNDLE));
|
||||
m_viewUnlockLabel.setFontWeight(Label.BOLD);
|
||||
m_viewAllLockLabel = new Label(new GlobalizedMessage(
|
||||
"cms.ui.workflow.task.view_all", CmsConstants.CMS_BUNDLE));
|
||||
m_viewAllLockLabel.setFontWeight(Label.BOLD);
|
||||
|
||||
add(new Label("<br />", false));
|
||||
add(m_viewLockLink);
|
||||
add(m_viewLockLabel);
|
||||
add(new Label(" ", false));
|
||||
add(m_viewUnlockLink);
|
||||
add(m_viewUnlockLabel);
|
||||
add(new Label(" ", false));
|
||||
add(m_viewAllLockLink);
|
||||
add(m_viewAllLockLabel);
|
||||
add(new Label("<br />", false));
|
||||
add(new Label("<br />", false));
|
||||
|
||||
add(getTasksList());
|
||||
add(getPaginator());
|
||||
|
||||
// m_actionLabel = new Label(GlobalizationUtil.globalize("cms.ui.action"));
|
||||
// m_actionLabel.setClassAttr("action");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param p
|
||||
*/
|
||||
@Override
|
||||
public void register(Page p) {
|
||||
super.register(p);
|
||||
|
||||
p.setVisibleDefault(m_creationPane, false);
|
||||
//ToDo
|
||||
// p.addComponentStateParam(this, m_folderSel.getStateParameter());
|
||||
//ToDo End
|
||||
|
||||
p.addGlobalStateParam(m_lockFilterParam);
|
||||
p.addGlobalStateParam(m_sortTypeParam);
|
||||
p.addGlobalStateParam(m_sortDirectionParam);
|
||||
|
||||
p.setVisibleDefault(m_viewLockLabel, false);
|
||||
p.setVisibleDefault(m_viewUnlockLabel, false);
|
||||
p.setVisibleDefault(m_viewAllLockLink, false);
|
||||
|
||||
p.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final PageState state = e.getPageState();
|
||||
|
||||
String lockFilterType = getLockFilterType(state);
|
||||
|
||||
if (lockFilterType.equals("lock")) {
|
||||
m_viewLockLabel.setVisible(state, true);
|
||||
m_viewLockLink.setVisible(state, false);
|
||||
m_viewUnlockLabel.setVisible(state, false);
|
||||
m_viewUnlockLink.setVisible(state, true);
|
||||
m_viewAllLockLabel.setVisible(state, false);
|
||||
m_viewAllLockLink.setVisible(state, true);
|
||||
} else if (lockFilterType.equals("unlock")) {
|
||||
m_viewLockLabel.setVisible(state, false);
|
||||
m_viewLockLink.setVisible(state, true);
|
||||
m_viewUnlockLabel.setVisible(state, true);
|
||||
m_viewUnlockLink.setVisible(state, false);
|
||||
m_viewAllLockLabel.setVisible(state, false);
|
||||
m_viewAllLockLink.setVisible(state, true);
|
||||
} else {
|
||||
m_viewLockLabel.setVisible(state, false);
|
||||
m_viewLockLink.setVisible(state, true);
|
||||
m_viewUnlockLabel.setVisible(state, false);
|
||||
m_viewUnlockLink.setVisible(state, true);
|
||||
m_viewAllLockLabel.setVisible(state, true);
|
||||
m_viewAllLockLink.setVisible(state, false);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void reset(PageState state) {
|
||||
m_typeSel.clearSelection(state);
|
||||
m_sectionSel.clearSelection(state);
|
||||
}
|
||||
|
||||
protected Paginator getPaginator() {
|
||||
if (m_paginator == null) {
|
||||
m_paginator = new Paginator(new TasksPaginationModelBuilder(),
|
||||
m_maxRows);
|
||||
}
|
||||
return m_paginator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bebop List component to display the tasks
|
||||
*
|
||||
*/
|
||||
private TaskList getTasksList() {
|
||||
if (m_taskList == null) {
|
||||
m_taskList = new TaskList(true);
|
||||
}
|
||||
return m_taskList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of enabled tasks for the specified user.
|
||||
*
|
||||
* @param state
|
||||
*
|
||||
* @return
|
||||
*
|
||||
*/
|
||||
protected int numberTasksForUser(PageState state) {
|
||||
return m_taskList.size(state);
|
||||
}
|
||||
|
||||
protected String getSortType(PageState state) {
|
||||
String sortType = (String) state.getValue(m_sortTypeParam);
|
||||
if (sortType == null) {
|
||||
sortType = SORT_DATE;
|
||||
}
|
||||
return sortType;
|
||||
}
|
||||
|
||||
protected String getSortDirection(PageState state) {
|
||||
String sortDirection = (String) state.getValue(m_sortDirectionParam);
|
||||
if (sortDirection == null) {
|
||||
sortDirection = SORT_UP;
|
||||
}
|
||||
return sortDirection;
|
||||
}
|
||||
|
||||
protected String getLockFilterType(PageState state) {
|
||||
String lockFilterType = (String) state.getValue(m_lockFilterParam);
|
||||
if (lockFilterType == null || lockFilterType.equals("")) {
|
||||
lockFilterType = "lock";
|
||||
}
|
||||
return lockFilterType;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds filters to the task query
|
||||
*/
|
||||
//ToDo
|
||||
// protected void addQueryFilters(DataQuery query, Party party, PageState state) {
|
||||
// query.setParameter("userId", party.getID());
|
||||
//
|
||||
// FilterFactory ff = query.getFilterFactory();
|
||||
//
|
||||
// // TODO: remove this hard coding of "Author", "Edit", and "Deploy"
|
||||
// // TODO: remove this hard coding of "Author", "Edit", and "Deploy"
|
||||
// CompoundFilter authorFilter = ff.and();
|
||||
// //cg query changed to refer to task type id
|
||||
// authorFilter.addFilter(ff.equals("taskType", CMSTaskType.AUTHOR));
|
||||
// authorFilter.addFilter(getTaskFilter(CMSTaskType.retrieve(
|
||||
// CMSTaskType.AUTHOR),
|
||||
// party, ff));
|
||||
//
|
||||
// CompoundFilter approveFilter = ff.and();
|
||||
// approveFilter.addFilter(ff.equals("taskType", CMSTaskType.EDIT));
|
||||
// approveFilter.addFilter(getTaskFilter(CMSTaskType.retrieve(
|
||||
// CMSTaskType.EDIT),
|
||||
// party, ff));
|
||||
//
|
||||
// CompoundFilter deployFilter = ff.and();
|
||||
// deployFilter.addFilter(ff.equals("taskType", CMSTaskType.DEPLOY));
|
||||
// deployFilter.addFilter(getTaskFilter(CMSTaskType.retrieve(
|
||||
// CMSTaskType.DEPLOY),
|
||||
// party, ff));
|
||||
//
|
||||
// CompoundFilter permissionFilter = ff.or();
|
||||
// permissionFilter.addFilter(authorFilter);
|
||||
// permissionFilter.addFilter(approveFilter);
|
||||
// permissionFilter.addFilter(deployFilter);
|
||||
//
|
||||
// query.addFilter(permissionFilter);
|
||||
//
|
||||
// String lockFilterType = getLockFilterType(state);
|
||||
// if (lockFilterType.equals("lock")) {
|
||||
// query.addEqualsFilter("isLocked", "t");
|
||||
// query.addEqualsFilter("status", "1");
|
||||
// } else if (lockFilterType.equals("unlock")) {
|
||||
// query.addEqualsFilter("isLocked", "f");
|
||||
// } // else show all
|
||||
// }
|
||||
// private static class RootFolderSelectionModel
|
||||
// extends FolderSelectionModel {
|
||||
//
|
||||
// CcmObjectSelectionModel m_sectionSel;
|
||||
//
|
||||
// public RootFolderSelectionModel(CcmObjectSelectionModel sectionSel) {
|
||||
// super("f");
|
||||
// m_sectionSel = sectionSel;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected BigDecimal getRootFolderID(PageState s) {
|
||||
// ContentSection sec = (ContentSection) m_sectionSel
|
||||
// .getSelectedObject(s);
|
||||
// Assert.exists(sec);
|
||||
//
|
||||
// User user = Web.getWebContext().getUser();
|
||||
// if (user != null) {
|
||||
// Folder folder = Folder.getUserHomeFolder(user, sec);
|
||||
// if (folder != null) {
|
||||
// return folder.getID();
|
||||
// }
|
||||
// }
|
||||
// return sec.getRootFolder().getID();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//ToDo End
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private class TasksPaginationModelBuilder implements PaginationModelBuilder {
|
||||
|
||||
@Override
|
||||
public int getTotalSize(Paginator paginator,
|
||||
PageState state) {
|
||||
return numberTasksForUser(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible(PageState state) {
|
||||
return numberTasksForUser(state) > m_maxRows;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class TaskList extends SimpleComponent {
|
||||
|
||||
private final static String QUERY_NAME
|
||||
= "com.arsdigita.cms.workflow.getEnabledUserTasks";
|
||||
private boolean m_paginate = false;
|
||||
|
||||
public TaskList(boolean paginate) {
|
||||
m_paginate = paginate;
|
||||
}
|
||||
|
||||
// private DataQuery makeQuery(PageState state) {
|
||||
// User user = (User) Kernel.getContext().getParty();
|
||||
//
|
||||
// DataQuery query = SessionManager.getSession()
|
||||
// .retrieveQuery(QUERY_NAME);
|
||||
// addQueryFilters(query, user, state);
|
||||
//
|
||||
// return query;
|
||||
// }
|
||||
public int size(PageState ps) {
|
||||
return ((Integer)m_taskCount.get(ps)).intValue();
|
||||
}
|
||||
|
||||
private RequestLocal m_taskCount = new RequestLocal() {
|
||||
|
||||
@Override
|
||||
public Object initialValue(PageState state) {
|
||||
// DataQuery query = makeQuery(state);
|
||||
// return new Long(query.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public void generateXML(PageState state,
|
||||
Element parent) {
|
||||
Element content = parent.newChildElement("cms:tasksPanel",
|
||||
CMS.CMS_XML_NS);
|
||||
exportAttributes(content);
|
||||
|
||||
// DataQuery query = makeQuery(state);
|
||||
String lockFilterType = getLockFilterType(state);
|
||||
content.addAttribute("lockFilterType", lockFilterType);
|
||||
|
||||
if (m_paginate) {
|
||||
// query.setRange(new Integer(m_paginator.getFirst(state)),
|
||||
// new Integer(m_paginator.getLast(state) + 1));
|
||||
}
|
||||
|
||||
String sortKey = getSortType(state);
|
||||
String sortDirection = getSortDirection(state);
|
||||
String sortPostfix = " asc";
|
||||
if (sortDirection.equals(SORT_DOWN)) {
|
||||
sortPostfix = " desc";
|
||||
}
|
||||
|
||||
// if (sortKey.equals(SORT_TITLE)) {
|
||||
// query.setOrder("lower(pageTitle) " + sortPostfix
|
||||
// + ", lower(status) asc, dueDate desc");
|
||||
// } else if (sortKey.equals(SORT_DATE)) {
|
||||
// query.setOrder("dueDate " + sortPostfix
|
||||
// + ", lower(status) asc, lower(pageTitle) asc");
|
||||
// } else if (sortKey.equals(SORT_USER)) {
|
||||
// query.setOrder("lockingUserID " + sortPostfix
|
||||
// + ", lower(status) asc, dueDate desc "
|
||||
// + ", lower(pageTitle) asc");
|
||||
// } else if (sortKey.equals(SORT_STATUS)) {
|
||||
// query.setOrder("lower(status) " + sortPostfix
|
||||
// + ", dueDate desc "
|
||||
// + ", lower(pageTitle) asc");
|
||||
//
|
||||
// } else if (sortKey.equals(SORT_ACTION)) {
|
||||
// query.setOrder("taskType " + sortPostfix
|
||||
// + ", lower(status) asc, dueDate desc "
|
||||
// + ", lower(pageTitle) asc");
|
||||
// } else if (sortKey.equals(SORT_WORKFLOW)) {
|
||||
// query.setOrder("processLabel " + sortPostfix
|
||||
// + ", lower(status) asc, dueDate desc "
|
||||
// + ", lower(pageTitle) asc");
|
||||
// }
|
||||
//
|
||||
// HashMap sections = new HashMap();
|
||||
//
|
||||
// while (query.next()) {
|
||||
// BigDecimal sectionID = (BigDecimal) query.get("sectionID");
|
||||
// String sectionPath = (String) sections.get(sectionID);
|
||||
// if (sectionPath == null) {
|
||||
// try {
|
||||
// ContentSection section
|
||||
// = (ContentSection) DomainObjectFactory
|
||||
// .newInstance(new OID(
|
||||
// ContentSection.BASE_DATA_OBJECT_TYPE,
|
||||
// sectionID));
|
||||
// sectionPath = section.getPath();
|
||||
// } catch (DataObjectNotFoundException ex) {
|
||||
// throw new UncheckedWrapperException(
|
||||
// "cannot find content section", ex);
|
||||
// }
|
||||
// sections.put(sectionID, sectionPath);
|
||||
// }
|
||||
//
|
||||
// Element task = content.newChildElement("cms:tasksPanelTask",
|
||||
// CMS.CMS_XML_NS);
|
||||
//
|
||||
// BigDecimal itemID = (BigDecimal) query.get("itemID");
|
||||
// String taskType = (String) query.get("taskType");
|
||||
//
|
||||
// task.addAttribute("taskID", query.get("taskID").toString());
|
||||
// task
|
||||
// .addAttribute("processID", query.get("processID").toString());
|
||||
// task.addAttribute("taskLabel", (String) query.get("taskLabel"));
|
||||
// task.addAttribute("taskDescription", (String) query.get(
|
||||
// "taskDescription"));
|
||||
// task.addAttribute("processLabel", (String) query.get(
|
||||
// "processLabel"));
|
||||
//
|
||||
// String isLocked = (String) query.get("isLocked");
|
||||
// task.addAttribute("isLocked", isLocked);
|
||||
// if (query.get("dueDate") != null) {
|
||||
// java.util.Date d = (java.util.Date) query.get("dueDate");
|
||||
// SimpleDateFormat df = new SimpleDateFormat(
|
||||
// "EEE, MMM d, yyyy");
|
||||
//
|
||||
// task.addAttribute("dueDate", df.format(d));
|
||||
// }
|
||||
//
|
||||
// task.addAttribute("itemID", itemID.toString());
|
||||
// task
|
||||
// .addAttribute("sectionID", query.get("sectionID").toString());
|
||||
// task.addAttribute("sectionPath", sectionPath);
|
||||
// task.addAttribute("pageName", (String) query.get("pageName"));
|
||||
// task.addAttribute("pageTitle", (String) query.get("pageTitle"));
|
||||
//
|
||||
// BigDecimal lockingUserID = (BigDecimal) query.get(
|
||||
// "lockingUserID");
|
||||
// if (lockingUserID != null) {
|
||||
// task.addAttribute("lockingUserID", lockingUserID.toString());
|
||||
// if (!"f".equals(isLocked)) {
|
||||
// User lockingUser = User.retrieve(lockingUserID);
|
||||
// if (lockingUser != null) {
|
||||
// task.addAttribute("assignee", lockingUser
|
||||
// .getDisplayName());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// task.addAttribute("taskType", taskType);
|
||||
// task.addAttribute("taskTypeClass", (String) query.get(
|
||||
// "taskTypeClass"));
|
||||
// task.addAttribute("status", query.get("status").toString());
|
||||
//
|
||||
// // control event for locking a task
|
||||
// try {
|
||||
// state.setControlEvent(this, TASK_ACTION, itemID.toString());
|
||||
// task.addAttribute("actionURL", state.stateAsURL());
|
||||
// state.clearControlEvent();
|
||||
// } catch (java.io.IOException ex) {
|
||||
// s_log.warn("Error: " + ex.getMessage());
|
||||
// }
|
||||
//
|
||||
// if ("Deploy".equals(taskType)) {
|
||||
// task.addAttribute("editTabNumber",
|
||||
// String.valueOf(
|
||||
// ContentItemPage.PUBLISHING_TAB));
|
||||
// } else {
|
||||
// task.addAttribute("editTabNumber",
|
||||
// String.valueOf(
|
||||
// ContentItemPage.AUTHORING_TAB));
|
||||
// }
|
||||
}
|
||||
|
||||
// m_actionLabel.generateXML(state, content);
|
||||
String[][] sortableHeaders = {{SORT_TITLE,
|
||||
"cms.ui.workflow.task.item_title"},
|
||||
{SORT_ACTION, "cms.ui.action"},
|
||||
{SORT_DATE, "cms.ui.tasks_due_date"},
|
||||
{SORT_STATUS,
|
||||
"cms.ui.tasks_status_no_colon"},
|
||||
{SORT_USER,
|
||||
"cms.ui.workflow.task.locking_user"},
|
||||
{SORT_WORKFLOW, "cms.ui.workflow"}};
|
||||
// for (int i = 0; i < sortableHeaders.length; i++) {
|
||||
// String header = sortableHeaders[i][0];
|
||||
// String labelKey = sortableHeaders[i][1];
|
||||
// if (sortDirection.equals(SORT_UP) && header.equals(sortKey)) {
|
||||
// state.setControlEvent(this, SORT_DOWN, header);
|
||||
// } else {
|
||||
// state.setControlEvent(this, SORT_UP, header);
|
||||
// }
|
||||
// SimpleContainer container = new SimpleContainer();
|
||||
// container.add(new Label(GlobalizationUtil.globalize(labelKey)));
|
||||
// if (header.equals(sortKey)) {
|
||||
// String imageURLStub = null;
|
||||
// if (SORT_UP.equals(sortDirection)) {
|
||||
// imageURLStub = UP_ARROW_IMAGE;
|
||||
// } else {
|
||||
// imageURLStub = DOWN_ARROW_IMAGE;
|
||||
// }
|
||||
// Image image = new Image(imageURLStub);
|
||||
// image.setBorder("0");
|
||||
// container.add(image);
|
||||
// }
|
||||
//
|
||||
// ControlLink link = new ControlLink(container);
|
||||
// link.setHint(GlobalizationUtil
|
||||
// .globalize("cms.ui.contentcenter.task_panel_control"));
|
||||
// link.setClassAttr(header);
|
||||
// link.generateXML(state, content);
|
||||
// state.clearControlEvent();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void respond(PageState state) throws ServletException {
|
||||
String key = state.getControlEventName();
|
||||
String value = state.getControlEventValue();
|
||||
if (TASK_ACTION.equals(key)) {
|
||||
BigDecimal itemID = new BigDecimal(value);
|
||||
//
|
||||
// try {
|
||||
// ContentItem item = new ContentItem(itemID);
|
||||
// Workflow wf = Workflow.getObjectWorkflow(item);
|
||||
// int tabNumber = ContentItemPage.AUTHORING_TAB;
|
||||
// String sectionPath = item.getContentSection().getPath();
|
||||
//
|
||||
// if (wf != null) {
|
||||
// User user = Web.getWebContext().getUser();
|
||||
// Engine engine = Engine.getInstance(
|
||||
// CMSEngine.CMS_ENGINE_TYPE);
|
||||
// Iterator i = engine.getEnabledTasks(user, wf.getID())
|
||||
// .iterator();
|
||||
// if (i.hasNext()) {
|
||||
// CMSTask task = (CMSTask) i.next();
|
||||
// Integer taskType = task.getTaskType().getID();
|
||||
//
|
||||
// if (taskType.equals(CMSTaskType.DEPLOY)) {
|
||||
// tabNumber = ContentItemPage.PUBLISHING_TAB;
|
||||
// } else // see if item is locked; if not, lock
|
||||
// {
|
||||
// if (!task.isLocked()) {
|
||||
// task.lock(user);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// String redirectURL = Web.getConfig()
|
||||
// .getDispatcherServletPath()
|
||||
// + sectionPath
|
||||
// + "/admin/item.jsp?item_id="
|
||||
// + itemID + "&set_tab=" + tabNumber;
|
||||
// throw new RedirectSignal(redirectURL, true);
|
||||
// } catch (DataObjectNotFoundException ex) {
|
||||
// throw new ServletException("Unknown content ID" + itemID);
|
||||
// }
|
||||
// } else
|
||||
if (SORT_UP.equals(key) || SORT_DOWN.equals(key)) {
|
||||
state.setValue(m_sortTypeParam, value);
|
||||
if (SORT_DOWN.equals(key)) {
|
||||
state.setValue(m_sortDirectionParam, SORT_DOWN);
|
||||
} else {
|
||||
state.setValue(m_sortDirectionParam, SORT_UP);
|
||||
}
|
||||
} else {
|
||||
throw new ServletException("Unknown control event: " + key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// private static Filter getTaskFilter(CMSTaskType taskType, Party party,
|
||||
// FilterFactory factory) {
|
||||
// PrivilegeDescriptor privilege;
|
||||
// String queryName;
|
||||
// String queryType;
|
||||
// OID partyOID = party.getOID();
|
||||
// privilege = taskType.getPrivilege();
|
||||
//
|
||||
// return PermissionService.getFilterQuery(factory, "itemID", privilege,
|
||||
// partyOID);
|
||||
// }
|
||||
}
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
package com.arsdigita.cms.ui.workflow;
|
||||
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.cms.CMS;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.workflow.Workflow;
|
||||
|
||||
/**
|
||||
* @author Uday Mathur
|
||||
* @author Michael Pih
|
||||
* @author <a href="mailto:jross@redhat.com">Justin Ross</a>
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
class WorkflowAddForm extends BaseWorkflowForm {
|
||||
|
||||
private final SingleSelectionModel<Long> m_model;
|
||||
|
||||
WorkflowAddForm(final SingleSelectionModel<Long> model) {
|
||||
super("workflow", gz("cms.ui.workflow.add"));
|
||||
|
||||
m_model = model;
|
||||
|
||||
addProcessListener(new ProcessListener());
|
||||
}
|
||||
|
||||
private class ProcessListener implements FormProcessListener {
|
||||
|
||||
@Override
|
||||
public final void process(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final String label = (String) m_title.getValue(state);
|
||||
final String description = (String) m_description.getValue(state);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final WorkflowAdminPaneController controller = cdiUtil.findBean(
|
||||
WorkflowAdminPaneController.class);
|
||||
|
||||
final Workflow workflow = controller.createWorkflow(
|
||||
CMS.getContext().getContentSection(),
|
||||
label,
|
||||
description);
|
||||
|
||||
m_model.setSelectedKey(state, workflow.getWorkflowId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
package com.arsdigita.cms.ui.workflow;
|
||||
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.cms.ui.BaseAdminPane;
|
||||
import com.arsdigita.cms.ui.BaseDeleteForm;
|
||||
import com.arsdigita.cms.ui.VisibilityComponent;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.workflow.Workflow;
|
||||
import org.libreccm.workflow.WorkflowRepository;
|
||||
|
||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jross@redhat.com">Justin Ross</a>
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public final class WorkflowAdminPane extends BaseAdminPane {
|
||||
|
||||
private final WorkflowRequestLocal m_workflow;
|
||||
|
||||
public WorkflowAdminPane() {
|
||||
super(gz("cms.ui.workflows"), new WorkflowListModelBuilder());
|
||||
|
||||
m_workflow = new SelectionRequestLocal();
|
||||
|
||||
setAdd(gz("cms.ui.workflow.add"),
|
||||
new WorkflowAddForm(getSelectionModel()));
|
||||
setEdit(gz("cms.ui.workflow.edit"), new WorkflowEditForm(m_workflow));
|
||||
setDelete(gz("cms.ui.workflow.delete"), new DeleteForm());
|
||||
|
||||
setIntroPane(new Label(gz("cms.ui.workflow.intro")));
|
||||
setItemPane(new WorkflowItemPane(m_workflow,
|
||||
getEditLink(),
|
||||
getDeleteLink()));
|
||||
|
||||
addAction(new VisibilityComponent(
|
||||
getAddLink(), AdminPrivileges.ADMINISTER_WORKFLOWS));
|
||||
}
|
||||
|
||||
private class DeleteForm extends BaseDeleteForm {
|
||||
|
||||
DeleteForm() {
|
||||
super(gz("cms.ui.workflow.delete_prompt"));
|
||||
|
||||
addSecurityListener(AdminPrivileges.ADMINISTER_WORKFLOWS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void process(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final CdiUtil cdiUtil= CdiUtil.createCdiUtil();
|
||||
final WorkflowRepository workflowRepo= cdiUtil.findBean(WorkflowRepository.class);
|
||||
|
||||
final Workflow workflow = m_workflow.getWorkflow(state);
|
||||
workflowRepo.delete(workflow);
|
||||
|
||||
getSelectionModel().clearSelection(state);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class SelectionRequestLocal extends WorkflowRequestLocal {
|
||||
|
||||
@Override
|
||||
protected final Object initialValue(final PageState state) {
|
||||
final String id = getSelectionModel().getSelectedKey(state)
|
||||
.toString();
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final WorkflowRepository templateRepo = cdiUtil.findBean(
|
||||
WorkflowRepository.class);
|
||||
|
||||
return templateRepo.findById(Long.parseLong(id));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
package com.arsdigita.cms.ui.workflow;
|
||||
|
||||
import com.arsdigita.bebop.ActionLink;
|
||||
|
||||
class WorkflowItemPane extends BaseWorkflowItemPane {
|
||||
|
||||
public WorkflowItemPane(final WorkflowRequestLocal workflow,
|
||||
final ActionLink editLink,
|
||||
final ActionLink deleteLink) {
|
||||
super(workflow, editLink, deleteLink);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,125 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
package com.arsdigita.cms.ui.workflow;
|
||||
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.toolbox.ui.ComponentAccess;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||
|
||||
/**
|
||||
* A <code>ComponentAccess</code> implementation that respects workflow
|
||||
*
|
||||
* @author Stanislav Freidin
|
||||
* @author Uday Mathur
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class WorkflowLockedComponentAccess extends ComponentAccess {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
WorkflowLockedComponentAccess.class);
|
||||
private final ItemSelectionModel itemModel;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param component The component
|
||||
* @param itemModel
|
||||
*/
|
||||
public WorkflowLockedComponentAccess(final Component component,
|
||||
final ItemSelectionModel itemModel) {
|
||||
super(component);
|
||||
this.itemModel = itemModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param component The component
|
||||
* @param check An access check
|
||||
* @param itemModel
|
||||
*/
|
||||
public WorkflowLockedComponentAccess(final Component component,
|
||||
final String check,
|
||||
final ItemSelectionModel itemModel) {
|
||||
super(component, check);
|
||||
this.itemModel = itemModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this item is locked from the workflow module. In addition check
|
||||
* if all the access checks registered to the component pass.
|
||||
*
|
||||
* @param state The page state
|
||||
*
|
||||
* @return true if all the access checks pass, false otherwise
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public boolean canAccess(final PageState state) {
|
||||
final ContentItem item = itemModel.getSelectedObject(state);
|
||||
|
||||
if (isVisible(state) == true) {
|
||||
if (super.canAccess(state)) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
||||
PermissionChecker.class);
|
||||
|
||||
final boolean result = permissionChecker.isPermitted(
|
||||
ItemPrivileges.EDIT, item);
|
||||
LOGGER.debug(
|
||||
"Superclass security check passed. Result of check "
|
||||
+ "for permission {}.{} is {}.",
|
||||
ItemPrivileges.class.getName(),
|
||||
ItemPrivileges.EDIT,
|
||||
result);
|
||||
|
||||
return result;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to change visiblity of action link created by
|
||||
* SecurityPropertyEditor add-method. If this method returns false, the link
|
||||
* will be hidden, p.ex. to hide a delete link if the component is already
|
||||
* empty.
|
||||
*
|
||||
* @param state The page state
|
||||
*
|
||||
* @return true for default behavior
|
||||
*/
|
||||
public boolean isVisible(final PageState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue