CCM NG/ccm-cms: ItemSearch UI now uses CCM NG APIs
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4503 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
16b312ed41
commit
0b90e5b716
|
|
@ -22,8 +22,10 @@ import com.arsdigita.bebop.Form;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.Resettable;
|
import com.arsdigita.bebop.Resettable;
|
||||||
import com.arsdigita.bebop.SimpleContainer;
|
import com.arsdigita.bebop.SimpleContainer;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import com.arsdigita.search.ui.QueryGenerator;
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
import org.apache.lucene.search.Query;
|
||||||
|
import org.librecms.contentsection.ContentItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper around the {@link ItemSearchSection} which embeds the form section
|
* A wrapper around the {@link ItemSearchSection} which embeds the form section
|
||||||
|
|
@ -32,9 +34,8 @@ import org.apache.logging.log4j.Logger;
|
||||||
* @author Stanislav Freidin (sfreidin@arsdigita.com)
|
* @author Stanislav Freidin (sfreidin@arsdigita.com)
|
||||||
* @author <a href="jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
public class ItemSearch extends Form implements Resettable {
|
public class ItemSearch extends Form implements Resettable, QueryGenerator {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(ItemSearch.class);
|
|
||||||
public static final String SINGLE_TYPE_PARAM = ItemSearchSection.SINGLE_TYPE_PARAM;
|
public static final String SINGLE_TYPE_PARAM = ItemSearchSection.SINGLE_TYPE_PARAM;
|
||||||
|
|
||||||
private ItemSearchSection itemSearchSection;
|
private ItemSearchSection itemSearchSection;
|
||||||
|
|
@ -58,30 +59,31 @@ public class ItemSearch extends Form implements Resettable {
|
||||||
* @param limitToContentSection limit the search to the current content
|
* @param limitToContentSection limit the search to the current content
|
||||||
* section
|
* section
|
||||||
*/
|
*/
|
||||||
public ItemSearch(String context, boolean limitToContentSection) {
|
public ItemSearch(final String context,
|
||||||
|
final boolean limitToContentSection) {
|
||||||
super("itemSearch", new SimpleContainer());
|
super("itemSearch", new SimpleContainer());
|
||||||
//setMethod("GET");
|
//setMethod("GET");
|
||||||
itemSearchSection = createSearchSection(context, limitToContentSection);
|
itemSearchSection = createSearchSection(context, limitToContentSection);
|
||||||
add(itemSearchSection);
|
add(itemSearchSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ItemSearchSection createSearchSection(String context,
|
protected ItemSearchSection createSearchSection(final String context,
|
||||||
boolean limitToContentSection) {
|
boolean limitToContentSection) {
|
||||||
return new ItemSearchSection(context, limitToContentSection);
|
return new ItemSearchSection(context, limitToContentSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasQuery(PageState state) {
|
public boolean hasQuery(final PageState state) {
|
||||||
return itemSearchSection.hasQuery(state);
|
return itemSearchSection.hasQuery(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QuerySpecification getQuerySpecification(PageState state) {
|
public Query getQuerySpecification(final PageState state) {
|
||||||
return itemSearchSection.getQuerySpecification(state);
|
return itemSearchSection.getQuerySpecification(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset(PageState state) {
|
public void reset(final PageState state) {
|
||||||
itemSearchSection.reset(state);
|
itemSearchSection.reset(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -23,7 +23,6 @@ import com.arsdigita.bebop.Form;
|
||||||
import com.arsdigita.bebop.Label;
|
import com.arsdigita.bebop.Label;
|
||||||
import com.arsdigita.bebop.Page;
|
import com.arsdigita.bebop.Page;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Resettable;
|
import com.arsdigita.bebop.Resettable;
|
||||||
import com.arsdigita.bebop.SimpleContainer;
|
import com.arsdigita.bebop.SimpleContainer;
|
||||||
import com.arsdigita.bebop.SingleSelectionModel;
|
import com.arsdigita.bebop.SingleSelectionModel;
|
||||||
|
|
@ -41,27 +40,29 @@ import com.arsdigita.bebop.event.TreeExpansionListener;
|
||||||
import com.arsdigita.bebop.form.Option;
|
import com.arsdigita.bebop.form.Option;
|
||||||
import com.arsdigita.bebop.form.SingleSelect;
|
import com.arsdigita.bebop.form.SingleSelect;
|
||||||
import com.arsdigita.bebop.form.Submit;
|
import com.arsdigita.bebop.form.Submit;
|
||||||
import com.arsdigita.bebop.parameters.BigDecimalParameter;
|
import com.arsdigita.bebop.parameters.LongParameter;
|
||||||
import com.arsdigita.cms.dispatcher.Utilities;
|
|
||||||
|
|
||||||
import com.arsdigita.cms.CMS;
|
import com.arsdigita.cms.CMS;
|
||||||
|
|
||||||
import org.librecms.contentsection.ContentSection;
|
import org.librecms.contentsection.ContentSection;
|
||||||
import org.librecms.contentsection.Folder;
|
import org.librecms.contentsection.Folder;
|
||||||
import com.arsdigita.cms.ui.authoring.NewItemForm;
|
|
||||||
import com.arsdigita.cms.ui.folder.FolderRequestLocal;
|
import com.arsdigita.cms.ui.folder.FolderRequestLocal;
|
||||||
import com.arsdigita.cms.ui.folder.FolderSelectionModel;
|
import com.arsdigita.cms.ui.folder.FolderSelectionModel;
|
||||||
import com.arsdigita.cms.ui.folder.FolderTreeModelBuilder;
|
import com.arsdigita.cms.ui.folder.FolderTreeModelBuilder;
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
import com.arsdigita.toolbox.ui.LayoutPanel;
|
||||||
import com.arsdigita.util.Assert;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.arsdigita.cms.CMSConfig;
|
import org.arsdigita.cms.CMSConfig;
|
||||||
|
import org.libreccm.categorization.Category;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.librecms.CmsConstants;
|
import org.librecms.CmsConstants;
|
||||||
import org.librecms.contentsection.ContentSectionConfig;
|
import org.librecms.contentsection.ContentSectionRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A pane that contains a folder tree on the left and a folder manipulator on
|
* A pane that contains a folder tree on the left and a folder manipulator on
|
||||||
|
|
@ -78,7 +79,7 @@ public class ItemSearchBrowsePane extends SimpleContainer implements Resettable,
|
||||||
|
|
||||||
private static final String CONTENT_TYPE_ID = "ct";
|
private static final String CONTENT_TYPE_ID = "ct";
|
||||||
private static final Logger LOGGER = LogManager.getLogger(
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
ItemSearchBrowsePane.class);
|
ItemSearchBrowsePane.class);
|
||||||
private final FolderSelectionModel folderSelectionModel;
|
private final FolderSelectionModel folderSelectionModel;
|
||||||
private final FolderRequestLocal folderRequestLocal;
|
private final FolderRequestLocal folderRequestLocal;
|
||||||
private final Tree tree;
|
private final Tree tree;
|
||||||
|
|
@ -94,12 +95,12 @@ public class ItemSearchBrowsePane extends SimpleContainer implements Resettable,
|
||||||
setAttribute("navbar-title",
|
setAttribute("navbar-title",
|
||||||
new GlobalizedMessage("cms.ui.folder_browser",
|
new GlobalizedMessage("cms.ui.folder_browser",
|
||||||
CmsConstants.CMS_BUNDLE)
|
CmsConstants.CMS_BUNDLE)
|
||||||
.localize().toString());
|
.localize().toString());
|
||||||
|
|
||||||
final BoxPanel left = new BoxPanel(BoxPanel.VERTICAL);
|
final BoxPanel left = new BoxPanel(BoxPanel.VERTICAL);
|
||||||
|
|
||||||
final Label label = new Label(new GlobalizedMessage(
|
final Label label = new Label(new GlobalizedMessage(
|
||||||
"cms.ui.folder_browser", CmsConstants.CMS_BUNDLE));
|
"cms.ui.folder_browser", CmsConstants.CMS_BUNDLE));
|
||||||
label.setClassAttr("heading");
|
label.setClassAttr("heading");
|
||||||
left.add(label);
|
left.add(label);
|
||||||
|
|
||||||
|
|
@ -107,17 +108,19 @@ public class ItemSearchBrowsePane extends SimpleContainer implements Resettable,
|
||||||
// subsites through the ItemSearchBrowsePane. A new parameter has been added to allow the
|
// subsites through the ItemSearchBrowsePane. A new parameter has been added to allow the
|
||||||
// administrator to pick between the old and new versions.
|
// administrator to pick between the old and new versions.
|
||||||
boolean linksOnlyInSameSubsite = CMSConfig.getConfig()
|
boolean linksOnlyInSameSubsite = CMSConfig.getConfig()
|
||||||
.isLinksOnlyInSameSubsite();
|
.isLinksOnlyInSameSubsite();
|
||||||
LOGGER.debug("linksOnlyInSameSubsite value is {}",
|
LOGGER.debug("linksOnlyInSameSubsite value is {}",
|
||||||
linksOnlyInSameSubsite);
|
linksOnlyInSameSubsite);
|
||||||
|
|
||||||
tree = new Tree(new FolderTreeModelBuilder() {
|
tree = new Tree(new FolderTreeModelBuilder() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Folder getRoot(PageState ps) {
|
protected Category getRootFolder(final PageState state) {
|
||||||
Folder root = getRootFolder(ps);
|
final Category root = ItemSearchBrowsePane.this.getRootFolder(
|
||||||
|
state);
|
||||||
|
|
||||||
if (null == root) {
|
if (null == root) {
|
||||||
return super.getRoot(ps);
|
return super.getRootFolder(state);
|
||||||
}
|
}
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
@ -139,7 +142,6 @@ public class ItemSearchBrowsePane extends SimpleContainer implements Resettable,
|
||||||
tree.addTreeExpansionListener(this);
|
tree.addTreeExpansionListener(this);
|
||||||
left.add(tree);
|
left.add(tree);
|
||||||
|
|
||||||
// CMSContainer container = new CMSContainer();
|
|
||||||
left.setClassAttr("main");
|
left.setClassAttr("main");
|
||||||
|
|
||||||
final BoxPanel body = new BoxPanel(BoxPanel.VERTICAL);
|
final BoxPanel body = new BoxPanel(BoxPanel.VERTICAL);
|
||||||
|
|
@ -147,49 +149,48 @@ public class ItemSearchBrowsePane extends SimpleContainer implements Resettable,
|
||||||
body.add(folderBrowser);
|
body.add(folderBrowser);
|
||||||
body.add(folderBrowser.getPaginator());
|
body.add(folderBrowser.getPaginator());
|
||||||
|
|
||||||
// m_newItem = new SectionNewItemForm("newItem");
|
|
||||||
// m_typeSel = new ParameterSingleSelectionModel(new BigDecimalParameter(CONTENT_TYPE_ID));
|
|
||||||
// m_newItem.addProcessListener(this);
|
|
||||||
//
|
|
||||||
// container.add(m_newItem);
|
|
||||||
//add(container);
|
|
||||||
mainPanel.setLeft(left);
|
mainPanel.setLeft(left);
|
||||||
mainPanel.setBody(body);
|
mainPanel.setBody(body);
|
||||||
add(mainPanel);
|
add(mainPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisible(PageState s) {
|
public boolean isVisible(final PageState state) {
|
||||||
// Always expand root node
|
// Always expand root node
|
||||||
if (tree.isCollapsed(getRootFolder(s).getID().toString(), s)) {
|
if (tree.isCollapsed(Long.toString(getRootFolder(state).getObjectId()),
|
||||||
tree.expand(getRootFolder(s).getID().toString(), s);
|
state)) {
|
||||||
|
tree.expand(Long.toString(getRootFolder(state).getObjectId()),
|
||||||
|
state);
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.isVisible(s);
|
return super.isVisible(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Form getSectionForm() {
|
private Form getSectionForm() {
|
||||||
Form sectionForm = new Form("isfbSectionForm",
|
final Form sectionForm = new Form("isfbSectionForm",
|
||||||
new BoxPanel(BoxPanel.HORIZONTAL));
|
new BoxPanel(BoxPanel.HORIZONTAL));
|
||||||
sectionForm.setClassAttr("navbar");
|
sectionForm.setClassAttr("navbar");
|
||||||
|
|
||||||
sectionSelect = new SingleSelect(new OIDParameter("isfbSection"));
|
sectionSelect = new SingleSelect(new LongParameter("isfbSection"));
|
||||||
ContentSectionCollection sections = ContentSection.getAllSections();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
while (sections.next()) {
|
final ContentSectionRepository sectionRepo = cdiUtil.findBean(
|
||||||
ContentSection section = sections.getContentSection();
|
ContentSectionRepository.class);
|
||||||
sectionSelect.addOption(new Option(section.getOID().toString(),
|
final List<ContentSection> sections = sectionRepo.findAll();
|
||||||
section.getDisplayName()));
|
|
||||||
}
|
sections.forEach(section -> sectionSelect.addOption(
|
||||||
|
new Option(Long.toString(section.getObjectId()),
|
||||||
|
section.getDisplayName())));
|
||||||
|
|
||||||
sectionForm.addInitListener(new FormInitListener() {
|
sectionForm.addInitListener(new FormInitListener() {
|
||||||
@Override
|
|
||||||
public void init(FormSectionEvent ev) {
|
|
||||||
PageState ps = ev.getPageState();
|
|
||||||
|
|
||||||
if (null == sectionSelect.getValue(ps)) {
|
@Override
|
||||||
|
public void init(final FormSectionEvent event) {
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
|
if (null == sectionSelect.getValue(state)) {
|
||||||
ContentSection section = CMS.getContext().
|
ContentSection section = CMS.getContext().
|
||||||
getContentSection();
|
getContentSection();
|
||||||
sectionSelect.setValue(ps, section.getOID());
|
sectionSelect.setValue(state, section.getObjectId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,48 +202,52 @@ public class ItemSearchBrowsePane extends SimpleContainer implements Resettable,
|
||||||
return sectionForm;
|
return sectionForm;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Folder getRootFolder(PageState ps) {
|
private Folder getRootFolder(final PageState state) {
|
||||||
LOGGER.debug("Getting the root folder.");
|
LOGGER.debug("Getting the root folder.");
|
||||||
if (sectionSelect != null) {
|
if (sectionSelect != null) {
|
||||||
// We have more than one subsite to choose between
|
// We have more than one subsite to choose between
|
||||||
OID sectionOID = (OID) sectionSelect.getValue(ps);
|
final Long sectionId = (Long) sectionSelect.getValue(state);
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
if (null != sectionOID) {
|
if (null == sectionId) {
|
||||||
LOGGER.debug("Using section " + sectionOID.toString());
|
|
||||||
} else {
|
|
||||||
LOGGER.debug("Using default section");
|
LOGGER.debug("Using default section");
|
||||||
|
} else {
|
||||||
|
LOGGER.debug("Using section " + sectionId.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null == sectionOID) {
|
if (null == sectionId) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentSection section = (ContentSection) DomainObjectFactory.
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
newInstance(sectionOID);
|
final ContentSectionRepository sectionRepo = cdiUtil.findBean(
|
||||||
|
ContentSectionRepository.class);
|
||||||
|
final ContentSection section = sectionRepo.findById(sectionId);
|
||||||
|
|
||||||
return section.getRootFolder();
|
return section.getRootDocumentsFolder();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register(Page p) {
|
public void register(final Page page) {
|
||||||
super.register(p);
|
super.register(page);
|
||||||
p.addComponentStateParam(this, folderSelectionModel.getStateParameter());
|
page.addComponentStateParam(this, folderSelectionModel
|
||||||
|
.getStateParameter());
|
||||||
|
|
||||||
// Only add the SingleSelect item if it exists
|
// Only add the SingleSelect item if it exists
|
||||||
if (sectionSelect != null) {
|
if (sectionSelect != null) {
|
||||||
p.addComponentStateParam(this, sectionSelect.getParameterModel());
|
page.addComponentStateParam(this, sectionSelect.getParameterModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the state of the new item component
|
// Save the state of the new item component
|
||||||
// p.addComponentStateParam(this, m_typeSel.getStateParameter());
|
// p.addComponentStateParam(this, m_typeSel.getStateParameter());
|
||||||
p.addActionListener(new ActionListener() {
|
page.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(final ActionEvent event) {
|
||||||
final PageState state = e.getPageState();
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
if (state.isVisibleOnPage(ItemSearchBrowsePane.this)) {
|
if (state.isVisibleOnPage(ItemSearchBrowsePane.this)) {
|
||||||
showHideSegments(state);
|
showHideSegments(state);
|
||||||
|
|
@ -256,27 +261,14 @@ public class ItemSearchBrowsePane extends SimpleContainer implements Resettable,
|
||||||
* Show/hide segments based on access checks.
|
* Show/hide segments based on access checks.
|
||||||
*
|
*
|
||||||
* @param state The page state
|
* @param state The page state
|
||||||
* @pre ( state != null )
|
|
||||||
*/
|
*/
|
||||||
private void showHideSegments(PageState state) {
|
private void showHideSegments(final PageState state) {
|
||||||
SecurityManager sm = Utilities.getSecurityManager(state);
|
//Empty
|
||||||
Folder folder = folderRequestLocal.getFolder(state);
|
|
||||||
Assert.exists(folder);
|
|
||||||
|
|
||||||
// MP: This should be checked on the current folder instead of just
|
|
||||||
// the content section.
|
|
||||||
// boolean newItem =
|
|
||||||
// sm.canAccess(state.getRequest(), SecurityManager.NEW_ITEM, folder);
|
|
||||||
//
|
|
||||||
// if (!newItem) {
|
|
||||||
// browseMode(state);
|
|
||||||
// }
|
|
||||||
// m_newItem.setVisible(state, newItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset(PageState s) {
|
public void reset(final PageState state) {
|
||||||
//m_browser.reset(s);
|
//Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemSearchFolderBrowser getFolderBrowser() {
|
public ItemSearchFolderBrowser getFolderBrowser() {
|
||||||
|
|
@ -290,106 +282,86 @@ public class ItemSearchBrowsePane extends SimpleContainer implements Resettable,
|
||||||
/**
|
/**
|
||||||
* sets the current level of expansion of the folder tree and in the folder
|
* sets the current level of expansion of the folder tree and in the folder
|
||||||
* browser table
|
* browser table
|
||||||
|
*
|
||||||
|
* @param state
|
||||||
|
* @param key
|
||||||
*/
|
*/
|
||||||
protected void setSelectedFolder(PageState s, String key) {
|
protected void setSelectedFolder(final PageState state,
|
||||||
|
final String key) {
|
||||||
|
|
||||||
//set the selected folder of the folder browser
|
//set the selected folder of the folder browser
|
||||||
folderBrowser.getFolderSelectionModel().setSelectedKey(s, key);
|
folderBrowser.getFolderSelectionModel().setSelectedKey(
|
||||||
|
state, Long.parseLong(key));
|
||||||
|
|
||||||
//set the selected folder of the folder tree
|
//set the selected folder of the folder tree
|
||||||
folderSelectionModel.setSelectedKey(s, key);
|
folderSelectionModel.setSelectedKey(state, Long.parseLong(key));
|
||||||
Folder current = (Folder) folderSelectionModel.getSelectedObject(s);
|
final Folder current = (Folder) folderSelectionModel.getSelectedObject(
|
||||||
Folder parent = (Folder) current.getParent();
|
state);
|
||||||
|
final Folder parent = current.getParentFolder();
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
BigDecimal id = parent.getID();
|
final long parentId = parent.getObjectId();
|
||||||
tree.expand(id.toString(), s);
|
tree.expand(Long.toString(parentId), state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement TreeExpansionListener
|
// Implement TreeExpansionListener
|
||||||
@Override
|
@Override
|
||||||
public void treeCollapsed(TreeExpansionEvent e) {
|
public void treeCollapsed(final TreeExpansionEvent event) {
|
||||||
PageState s = e.getPageState();
|
final PageState state = event.getPageState();
|
||||||
folderSelectionModel.setSelectedKey(s, e.getNodeKey());
|
folderSelectionModel.setSelectedKey(
|
||||||
|
state, Long.parseLong((String) event.getNodeKey()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void treeExpanded(TreeExpansionEvent e) {
|
public void treeExpanded(final TreeExpansionEvent event) {
|
||||||
return;
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(final ChangeEvent event) {
|
||||||
PageState s = e.getPageState();
|
final PageState state = event.getPageState();
|
||||||
Folder current = (Folder) folderSelectionModel.getSelectedObject(s);
|
final Folder current = (Folder) folderSelectionModel.getSelectedObject(state);
|
||||||
Folder parent = (Folder) current.getParent();
|
final Folder parent = current.getParentFolder();
|
||||||
folderBrowser.getPaginator().reset(s);
|
folderBrowser.getPaginator().reset(state);
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
BigDecimal id = parent.getID();
|
final Long parentId = parent.getObjectId();
|
||||||
tree.expand(id.toString(), s);
|
tree.expand(parentId.toString(), state);
|
||||||
}
|
}
|
||||||
//m_browser.getPermissionsPane().reset(s);
|
|
||||||
//m_browser.setPermissionLinkVis(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(FormSectionEvent e) {
|
public void process(final FormSectionEvent event) {
|
||||||
PageState s = e.getPageState();
|
final PageState state = event.getPageState();
|
||||||
final Object source = e.getSource();
|
browseMode(state);
|
||||||
// if (source == m_newItem) {
|
|
||||||
// BigDecimal typeID = m_newItem.getTypeID(s);
|
|
||||||
// m_typeSel.setSelectedKey(s, typeID);
|
|
||||||
// newItemMode(s);
|
|
||||||
// } else {
|
|
||||||
browseMode(s);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void submitted(FormSectionEvent e) {
|
public void submitted(final FormSectionEvent event) {
|
||||||
PageState s = e.getPageState();
|
//Nothing
|
||||||
final Object source = e.getSource();
|
|
||||||
// if (source == m_newItem) {
|
|
||||||
// BigDecimal typeID = m_newItem.getTypeID(s);
|
|
||||||
// m_typeSel.setSelectedKey(s, typeID);
|
|
||||||
// //newItemMode(s);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void browseMode(PageState s) {
|
private void browseMode(final PageState state) {
|
||||||
// m_browseSeg.setVisible(s, true);
|
typeSelectionModel.clearSelection(state);
|
||||||
typeSelectionModel.clearSelection(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void newItemMode(PageState s) {
|
private void newItemMode(final PageState state) {
|
||||||
// m_newItemSeg.setVisible(s, true);
|
//Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
private FolderSelectionModel createFolderSelectionModel() {
|
private FolderSelectionModel createFolderSelectionModel() {
|
||||||
return new FolderSelectionModel("folder") {
|
return new FolderSelectionModel("folder") {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BigDecimal getRootFolderID(PageState ps) {
|
protected Long getRootFolderID(final PageState state) {
|
||||||
Folder root = getRootFolder(ps);
|
final Folder root = getRootFolder(state);
|
||||||
|
|
||||||
if (null == root) {
|
if (null == root) {
|
||||||
return super.getRootFolderID(ps);
|
return super.getRootFolderID(state);
|
||||||
}
|
}
|
||||||
return root.getID();
|
return root.getObjectId();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SectionNewItemForm extends NewItemForm {
|
|
||||||
|
|
||||||
public SectionNewItemForm(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ContentSection getContentSection(PageState s) {
|
|
||||||
return CMS.getContext().getContentSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,410 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.BoxPanel;
|
||||||
|
import com.arsdigita.bebop.Component;
|
||||||
|
import com.arsdigita.bebop.Form;
|
||||||
|
import com.arsdigita.bebop.FormData;
|
||||||
|
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.PaginationModelBuilder;
|
||||||
|
import com.arsdigita.bebop.Paginator;
|
||||||
|
import com.arsdigita.bebop.RequestLocal;
|
||||||
|
import com.arsdigita.bebop.SimpleContainer;
|
||||||
|
import com.arsdigita.bebop.Table;
|
||||||
|
import com.arsdigita.bebop.event.FormInitListener;
|
||||||
|
import com.arsdigita.bebop.event.FormProcessListener;
|
||||||
|
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||||
|
import com.arsdigita.bebop.form.Submit;
|
||||||
|
import com.arsdigita.bebop.form.TextField;
|
||||||
|
import com.arsdigita.bebop.parameters.BigDecimalParameter;
|
||||||
|
import com.arsdigita.bebop.parameters.ParameterData;
|
||||||
|
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.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.toolbox.ui.LayoutPanel;
|
||||||
|
import com.arsdigita.util.LockableImpl;
|
||||||
|
|
||||||
|
import org.arsdigita.cms.CMSConfig;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
import org.librecms.contentsection.ContentItem;
|
||||||
|
import org.librecms.contentsection.ContentItemManager;
|
||||||
|
import org.librecms.contentsection.ContentItemRepository;
|
||||||
|
import org.librecms.contentsection.ContentType;
|
||||||
|
import org.librecms.contentsection.Folder;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter <jens@jp-digital.de>
|
||||||
|
*/
|
||||||
|
public class ItemSearchFlatBrowsePane extends SimpleContainer {
|
||||||
|
|
||||||
|
private static final String QUERY_PARAM = "queryStr";
|
||||||
|
public static final String WIDGET_PARAM = "widget";
|
||||||
|
public static final String SEARCHWIDGET_PARAM = "searchWidget";
|
||||||
|
public static final String FILTER_SUBMIT = "filterSubmit";
|
||||||
|
private final Table resultsTable;
|
||||||
|
private final Paginator paginator;
|
||||||
|
private final StringParameter queryParam;
|
||||||
|
private final QueryFieldsRequestLocal queryFields
|
||||||
|
= new QueryFieldsRequestLocal();
|
||||||
|
private final static CMSConfig CMS_CONFIG = CMSConfig.getConfig();
|
||||||
|
|
||||||
|
public ItemSearchFlatBrowsePane() {
|
||||||
|
//super(name);
|
||||||
|
super();
|
||||||
|
|
||||||
|
setIdAttr("itemSearchFlatBrowse");
|
||||||
|
|
||||||
|
//final BoxPanel mainPanel = new BoxPanel(BoxPanel.VERTICAL);
|
||||||
|
final LayoutPanel mainPanel = new LayoutPanel();
|
||||||
|
|
||||||
|
queryParam = new StringParameter(QUERY_PARAM);
|
||||||
|
|
||||||
|
mainPanel.setLeft(new FilterForm());
|
||||||
|
|
||||||
|
resultsTable = new ResultsTable();
|
||||||
|
paginator = new Paginator(
|
||||||
|
(PaginationModelBuilder) resultsTable.getModelBuilder(),
|
||||||
|
CMS_CONFIG.getItemSearchFlatBrowsePanePageSize());
|
||||||
|
final BoxPanel body = new BoxPanel(BoxPanel.VERTICAL);
|
||||||
|
body.add(paginator);
|
||||||
|
|
||||||
|
body.add(resultsTable);
|
||||||
|
|
||||||
|
mainPanel.setBody(body);
|
||||||
|
add(mainPanel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(final Page page) {
|
||||||
|
super.register(page);
|
||||||
|
page.addComponentStateParam(this, queryParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addQueryField(final String queryField) {
|
||||||
|
queryFields.addQueryField(queryField);
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetQueryFields() {
|
||||||
|
queryFields.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ResultsTable extends Table {
|
||||||
|
|
||||||
|
private static final String TABLE_COL_TITLE = "title";
|
||||||
|
private static final String TABLE_COL_PLACE = "place";
|
||||||
|
private static final String TABLE_COL_TYPE = "type";
|
||||||
|
|
||||||
|
public ResultsTable() {
|
||||||
|
super();
|
||||||
|
setEmptyView(new Label(new GlobalizedMessage(
|
||||||
|
"cms.ui.item_search.flat.no_items",
|
||||||
|
CmsConstants.CMS_BUNDLE)));
|
||||||
|
setClassAttr("dataTable");
|
||||||
|
|
||||||
|
final TableColumnModel columnModel = getColumnModel();
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
0,
|
||||||
|
new GlobalizedMessage("cms.ui.item_search.flat.title",
|
||||||
|
CmsConstants.CMS_BUNDLE).localize(),
|
||||||
|
TABLE_COL_TITLE));
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
1,
|
||||||
|
new GlobalizedMessage("cms.ui.item_search.flat.place",
|
||||||
|
CmsConstants.CMS_BUNDLE).localize(),
|
||||||
|
TABLE_COL_PLACE));
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
2,
|
||||||
|
new GlobalizedMessage("cms.ui.item_search.flat.type",
|
||||||
|
CmsConstants.CMS_BUNDLE).localize(),
|
||||||
|
TABLE_COL_TYPE));
|
||||||
|
|
||||||
|
setModelBuilder(new ResultsTableModelBuilder());
|
||||||
|
|
||||||
|
columnModel.get(0).setCellRenderer(new TitleCellRenderer());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ResultsTableModelBuilder extends LockableImpl implements
|
||||||
|
TableModelBuilder,
|
||||||
|
PaginationModelBuilder {
|
||||||
|
|
||||||
|
private final RequestLocal collection = new RequestLocal();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public TableModel makeModel(final Table table, final PageState state) {
|
||||||
|
|
||||||
|
if (collection.get(state) == null) {
|
||||||
|
query(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResultsTableModel(
|
||||||
|
table,
|
||||||
|
state,
|
||||||
|
(List<ContentItem>) collection.get(state));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalSize(final Paginator paginator,
|
||||||
|
final PageState state) {
|
||||||
|
if (collection.get(state) == null) {
|
||||||
|
query(state);
|
||||||
|
}
|
||||||
|
return (int) ((List<ContentItem>) collection.get(state)).size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVisible(final PageState state) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void query(final PageState state) {
|
||||||
|
//Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ResultsTableModel implements TableModel {
|
||||||
|
|
||||||
|
private final Table table;
|
||||||
|
private final List<ContentItem> collection;
|
||||||
|
private ContentItem currentItem;
|
||||||
|
private int index = -1;
|
||||||
|
|
||||||
|
public ResultsTableModel(final Table table,
|
||||||
|
final PageState state,
|
||||||
|
final List<ContentItem> collection) {
|
||||||
|
this.table = table;
|
||||||
|
|
||||||
|
this.collection = collection;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
return table.getColumnModel().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean nextRow() {
|
||||||
|
index++;
|
||||||
|
|
||||||
|
if (collection != null && index < collection.size()) {
|
||||||
|
currentItem = collection.get(index);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getElementAt(final int columnIndex) {
|
||||||
|
switch (columnIndex) {
|
||||||
|
case 0:
|
||||||
|
return currentItem.getDisplayName();
|
||||||
|
case 1:
|
||||||
|
return getItemPath(currentItem);
|
||||||
|
case 2:
|
||||||
|
if (currentItem.getContentType() == null) {
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
return currentItem.getContentType().getDisplayName();
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getItemPath(final ContentItem item) {
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final ContentItemManager itemManager = cdiUtil.findBean(
|
||||||
|
ContentItemManager.class);
|
||||||
|
|
||||||
|
return itemManager.getItemPath(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getKeyAt(final int columnIndex) {
|
||||||
|
return currentItem.getObjectId();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TitleCellRenderer extends LockableImpl
|
||||||
|
implements 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) {
|
||||||
|
|
||||||
|
if (value == null) {
|
||||||
|
return new Label("???");
|
||||||
|
}
|
||||||
|
|
||||||
|
final Link link = new Link(value.toString(), "");
|
||||||
|
|
||||||
|
final String widget = (String) state.getValue(new StringParameter(
|
||||||
|
WIDGET_PARAM));
|
||||||
|
final String searchWidget = (String) state.getValue(
|
||||||
|
new StringParameter(
|
||||||
|
SEARCHWIDGET_PARAM));
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final ContentItemRepository itemRepo = cdiUtil.findBean(
|
||||||
|
ContentItemRepository.class);
|
||||||
|
final Optional<ContentItem> page = itemRepo.findById(Long.parseLong(
|
||||||
|
(String) key));
|
||||||
|
|
||||||
|
final boolean useURL = "true".equals(state.getValue(
|
||||||
|
new StringParameter(
|
||||||
|
ItemSearchPopup.URL_PARAM)));
|
||||||
|
|
||||||
|
final String targetValue;
|
||||||
|
if (useURL) {
|
||||||
|
targetValue = ItemSearchPopup.getItemURL(
|
||||||
|
state.getRequest(), page.get().getObjectId());
|
||||||
|
} else {
|
||||||
|
targetValue = key.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
final StringBuffer buffer = new StringBuffer(30);
|
||||||
|
buffer.append(String.format(
|
||||||
|
"window.opener.document.%s.value=\"%s\"; ", widget,
|
||||||
|
targetValue));
|
||||||
|
if (searchWidget != null) {
|
||||||
|
buffer.append(String.format(
|
||||||
|
"window.opener.document.%s.value=\"%s\"; ",
|
||||||
|
searchWidget,
|
||||||
|
page.get().getDisplayName().replace("\"", "\\\"")));
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.append("self.close(); return false;");
|
||||||
|
|
||||||
|
link.setOnClick(buffer.toString());
|
||||||
|
|
||||||
|
return link;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class FilterForm extends Form implements FormInitListener,
|
||||||
|
FormProcessListener {
|
||||||
|
|
||||||
|
private final Submit submit;
|
||||||
|
|
||||||
|
public FilterForm() {
|
||||||
|
super("ItemSearchFlatBrowsePane");
|
||||||
|
|
||||||
|
add(new Label(new GlobalizedMessage(
|
||||||
|
"cms.ui.item_search.flat.filter",
|
||||||
|
CmsConstants.CMS_BUNDLE)));
|
||||||
|
final TextField filter = new TextField(new StringParameter(
|
||||||
|
QUERY_PARAM));
|
||||||
|
add(filter);
|
||||||
|
|
||||||
|
submit = new Submit(FILTER_SUBMIT,
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"cms.ui.item_search.flat.filter.submit",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
|
add(submit);
|
||||||
|
|
||||||
|
addInitListener(this);
|
||||||
|
addProcessListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(final FormSectionEvent fse) throws FormProcessException {
|
||||||
|
final PageState state = fse.getPageState();
|
||||||
|
final FormData data = fse.getFormData();
|
||||||
|
|
||||||
|
final String query = (String) data.get(QUERY_PARAM);
|
||||||
|
if ((query == null) || query.isEmpty()) {
|
||||||
|
data.setParameter(
|
||||||
|
QUERY_PARAM,
|
||||||
|
new ParameterData(
|
||||||
|
queryParam,
|
||||||
|
state.getValue(
|
||||||
|
new StringParameter(ItemSearchPopup.QUERY))));
|
||||||
|
state.setValue(queryParam,
|
||||||
|
data.getParameter(QUERY_PARAM).getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(final FormSectionEvent fse) throws
|
||||||
|
FormProcessException {
|
||||||
|
final FormData data = fse.getFormData();
|
||||||
|
final PageState state = fse.getPageState();
|
||||||
|
|
||||||
|
state.setValue(queryParam, data.get(QUERY_PARAM));
|
||||||
|
state.setValue(new StringParameter(ItemSearchPopup.QUERY),
|
||||||
|
data.get(QUERY_PARAM));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class QueryFieldsRequestLocal extends RequestLocal {
|
||||||
|
|
||||||
|
private List<String> queryFields = new ArrayList<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object initialValue(final PageState state) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getQueryFields() {
|
||||||
|
return queryFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQueryFields(final List<String> queryFields) {
|
||||||
|
this.queryFields = queryFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addQueryField(final String queryField) {
|
||||||
|
queryFields.add(queryField);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
queryFields = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,457 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.BebopConfig;
|
||||||
|
import com.arsdigita.bebop.Component;
|
||||||
|
import com.arsdigita.bebop.Label;
|
||||||
|
import com.arsdigita.bebop.Link;
|
||||||
|
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.SimpleContainer;
|
||||||
|
import com.arsdigita.bebop.Table;
|
||||||
|
import com.arsdigita.bebop.Text;
|
||||||
|
import com.arsdigita.bebop.event.ActionEvent;
|
||||||
|
import com.arsdigita.bebop.event.ActionListener;
|
||||||
|
import com.arsdigita.bebop.event.TableActionAdapter;
|
||||||
|
import com.arsdigita.bebop.event.TableActionEvent;
|
||||||
|
import com.arsdigita.bebop.event.TableActionListener;
|
||||||
|
import com.arsdigita.bebop.parameters.BigDecimalParameter;
|
||||||
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
|
import com.arsdigita.bebop.table.AbstractTableModelBuilder;
|
||||||
|
import com.arsdigita.bebop.table.DefaultTableCellRenderer;
|
||||||
|
import com.arsdigita.bebop.table.TableColumn;
|
||||||
|
import com.arsdigita.bebop.table.TableModel;
|
||||||
|
import com.arsdigita.bebop.util.BebopConstants;
|
||||||
|
import com.arsdigita.cms.CMS;
|
||||||
|
import com.arsdigita.cms.dispatcher.Utilities;
|
||||||
|
import com.arsdigita.cms.ui.folder.FolderSelectionModel;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.util.Assert;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.arsdigita.cms.CMSConfig;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.core.CcmObject;
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
import org.librecms.contentsection.ContentItem;
|
||||||
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
import org.librecms.contentsection.ContentSectionConfig;
|
||||||
|
import org.librecms.contentsection.ContentType;
|
||||||
|
import org.librecms.contentsection.Folder;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Browse folders and items. If the user clicks on a folder, the folder
|
||||||
|
* selection model is updated. If the user clicks on any other item, an separate
|
||||||
|
* item selection model is updated.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:lutter@arsdigita.com">David Lutterkort</a>
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class ItemSearchFolderBrowser extends Table {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
|
ItemSearchFolderBrowser.class);
|
||||||
|
private static final GlobalizedMessage[] HEADERS = {
|
||||||
|
globalize("cms.ui.folder.name"),
|
||||||
|
globalize("cms.ui.folder.title"),
|
||||||
|
globalize("cms.ui.folder.type")};
|
||||||
|
private FolderSelectionModel currentFolder;
|
||||||
|
private TableActionListener folderChanger;
|
||||||
|
private TableActionListener deleter;
|
||||||
|
private TableActionListener indexChanger;
|
||||||
|
private TableColumn nameColumn;
|
||||||
|
private Paginator paginator;
|
||||||
|
|
||||||
|
public ItemSearchFolderBrowser(final FolderSelectionModel currentFolder) {
|
||||||
|
|
||||||
|
super((FolderTableModelBuilder) null, HEADERS);
|
||||||
|
|
||||||
|
final FolderTableModelBuilder builder = new FolderTableModelBuilder();
|
||||||
|
setModelBuilder(builder);
|
||||||
|
|
||||||
|
paginator = new Paginator(
|
||||||
|
builder, CMSConfig.getConfig().getFolderBrowseListSize());
|
||||||
|
|
||||||
|
this.currentFolder = currentFolder;
|
||||||
|
|
||||||
|
setClassAttr("dataTable");
|
||||||
|
|
||||||
|
getHeader().setDefaultRenderer(
|
||||||
|
new com.arsdigita.cms.ui.util.DefaultTableCellRenderer());
|
||||||
|
nameColumn = getColumn(0);
|
||||||
|
nameColumn.setCellRenderer(new NameCellRenderer());
|
||||||
|
|
||||||
|
folderChanger = new FolderChanger();
|
||||||
|
addTableActionListener(folderChanger);
|
||||||
|
|
||||||
|
setEmptyView(new Label(globalize("cms.ui.folder.no_items")));
|
||||||
|
|
||||||
|
Assert.exists(currentFolder.getStateParameter());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Paginator getPaginator() {
|
||||||
|
return paginator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(final Page page) {
|
||||||
|
super.register(page);
|
||||||
|
page.addComponentStateParam(this, currentFolder.getStateParameter());
|
||||||
|
|
||||||
|
page.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
public void actionPerformed(final ActionEvent event) {
|
||||||
|
// MP: This action listener should only be called when the
|
||||||
|
// folder browser is visible.
|
||||||
|
showHideFolderActions(event.getPageState());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private Folder getCurrentFolder(final PageState state) {
|
||||||
|
return (Folder) currentFolder.getSelectedObject(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showHideFolderActions(final PageState state) {
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
public FolderSelectionModel getFolderSelectionModel() {
|
||||||
|
return currentFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class FolderTableModelBuilder
|
||||||
|
extends AbstractTableModelBuilder implements PaginationModelBuilder {
|
||||||
|
|
||||||
|
private RequestLocal size = new RequestLocal() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object initialValue(final PageState state) {
|
||||||
|
List<ContentItem> items = getItemCollection(state);
|
||||||
|
|
||||||
|
if (null == items) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return items.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
private RequestLocal items = new RequestLocal() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object initialValue(final PageState state) {
|
||||||
|
List<ContentItem> items = getItemCollection(state);
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TableModel makeModel(final Table table, final PageState state) {
|
||||||
|
final FolderSelectionModel selectionModel
|
||||||
|
= ((ItemSearchFolderBrowser) table)
|
||||||
|
.getFolderSelectionModel();
|
||||||
|
final Folder folder = getCurrentFolder(state);
|
||||||
|
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
if (null == folder) {
|
||||||
|
LOGGER.debug("Selected folder is null");
|
||||||
|
} else {
|
||||||
|
LOGGER.debug("Selected folder: {} {}",
|
||||||
|
folder.getDisplayName(),
|
||||||
|
folder.getObjectId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (folder == null) {
|
||||||
|
return Table.EMPTY_MODEL;
|
||||||
|
} else {
|
||||||
|
table.getRowSelectionModel().clearSelection(state);
|
||||||
|
return new FolderTableModel((List<ContentItem>) items.
|
||||||
|
get(state));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ContentItem> getItemCollection(final PageState state) {
|
||||||
|
final Folder folder = getCurrentFolder(state);
|
||||||
|
|
||||||
|
final List<ContentItem> items = folder.getObjects()
|
||||||
|
.stream()
|
||||||
|
.map(categorization -> categorization.getCategorizedObject())
|
||||||
|
.filter(object -> object instanceof ContentItem)
|
||||||
|
.map(object -> (ContentItem) object)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalSize(final Paginator paginator,
|
||||||
|
final PageState state) {
|
||||||
|
|
||||||
|
return (int) this.size.get(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether the paginator should be visible, based on the
|
||||||
|
* visibility of the folder browser itself and how many items are
|
||||||
|
* displayed
|
||||||
|
*
|
||||||
|
* @return true if folder browser is visible and there is more than 1
|
||||||
|
* page of items, false otherwise
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isVisible(final PageState state) {
|
||||||
|
final int size = (int) this.size.get(state);
|
||||||
|
|
||||||
|
return ItemSearchFolderBrowser.this.isVisible(state)
|
||||||
|
&& (size > CMSConfig.getConfig()
|
||||||
|
.getFolderBrowseListSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produce links to view an item or control links for folders to change into
|
||||||
|
* the folder.
|
||||||
|
*/
|
||||||
|
private class NameCellRenderer extends DefaultTableCellRenderer {
|
||||||
|
|
||||||
|
public NameCellRenderer() {
|
||||||
|
super(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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) {
|
||||||
|
if (value instanceof Folder) {
|
||||||
|
return super.getComponent(table,
|
||||||
|
state,
|
||||||
|
((CcmObject) value).getDisplayName(),
|
||||||
|
isSelected,
|
||||||
|
key,
|
||||||
|
row,
|
||||||
|
column);
|
||||||
|
} else if (value instanceof ContentItem) {
|
||||||
|
final ContentItem item = (ContentItem) value;
|
||||||
|
|
||||||
|
final ContentSection section = CMS.getContext()
|
||||||
|
.getContentSection();
|
||||||
|
final long objectId = (long) key;
|
||||||
|
|
||||||
|
final String name = item.getDisplayName();
|
||||||
|
|
||||||
|
if (section == null) {
|
||||||
|
return new Text(name);
|
||||||
|
} else {
|
||||||
|
final SimpleContainer container = new SimpleContainer();
|
||||||
|
|
||||||
|
final String widget = (String) state.getValue(
|
||||||
|
new StringParameter(
|
||||||
|
ItemSearchPopup.WIDGET_PARAM));
|
||||||
|
String searchWidget = (String) state.getValue(
|
||||||
|
new StringParameter("searchWidget"));
|
||||||
|
boolean useURL = "true".equals(state.getValue(
|
||||||
|
new StringParameter(
|
||||||
|
ItemSearchPopup.URL_PARAM)));
|
||||||
|
|
||||||
|
String fillString;
|
||||||
|
if (useURL) {
|
||||||
|
fillString = ItemSearchPopup.getItemURL(
|
||||||
|
state.getRequest(), item.getObjectId());
|
||||||
|
} else {
|
||||||
|
fillString = Long.toString(objectId);
|
||||||
|
}
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final GlobalizationHelper globalizationHelper = cdiUtil
|
||||||
|
.findBean(GlobalizationHelper.class);
|
||||||
|
final String title = item.getTitle().getValue(
|
||||||
|
globalizationHelper.getNegotiatedLocale());
|
||||||
|
|
||||||
|
final Label jsLabel = new Label(
|
||||||
|
generateJSLabel(objectId,
|
||||||
|
widget,
|
||||||
|
searchWidget,
|
||||||
|
fillString,
|
||||||
|
title),
|
||||||
|
false);
|
||||||
|
container.add(jsLabel);
|
||||||
|
|
||||||
|
final String url = "#";
|
||||||
|
|
||||||
|
final Link link = new Link(name, url);
|
||||||
|
link.setClassAttr("title");
|
||||||
|
link.setOnClick("return fillItem" + objectId + "()");
|
||||||
|
|
||||||
|
container.add(link);
|
||||||
|
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException(String.format(
|
||||||
|
"Expected value to be either a '{}' or a '{]', but was '{}'.",
|
||||||
|
Folder.class.getName(),
|
||||||
|
ContentItem.class.getName(),
|
||||||
|
value.getClass().getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String generateJSLabel(final long id,
|
||||||
|
final String widget,
|
||||||
|
final String searchWidget,
|
||||||
|
final String fill,
|
||||||
|
final String title) {
|
||||||
|
final StringBuilder buffer = new StringBuilder();
|
||||||
|
buffer.append(" <script language=javascript> ");
|
||||||
|
buffer.append(" <!-- \n");
|
||||||
|
buffer.append(" function fillItem").append(id).append("() { \n");
|
||||||
|
buffer.append(" window.opener.document.").append(widget).append(
|
||||||
|
".value=\"").
|
||||||
|
append(fill).append("\";\n");
|
||||||
|
if (searchWidget != null) {
|
||||||
|
buffer.append(" window.opener.document.").append(searchWidget)
|
||||||
|
.append(".value=\"").
|
||||||
|
append(title.
|
||||||
|
replace("\"", "\\\"")).append("\";\n");
|
||||||
|
}
|
||||||
|
// set protocol to 'other' in FCKEditor, else relative url prepended by http://
|
||||||
|
if (BebopConfig.getConfig().getDefaultDhtmlEditor().equals(
|
||||||
|
BebopConstants.BEBOP_FCKEDITOR)) {
|
||||||
|
buffer.append(
|
||||||
|
" if(window.opener.document.getElementById('cmbLinkProtocol')) {\n");
|
||||||
|
buffer.append(
|
||||||
|
" window.opener.document.getElementById('cmbLinkProtocol').value=\"\";\n");
|
||||||
|
buffer.append(" }\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.append(" self.close(); \n"
|
||||||
|
+ " return false; \n"
|
||||||
|
+ " } \n"
|
||||||
|
+ " --> \n"
|
||||||
|
+ " </script> ");
|
||||||
|
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table model around ItemCollection
|
||||||
|
*/
|
||||||
|
private static class FolderTableModel implements TableModel {
|
||||||
|
|
||||||
|
private static final int NAME = 0;
|
||||||
|
private static final int TITLE = 1;
|
||||||
|
private static final int TYPE = 2;
|
||||||
|
private final List<ContentItem> items;
|
||||||
|
private int index = -1;
|
||||||
|
|
||||||
|
public FolderTableModel(final List<ContentItem> items) {
|
||||||
|
this.items = items;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean nextRow() {
|
||||||
|
index++;
|
||||||
|
if (index < items.size()) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getElementAt(final int columnIndex) {
|
||||||
|
switch (columnIndex) {
|
||||||
|
case NAME:
|
||||||
|
return items.get(index);
|
||||||
|
case TITLE:
|
||||||
|
return items.get(index).getDisplayName();
|
||||||
|
case TYPE:
|
||||||
|
return items.get(index).getContentType().getDisplayName();
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException(String.format(
|
||||||
|
"Column index {} not in table model.", columnIndex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getKeyAt(final int columnIndex) {
|
||||||
|
return items.get(index).getObjectId();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class FolderChanger extends TableActionAdapter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cellSelected(final TableActionEvent event) {
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
final int col = event.getColumn();
|
||||||
|
|
||||||
|
if (nameColumn != getColumn(col)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final String key = (String) event.getRowKey();
|
||||||
|
if (key.startsWith("-")) {
|
||||||
|
clearSelection(state);
|
||||||
|
getFolderSelectionModel().setSelectedKey(
|
||||||
|
state, Long.parseLong(key.substring(1)));
|
||||||
|
paginator.reset(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getting the GlobalizedMessage using a CMS Class targetBundle.
|
||||||
|
*
|
||||||
|
* @param key The resource key
|
||||||
|
*
|
||||||
|
* @pre ( key != null )
|
||||||
|
*/
|
||||||
|
private static GlobalizedMessage globalize(final String key) {
|
||||||
|
return new GlobalizedMessage(key, CmsConstants.CMS_FOLDER_BUNDLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,494 +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;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Bebop;
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.Link;
|
|
||||||
import com.arsdigita.bebop.Page;
|
|
||||||
import com.arsdigita.bebop.RequestLocal;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.PaginationModelBuilder;
|
|
||||||
import com.arsdigita.bebop.Paginator;
|
|
||||||
import com.arsdigita.bebop.SimpleContainer;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.event.ActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.ActionListener;
|
|
||||||
import com.arsdigita.bebop.event.TableActionAdapter;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.TableActionListener;
|
|
||||||
import com.arsdigita.bebop.parameters.BigDecimalParameter;
|
|
||||||
import com.arsdigita.bebop.parameters.StringParameter;
|
|
||||||
import com.arsdigita.bebop.table.AbstractTableModelBuilder;
|
|
||||||
import com.arsdigita.bebop.table.DefaultTableCellRenderer;
|
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.util.BebopConstants;
|
|
||||||
import com.arsdigita.cms.CMS;
|
|
||||||
import com.arsdigita.cms.ContentItem;
|
|
||||||
import com.arsdigita.cms.ContentPage;
|
|
||||||
import com.arsdigita.cms.ContentSection;
|
|
||||||
import com.arsdigita.cms.ContentType;
|
|
||||||
import com.arsdigita.cms.Folder;
|
|
||||||
import com.arsdigita.cms.SecurityManager;
|
|
||||||
import com.arsdigita.cms.dispatcher.Utilities;
|
|
||||||
import com.arsdigita.cms.ui.folder.FolderSelectionModel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.persistence.CompoundFilter;
|
|
||||||
import com.arsdigita.persistence.FilterFactory;
|
|
||||||
import com.arsdigita.toolbox.GlobalisationUtil;
|
|
||||||
import com.arsdigita.util.Assert;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Browse folders and items. If the user clicks on a folder, the folder selection model is updated.
|
|
||||||
* If the user clicks on any other item, an separate item selection model is updated.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:lutter@arsdigita.com">David Lutterkort</a>
|
|
||||||
* @version $Revision: #9 $ $DateTime: 2004/08/17 23:15:09 $
|
|
||||||
*/
|
|
||||||
public class ItemSearchFolderBrowser extends Table {
|
|
||||||
|
|
||||||
private static final org.apache.log4j.Logger s_log = org.apache.log4j.Logger.getLogger(
|
|
||||||
ItemSearchFolderBrowser.class);
|
|
||||||
private static GlobalizedMessage[] s_headers = {
|
|
||||||
globalize("cms.ui.folder.name"),
|
|
||||||
globalize("cms.ui.folder.title"),
|
|
||||||
globalize("cms.ui.folder.type")};
|
|
||||||
private FolderSelectionModel m_currentFolder;
|
|
||||||
private TableActionListener m_folderChanger;
|
|
||||||
private TableActionListener m_deleter;
|
|
||||||
private TableActionListener m_indexChanger;
|
|
||||||
private TableColumn m_nameColumn;
|
|
||||||
private Paginator m_paginator;
|
|
||||||
|
|
||||||
public ItemSearchFolderBrowser(FolderSelectionModel currentFolder) {
|
|
||||||
super((FolderTableModelBuilder) null, s_headers);
|
|
||||||
|
|
||||||
FolderTableModelBuilder builder = new FolderTableModelBuilder();
|
|
||||||
setModelBuilder(builder);
|
|
||||||
|
|
||||||
m_paginator = new Paginator(builder, ContentSection.getConfig().
|
|
||||||
getFolderBrowseListSize());
|
|
||||||
|
|
||||||
m_currentFolder = currentFolder;
|
|
||||||
|
|
||||||
setClassAttr("dataTable");
|
|
||||||
|
|
||||||
getHeader().setDefaultRenderer(
|
|
||||||
new com.arsdigita.cms.ui.util.DefaultTableCellRenderer());
|
|
||||||
m_nameColumn = getColumn(0);
|
|
||||||
m_nameColumn.setCellRenderer(new NameCellRenderer());
|
|
||||||
|
|
||||||
m_folderChanger = new FolderChanger();
|
|
||||||
addTableActionListener(m_folderChanger);
|
|
||||||
|
|
||||||
setEmptyView(new Label(globalize("cms.ui.folder.no_items")));
|
|
||||||
|
|
||||||
Assert.exists(m_currentFolder.getStateParameter());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Paginator getPaginator() {
|
|
||||||
return m_paginator;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(Page p) {
|
|
||||||
super.register(p);
|
|
||||||
p.addComponentStateParam(this, m_currentFolder.getStateParameter());
|
|
||||||
|
|
||||||
p.addActionListener(new ActionListener() {
|
|
||||||
|
|
||||||
public void actionPerformed(ActionEvent event) {
|
|
||||||
// MP: This action listener should only be called when the
|
|
||||||
// folder browser is visible.
|
|
||||||
showHideFolderActions(event.getPageState());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private Folder getCurrentFolder(PageState state) {
|
|
||||||
return (Folder) m_currentFolder.getSelectedObject(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showHideFolderActions(PageState state) {
|
|
||||||
SecurityManager sm = Utilities.getSecurityManager(state);
|
|
||||||
Folder folder = getCurrentFolder(state);
|
|
||||||
Assert.exists(folder);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FolderSelectionModel getFolderSelectionModel() {
|
|
||||||
return m_currentFolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class FolderTableModelBuilder
|
|
||||||
extends AbstractTableModelBuilder implements PaginationModelBuilder {
|
|
||||||
|
|
||||||
private RequestLocal m_size = new RequestLocal() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Object initialValue(PageState state) {
|
|
||||||
Folder.ItemCollection itemColl = getItemCollection(state);
|
|
||||||
|
|
||||||
if (null == itemColl) {
|
|
||||||
return new Integer(0);
|
|
||||||
}
|
|
||||||
return new Integer((int) itemColl.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
private RequestLocal m_itemColl = new RequestLocal() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Object initialValue(PageState state) {
|
|
||||||
Folder.ItemCollection itemColl = getItemCollection(state);
|
|
||||||
|
|
||||||
itemColl.addOrder("item.name");
|
|
||||||
itemColl.setRange(new Integer(m_paginator.getFirst(state)),
|
|
||||||
new Integer(m_paginator.getLast(state) + 1));
|
|
||||||
|
|
||||||
return itemColl;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
public TableModel makeModel(Table t, PageState s) {
|
|
||||||
FolderSelectionModel sel = ((ItemSearchFolderBrowser) t).
|
|
||||||
getFolderSelectionModel();
|
|
||||||
Folder f = getCurrentFolder(s);
|
|
||||||
|
|
||||||
if (s_log.isDebugEnabled()) {
|
|
||||||
if (null == f) {
|
|
||||||
s_log.debug("Selected folder is null");
|
|
||||||
} else {
|
|
||||||
s_log.debug("Selected folder: " + f.getLabel() + " " + f.
|
|
||||||
getOID().toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (f == null) {
|
|
||||||
return Table.EMPTY_MODEL;
|
|
||||||
} else {
|
|
||||||
t.getRowSelectionModel().clearSelection(s);
|
|
||||||
return new FolderTableModel((Folder.ItemCollection) m_itemColl.
|
|
||||||
get(s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Folder.ItemCollection getItemCollection(PageState state) {
|
|
||||||
Folder f = getCurrentFolder(state);
|
|
||||||
Folder.ItemCollection itemColl = f.getPrimaryInstances();
|
|
||||||
|
|
||||||
if (null == itemColl) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
BigDecimal singleTypeID = (BigDecimal) state.getValue(new BigDecimalParameter(
|
|
||||||
ItemSearch.SINGLE_TYPE_PARAM));
|
|
||||||
|
|
||||||
if (singleTypeID != null) {
|
|
||||||
|
|
||||||
// The Filter Factory
|
|
||||||
FilterFactory ff = itemColl.getFilterFactory();
|
|
||||||
|
|
||||||
// Create an or-filter
|
|
||||||
CompoundFilter or = ff.or();
|
|
||||||
|
|
||||||
// The content type must be either of the requested type
|
|
||||||
or.addFilter(ff.equals(ContentItem.CONTENT_TYPE + "."
|
|
||||||
+ ContentType.ID, singleTypeID));
|
|
||||||
|
|
||||||
// Or must be a sibling of the requested type
|
|
||||||
/*
|
|
||||||
* jensp 2011-11-14: The orginal code here was only traversing
|
|
||||||
* one level, but ContentType hierarchies may have several
|
|
||||||
* levels. Therefore, this code was replaced by method which is
|
|
||||||
* called recursivly until the type with no descendents is
|
|
||||||
* reached.
|
|
||||||
*/
|
|
||||||
createSiblingFilter(or, ff, singleTypeID);
|
|
||||||
/*try {
|
|
||||||
ContentType ct = new ContentType(singleTypeID);
|
|
||||||
|
|
||||||
StringTokenizer strTok = new StringTokenizer(ct.
|
|
||||||
getDescendants(), "/");
|
|
||||||
while (strTok.hasMoreElements()) {
|
|
||||||
or.addFilter(ff.equals(ContentItem.CONTENT_TYPE + "."
|
|
||||||
+ ContentType.ID,
|
|
||||||
(String) strTok.nextElement()));
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
// WTF? The selected content type does not exist in the table???
|
|
||||||
s_log.error(String.format(
|
|
||||||
"Something is very wrong here, the ContentType '%s' "
|
|
||||||
+ "seems not to exist. Ignoring for now, but please "
|
|
||||||
+ "make your checks.",
|
|
||||||
singleTypeID.toString()),
|
|
||||||
ex);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
itemColl.addFilter(or);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
itemColl.addOrder("isFolder desc");
|
|
||||||
itemColl.addOrder("lower(item." + ContentItem.NAME + ") ");
|
|
||||||
return itemColl;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createSiblingFilter(final CompoundFilter filter,
|
|
||||||
final FilterFactory filterFactory,
|
|
||||||
final BigDecimal typeId) {
|
|
||||||
final ContentType type = new ContentType(typeId);
|
|
||||||
if ((type.getDescendants() == null)
|
|
||||||
|| type.getDescendants().trim().isEmpty()) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
final String[] descendantsIds = type.getDescendants().split("/");
|
|
||||||
|
|
||||||
for (String descendantId : descendantsIds) {
|
|
||||||
filter.addFilter(filterFactory.equals(String.format(
|
|
||||||
ContentItem.CONTENT_TYPE + "." + ContentType.ID),
|
|
||||||
descendantId));
|
|
||||||
createSiblingFilter(filter, filterFactory, descendantId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createSiblingFilter(final CompoundFilter filter,
|
|
||||||
final FilterFactory filterFactory,
|
|
||||||
final String typeId) {
|
|
||||||
try {
|
|
||||||
final BigDecimal _typeId = new BigDecimal(typeId);
|
|
||||||
createSiblingFilter(filter, filterFactory, _typeId);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
s_log.error(String.format("Failed to parse typeId '%s'.",
|
|
||||||
typeId),
|
|
||||||
ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTotalSize(Paginator paginator, PageState state) {
|
|
||||||
|
|
||||||
Integer size = (Integer) m_size.get(state);
|
|
||||||
return size.intValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates whether the paginator should be visible, based on the visibility of the folder
|
|
||||||
* browser itself and how many items are displayed
|
|
||||||
*
|
|
||||||
* @return true if folder browser is visible and there is more than 1 page of items, false
|
|
||||||
* otherwise
|
|
||||||
*/
|
|
||||||
public boolean isVisible(PageState state) {
|
|
||||||
int size = ((Integer) m_size.get(state)).intValue();
|
|
||||||
|
|
||||||
return ItemSearchFolderBrowser.this.isVisible(state)
|
|
||||||
&& (size
|
|
||||||
> ContentSection.getConfig().getFolderBrowseListSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Produce links to view an item or control links for folders to change into the folder.
|
|
||||||
*/
|
|
||||||
private class NameCellRenderer extends DefaultTableCellRenderer {
|
|
||||||
|
|
||||||
public NameCellRenderer() {
|
|
||||||
super(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(Table table, PageState state,
|
|
||||||
Object value, boolean isSelected,
|
|
||||||
Object key, int row, int column) {
|
|
||||||
Folder.ItemCollection coll = (Folder.ItemCollection) value;
|
|
||||||
String name = coll.getName();
|
|
||||||
if (coll.isFolder()) {
|
|
||||||
return super.getComponent(table, state, name, isSelected, key,
|
|
||||||
row, column);
|
|
||||||
} else {
|
|
||||||
ContentSection section = CMS.getContext().getContentSection();
|
|
||||||
BigDecimal id = (BigDecimal) key;
|
|
||||||
|
|
||||||
if (section == null) {
|
|
||||||
return new Label(name);
|
|
||||||
} else {
|
|
||||||
//ItemResolver resolver = section.getItemResolver();
|
|
||||||
|
|
||||||
//String url =
|
|
||||||
//resolver.generateItemURL
|
|
||||||
//(state, id, name, section, coll.getVersion()));
|
|
||||||
SimpleContainer container = new SimpleContainer();
|
|
||||||
|
|
||||||
String widget = (String) state.getValue(new StringParameter(
|
|
||||||
ItemSearchPopup.WIDGET_PARAM));
|
|
||||||
String searchWidget = (String) state.getValue(
|
|
||||||
new StringParameter("searchWidget"));
|
|
||||||
boolean useURL = "true".equals(state.getValue(new StringParameter(
|
|
||||||
ItemSearchPopup.URL_PARAM)));
|
|
||||||
|
|
||||||
String fillString;
|
|
||||||
if (useURL) {
|
|
||||||
fillString = ItemSearchPopup.getItemURL(state.getRequest(),
|
|
||||||
coll.getDomainObject().getOID());
|
|
||||||
} else {
|
|
||||||
fillString = id.toString();// + " (" + name + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
String title = ((ContentPage) coll.getDomainObject()).getTitle();
|
|
||||||
|
|
||||||
Label js = new Label(
|
|
||||||
generateJSLabel(id, widget, searchWidget, fillString, title),
|
|
||||||
false);
|
|
||||||
container.add(js);
|
|
||||||
|
|
||||||
String url = "#";
|
|
||||||
|
|
||||||
Link link = new Link(name, url);
|
|
||||||
link.setClassAttr("title");
|
|
||||||
link.setOnClick("return fillItem" + id + "()");
|
|
||||||
|
|
||||||
container.add(link);
|
|
||||||
|
|
||||||
return container;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String generateJSLabel(BigDecimal id, String widget, String searchWidget,
|
|
||||||
String fill, String title) {
|
|
||||||
StringBuilder buffer = new StringBuilder();
|
|
||||||
buffer.append(" <script language=javascript> ");
|
|
||||||
buffer.append(" <!-- \n");
|
|
||||||
buffer.append(" function fillItem").append(id).append("() { \n");
|
|
||||||
buffer.append(" window.opener.document.").append(widget).append(".value=\"").
|
|
||||||
append(fill).append("\";\n");
|
|
||||||
if (searchWidget != null) {
|
|
||||||
buffer.append(" window.opener.document.").append(searchWidget).append(".value=\"").
|
|
||||||
append(title.
|
|
||||||
replace("\"", "\\\"")).append("\";\n");
|
|
||||||
}
|
|
||||||
// set protocol to 'other' in FCKEditor, else relative url prepended by http://
|
|
||||||
if (Bebop.getConfig().getDHTMLEditor().equals(
|
|
||||||
BebopConstants.BEBOP_FCKEDITOR)) {
|
|
||||||
buffer.append(
|
|
||||||
" if(window.opener.document.getElementById('cmbLinkProtocol')) {\n");
|
|
||||||
buffer.append(
|
|
||||||
" window.opener.document.getElementById('cmbLinkProtocol').value=\"\";\n");
|
|
||||||
buffer.append(" }\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.append(" self.close(); \n"
|
|
||||||
+ " return false; \n"
|
|
||||||
+ " } \n"
|
|
||||||
+ " --> \n"
|
|
||||||
+ " </script> ");
|
|
||||||
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Table model around ItemCollection
|
|
||||||
*/
|
|
||||||
private static class FolderTableModel implements TableModel {
|
|
||||||
|
|
||||||
private static final int NAME = 0;
|
|
||||||
private static final int TITLE = 1;
|
|
||||||
private static final int TYPE = 2;
|
|
||||||
private Folder.ItemCollection m_itemColl;
|
|
||||||
|
|
||||||
public FolderTableModel(Folder.ItemCollection itemColl) {
|
|
||||||
m_itemColl = itemColl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean nextRow() {
|
|
||||||
return m_itemColl != null ? m_itemColl.next() : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getElementAt(int columnIndex) {
|
|
||||||
switch (columnIndex) {
|
|
||||||
case NAME:
|
|
||||||
return m_itemColl;
|
|
||||||
case TITLE:
|
|
||||||
return m_itemColl.getDisplayName();
|
|
||||||
case TYPE:
|
|
||||||
return m_itemColl.getTypeLabel();
|
|
||||||
default:
|
|
||||||
throw new IndexOutOfBoundsException("Column index "
|
|
||||||
+ columnIndex
|
|
||||||
+ " not in table model.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getKeyAt(int columnIndex) {
|
|
||||||
// Mark folders by using their negative ID (dirty, dirty)
|
|
||||||
return (m_itemColl.isFolder()) ? m_itemColl.getID().negate()
|
|
||||||
: m_itemColl.getID();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class FolderChanger extends TableActionAdapter {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(TableActionEvent e) {
|
|
||||||
PageState s = e.getPageState();
|
|
||||||
int col = e.getColumn().intValue();
|
|
||||||
|
|
||||||
if (m_nameColumn != getColumn(col)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String key = (String) e.getRowKey();
|
|
||||||
if (key.startsWith("-")) {
|
|
||||||
clearSelection(s);
|
|
||||||
getFolderSelectionModel().setSelectedKey(s, key.substring(1));
|
|
||||||
m_paginator.reset(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getting the GlobalizedMessage using a CMS Class targetBundle.
|
|
||||||
*
|
|
||||||
* @param key The resource key
|
|
||||||
*
|
|
||||||
* @pre ( key != null )
|
|
||||||
*/
|
|
||||||
private static GlobalizedMessage globalize(String key) {
|
|
||||||
//return FolderManipulator.globalize(key);
|
|
||||||
final GlobalisationUtil util = new GlobalisationUtil(
|
|
||||||
"com.arsdigita.cms."
|
|
||||||
+ "ui.folder.CMSFolderResources");
|
|
||||||
return util.globalize(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -27,25 +27,40 @@ import com.arsdigita.bebop.event.RequestListener;
|
||||||
import com.arsdigita.bebop.parameters.BigDecimalParameter;
|
import com.arsdigita.bebop.parameters.BigDecimalParameter;
|
||||||
import com.arsdigita.bebop.parameters.BooleanParameter;
|
import com.arsdigita.bebop.parameters.BooleanParameter;
|
||||||
import com.arsdigita.bebop.parameters.IntegerParameter;
|
import com.arsdigita.bebop.parameters.IntegerParameter;
|
||||||
|
import com.arsdigita.bebop.parameters.LongParameter;
|
||||||
import com.arsdigita.bebop.parameters.StringParameter;
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
import com.arsdigita.cms.dispatcher.CMSPage;
|
import com.arsdigita.cms.dispatcher.CMSPage;
|
||||||
import com.arsdigita.dispatcher.RequestContext;
|
import com.arsdigita.dispatcher.RequestContext;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.templating.PresentationManager;
|
import com.arsdigita.templating.PresentationManager;
|
||||||
import com.arsdigita.templating.Templating;
|
import com.arsdigita.templating.Templating;
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
import com.arsdigita.util.UncheckedWrapperException;
|
||||||
|
|
||||||
import org.libreccm.web.CcmApplication;
|
import org.libreccm.web.CcmApplication;
|
||||||
|
|
||||||
import com.arsdigita.web.Web;
|
import com.arsdigita.web.Web;
|
||||||
import com.arsdigita.xml.Document;
|
import com.arsdigita.xml.Document;
|
||||||
|
|
||||||
|
import org.arsdigita.cms.CMSConfig;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.security.Shiro;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
import org.librecms.contentsection.ContentItemVersion;
|
||||||
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
import org.librecms.contentsection.ContentSectionRepository;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>The Item Search page.</p>
|
* <p>
|
||||||
|
* The Item Search page.</p>
|
||||||
*
|
*
|
||||||
* @author Scott Seago (scott@arsdigita.com)
|
* @author Scott Seago (scott@arsdigita.com)
|
||||||
* @author Sören Bernstein <quasi@quasiweb.de>
|
* @author Sören Bernstein <quasi@quasiweb.de>
|
||||||
|
|
@ -53,27 +68,33 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
*/
|
*/
|
||||||
public class ItemSearchPage extends CMSPage {
|
public class ItemSearchPage extends CMSPage {
|
||||||
|
|
||||||
private final static String XSL_CLASS = "CMS Admin";
|
|
||||||
private TabbedPane m_tabbedPane;
|
|
||||||
private ItemSearchFlatBrowsePane m_flatBrowse;
|
|
||||||
private ItemSearchBrowsePane m_browse;
|
|
||||||
private ItemSearchPopup m_search;
|
|
||||||
private ItemSearchCreateItemPane m_create;
|
|
||||||
private BigDecimalParameter m_sectionId;
|
|
||||||
private int m_lastTab;
|
|
||||||
private static final CMSConfig s_conf = CMSConfig.getInstanceOf();
|
|
||||||
private static final boolean LIMIT_TO_CONTENT_SECTION = false;
|
|
||||||
public static final String CONTENT_SECTION = "section_id";
|
public static final String CONTENT_SECTION = "section_id";
|
||||||
|
|
||||||
|
private static final boolean LIMIT_TO_CONTENT_SECTION = false;
|
||||||
|
private final static String XSL_CLASS = "CMS Admin";
|
||||||
|
|
||||||
|
private TabbedPane tabbedPane;
|
||||||
|
private ItemSearchFlatBrowsePane flatBrowsePane;
|
||||||
|
private ItemSearchBrowsePane browsePane;
|
||||||
|
private ItemSearchPopup searchPopup;
|
||||||
|
// private ItemSearchCreateItemPane m_create;
|
||||||
|
private final LongParameter sectionId;
|
||||||
|
private int lastTab;
|
||||||
|
private static final CMSConfig CONFIG = CMSConfig.getConfig();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new ItemSearchPage
|
* Construct a new ItemSearchPage
|
||||||
*/
|
*/
|
||||||
public ItemSearchPage() {
|
public ItemSearchPage() {
|
||||||
super(GlobalizationUtil.globalize("cms.ui.item_search.page_title").localize().toString(), new SimpleContainer());
|
super(new GlobalizedMessage("cms.ui.item_search.page_title",
|
||||||
|
CmsConstants.CMS_BUNDLE).localize()
|
||||||
|
.toString(),
|
||||||
|
new SimpleContainer());
|
||||||
|
|
||||||
setClassAttr("cms-admin");
|
setClassAttr("cms-admin");
|
||||||
|
|
||||||
addGlobalStateParam(new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM));
|
addGlobalStateParam(
|
||||||
|
new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM));
|
||||||
addGlobalStateParam(new StringParameter(ItemSearchPopup.WIDGET_PARAM));
|
addGlobalStateParam(new StringParameter(ItemSearchPopup.WIDGET_PARAM));
|
||||||
addGlobalStateParam(new StringParameter("searchWidget"));
|
addGlobalStateParam(new StringParameter("searchWidget"));
|
||||||
addGlobalStateParam(new StringParameter("publishWidget"));
|
addGlobalStateParam(new StringParameter("publishWidget"));
|
||||||
|
|
@ -81,64 +102,71 @@ public class ItemSearchPage extends CMSPage {
|
||||||
addGlobalStateParam(new IntegerParameter("lastTab"));
|
addGlobalStateParam(new IntegerParameter("lastTab"));
|
||||||
addGlobalStateParam(new BooleanParameter("disableCreatePane"));
|
addGlobalStateParam(new BooleanParameter("disableCreatePane"));
|
||||||
addGlobalStateParam(new BooleanParameter("editAfterCreate"));
|
addGlobalStateParam(new BooleanParameter("editAfterCreate"));
|
||||||
addGlobalStateParam(new StringParameter("queryField"));
|
addGlobalStateParam(new StringParameter("queryField"));
|
||||||
m_sectionId = new BigDecimalParameter(CONTENT_SECTION);
|
sectionId = new LongParameter(CONTENT_SECTION);
|
||||||
addGlobalStateParam(m_sectionId);
|
addGlobalStateParam(sectionId);
|
||||||
|
|
||||||
m_flatBrowse = getFlatBrowsePane();
|
flatBrowsePane = getFlatBrowsePane();
|
||||||
m_browse = getBrowsePane();
|
browsePane = getBrowsePane();
|
||||||
m_search = getSearchPane();
|
searchPopup = getSearchPane();
|
||||||
m_create = getCreatePane();
|
// m_create = getCreatePane();
|
||||||
|
|
||||||
m_tabbedPane = createTabbedPane();
|
tabbedPane = createTabbedPane();
|
||||||
m_tabbedPane.setIdAttr("page-body");
|
tabbedPane.setIdAttr("page-body");
|
||||||
add(m_tabbedPane);
|
add(tabbedPane);
|
||||||
|
|
||||||
addRequestListener(new RequestListener() {
|
addRequestListener(new RequestListener() {
|
||||||
|
|
||||||
public void pageRequested(final RequestEvent event) {
|
public void pageRequested(final RequestEvent event) {
|
||||||
final PageState state = event.getPageState();
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
final String query = (String) state.getValue(new StringParameter(ItemSearchPopup.QUERY));
|
final String query = (String) state.getValue(
|
||||||
final Boolean disableCreatePane = (Boolean) state.getValue(new BooleanParameter("disableCreatePane"));
|
new StringParameter(ItemSearchPopup.QUERY));
|
||||||
|
final Boolean disableCreatePane = (Boolean) state.getValue(
|
||||||
|
new BooleanParameter("disableCreatePane"));
|
||||||
|
|
||||||
BigDecimal typeParam =
|
BigDecimal typeParam = (BigDecimal) state.getValue(
|
||||||
(BigDecimal) state.getValue(new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM));
|
new BigDecimalParameter(ItemSearch.SINGLE_TYPE_PARAM));
|
||||||
if ((typeParam == null) || disableCreatePane) {
|
if ((typeParam == null) || disableCreatePane) {
|
||||||
m_tabbedPane.setTabVisible(state, m_create, false);
|
// tabbedPane.setTabVisible(state, m_create, false);
|
||||||
m_create.setVisible(state, false);
|
// m_create.setVisible(state, false);
|
||||||
} else {
|
} else {
|
||||||
m_tabbedPane.setTabVisible(state, m_create, true);
|
// tabbedPane.setTabVisible(state, m_create, true);
|
||||||
m_create.setVisible(state, true);
|
// m_create.setVisible(state, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.getValue(new IntegerParameter("lastTab")) == null) {
|
if (state.getValue(new IntegerParameter("lastTab")) == null) {
|
||||||
if ((query == null) || query.isEmpty()) {
|
if ((query == null) || query.isEmpty()) {
|
||||||
m_tabbedPane.setSelectedIndex(state, 1);
|
tabbedPane.setSelectedIndex(state, 1);
|
||||||
} else {
|
} else {
|
||||||
m_tabbedPane.setSelectedIndex(state, 0);
|
tabbedPane.setSelectedIndex(state, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// m_tabbedPane.setTabVisible(state, m_create, false);
|
// m_tabbedPane.setTabVisible(state, m_create, false);
|
||||||
// m_create.setVisible(state, false);
|
// m_create.setVisible(state, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state.setValue(new IntegerParameter("lastTab"), m_tabbedPane.getSelectedIndex(state));
|
state.setValue(new IntegerParameter("lastTab"), tabbedPane
|
||||||
|
.getSelectedIndex(state));
|
||||||
|
|
||||||
if (state.getValue(new StringParameter("defaultCreationFolder")) != null) {
|
if (state.getValue(new StringParameter("defaultCreationFolder"))
|
||||||
m_create.setDefaultFolder((String) state.getValue(new StringParameter("defaultCreationFolder")));
|
!= null) {
|
||||||
|
// m_create.setDefaultFolder((String) state.getValue(
|
||||||
|
// new StringParameter("defaultCreationFolder")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.getValue(new BooleanParameter("editAfterCreate")) != null) {
|
if (state.getValue(new BooleanParameter("editAfterCreate"))
|
||||||
m_create.setEditAfterCreate((Boolean) state.getValue(new BooleanParameter("editAfterCreate")));
|
!= null) {
|
||||||
|
// m_create.setEditAfterCreate((Boolean) state.getValue(
|
||||||
|
// new BooleanParameter("editAfterCreate")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.getValue(new StringParameter("queryField")) == null) {
|
if (state.getValue(new StringParameter("queryField")) == null) {
|
||||||
//Because of Bebops silly stateful behaviour we have to do this...
|
//Because of Bebops silly stateful behaviour we have to do this...
|
||||||
m_flatBrowse.resetQueryFields();
|
flatBrowsePane.resetQueryFields();
|
||||||
}else {
|
} else {
|
||||||
m_flatBrowse.addQueryField((String) state.getValue(new StringParameter("queryField")));
|
flatBrowsePane.addQueryField((String) state.getValue(
|
||||||
|
new StringParameter("queryField")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (m_lastTab != m_tabbedPane.getSelectedIndex(state)) {
|
// if (m_lastTab != m_tabbedPane.getSelectedIndex(state)) {
|
||||||
|
|
@ -156,7 +184,6 @@ public class ItemSearchPage extends CMSPage {
|
||||||
// } else {
|
// } else {
|
||||||
// m_tabbedPane.setSelectedIndex(state, 1);
|
// m_tabbedPane.setSelectedIndex(state, 1);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// if (m_tabbedPane.getCurrentPane(state) == m_create) {
|
// if (m_tabbedPane.getCurrentPane(state) == m_create) {
|
||||||
// m_tabbedPane.setTabVisible(state, m_create, false);
|
// m_tabbedPane.setTabVisible(state, m_create, false);
|
||||||
// m_create.setVisible(state, false);
|
// m_create.setVisible(state, false);
|
||||||
|
|
@ -175,7 +202,6 @@ public class ItemSearchPage extends CMSPage {
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// m_flatBrowse.addProcessListener(new FormProcessListener() {
|
// m_flatBrowse.addProcessListener(new FormProcessListener() {
|
||||||
//
|
//
|
||||||
// public void process(final FormSectionEvent fse) throws FormProcessException {
|
// public void process(final FormSectionEvent fse) throws FormProcessException {
|
||||||
|
|
@ -187,157 +213,175 @@ public class ItemSearchPage extends CMSPage {
|
||||||
// });
|
// });
|
||||||
} // END constructor
|
} // END constructor
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates, and then caches, the Browse pane.
|
* Creates, and then caches, the Browse pane.
|
||||||
*
|
*
|
||||||
* Overriding this method to return null will prevent this tab from
|
* Overriding this method to return null will prevent this tab from
|
||||||
* appearing. Note: not implemented yet.
|
* appearing. Note: not implemented yet.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
protected ItemSearchBrowsePane getBrowsePane() {
|
protected ItemSearchBrowsePane getBrowsePane() {
|
||||||
if (m_browse == null) {
|
if (browsePane == null) {
|
||||||
m_browse = new ItemSearchBrowsePane();
|
browsePane = new ItemSearchBrowsePane();
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_browse;
|
return browsePane;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ItemSearchFlatBrowsePane getFlatBrowsePane() {
|
protected ItemSearchFlatBrowsePane getFlatBrowsePane() {
|
||||||
if (m_flatBrowse == null) {
|
if (flatBrowsePane == null) {
|
||||||
//m_flatBrowse = new ItemSearchFlatBrowsePane("flatBrowse");
|
//m_flatBrowse = new ItemSearchFlatBrowsePane("flatBrowse");
|
||||||
m_flatBrowse = new ItemSearchFlatBrowsePane();
|
flatBrowsePane = new ItemSearchFlatBrowsePane();
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_flatBrowse;
|
return flatBrowsePane;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates, and then caches, the Creation pane.
|
* Creates, and then caches, the Creation pane. Overriding this method to
|
||||||
* Overriding this method to return null will prevent this tab from
|
* return null will prevent this tab from appearing.
|
||||||
* appearing.
|
|
||||||
*/
|
*/
|
||||||
protected ItemSearchPopup getSearchPane() {
|
protected ItemSearchPopup getSearchPane() {
|
||||||
if (m_search == null) {
|
if (searchPopup == null) {
|
||||||
// Always search in every content section
|
// Always search in every content section
|
||||||
// m_search = new ItemSearchPopup(ContentItem.DRAFT, CMS.getConfig().limitToContentSection());
|
// m_search = new ItemSearchPopup(ContentItem.DRAFT, CMS.getConfig().limitToContentSection());
|
||||||
m_search = new ItemSearchPopup(ContentItem.DRAFT, LIMIT_TO_CONTENT_SECTION);
|
searchPopup = new ItemSearchPopup(ContentItemVersion.DRAFT
|
||||||
|
.toString(),
|
||||||
|
LIMIT_TO_CONTENT_SECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_search;
|
return searchPopup;
|
||||||
}
|
|
||||||
|
|
||||||
protected ItemSearchCreateItemPane getCreatePane() {
|
|
||||||
if (m_create == null) {
|
|
||||||
m_create = new ItemSearchCreateItemPane(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_create;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// protected ItemSearchCreateItemPane getCreatePane() {
|
||||||
|
// if (m_create == null) {
|
||||||
|
// m_create = new ItemSearchCreateItemPane(this);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return m_create;
|
||||||
|
// }
|
||||||
/**
|
/**
|
||||||
* Created the TabbedPane to use for this page.
|
* 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,
|
* Sets the class attribute for this tabbed pane. The default implementation
|
||||||
* or to add additional tabs after the default CMS tabs are added.
|
* 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() {
|
protected TabbedPane createTabbedPane() {
|
||||||
TabbedPane pane = new TabbedPane();
|
TabbedPane pane = new TabbedPane();
|
||||||
pane.setClassAttr(XSL_CLASS);
|
pane.setClassAttr(XSL_CLASS);
|
||||||
|
|
||||||
|
|
||||||
addToPane(pane, "flatBrowse", getFlatBrowsePane());
|
addToPane(pane, "flatBrowse", getFlatBrowsePane());
|
||||||
addToPane(pane, "browse", getBrowsePane());
|
addToPane(pane, "browse", getBrowsePane());
|
||||||
addToPane(pane, "search", getSearchPane());
|
addToPane(pane, "search", getSearchPane());
|
||||||
addToPane(pane, "create", getCreatePane());
|
// addToPane(pane, "create", getCreatePane());
|
||||||
|
|
||||||
if ("browse".equals(s_conf.getItemSearchDefaultTab())) {
|
if ("browse".equals(CONFIG.getItemSearchDefaultTab())) {
|
||||||
pane.setDefaultPane(m_browse);
|
pane.setDefaultPane(browsePane);
|
||||||
}
|
}
|
||||||
if ("search".equals(s_conf.getItemSearchDefaultTab())) {
|
if ("search".equals(CONFIG.getItemSearchDefaultTab())) {
|
||||||
pane.setDefaultPane(m_search);
|
pane.setDefaultPane(searchPopup);
|
||||||
}
|
}
|
||||||
|
|
||||||
//pane.setDefaultPane(m_flatBrowse);
|
//pane.setDefaultPane(m_flatBrowse);
|
||||||
pane.setDefaultPane(m_browse);
|
pane.setDefaultPane(browsePane);
|
||||||
|
|
||||||
return pane;
|
return pane;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the specified component, with the specified tab name, to the
|
* Adds the specified component, with the specified tab name, to the tabbed
|
||||||
* tabbed pane only if it is not null.
|
* pane only if it is not null.
|
||||||
*
|
*
|
||||||
* @param pane The pane to which to add the tab
|
* @param pane The pane to which to add the tab
|
||||||
* @param tabName The name of the tab if it's added
|
* @param tabName The name of the tab if it's added
|
||||||
* @param comp The component to add to the pane
|
* @param comp The component to add to the pane
|
||||||
*/
|
*/
|
||||||
protected void addToPane(TabbedPane pane, String tabName, Component comp) {
|
protected void addToPane(final TabbedPane pane,
|
||||||
|
final String tabName,
|
||||||
|
final Component comp) {
|
||||||
if (comp != null) {
|
if (comp != null) {
|
||||||
|
pane.addTab(new GlobalizedMessage(String.format(
|
||||||
pane.addTab(GlobalizationUtil
|
"cms.ui.item_search.%s", tabName), CmsConstants.CMS_BUNDLE)
|
||||||
.globalize("cms.ui.item_search." + tabName)
|
.localize().toString(),
|
||||||
.localize().toString()
|
comp);
|
||||||
,comp);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This strange voodoo from Dan. No idea what it does.
|
* This strange voodoo from Dan. No idea what it does.
|
||||||
|
*
|
||||||
|
* @throws java.io.IOException
|
||||||
|
* @throws javax.servlet.ServletException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void dispatch(final HttpServletRequest request,
|
public void dispatch(final HttpServletRequest request,
|
||||||
final HttpServletResponse response,
|
final HttpServletResponse response,
|
||||||
RequestContext actx)
|
final RequestContext actx) {
|
||||||
throws IOException, ServletException {
|
|
||||||
new CMSExcursion() {
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final Shiro shiro = cdiUtil.findBean(Shiro.class);
|
||||||
|
|
||||||
|
shiro.getSystemUser().execute(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void excurse()
|
public void run() {
|
||||||
throws IOException, ServletException {
|
|
||||||
ContentSection section = null;
|
|
||||||
Application app = Web.getWebContext().getApplication();
|
|
||||||
if (app instanceof ContentSection) {
|
|
||||||
section = (ContentSection) app;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
section = new ContentSection((BigDecimal) m_sectionId.transformValue(request));
|
|
||||||
} catch (DataObjectNotFoundException ex) {
|
|
||||||
throw new UncheckedWrapperException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setContentSection(section);
|
|
||||||
|
|
||||||
final Document doc = buildDocument(request, response);
|
final CcmApplication application = Web.getWebContext()
|
||||||
final PresentationManager pm =
|
.getApplication();
|
||||||
Templating.getPresentationManager();
|
|
||||||
|
final CdiUtil util = CdiUtil.createCdiUtil();
|
||||||
|
final ContentSectionRepository sectionRepo = util.findBean(
|
||||||
|
ContentSectionRepository.class);
|
||||||
|
|
||||||
|
final ContentSection section;
|
||||||
|
if (application instanceof ContentSection) {
|
||||||
|
section = (ContentSection) application;
|
||||||
|
} else {
|
||||||
|
section = sectionRepo.findById(Long.parseLong(
|
||||||
|
(String) sectionId.transformValue(request)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Web.getWebContext().setContentSection(section);
|
||||||
|
|
||||||
|
final Document doc;
|
||||||
|
try {
|
||||||
|
doc = buildDocument(request, response);
|
||||||
|
} catch (ServletException ex) {
|
||||||
|
throw new UncheckedWrapperException(ex);
|
||||||
|
}
|
||||||
|
final PresentationManager pm = Templating
|
||||||
|
.getPresentationManager();
|
||||||
|
|
||||||
pm.servePage(doc, request, response);
|
pm.servePage(doc, request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
}.run();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setTabActive(final PageState state, final Component component, final boolean value) {
|
protected void setTabActive(final PageState state, final Component component,
|
||||||
m_tabbedPane.setTabVisible(state, component, value);
|
final boolean value) {
|
||||||
|
tabbedPane.setTabVisible(state, component, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setTabActive(final PageState state, final int index, final boolean value) {
|
protected void setTabActive(final PageState state, final int index,
|
||||||
m_tabbedPane.setTabVisible(state, index, value);
|
final boolean value) {
|
||||||
|
tabbedPane.setTabVisible(state, index, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setDefaultCreationFolder(final Folder folder) {
|
// protected void setDefaultCreationFolder(final Folder folder) {
|
||||||
m_create.setDefaultFolder(folder.getOID().toString());
|
// m_create.setDefaultFolder(folder.getOID().toString());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
protected void setEditAfterCreate(final boolean editAfterCreate) {
|
// protected void setEditAfterCreate(final boolean editAfterCreate) {
|
||||||
m_create.setEditAfterCreate(editAfterCreate);
|
// m_create.setEditAfterCreate(editAfterCreate);
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,200 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.Component;
|
||||||
|
import com.arsdigita.bebop.Page;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.search.SearchConstants;
|
||||||
|
|
||||||
|
import org.librecms.contentsection.ContentItem;
|
||||||
|
|
||||||
|
import com.arsdigita.xml.Element;
|
||||||
|
|
||||||
|
import com.arsdigita.search.ui.QueryGenerator;
|
||||||
|
import com.arsdigita.search.ui.ResultsPane;
|
||||||
|
import com.arsdigita.web.Web;
|
||||||
|
|
||||||
|
import org.libreccm.core.CcmObject;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An extension of {@link ItemSearch} for use in a popup search window. The
|
||||||
|
* display of results is altered so that selecting a result closes the window &
|
||||||
|
* passes the id of the selected item back to the opener.
|
||||||
|
*
|
||||||
|
* @author Stanislav Freidin (sfreidin@arsdigita.com)
|
||||||
|
* @author <a href=mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class ItemSearchPopup extends ItemSearch {
|
||||||
|
|
||||||
|
// private static final org.apache.log4j.Logger s_log = org.apache.log4j.Logger.getLogger(
|
||||||
|
// ItemSearchPopup.class);
|
||||||
|
public static final String WIDGET_PARAM = "widget";
|
||||||
|
public static final String URL_PARAM = "useURL";
|
||||||
|
public static final String QUERY = "query";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new <code>ItemSearchPopup</code> component
|
||||||
|
*
|
||||||
|
* @param context the context for the retrieved items. Should
|
||||||
|
* be {@link ContentItem#DRAFT} or
|
||||||
|
* {@link ContentItem#LIVE}
|
||||||
|
* @param limitToContentSection limit the search to the current content
|
||||||
|
* section
|
||||||
|
*/
|
||||||
|
public ItemSearchPopup(final String context,
|
||||||
|
final boolean limitToContentSection) {
|
||||||
|
super(context, limitToContentSection);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide results by default
|
||||||
|
@Override
|
||||||
|
public void register(final Page page) {
|
||||||
|
super.register(page);
|
||||||
|
page.addGlobalStateParam(new StringParameter(WIDGET_PARAM));
|
||||||
|
page.addGlobalStateParam(new StringParameter(URL_PARAM));
|
||||||
|
page.addGlobalStateParam(new StringParameter(QUERY));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ItemSearchSection createSearchSection(
|
||||||
|
final String context, final boolean limitToContentSection) {
|
||||||
|
return new ItemSearchSectionPopup(context, limitToContentSection);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ItemSearchSectionPopup extends ItemSearchSection {
|
||||||
|
|
||||||
|
public ItemSearchSectionPopup(final String context,
|
||||||
|
final boolean limitToContentSection) {
|
||||||
|
super(context, limitToContentSection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Component createResultsPane(final QueryGenerator generator) {
|
||||||
|
return new PopupResultsPane(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default context is Live.No need to append &context=live explicitly.
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @param objectId
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getItemURL(final HttpServletRequest request,
|
||||||
|
final Long objectId) {
|
||||||
|
// redirect doesn't use /ccm prefix for some reason, so just returning the raw string.
|
||||||
|
//ParameterMap map = new ParameterMap();
|
||||||
|
//map.setParameter("oid", oid.toString());
|
||||||
|
//return URL.there(request, "/redirect/", map).toString();
|
||||||
|
// Always link directly to the live version.
|
||||||
|
if (Web.getWebappContextPath() == null) {
|
||||||
|
return "/redirect/?oid=" + objectId.toString();
|
||||||
|
} else {
|
||||||
|
return Web.getWebappContextPath() + "/redirect/?oid=" + objectId
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class PopupResultsPane extends ResultsPane {
|
||||||
|
|
||||||
|
public PopupResultsPane(final QueryGenerator generator) {
|
||||||
|
super(generator);
|
||||||
|
setRelativeURLs(true);
|
||||||
|
setSearchHelpMsg(new GlobalizedMessage("cms.ui.search.help",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
|
setNoResultsMsg(new GlobalizedMessage("cms.ui.search.no_results",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Element generateDocumentXML(final PageState state,
|
||||||
|
final CcmObject doc) {
|
||||||
|
final Element element = super.generateDocumentXML(state, doc);
|
||||||
|
|
||||||
|
element.addAttribute("class", "jsButton");
|
||||||
|
|
||||||
|
final String widget = (String) state.getValue(new StringParameter(
|
||||||
|
WIDGET_PARAM));
|
||||||
|
final String searchWidget = (String) state.getValue(
|
||||||
|
new StringParameter("searchWidget"));
|
||||||
|
|
||||||
|
final boolean useURL = "true".equals(state.getValue(
|
||||||
|
new StringParameter(URL_PARAM)));
|
||||||
|
|
||||||
|
String fillString;
|
||||||
|
if (useURL) {
|
||||||
|
fillString = getItemURL(state.getRequest(), doc.getObjectId());
|
||||||
|
} else {
|
||||||
|
fillString = Long.toString(doc.getObjectId());
|
||||||
|
}
|
||||||
|
|
||||||
|
final String title = doc.getDisplayName();
|
||||||
|
|
||||||
|
final Element jsLabel = new Element(
|
||||||
|
SearchConstants.XML_PREFIX + "jsAction",
|
||||||
|
SearchConstants.XML_NS);
|
||||||
|
jsLabel.addAttribute(
|
||||||
|
"name", "fillItem" + Long.toString(doc.getObjectId()) + "()");
|
||||||
|
jsLabel.setText(generateJSLabel(doc.getObjectId(),
|
||||||
|
widget,
|
||||||
|
searchWidget,
|
||||||
|
fillString,
|
||||||
|
title));
|
||||||
|
jsLabel.addAttribute("action",
|
||||||
|
String.format(
|
||||||
|
"window.opener.document.%s.value = \"%s\"; self.close(); return false;",
|
||||||
|
widget,
|
||||||
|
fillString));
|
||||||
|
element.addContent(jsLabel);
|
||||||
|
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String generateJSLabel(final Long docId,
|
||||||
|
final String widget,
|
||||||
|
final String searchWidget,
|
||||||
|
final String fill,
|
||||||
|
final String title) {
|
||||||
|
return " <script language=\"javascript\"> "
|
||||||
|
+ " <!-- \n"
|
||||||
|
+ " function fillItem" + docId + "() { \n"
|
||||||
|
+ " alert('test');\n"
|
||||||
|
+ " window.opener.document." + widget + ".value=\""
|
||||||
|
+ fill + "\";\n"
|
||||||
|
+ " self.close(); \n"
|
||||||
|
+ " return false; \n"
|
||||||
|
+ " } \n"
|
||||||
|
+ " --> \n"
|
||||||
|
+ " </script> ";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -26,28 +26,26 @@ import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.search.SearchConstants;
|
import com.arsdigita.search.SearchConstants;
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
import com.arsdigita.util.UncheckedWrapperException;
|
||||||
|
|
||||||
import org.libreccm.security.Party;
|
|
||||||
import com.arsdigita.xml.Element;
|
import com.arsdigita.xml.Element;
|
||||||
import com.arsdigita.xml.XML;
|
import com.arsdigita.xml.XML;
|
||||||
|
|
||||||
import com.arsdigita.web.URL;
|
import com.arsdigita.web.URL;
|
||||||
import com.arsdigita.web.ParameterMap;
|
import com.arsdigita.web.ParameterMap;
|
||||||
import com.arsdigita.web.Web;
|
import com.arsdigita.web.Web;
|
||||||
|
|
||||||
import java.beans.BeanInfo;
|
import java.beans.BeanInfo;
|
||||||
import java.beans.IntrospectionException;
|
import java.beans.IntrospectionException;
|
||||||
import java.beans.Introspector;
|
import java.beans.Introspector;
|
||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.logging.Level;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue