Skip to content

Commit

Permalink
#117 added property with list of values - enhancemented template form.
Browse files Browse the repository at this point in the history
  • Loading branch information
rinkesj committed Jul 2, 2015
1 parent 7bb976d commit 0e7a1f9
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
<input type="button" wicket:id="addButton" class="remove-button" value="+"/>
<!-- <table> -->
<!-- <tr wicket:id="values"><td wicket:id="content"></td><td><input type="button" wicket:id="removeValueLink" class="remove-button" value="X"></td></tr> -->
<!-- </table> -->
<span>
<span wicket:id="values"><span wicket:id="content"></span><input type="button" wicket:id="removeValueLink" class="remove-button" value="X">, </span>
</span>
</wicket:panel>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.template;

import java.io.Serializable;

import odml.core.Property;
import odml.core.Value;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.extensions.ajax.markup.html.AjaxEditableLabel;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.PropertyListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;

import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils;

public class PropertyMultiValuePanel extends Panel {

private static final long serialVersionUID = 1L;

private int valueSuffix = 1;
private Property property;

public PropertyMultiValuePanel(String id, final IModel<Property> model) {
super(id, new CompoundPropertyModel<Property>(model));
setOutputMarkupId(true);
property = model.getObject();
valueSuffix = property.valueCount() + 1;

PropertyListView<Value> values = new PropertyListView<Value>("values") {

private static final long serialVersionUID = 1L;

@Override
protected void populateItem(final ListItem<Value> item) {

int index = item.getIndex();
item.add(new AjaxEditableLabel<Serializable>("content", new PropertyValueModel(property, index)) {

private static final long serialVersionUID = 1L;

@Override
protected String defaultNullLabel() {
return "...";
}
});
item.add(new AjaxLink<Void>("removeValueLink") {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
int index = item.getIndex();
property.removeValue(index);
target.add(PropertyMultiValuePanel.this);
}

@Override
protected void onConfigure() {
super.onConfigure();
setVisible(property.valueCount() > 1);
}
});
}
};
values.setReuseItems(true);

add(values);

AjaxLink<Void> addLink = new AjaxLink<Void>("addButton") {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
property.addValue(ResourceUtils.getString("text.template.empty.propertyValue") + valueSuffix++);
target.add(PropertyMultiValuePanel.this);
}
};

add(addLink);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.template;

import java.io.Serializable;

import odml.core.Property;
import odml.core.Value;

import org.apache.wicket.model.Model;

/**
* Model for working with {@link Value} in {@link Property}.
*
* Value doesn't have visible getters/setters. This model work with Value via Property instance.
*
* @author Jakub Rinkes
*
*/
public class PropertyValueModel extends Model<Serializable> {

private static final long serialVersionUID = 1L;

private Property property;
private int valueIndex;

public PropertyValueModel(Property property, int valueIndex) {
this.property = property;
this.valueIndex = valueIndex;
}

@Override
public Serializable getObject() {

if (property.valueCount() == 0)
return null;

return (Serializable) property.getValue(valueIndex);
}

@Override
public void setObject(Serializable object) {


if (object instanceof String && ((String) object).equalsIgnoreCase("...")) {
// fixed default empty value from AjaxEditableLabel - default value is cleared - textfield will be empty.
property.setValueAt("", valueIndex);
} else {
property.setValueAt(object, valueIndex);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
<body>
<wicket:panel>
<label><wicket:message key="label.template.property"/>: <span wicket:id="name" class="editable"/>
- <wicket:message key="label.template.type"></wicket:message>: <span wicket:id="type" class="editable"/>
- <wicket:message key="label.template.value"></wicket:message>: <span wicket:id="value" class="editable"/> </label>
- <wicket:message key="label.template.type"></wicket:message>: <span wicket:id="type" class="editable"/></label>
- <input type="checkbox" wicket:id="required"/><label><wicket:message key="label.template.property.required"/></label>
- <input type="button" wicket:id="remove-property" value="X" class="remove-button"/>
<br />
<wicket:enclosure child="definition">
<div wicket:id="definition" class="definition editable">
</div>
<wicket:message key="label.template.value"></wicket:message>: <span wicket:id="value" class="editable"/>
</wicket:enclosure>
</wicket:panel>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,17 @@ public TemplatePropertyPanel(String id, IModel<Property> model, TemplateTreeView

private void setupComponents(IModel<Property> model) {

add(new AjaxEditableLabel<String>("name"){
add(new AjaxEditableLabel<String>("name") {

private static final long serialVersionUID = 1L;

@Override
protected String defaultNullLabel() {
return ResourceUtils.getString("text.template.empty.propertyName");
}

});
add(new AjaxEditableLabel<Object>("value"){

private static final long serialVersionUID = 1L;

@Override
protected String defaultNullLabel() {
return ResourceUtils.getString("text.template.empty.propertyValue");
}


});
add(new PropertyMultiValuePanel("value", model));
add(new AjaxEditableMultiLineLabel<String>("definition") {

private static final long serialVersionUID = 1L;
Expand All @@ -83,40 +74,39 @@ protected void onConfigure() {
super.onConfigure();
setVisible(TemplatePropertyPanel.this.viewModel.isDefinitionVisible());
}

@Override
protected String defaultNullLabel() {
return ResourceUtils.getString("text.template.empty.definition");
}
});
add(new AjaxEditableLabel<String>("type"){

add(new AjaxEditableLabel<String>("type") {

private static final long serialVersionUID = 1L;

@Override
protected String defaultNullLabel() {
return ResourceUtils.getString("text.template.empty.propertyType");
}
});
add(new AjaxLink<Void>("remove-property"){

add(new AjaxLink<Void>("remove-property") {

private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
Property property = (Property) TemplatePropertyPanel.this.getDefaultModelObject();
property.getParent().removeProperty(property.getName());

target.add(container);
}



});

add(new AjaxCheckBox("required", new PropertyModel<Boolean>(model.getObject(), "guiHelper.required")) {

private static final long serialVersionUID = 1L;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.extensions.ajax.markup.html.AjaxEditableLabel;
import org.apache.wicket.extensions.ajax.markup.html.AjaxEditableMultiLineLabel;
import org.apache.wicket.markup.html.WebMarkupContainer;
Expand All @@ -56,6 +55,7 @@ public class TemplateSectionPanel extends Panel {
private WebMarkupContainer head;
private MarkupContainer mainContainer;
private TemplateTreeViewModel viewModel;
private int propertySuffix;

public TemplateSectionPanel(String id, IModel<Section> model, final MarkupContainer container, final List<Section> choices, TemplateTreeViewModel viewModel) {
super(id, new CompoundPropertyModel<Section>(model));
Expand All @@ -68,6 +68,7 @@ public TemplateSectionPanel(String id, IModel<Section> model, final MarkupContai
head = new WebMarkupContainer("head");
content.setOutputMarkupPlaceholderTag(true);
add(content, head);
propertySuffix = model.getObject().propertyCount() + 1;

setupHeadAndControlComponents(model, choices);
setupContentComponents(choices);
Expand Down Expand Up @@ -101,7 +102,7 @@ protected void populateItem(ListItem<Section> item) {
private void setupHeadAndControlComponents(final IModel<Section> model, final List<Section> choices) {
// head + control
final boolean notRootSection = model.getObject().getParent() != null;

head.add(new AjaxEditableLabel<String>("name") {

private static final long serialVersionUID = 1L;
Expand All @@ -116,14 +117,14 @@ protected String defaultNullLabel() {
}
}
});

String key;
if(notRootSection){
if (notRootSection) {
key = "label.template.section";
} else {
key = "label.template.templateName";
}

head.add(new Label("sectionNameLabel", ResourceUtils.getString(key)));

head.add(new AjaxEditableMultiLineLabel<String>("definition") {
Expand Down Expand Up @@ -203,7 +204,7 @@ public void onClick(AjaxRequestTarget target) {
public void onClick(AjaxRequestTarget target) {

try {
Property property = new Property("NewProperty", new Object());
Property property = new Property(ResourceUtils.getString("text.template.empty.propertyName") + propertySuffix++, ResourceUtils.getString("text.template.empty.propertyValue"));
TemplateSectionPanel.this.model.getObject().add(property);
} catch (Exception e) {
e.printStackTrace();
Expand Down

0 comments on commit 0e7a1f9

Please sign in to comment.