-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#117 added property with list of values - enhancemented template form.
- Loading branch information
rinkesj
committed
Jul 2, 2015
1 parent
7bb976d
commit 0e7a1f9
Showing
6 changed files
with
174 additions
and
32 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
.../cz/zcu/kiv/eegdatabase/wui/ui/experiments/metadata/template/PropertyMultiValuePanel.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
86 changes: 86 additions & 0 deletions
86
.../cz/zcu/kiv/eegdatabase/wui/ui/experiments/metadata/template/PropertyMultiValuePanel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
.../java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/metadata/template/PropertyValueModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters