CCM NG/ccm-cms: ArticlePropertyForm now works

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4830 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2017-07-01 15:34:56 +00:00
parent da7c2a5190
commit d0c7265b13
8 changed files with 197 additions and 148 deletions

View File

@ -101,7 +101,7 @@ public class ArticlePropertiesStep extends GenericArticlePropertiesStep {
sheet.add(new GlobalizedMessage("cms.contenttypes.ui.lead", sheet.add(new GlobalizedMessage("cms.contenttypes.ui.lead",
CmsConstants.CMS_BUNDLE), CmsConstants.CMS_BUNDLE),
"lead"); "description");
return sheet; return sheet;
} }

View File

@ -430,7 +430,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
// link if the current item is a template. // link if the current item is a template.
final ContentItem item = itemRequestLocal.getContentItem(state); 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... // Templates will be ContentItems in LibreCMS...
// if (item instanceof Template) { // if (item instanceof Template) {
// tabbedPane.setTabVisible(state, templatesPane, false); // tabbedPane.setTabVisible(state, templatesPane, false);

View File

@ -104,8 +104,7 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
private static final Logger LOGGER = LogManager private static final Logger LOGGER = LogManager
.getLogger(AuthoringKitWizard.class); .getLogger(AuthoringKitWizard.class);
public final String SELECTED_LANGUAGE = "selectedLanguage"; // public final String SELECTED_LANGUAGE = "selectedLanguage";
private static Class[] arguments = new Class[]{ private static Class[] arguments = new Class[]{
ItemSelectionModel.class, ItemSelectionModel.class,
AuthoringKitWizard.class, AuthoringKitWizard.class,
@ -166,7 +165,8 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
final ConfigurationManager confManager = cdiUtil.findBean( final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class); ConfigurationManager.class);
selectedLanguageParam = new StringParameter(SELECTED_LANGUAGE); selectedLanguageParam = new StringParameter(
ContentItemPage.SELECTED_LANGUAGE);
final GlobalizationHelper globalizationHelper = cdiUtil final GlobalizationHelper globalizationHelper = cdiUtil
.findBean(GlobalizationHelper.class); .findBean(GlobalizationHelper.class);
selectedLanguageParam.setDefaultValue(globalizationHelper selectedLanguageParam.setDefaultValue(globalizationHelper
@ -622,7 +622,8 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
| InvocationTargetException | InvocationTargetException
| NoSuchMethodException | NoSuchMethodException
| SecurityException ex) { | SecurityException ex) {
LOGGER.error("Failed to instantiate authoring kit component \"{}\"...", LOGGER.error(
"Failed to instantiate authoring kit component \"{}\"...",
className); className);
LOGGER.error("Exception is: ", ex); LOGGER.error("Exception is: ", ex);
throw new UncheckedWrapperException(String.format( throw new UncheckedWrapperException(String.format(

View File

@ -195,28 +195,33 @@ public abstract class BasicPageForm extends BasicItemForm {
* Class specific implementation of FormValidationListener interface * Class specific implementation of FormValidationListener interface
* (inherited from BasicItemForm). * (inherited from BasicItemForm).
* *
* @param fse * @param event
* *
* @throws FormProcessException * @throws FormProcessException
*/ */
@Override @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() final ContentItem item = getItemSelectionModel()
.getSelectedItem(fse.getPageState()); .getSelectedItem(event.getPageState());
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentItemManager itemManager = cdiUtil final BasicPageFormController controller = cdiUtil
.findBean(ContentItemManager.class); .findBean(BasicPageFormController.class);
final Optional<Folder> folder = itemManager.getItemFolder(item); final Optional<Folder> folder = controller.getItemFolder(item);
if (folder.isPresent()) { if (folder.isPresent()) {
final String name = fse.getFormData().getString(NAME); final String name = event.getFormData().getString(NAME);
if (!item.getName() final String selectedLang = (String) state
.getValue(KernelConfig.getConfig().getDefaultLocale()) .getValue(selectedLanguageParam);
.equals(name)) { final Locale selectedLocale = new Locale(selectedLang);
validateNameUniqueness(folder.get(), fse); if (!item.getName().hasValue(selectedLocale)
|| !item.getName().getValue(selectedLocale).equals(name)) {
validateNameUniqueness(folder.get(), event);
} }
} }
} }

View File

@ -30,6 +30,7 @@ import org.librecms.contentsection.Folder;
import org.librecms.contentsection.FolderRepository; import org.librecms.contentsection.FolderRepository;
import java.util.Locale; import java.util.Locale;
import java.util.Optional;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
@ -126,4 +127,17 @@ class BasicPageFormController {
return item; 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();
}
}
} }

View File

@ -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);
}
}

View File

@ -25,11 +25,9 @@ import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.LockableImpl; import com.arsdigita.util.LockableImpl;
/** /**
* Displays a list of label-value pairs that * Displays a list of label-value pairs that represent the properties of some
* represent the properties of some object. For example, a * object. For example, a typical <code>PropertySheet</code> may look like this:
* typical <code>PropertySheet</code> may look like this:
* <p> * <p>
* <table cellpadding=4 cellspacing=0 border=0> * <table cellpadding=4 cellspacing=0 border=0>
* <tr><th>First Name:</th><td>Stanislav</td></tr> * <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> * <tr><th>Mission:</th><td>Sleep</td></tr>
* </table> * </table>
* <p> * <p>
* This class relies on the {@link PropertySheetModelBuilder} to * This class relies on the {@link PropertySheetModelBuilder} to supply it with
* supply it with the right {@link PropertySheetModel} during * the right {@link PropertySheetModel} during each request. It is up to the
* each request. It is up to the user to provide the right * user to provide the right builder.
* builder.
* <p> * <p>
* *
* @author Stanislav Freidin * @author Stanislav Freidin
* @version $Id: PropertySheet.java 287 2005-02-22 00:29:02Z sskracic $
* *
*/ */
public class PropertySheet extends Table { public class PropertySheet extends Table {
private PropertySheetModelBuilder m_builder;
/** /**
* Constructs a new <code>PropertySheet</code>. * Constructs a new <code>PropertySheet</code>.
* *
* @param modelBuilder the property sheet model builder * @param modelBuilder the property sheet model builder that is responsible
* that is responsible for building the property * for building the property sheet model
* sheet model
* *
*/ */
public PropertySheet(PropertySheetModelBuilder modelBuilder) { public PropertySheet(final PropertySheetModelBuilder modelBuilder) {
super(new PSTMBAdapter(modelBuilder), new Object[]{"Label", "Value"});
super.setHeader(null);
super.getColumn(0).setCellRenderer(new GlobalizedLabelCellRenderer(Label.BOLD)); this(modelBuilder, false);
super.getColumn(1).setCellRenderer(new StringLabelCellRenderer(null));
} }
/** /**
* Constructs a new <code>PropertySheet</code> and sets the output * Constructs a new <code>PropertySheet</code> and sets the output escape
* escape value. * value.
* *
* @param modelBuilder the property sheet model builder * @param modelBuilder the property sheet model builder that is
* that is responsible for building the property * responsible for building the property sheet
* sheet model * model
* @param valueOutputEscape the value of the label-value * @param valueOutputEscape the value of the label-value pair's
* pair's output-escaping * 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(new PSTMBAdapter(modelBuilder), new Object[]{"Label", "Value"});
super.setHeader(null); super.setHeader(null);
super.getColumn(0).setCellRenderer(new GlobalizedLabelCellRenderer(Label.BOLD)); super
super.getColumn(1).setCellRenderer(new StringLabelCellRenderer(valueOutputEscape)); .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;
} }
// Convert a PropertySheetModelBuilder to a TableModelBuilder // Convert a PropertySheetModelBuilder to a TableModelBuilder
private static class PSTMBAdapter private static class PSTMBAdapter
extends LockableImpl implements TableModelBuilder { extends LockableImpl implements TableModelBuilder {
private PropertySheetModelBuilder m_builder; private PropertySheetModelBuilder modelBuilder;
public PSTMBAdapter(PropertySheetModelBuilder b) { public PSTMBAdapter(final PropertySheetModelBuilder modelBuilder) {
m_builder = b; this.modelBuilder = modelBuilder;
} }
public TableModel makeModel(Table t, PageState s) { @Override
public TableModel makeModel(final Table table, final PageState state) {
return new TableModelAdapter( return new TableModelAdapter(
m_builder.makeModel((PropertySheet)t, s) modelBuilder.makeModel((PropertySheet) table, state)
); );
} }
@Override
public void lock() { public void lock() {
m_builder.lock(); modelBuilder.lock();
super.lock(); super.lock();
} }
} }
// Wraps a PropertySheetModel // Wraps a PropertySheetModel
private static class TableModelAdapter implements TableModel { private static class TableModelAdapter implements TableModel {
private PropertySheetModel m_model; private final PropertySheetModel propertySheetModel;
private int m_row; private int currentRow;
public TableModelAdapter(PropertySheetModel model) { public TableModelAdapter(final PropertySheetModel propertySheetModel) {
m_model = model; this.propertySheetModel = propertySheetModel;
m_row = -1; currentRow = -1;
} }
public int getColumnCount() { return 2; } @Override
public int getColumnCount() {
return 2;
}
@Override
public boolean nextRow() { public boolean nextRow() {
m_row++; currentRow++;
return m_model.nextRow(); return propertySheetModel.nextRow();
} }
public Object getElementAt(int columnIndex) { @Override
if(columnIndex == 0) { public Object getElementAt(final int columnIndex) {
return m_model.getGlobalizedLabel(); if (columnIndex == 0) {
return propertySheetModel.getGlobalizedLabel();
} else { } else {
return m_model.getValue(); return propertySheetModel.getValue();
} }
} }
public Object getKeyAt(int columnIndex) { @Override
return new Integer(m_row); public Object getKeyAt(final int columnIndex) {
return currentRow;
} }
public PropertySheetModel getPSModel() { 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");
}
}; };
} }

View File

@ -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);
}
}