CCM NG/ccm-cms: ArticlePropertyForm now works
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4830 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
da7c2a5190
commit
d0c7265b13
|
|
@ -101,7 +101,7 @@ public class ArticlePropertiesStep extends GenericArticlePropertiesStep {
|
|||
|
||||
sheet.add(new GlobalizedMessage("cms.contenttypes.ui.lead",
|
||||
CmsConstants.CMS_BUNDLE),
|
||||
"lead");
|
||||
"description");
|
||||
|
||||
return sheet;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -430,7 +430,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
|||
// link if the current item is a template.
|
||||
final ContentItem item = itemRequestLocal.getContentItem(state);
|
||||
|
||||
// ToDo: Reable when Templates have been ported. Not clear yet if
|
||||
// ToDo: Reenable when Templates have been ported. Not clear yet if
|
||||
// Templates will be ContentItems in LibreCMS...
|
||||
// if (item instanceof Template) {
|
||||
// tabbedPane.setTabVisible(state, templatesPane, false);
|
||||
|
|
|
|||
|
|
@ -104,8 +104,7 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
|
|||
private static final Logger LOGGER = LogManager
|
||||
.getLogger(AuthoringKitWizard.class);
|
||||
|
||||
public final String SELECTED_LANGUAGE = "selectedLanguage";
|
||||
|
||||
// public final String SELECTED_LANGUAGE = "selectedLanguage";
|
||||
private static Class[] arguments = new Class[]{
|
||||
ItemSelectionModel.class,
|
||||
AuthoringKitWizard.class,
|
||||
|
|
@ -166,7 +165,8 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
|
|||
final ConfigurationManager confManager = cdiUtil.findBean(
|
||||
ConfigurationManager.class);
|
||||
|
||||
selectedLanguageParam = new StringParameter(SELECTED_LANGUAGE);
|
||||
selectedLanguageParam = new StringParameter(
|
||||
ContentItemPage.SELECTED_LANGUAGE);
|
||||
final GlobalizationHelper globalizationHelper = cdiUtil
|
||||
.findBean(GlobalizationHelper.class);
|
||||
selectedLanguageParam.setDefaultValue(globalizationHelper
|
||||
|
|
@ -431,7 +431,7 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
|
|||
}
|
||||
|
||||
page.addGlobalStateParam(selectedLanguageParam);
|
||||
|
||||
|
||||
page.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
|
|
@ -603,7 +603,7 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
|
|||
* @return The instance of the component.
|
||||
*/
|
||||
protected Component instantiateStep(final String className) {
|
||||
|
||||
|
||||
LOGGER.debug("Instantiating kit wizard \"{}\" with arguments {}...",
|
||||
className,
|
||||
arguments);
|
||||
|
|
@ -622,8 +622,9 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
|
|||
| InvocationTargetException
|
||||
| NoSuchMethodException
|
||||
| SecurityException ex) {
|
||||
LOGGER.error("Failed to instantiate authoring kit component \"{}\"...",
|
||||
className);
|
||||
LOGGER.error(
|
||||
"Failed to instantiate authoring kit component \"{}\"...",
|
||||
className);
|
||||
LOGGER.error("Exception is: ", ex);
|
||||
throw new UncheckedWrapperException(String.format(
|
||||
"Failed to instantiate authoring kit component \"%s\".",
|
||||
|
|
|
|||
|
|
@ -195,28 +195,33 @@ public abstract class BasicPageForm extends BasicItemForm {
|
|||
* Class specific implementation of FormValidationListener interface
|
||||
* (inherited from BasicItemForm).
|
||||
*
|
||||
* @param fse
|
||||
* @param event
|
||||
*
|
||||
* @throws FormProcessException
|
||||
*/
|
||||
@Override
|
||||
public void validate(final FormSectionEvent fse) throws FormProcessException {
|
||||
public void validate(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
super.validate(fse); //noop, BasicItemForm#validate does nothing
|
||||
super.validate(event);
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final ContentItem item = getItemSelectionModel()
|
||||
.getSelectedItem(fse.getPageState());
|
||||
.getSelectedItem(event.getPageState());
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ContentItemManager itemManager = cdiUtil
|
||||
.findBean(ContentItemManager.class);
|
||||
final BasicPageFormController controller = cdiUtil
|
||||
.findBean(BasicPageFormController.class);
|
||||
|
||||
final Optional<Folder> folder = itemManager.getItemFolder(item);
|
||||
final Optional<Folder> folder = controller.getItemFolder(item);
|
||||
if (folder.isPresent()) {
|
||||
final String name = fse.getFormData().getString(NAME);
|
||||
if (!item.getName()
|
||||
.getValue(KernelConfig.getConfig().getDefaultLocale())
|
||||
.equals(name)) {
|
||||
validateNameUniqueness(folder.get(), fse);
|
||||
final String name = event.getFormData().getString(NAME);
|
||||
final String selectedLang = (String) state
|
||||
.getValue(selectedLanguageParam);
|
||||
final Locale selectedLocale = new Locale(selectedLang);
|
||||
if (!item.getName().hasValue(selectedLocale)
|
||||
|| !item.getName().getValue(selectedLocale).equals(name)) {
|
||||
validateNameUniqueness(folder.get(), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -320,9 +325,9 @@ public abstract class BasicPageForm extends BasicItemForm {
|
|||
|
||||
if (workflowTemplate == null) {
|
||||
item = controller
|
||||
.createContentItem(name,
|
||||
section,
|
||||
folder,
|
||||
.createContentItem(name,
|
||||
section,
|
||||
folder,
|
||||
clazz,
|
||||
initializer,
|
||||
locale);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import org.librecms.contentsection.Folder;
|
|||
import org.librecms.contentsection.FolderRepository;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -126,4 +127,17 @@ class BasicPageFormController {
|
|||
return item;
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected Optional<Folder> getItemFolder(final ContentItem item) {
|
||||
|
||||
final Optional<ContentItem> contentItem = itemRepo
|
||||
.findById(item.getObjectId());
|
||||
|
||||
if (contentItem.isPresent()) {
|
||||
return itemManager.getItemFolder(contentItem.get());
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.bebop;
|
||||
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
// Renders strings as labels
|
||||
|
||||
public class GlobalizedLabelCellRenderer extends StringLabelCellRenderer {
|
||||
|
||||
public GlobalizedLabelCellRenderer(final String weight) {
|
||||
super(weight);
|
||||
}
|
||||
|
||||
public GlobalizedLabelCellRenderer(final boolean outputEscape) {
|
||||
super(outputEscape);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Label getLabel(final Object value) {
|
||||
return new Label((GlobalizedMessage) value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -25,11 +25,9 @@ import com.arsdigita.bebop.util.GlobalizationUtil;
|
|||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.util.LockableImpl;
|
||||
|
||||
|
||||
/**
|
||||
* Displays a list of label-value pairs that
|
||||
* represent the properties of some object. For example, a
|
||||
* typical <code>PropertySheet</code> may look like this:
|
||||
* Displays a list of label-value pairs that represent the properties of some
|
||||
* object. For example, a typical <code>PropertySheet</code> may look like this:
|
||||
* <p>
|
||||
* <table cellpadding=4 cellspacing=0 border=0>
|
||||
* <tr><th>First Name:</th><td>Stanislav</td></tr>
|
||||
|
|
@ -37,183 +35,117 @@ import com.arsdigita.util.LockableImpl;
|
|||
* <tr><th>Mission:</th><td>Sleep</td></tr>
|
||||
* </table>
|
||||
* <p>
|
||||
* This class relies on the {@link PropertySheetModelBuilder} to
|
||||
* supply it with the right {@link PropertySheetModel} during
|
||||
* each request. It is up to the user to provide the right
|
||||
* builder.
|
||||
* This class relies on the {@link PropertySheetModelBuilder} to supply it with
|
||||
* the right {@link PropertySheetModel} during each request. It is up to the
|
||||
* user to provide the right builder.
|
||||
* <p>
|
||||
*
|
||||
* @author Stanislav Freidin
|
||||
* @version $Id: PropertySheet.java 287 2005-02-22 00:29:02Z sskracic $
|
||||
*
|
||||
*/
|
||||
public class PropertySheet extends Table {
|
||||
|
||||
|
||||
private PropertySheetModelBuilder m_builder;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>PropertySheet</code>.
|
||||
*
|
||||
* @param modelBuilder the property sheet model builder
|
||||
* that is responsible for building the property
|
||||
* sheet model
|
||||
* @param modelBuilder the property sheet model builder that is responsible
|
||||
* for building the property sheet model
|
||||
*
|
||||
*/
|
||||
public PropertySheet(PropertySheetModelBuilder modelBuilder) {
|
||||
super(new PSTMBAdapter(modelBuilder), new Object[]{"Label", "Value"});
|
||||
super.setHeader(null);
|
||||
public PropertySheet(final PropertySheetModelBuilder modelBuilder) {
|
||||
|
||||
super.getColumn(0).setCellRenderer(new GlobalizedLabelCellRenderer(Label.BOLD));
|
||||
super.getColumn(1).setCellRenderer(new StringLabelCellRenderer(null));
|
||||
this(modelBuilder, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new <code>PropertySheet</code> and sets the output
|
||||
* escape value.
|
||||
* Constructs a new <code>PropertySheet</code> and sets the output escape
|
||||
* value.
|
||||
*
|
||||
* @param modelBuilder the property sheet model builder
|
||||
* that is responsible for building the property
|
||||
* sheet model
|
||||
* @param valueOutputEscape the value of the label-value
|
||||
* pair's output-escaping
|
||||
* @param modelBuilder the property sheet model builder that is
|
||||
* responsible for building the property sheet
|
||||
* model
|
||||
* @param valueOutputEscape the value of the label-value pair's
|
||||
* output-escaping
|
||||
*
|
||||
*/
|
||||
public PropertySheet(PropertySheetModelBuilder modelBuilder, boolean valueOutputEscape) {
|
||||
public PropertySheet(final PropertySheetModelBuilder modelBuilder,
|
||||
final boolean valueOutputEscape) {
|
||||
|
||||
super(new PSTMBAdapter(modelBuilder), new Object[]{"Label", "Value"});
|
||||
super.setHeader(null);
|
||||
|
||||
super.getColumn(0).setCellRenderer(new GlobalizedLabelCellRenderer(Label.BOLD));
|
||||
super.getColumn(1).setCellRenderer(new StringLabelCellRenderer(valueOutputEscape));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link PropertySheetModelBuilder}.
|
||||
* @return the {@link PropertySheetModelBuilder}.
|
||||
*/
|
||||
public PropertySheetModelBuilder getPropertySheetModelBuilder() {
|
||||
return m_builder;
|
||||
super
|
||||
.getColumn(0)
|
||||
.setCellRenderer(new GlobalizedLabelCellRenderer(Label.BOLD));
|
||||
super.getColumn(1).setCellRenderer(new StringLabelCellRenderer(
|
||||
valueOutputEscape));
|
||||
}
|
||||
|
||||
// Convert a PropertySheetModelBuilder to a TableModelBuilder
|
||||
private static class PSTMBAdapter
|
||||
extends LockableImpl implements TableModelBuilder {
|
||||
|
||||
private PropertySheetModelBuilder m_builder;
|
||||
private PropertySheetModelBuilder modelBuilder;
|
||||
|
||||
public PSTMBAdapter(PropertySheetModelBuilder b) {
|
||||
m_builder = b;
|
||||
public PSTMBAdapter(final PropertySheetModelBuilder modelBuilder) {
|
||||
this.modelBuilder = modelBuilder;
|
||||
}
|
||||
|
||||
public TableModel makeModel(Table t, PageState s) {
|
||||
@Override
|
||||
public TableModel makeModel(final Table table, final PageState state) {
|
||||
return new TableModelAdapter(
|
||||
m_builder.makeModel((PropertySheet)t, s)
|
||||
);
|
||||
modelBuilder.makeModel((PropertySheet) table, state)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lock() {
|
||||
m_builder.lock();
|
||||
modelBuilder.lock();
|
||||
super.lock();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Wraps a PropertySheetModel
|
||||
private static class TableModelAdapter implements TableModel {
|
||||
|
||||
private PropertySheetModel m_model;
|
||||
private int m_row;
|
||||
private final PropertySheetModel propertySheetModel;
|
||||
private int currentRow;
|
||||
|
||||
public TableModelAdapter(PropertySheetModel model) {
|
||||
m_model = model;
|
||||
m_row = -1;
|
||||
public TableModelAdapter(final PropertySheetModel propertySheetModel) {
|
||||
this.propertySheetModel = propertySheetModel;
|
||||
currentRow = -1;
|
||||
}
|
||||
|
||||
public int getColumnCount() { return 2; }
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextRow() {
|
||||
m_row++;
|
||||
return m_model.nextRow();
|
||||
currentRow++;
|
||||
return propertySheetModel.nextRow();
|
||||
}
|
||||
|
||||
public Object getElementAt(int columnIndex) {
|
||||
if(columnIndex == 0) {
|
||||
return m_model.getGlobalizedLabel();
|
||||
@Override
|
||||
public Object getElementAt(final int columnIndex) {
|
||||
if (columnIndex == 0) {
|
||||
return propertySheetModel.getGlobalizedLabel();
|
||||
} else {
|
||||
return m_model.getValue();
|
||||
return propertySheetModel.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
public Object getKeyAt(int columnIndex) {
|
||||
return new Integer(m_row);
|
||||
@Override
|
||||
public Object getKeyAt(final int columnIndex) {
|
||||
return currentRow;
|
||||
}
|
||||
|
||||
public PropertySheetModel getPSModel() {
|
||||
return m_model;
|
||||
return propertySheetModel;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Renders strings as labels
|
||||
public static class StringLabelCellRenderer implements TableCellRenderer {
|
||||
|
||||
private String m_weight;
|
||||
private boolean m_outputEscape = false;
|
||||
|
||||
public StringLabelCellRenderer(String weight) {
|
||||
m_weight = weight;
|
||||
}
|
||||
|
||||
public StringLabelCellRenderer(boolean outputEscape) {
|
||||
m_outputEscape = outputEscape;
|
||||
}
|
||||
|
||||
public Component getComponent(Table table, PageState state, Object value,
|
||||
boolean isSelected, Object key,
|
||||
int row, int column) {
|
||||
Label t = getLabel(value);
|
||||
//t.setOutputEscaping(false);
|
||||
t.setOutputEscaping(m_outputEscape);
|
||||
if(m_weight != null) {
|
||||
t.setFontWeight(m_weight);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
protected Label getLabel(Object value) {
|
||||
return new Label((String)value);
|
||||
}
|
||||
}
|
||||
|
||||
// Renders strings as labels
|
||||
public static class GlobalizedLabelCellRenderer extends StringLabelCellRenderer {
|
||||
|
||||
public GlobalizedLabelCellRenderer(String weight) {
|
||||
super(weight);
|
||||
}
|
||||
|
||||
public GlobalizedLabelCellRenderer(boolean outputEscape) {
|
||||
super(outputEscape);
|
||||
}
|
||||
|
||||
protected Label getLabel(Object value) {
|
||||
return new Label((GlobalizedMessage)value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An empty {@link PropertySheetModel}.
|
||||
*/
|
||||
public static final PropertySheetModel EMPTY_MODEL =
|
||||
new PropertySheetModel() {
|
||||
public boolean nextRow() { return false; }
|
||||
public String getLabel() {
|
||||
throw new IllegalStateException("The model is empty");
|
||||
}
|
||||
public GlobalizedMessage getGlobalizedLabel() {
|
||||
throw new IllegalStateException((String) GlobalizationUtil.globalize("bebop.the_model_is_empty").localize());
|
||||
}
|
||||
public String getValue() {
|
||||
throw new IllegalStateException("The model is empty");
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.bebop;
|
||||
|
||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
||||
|
||||
// Renders strings as labels
|
||||
|
||||
public class StringLabelCellRenderer implements TableCellRenderer {
|
||||
|
||||
private String weight;
|
||||
private boolean outputEscape = false;
|
||||
|
||||
public StringLabelCellRenderer(final String weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public StringLabelCellRenderer(boolean outputEscape) {
|
||||
this.outputEscape = outputEscape;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getComponent(final Table table,
|
||||
final PageState state, Object value,
|
||||
final boolean isSelected,
|
||||
final Object key,
|
||||
final int row,
|
||||
final int column) {
|
||||
final Label target = getLabel(value);
|
||||
target.setOutputEscaping(outputEscape);
|
||||
if (weight != null) {
|
||||
target.setFontWeight(weight);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
protected Label getLabel(Object value) {
|
||||
return new Label((String) value);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue