Skip to content

Commit

Permalink
update form table model
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelienxelians committed Oct 16, 2023
1 parent 1cb25f5 commit 5109607
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 129 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>fr.xelians</groupId>
<artifactId>datahub-studio</artifactId>
<version>2.0.1</version>
<version>3.0.0</version>
<packaging>jar</packaging>

<name>datahub-studio</name>
Expand Down Expand Up @@ -259,6 +259,12 @@
<groupId>org.relaxng</groupId>
<artifactId>jing</artifactId>
<version>${relaxng.version}</version>
<exclusions>
<exclusion>
<groupId>org.ibissource</groupId>
<artifactId>ibis-xerces</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
Expand Down
28 changes: 4 additions & 24 deletions src/main/java/fr/xelians/xdh/studio/form/WorkerForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,31 +457,11 @@ public interface InputFormToggleTableSpec{
public interface InputFormTableSpec extends InputFormBaseSpec{

/**
* Add an input text for text values. The value of the corresponding key will be of type String
* @param parameter the name fo the parameter should be equal to the parameter name of the constructor
* @param label the {{@link fr.xelians.xdh.studio.translation.Label.Translation}} use for form labels translation. Use {{@link Label#of(String, String)}} to get a {{@link fr.xelians.xdh.studio.translation.Label.Translation}} instances
* @param mandatory if the form field is mandatory
* @return {{@link InputTextTableSpec}} specification for input text with text values
*/
InputTextTableSpec addInputTextText(String parameter, Label.Translation label, boolean mandatory);

/**
* Add an input select for text values. The value of the corresponding key will be of type String
* @param parameter the name fo the parameter should be equal to the parameter name of the constructor
* @param label the {{@link fr.xelians.xdh.studio.translation.Label.Translation}} use for form labels translation. Use {{@link Label#of(String, String)}} to get a {{@link fr.xelians.xdh.studio.translation.Label.Translation}} instances
* @param mandatory if the form field is mandatory
* @return {{@link InputFormMultiTableSpec}} specification for input multivalued
*/
InputFormMultiTableSpec addInputSelectText(String parameter, Label.Translation label, boolean mandatory);

/**
* Add an input toggle. The value of the corresponding key will be of type Boolean
* @param parameter the name fo the parameter should be equal to the parameter name of the constructor
* @param label the {{@link fr.xelians.xdh.studio.translation.Label.Translation}} use for form labels translation. Use {{@link Label#of(String, String)}} to get a {{@link fr.xelians.xdh.studio.translation.Label.Translation}} instances
* @param mandatory if the form field is mandatory
* @return {{@link InputTextTableSpec}} specification for input text with text values
* Add table fields columns
* @param form a form object describing all the columns in the table
* @return {{@link InputFormTableSpec}}
*/
InputFormToggleTableSpec addInputFormToggle(String parameter, Label.Translation label, boolean mandatory);
InputFormTableSpec withFields(Form form);

/**
* Add an information
Expand Down
102 changes: 3 additions & 99 deletions src/main/java/fr/xelians/xdh/studio/form/WorkerFormBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,9 @@ private InputFormTableSpec(String parameter, Label.Translation label, boolean ma
}

@Override
public WorkerForm.InputTextTableSpec addInputTextText(String parameter, Label.Translation label, boolean mandatory) {
return new InputTextTableSpec(InputValueType.TEXT, InputFormType.TEXT, parameter, label, mandatory, this);
}

@Override
public WorkerForm.InputFormMultiTableSpec addInputSelectText(String parameter, Label.Translation label, boolean mandatory) {
return new InputFormMultiTableSpec(InputValueType.TEXT, InputFormType.SELECT, parameter, label, mandatory, this);
}

@Override
public WorkerForm.InputFormToggleTableSpec addInputFormToggle(String parameter, Label.Translation label, boolean mandatory) {
return new InputFormToggleTableSpec(parameter, label, mandatory, this);
public WorkerForm.InputFormTableSpec withFields(WorkerForm.Form form) {
this.inputFormTable.inputFormColumns = form.getInputForms();
return this;
}

@Override
Expand All @@ -349,94 +340,7 @@ public WorkerForm.Builder and() {
return builder.addInput(inputFormTable);
}

private void addInputForm(WorkerForm.InputFormBase inputFormBase){
inputFormTable.addInputFormColumn(inputFormBase);
}

private class InputFormMultiTableSpec implements WorkerForm.InputFormMultiTableSpec{

protected InputFormMulti<String> inputFormMulti;

private InputFormTableSpec inputFormTableSpec;

private InputFormMultiTableSpec(InputValueType inputValueType, InputFormType inputFormType, String parameter, Label.Translation label, boolean mandatory, InputFormTableSpec inputFormTableSpec){
this.inputFormMulti = new InputFormMulti();
this.inputFormMulti.setInputValueType(inputValueType);
this.inputFormMulti.setParameter(parameter);
this.inputFormMulti.setLabel(label);
this.inputFormMulti.setMandatory(mandatory);
this.inputFormMulti.setInputFormType(inputFormType);
this.inputFormTableSpec = inputFormTableSpec;
}

public InputFormMultiTableSpec withChoices(List<WorkerForm.MultiValueChoice.Choice<String>> choices){
inputFormMulti.setChoices(choices);
return this;
}

public InputFormTableSpec and(){
inputFormTableSpec.addInputForm(inputFormMulti);
return inputFormTableSpec;
}

}

private class InputTextTableSpec implements WorkerForm.InputTextTableSpec{

private InputFormUnique<String> inputFormUnique;

private InputFormTableSpec inputFormTableSpec;

private InputTextTableSpec(InputValueType inputValueType, InputFormType inputFormType, String parameter, Label.Translation label, boolean mandatory, InputFormTableSpec inputFormTableSpec){
this.inputFormUnique = new InputFormUnique();
this.inputFormUnique.setInputFormType(InputFormType.TEXT);
this.inputFormUnique.setInputValueType(inputValueType);
this.inputFormUnique.setParameter(parameter);
this.inputFormUnique.setLabel(label);
this.inputFormUnique.setMandatory(mandatory);
this.inputFormUnique.setInputFormType(inputFormType);
this.inputFormTableSpec = inputFormTableSpec;
}

@Override
public WorkerForm.InputTextTableSpec withMinValue(String value) {
inputFormUnique.setMin(value);
return this;
}

@Override
public WorkerForm.InputTextTableSpec withMaxValue(String value) {
inputFormUnique.setMax(value);
return this;
}

@Override
public WorkerForm.InputFormTableSpec and() {
inputFormTableSpec.addInputForm(inputFormUnique);
return inputFormTableSpec;
}
}

private class InputFormToggleTableSpec implements WorkerForm.InputFormToggleTableSpec{

private InputFormToggle inputFormToggle;
private InputFormTableSpec inputFormTableSpec;

private InputFormToggleTableSpec(String parameter, Label.Translation label, boolean mandatory, InputFormTableSpec inputFormTableSpec) {
this.inputFormToggle = new InputFormToggle();
this.inputFormToggle.setInputFormType(InputFormType.TOGGLE);
this.inputFormToggle.setParameter(parameter);
this.inputFormToggle.setLabel(label);
this.inputFormToggle.setMandatory(mandatory);
this.inputFormTableSpec = inputFormTableSpec;
}

@Override
public WorkerForm.InputFormTableSpec and() {
inputFormTableSpec.addInputForm(inputFormToggle);
return inputFormTableSpec;
}
}
}

private class InputFormFileSpec implements WorkerForm.InputFormFileSpec {
Expand Down
8 changes: 3 additions & 5 deletions src/test/java/fr/xelians/xdh/studio/form/WorkerFormTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ public void testWorkerForm(){
.addInputFormFile(PARAM_5, Label.of(LABEL_5, LABEL_5), false)
.and()
.addInputFormTable(PARAM_6, Label.of(LABEL_6, LABEL_6), true)
.addInputTextText(PARAM_1, Label.of(LABEL_1, LABEL_1), false)
.and()
.addInputSelectText(PARAM_2, Label.of(LABEL_2, LABEL_2), true)
.withChoices(List.of(WorkerForm.MultiValueChoice.of(VALUE_5), WorkerForm.MultiValueChoice.of(VALUE_6)))
.and()
.withFields(WorkerForm.builder().addInputTextText(PARAM_1, Label.of(LABEL_1, LABEL_1), false).and()
.addInputSelectText(PARAM_2, Label.of(LABEL_2, LABEL_2), true)
.withChoices(List.of(WorkerForm.MultiValueChoice.of(VALUE_5), WorkerForm.MultiValueChoice.of(VALUE_6))).and().build())
.and()
.build();

Expand Down

0 comments on commit 5109607

Please sign in to comment.