Index: src/main/java/org/hippoecm/frontend/editor/plugins/field/PropertyFieldPlugin.java =================================================================== --- src/main/java/org/hippoecm/frontend/editor/plugins/field/PropertyFieldPlugin.java (revision 28566) +++ src/main/java/org/hippoecm/frontend/editor/plugins/field/PropertyFieldPlugin.java (working copy) @@ -1,12 +1,12 @@ /* * Copyright 2008 Hippo. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -67,6 +67,8 @@ // use caption for backwards compatibility; i18n should use field name add(new Label("name", getCaptionModel())); + add(createNrItemsLabel()); + Label required = new Label("required", "*"); if (field != null) { subscribe(); Index: src/main/java/org/hippoecm/frontend/editor/plugins/field/NodeFieldPlugin.java =================================================================== --- src/main/java/org/hippoecm/frontend/editor/plugins/field/NodeFieldPlugin.java (revision 28566) +++ src/main/java/org/hippoecm/frontend/editor/plugins/field/NodeFieldPlugin.java (working copy) @@ -1,12 +1,12 @@ /* * Copyright 2008 Hippo. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -30,6 +30,8 @@ import org.apache.wicket.markup.html.panel.Fragment; import org.apache.wicket.markup.repeater.Item; import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.StringResourceModel; import org.hippoecm.frontend.editor.TemplateEngineException; import org.hippoecm.frontend.model.AbstractProvider; import org.hippoecm.frontend.model.ChildNodeProvider; @@ -38,6 +40,7 @@ import org.hippoecm.frontend.model.event.JcrEvent; import org.hippoecm.frontend.plugin.IPluginContext; import org.hippoecm.frontend.plugin.config.IPluginConfig; +import org.hippoecm.frontend.plugin.config.impl.JavaPluginConfig; import org.hippoecm.frontend.service.IRenderService; import org.hippoecm.frontend.types.IFieldDescriptor; import org.hippoecm.frontend.types.ITypeDescriptor; @@ -59,6 +62,8 @@ // use caption for backwards compatibility; i18n should use field name add(new Label("name", getCaptionModel())); + add(createNrItemsLabel()); + Label required = new Label("required", "*"); if (field != null && !field.getValidators().contains("required")) { required.setVisible(false); @@ -220,5 +225,4 @@ return new Label("add").setVisible(false); } } - } Index: src/main/java/org/hippoecm/frontend/editor/plugins/field/AbstractFieldPlugin.java =================================================================== --- src/main/java/org/hippoecm/frontend/editor/plugins/field/AbstractFieldPlugin.java (revision 28566) +++ src/main/java/org/hippoecm/frontend/editor/plugins/field/AbstractFieldPlugin.java (working copy) @@ -1,12 +1,12 @@ /* - * Copyright 2008 Hippo. - * + * Copyright 2008-2011 Hippo. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,6 +15,7 @@ */ package org.hippoecm.frontend.editor.plugins.field; +import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -23,7 +24,9 @@ import javax.jcr.Item; +import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; import org.apache.wicket.model.StringResourceModel; @@ -64,6 +67,13 @@ private static final long serialVersionUID = 1L; + private static final String CLUSTER_OPTIONS = "cluster.options"; + + private static final String MAX_ITEMS = "maxitems"; + private static final int DEFAULT_MAX_ITEMS = 0; + private final int maxItems; + private IPluginConfig parameters; + static abstract class ValidationFilter extends Model { private static final long serialVersionUID = 1L; @@ -113,6 +123,9 @@ protected AbstractFieldPlugin(IPluginContext context, IPluginConfig config) { super(context, config); + this.parameters = new JavaPluginConfig(config.getPluginConfig(CLUSTER_OPTIONS)); + this.maxItems = this.parameters.containsKey(MAX_ITEMS)? this.parameters.getInt(MAX_ITEMS) : this.DEFAULT_MAX_ITEMS; + helper = new FieldPluginHelper(context, config); if (helper.getValidationModel() != null && helper.getValidationModel() instanceof IObservable) { context.registerService(new Observer((IObservable) helper.getValidationModel()) { @@ -151,7 +164,7 @@ mode = IEditor.Mode.VIEW; } } - + if (IEditor.Mode.COMPARE == mode) { comparingController = new ComparingController(context, config, this, getComparer(), getItemId()); @@ -300,7 +313,7 @@ if (engine != null) { ITypeDescriptor subType = field.getTypeDescriptor(); AbstractProvider provider = newProvider(field, subType, model); - if (IEditor.Mode.EDIT == mode && provider.size() == 0 + if (IEditor.Mode.EDIT == mode && (provider.size() == 0) && (!field.isMultiple() || field.getValidators().contains("required"))) { provider.addNew(); } @@ -315,7 +328,7 @@ /** * Factory method for provider of models that will be used to instantiate templates. * This method may be called from the base class constructor. - * + * * @param descriptor * @param type * @param parentModel @@ -326,7 +339,18 @@ protected boolean canAddItem() { IFieldDescriptor field = getFieldHelper().getField(); - return IEditor.Mode.EDIT == mode && (field != null) && (field.isMultiple() || provider.size() == 0); + if (IEditor.Mode.EDIT == mode && (field != null)) { + if (field.isMultiple()) { + if (getMaxItems() > 0) { + return getNumberOfItems() < getMaxItems(); + } + return true; + } + + return getNumberOfItems() == 0; + } + + return false; } protected boolean canRemoveItem() { @@ -479,12 +503,26 @@ } } - IPluginConfig parameters = new JavaPluginConfig(getPluginConfig().getPluginConfig("cluster.options")); - parameters.put(ITemplateEngine.ENGINE, getPluginConfig().getString(ITemplateEngine.ENGINE)); - parameters.put(RenderService.WICKET_ID, id); - parameters.put(ITemplateEngine.MODE, mode.toString()); + this.parameters.put(ITemplateEngine.ENGINE, getPluginConfig().getString(ITemplateEngine.ENGINE)); + this.parameters.put(RenderService.WICKET_ID, id); + this.parameters.put(ITemplateEngine.MODE, mode.toString()); return getPluginContext().newCluster(template, parameters); } + protected Component createNrItemsLabel() { + if ((IEditor.Mode.EDIT == mode) && (getMaxItems() > 0)) { + final IModel propertyModel = new StringResourceModel("nrItemsLabel", this, new Model(this)); + return new Label("nrItemsLabel", propertyModel).setOutputMarkupId(true); + } + return new Label("nrItemsLabel").setVisible(false); + } + + public int getMaxItems() { + return maxItems; + } + + public int getNumberOfItems() { + return provider.size(); + } } Index: src/main/java/org/hippoecm/frontend/editor/plugins/field/PropertyFieldPlugin.html =================================================================== --- src/main/java/org/hippoecm/frontend/editor/plugins/field/PropertyFieldPlugin.html (revision 28566) +++ src/main/java/org/hippoecm/frontend/editor/plugins/field/PropertyFieldPlugin.html (working copy) @@ -20,6 +20,7 @@ [ field name ] * +
[1 of 3]
Index: src/main/java/org/hippoecm/frontend/editor/plugins/field/NodeFieldPlugin.html =================================================================== --- src/main/java/org/hippoecm/frontend/editor/plugins/field/NodeFieldPlugin.html (revision 28566) +++ src/main/java/org/hippoecm/frontend/editor/plugins/field/NodeFieldPlugin.html (working copy) @@ -1,5 +1,5 @@