Skip to content

Commit

Permalink
#117 metadata implementation improved:
Browse files Browse the repository at this point in the history
- Added missing titles on TemplateFormPage.
- Added new feature for sharing template between persons.
- Added required fields in wizard, used gui helper from odml.
  • Loading branch information
rinkesj committed Jul 2, 2015
1 parent 18a2ad8 commit b898269
Show file tree
Hide file tree
Showing 13 changed files with 328 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.MetadataFormPage;
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.template.ListTemplatePage;
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.template.TemplateFormPage;
import cz.zcu.kiv.eegdatabase.wui.ui.experiments.metadata.template.TemplateSharePage;
import cz.zcu.kiv.eegdatabase.wui.ui.groups.ListOfMembersGroupPage;
import cz.zcu.kiv.eegdatabase.wui.ui.groups.ListResearchGroupsPage;
import cz.zcu.kiv.eegdatabase.wui.ui.groups.MyGroupsPage;
Expand Down Expand Up @@ -255,6 +256,7 @@ private void mountPages() {
mountPage("experiments-add-file", AddDataFilePage.class);
mountPage("experiments-add-param", ExperimentOptParamValueFormPage.class);
mountPage("experiments-template-list", ListTemplatePage.class);
mountPage("experiments-template-share", TemplateSharePage.class);
mountPage("experiments-add-template", TemplateFormPage.class);
mountPage("experiments-add-metadata", MetadataFormPage.class);
mountPage("file-detail", DataFileDetailPage.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,42 @@
import org.apache.wicket.model.PropertyModel;

public class FormPropertyPanel extends Panel {

private static final long serialVersionUID = 1L;

private TextField textField;
private DropDownChoice<Value> choice;

public FormPropertyPanel(String id, IModel<Property> model) {
super(id, new CompoundPropertyModel<Property>(model));

setupLabels();
setupFormComponents(model);
}

private void setupFormComponents(IModel<Property> model) {

textField = new TextField("textfield", new PropertyModel(model.getObject(), "value"));
add(textField);

choice = new DropDownChoice<Value>("select", new Model<Value>(),new PropertyModel<List<Value>>(model.getObject(), "values"));
choice = new DropDownChoice<Value>("select", new Model<Value>(), new PropertyModel<List<Value>>(model.getObject(), "values"));
add(choice);

boolean singleValue = model.getObject().getValues() != null ? model.getObject().getValues().size() == 1 : true;
textField.setVisibilityAllowed(singleValue);
choice.setVisibilityAllowed(!singleValue);

textField.setLabel(new Model<String>(model.getObject().getName()));
choice.setLabel(new Model<String>(model.getObject().getName()));

boolean required = model.getObject().getGuiHelper().getRequired();
textField.setRequired(required);
choice.setRequired(required);

}

private void setupLabels() {

add(new Label("name"));
add(new Label("definition"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public FormSectionPanel(String id, IModel<Section> model) {
}

private void setupLists() {

PropertyListView<Property> properties = new PropertyListView<Property>("properties") {

private static final long serialVersionUID = 1L;
Expand All @@ -54,7 +54,7 @@ protected void populateItem(ListItem<Property> item) {
item.add(new FormPropertyPanel("property", item.getModel()));
}
};
add(properties);
add(properties.setReuseItems(true));

PropertyListView<Section> sections = new PropertyListView<Section>("sections") {

Expand All @@ -65,7 +65,7 @@ protected void populateItem(ListItem<Section> item) {
item.add(new FormSectionPanel("section", item.getModel()));
}
};
add(sections);
add(sections.setReuseItems(true));
}

private void setupLabels() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
<div wicket:id="feedback"></div>
<select wicket:id="template-choice"></select>
<div wicket:id="wizard"></div>
</wicket:panel>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,46 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.List;

import odml.core.Reader;
import odml.core.Section;
import odml.core.Writer;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.wizard.Wizard;
import org.apache.wicket.extensions.wizard.WizardModel;
import org.apache.wicket.feedback.ComponentFeedbackMessageFilter;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.sun.xml.messaging.saaj.util.ByteInputStream;

import cz.zcu.kiv.eegdatabase.data.pojo.Template;
import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession;
import cz.zcu.kiv.eegdatabase.wui.components.form.input.AjaxDropDownChoice;
import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils;
import cz.zcu.kiv.eegdatabase.wui.core.experiments.metadata.TemplateFacade;

public class MetadataForm extends Panel {

private static final long serialVersionUID = -8842966593408416974L;


protected Log log = LogFactory.getLog(getClass());

@SpringBean
private TemplateFacade templateFacade;

private CompoundPropertyModel<Section> model;

public MetadataForm(String id) {
Expand All @@ -52,27 +73,28 @@ public MetadataForm(String id) {

public MetadataForm(String id, IModel<Section> model) {
super(id);

this.model = new CompoundPropertyModel<Section>(model);
setDefaultModel(this.model);
setOutputMarkupId(true);
add(new FeedbackPanel("feedback"));

// TODO select template not work.
WizardModel wizardModel = new WizardModel();
for(Section section : model.getObject().getSections()){
for (Section section : model.getObject().getSections()) {
wizardModel.add(new MetadataWizardStep(new Model<Section>(section)));
}
Wizard wizard = new Wizard("wizard", wizardModel, true){

Wizard wizard = new Wizard("wizard", wizardModel, true) {

private static final long serialVersionUID = 1L;

@Override
public void onFinish() {
try {
FileOutputStream stream = new FileOutputStream(new File("D:\\trash\\saveform.xml"));
Section data = MetadataForm.this.model.getObject();
FileOutputStream stream = new FileOutputStream(new File("D:\\trash\\"+ data.getName() + ".xml"));

Writer writer = new Writer(MetadataForm.this.model.getObject(), true, true);
Writer writer = new Writer(data, true, true);
if (writer.write(stream)) {
info("Save template done.");
} else {
Expand All @@ -83,20 +105,41 @@ public void onFinish() {
}
}

@Override
protected Component newFeedbackPanel(String id) {

ComponentFeedbackMessageFilter filter = new ComponentFeedbackMessageFilter(this);
return new FeedbackPanel(id, filter);
}

@Override
public void onCancel() {
throw new RestartResponseAtInterceptPageException(MetadataForm.this.getPage().getPageClass(), MetadataForm.this.getPage().getPageParameters());
}

};

add(wizard);

int personId = EEGDataBaseSession.get().getLoggedUser().getPersonId();
List<Template> templatesByPerson = templateFacade.getTemplatesByPerson(personId);
ChoiceRenderer<Template> templateChoiceRenderer = new ChoiceRenderer<Template>("name", "templateId");
AjaxDropDownChoice<Template> templateSelection = new AjaxDropDownChoice<Template>("template-choice", new Model<Template>(), templatesByPerson, templateChoiceRenderer) {

private static final long serialVersionUID = 1L;

@Override
protected void onSelectionChangeAjaxified(AjaxRequestTarget target, Template template) {

try {
Reader reader = new Reader();
Section section = reader.load(new ByteInputStream(template.getTemplate(), template.getTemplate().length));
section.setName(template.getName());
MetadataForm.this.model.setObject(section);
} catch (Exception e) {
log.error(e.getMessage(), e);
error(ResourceUtils.getString("text.template.error.load"));
}

target.add(MetadataForm.this);
}

};

add(templateSelection);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.feedback.ComponentFeedbackMessageFilter;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.spring.injection.annot.SpringBean;
Expand Down Expand Up @@ -69,11 +70,11 @@ public MetadataFormPage() {
section = reader.load(template);

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error(e.getMessage(), e);
}

add(new MetadataForm("metadata-form", new Model<Section>(section)));
getFeedback().setFilter(new ComponentFeedbackMessageFilter(this));
}

public MetadataFormPage(final PageParameters parameters) {
Expand All @@ -92,12 +93,14 @@ public MetadataFormPage(final PageParameters parameters) {
Reader reader = new Reader();
try {
Section section = reader.load(new ByteInputStream(template.getTemplate(), template.getTemplate().length));
section.setName(template.getName());
add(new MetadataForm("metadata-form", new Model<Section>(section)));

} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RestartResponseAtInterceptPageException(ListTemplatePage.class);
}


getFeedback().setFilter(new ComponentFeedbackMessageFilter(this));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ <h1>
</h1>

<a href="#" class="lightButtonLink" wicket:id="addTemplateLink"><wicket:message key="pageTitle.template.new"></wicket:message></a>
<a href="#" class="lightButtonLink" wicket:id="shareTemplateLink"><wicket:message key="pageTitle.template.share"></wicket:message></a>
<table class="dataTable" wicket:id="list"></table>
</div>
</wicket:extend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public ListTemplatePage() {
provider, ITEMS_PER_PAGE);

add(new BookmarkablePageLink<Void>("addTemplateLink",TemplateFormPage.class));
add(new BookmarkablePageLink<Void>("shareTemplateLink", TemplateSharePage.class));

add(list);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<div class="leftMenu" wicket:id="leftMenu"></div>

<div class="mainContentWithMenu">
<h1 wicket:id="title"></h1>
<div wicket:id="template-panel"></div>
</div>
</wicket:extend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.apache.commons.logging.LogFactory;
import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.spring.injection.annot.SpringBean;
Expand All @@ -54,15 +56,19 @@ public class TemplateFormPage extends MenuPage {

public TemplateFormPage() {

setPageTitle(ResourceUtils.getModel("pageTitle.template.new"));
IModel<String> title = ResourceUtils.getModel("pageTitle.template.new");
setPageTitle(title);
add(new Label("title", title));
add(new ButtonPageMenu("leftMenu", ExperimentsPageLeftMenu.values()));

add(new TemplateForm("template-panel"));
}

public TemplateFormPage(PageParameters parameters) {

setPageTitle(ResourceUtils.getModel("pageTitle.template.edit"));
IModel<String> title = ResourceUtils.getModel("pageTitle.template.edit");
setPageTitle(title);
add(new Label("title", title));
add(new ButtonPageMenu("leftMenu", ExperimentsPageLeftMenu.values()));

StringValue value = parameters.get(DEFAULT_PARAM_ID);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!--
This file is part of the EEG-database project
==========================================
Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/)
***********************************************************************************************************************
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. See the License for the
specific language governing permissions and limitations under the License.
***********************************************************************************************************************
TemplateSharePage.html, 2015/03/24 00:01 Jakub Rinkes
-->
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:extend>
<div class="leftMenu" wicket:id="leftMenu"></div>

<div class="mainContentWithMenu">

<h1><wicket:message key="pageTitle.template.share"></wicket:message></h1>

<form wicket:id="form" class="standardInputForm">
<div class="itemBox">
<label for=givenname class="textFieldLabel"><wicket:message key="label.selectTemplate"></wicket:message></label>
<select wicket:id="template-choice" class="selectBox"></select>
</div>
<div class="itemBox">
<label for=givenname class="textFieldLabel"><wicket:message key="label.selectPerson"></wicket:message></label>
<input type="text" wicket:id="person-choice" />
</div>
<div class="itemBox">
<input type="submit" wicket:id="share-button" class="submitButton lightButtonLink" />
</div>
</form>
</div>
</wicket:extend>
</body>
</html>
Loading

0 comments on commit b898269

Please sign in to comment.