Commit 810d8a34 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

Fix FileWidget Initialization

parent c90d56b7
...@@ -148,7 +148,11 @@ public class ModelHelper { ...@@ -148,7 +148,11 @@ public class ModelHelper {
} }
public static FileWidgetInputType getDefaultFileWidgetInputType(final FileWidget widget) { public static FileWidgetInputType getDefaultFileWidgetInputType(final FileWidget widget) {
if (ModelHelper.isAnEntryPageFlowOnAPool(ModelHelper.getParentForm(widget))) { final Form parentForm = ModelHelper.getParentForm(widget);
if (parentForm == null) {
return FileWidgetInputType.RESOURCE;
}
if (ModelHelper.isAnEntryPageFlowOnAPool(parentForm)) {
return FileWidgetInputType.RESOURCE; return FileWidgetInputType.RESOURCE;
} }
return FileWidgetInputType.DOCUMENT; return FileWidgetInputType.DOCUMENT;
......
...@@ -26,6 +26,7 @@ import org.bonitasoft.studio.model.form.DateFormField; ...@@ -26,6 +26,7 @@ import org.bonitasoft.studio.model.form.DateFormField;
import org.bonitasoft.studio.model.form.DurationFormField; import org.bonitasoft.studio.model.form.DurationFormField;
import org.bonitasoft.studio.model.form.DynamicTable; import org.bonitasoft.studio.model.form.DynamicTable;
import org.bonitasoft.studio.model.form.FileWidget; import org.bonitasoft.studio.model.form.FileWidget;
import org.bonitasoft.studio.model.form.FileWidgetInputType;
import org.bonitasoft.studio.model.form.FormFactory; import org.bonitasoft.studio.model.form.FormFactory;
import org.bonitasoft.studio.model.form.Group; import org.bonitasoft.studio.model.form.Group;
import org.bonitasoft.studio.model.form.ListFormField; import org.bonitasoft.studio.model.form.ListFormField;
...@@ -39,6 +40,8 @@ import org.bonitasoft.studio.model.form.TextAreaFormField; ...@@ -39,6 +40,8 @@ import org.bonitasoft.studio.model.form.TextAreaFormField;
import org.bonitasoft.studio.model.form.TextFormField; import org.bonitasoft.studio.model.form.TextFormField;
import org.bonitasoft.studio.model.form.TextInfo; import org.bonitasoft.studio.model.form.TextInfo;
import org.bonitasoft.studio.model.form.Widget; import org.bonitasoft.studio.model.form.Widget;
import org.bonitasoft.studio.model.process.builders.PoolBuilder;
import org.bonitasoft.studio.model.process.builders.TaskBuilder;
import org.bonitasoft.studio.model.process.diagram.form.providers.ElementInitializers; import org.bonitasoft.studio.model.process.diagram.form.providers.ElementInitializers;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
...@@ -55,10 +58,10 @@ import org.mockito.runners.MockitoJUnitRunner; ...@@ -55,10 +58,10 @@ import org.mockito.runners.MockitoJUnitRunner;
public class CreateWidgetSwitchTest { public class CreateWidgetSwitchTest {
private CreateWidgetSwitch createWidgetSwitch; private CreateWidgetSwitch createWidgetSwitch;
@Mock @Mock
private ElementInitializers initializer; private ElementInitializers initializer;
private FormFactory formFactory; private FormFactory formFactory;
/** /**
...@@ -67,7 +70,7 @@ public class CreateWidgetSwitchTest { ...@@ -67,7 +70,7 @@ public class CreateWidgetSwitchTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
formFactory = FormFactory.eINSTANCE; formFactory = FormFactory.eINSTANCE;
createWidgetSwitch = new CreateWidgetSwitch(initializer); createWidgetSwitch = new CreateWidgetSwitch(TaskBuilder.createTaskBuilder().build(), initializer);
} }
/** /**
...@@ -76,122 +79,127 @@ public class CreateWidgetSwitchTest { ...@@ -76,122 +79,127 @@ public class CreateWidgetSwitchTest {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
} }
@Test @Test
public void shouldDoSwitchTextField_InitializeWidget() throws Exception { public void shouldDoSwitchTextField_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createTextFormField()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createTextFormField());
assertThat(widget).isNotNull().isInstanceOf(TextFormField.class); assertThat(widget).isNotNull().isInstanceOf(TextFormField.class);
verify(initializer).init_TextFormField_3112((TextFormField) widget); verify(initializer).init_TextFormField_3112((TextFormField) widget);
} }
@Test @Test
public void shouldDoSwitchTextArea_InitializeWidget() throws Exception { public void shouldDoSwitchTextArea_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createTextAreaFormField()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createTextAreaFormField());
assertThat(widget).isNotNull().isInstanceOf(TextAreaFormField.class); assertThat(widget).isNotNull().isInstanceOf(TextAreaFormField.class);
verify(initializer).init_TextAreaFormField_3113((TextAreaFormField) widget); verify(initializer).init_TextAreaFormField_3113((TextAreaFormField) widget);
} }
@Test @Test
public void shouldDoSwitchDate_InitializeWidget() throws Exception { public void shouldDoSwitchDate_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createDateFormField()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createDateFormField());
assertThat(widget).isNotNull().isInstanceOf(DateFormField.class); assertThat(widget).isNotNull().isInstanceOf(DateFormField.class);
verify(initializer).init_DateFormField_3105((DateFormField) widget); verify(initializer).init_DateFormField_3105((DateFormField) widget);
} }
@Test @Test
public void shouldDoSwitchSelect_InitializeWidget() throws Exception { public void shouldDoSwitchSelect_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createSelectFormField()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createSelectFormField());
assertThat(widget).isNotNull().isInstanceOf(SelectFormField.class); assertThat(widget).isNotNull().isInstanceOf(SelectFormField.class);
verify(initializer).init_SelectFormField_3111((SelectFormField) widget); verify(initializer).init_SelectFormField_3111((SelectFormField) widget);
} }
@Test @Test
public void shouldDoSwitchPassword_InitializeWidget() throws Exception { public void shouldDoSwitchPassword_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createPasswordFormField()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createPasswordFormField());
assertThat(widget).isNotNull().isInstanceOf(PasswordFormField.class); assertThat(widget).isNotNull().isInstanceOf(PasswordFormField.class);
verify(initializer).init_PasswordFormField_3109((PasswordFormField) widget); verify(initializer).init_PasswordFormField_3109((PasswordFormField) widget);
} }
@Test @Test
public void shouldDoSwitchList_InitializeWidget() throws Exception { public void shouldDoSwitchList_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createListFormField()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createListFormField());
assertThat(widget).isNotNull().isInstanceOf(ListFormField.class); assertThat(widget).isNotNull().isInstanceOf(ListFormField.class);
verify(initializer).init_ListFormField_3107((ListFormField) widget); verify(initializer).init_ListFormField_3107((ListFormField) widget);
} }
@Test @Test
public void shouldDoSwitchCheckbox_InitializeWidget() throws Exception { public void shouldDoSwitchCheckbox_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createCheckBoxSingleFormField()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createCheckBoxSingleFormField());
assertThat(widget).isNotNull().isInstanceOf(CheckBoxSingleFormField.class); assertThat(widget).isNotNull().isInstanceOf(CheckBoxSingleFormField.class);
verify(initializer).init_CheckBoxSingleFormField_3118((CheckBoxSingleFormField) widget); verify(initializer).init_CheckBoxSingleFormField_3118((CheckBoxSingleFormField) widget);
} }
@Test @Test
public void shouldDoSwitchCheckboxList_InitializeWidget() throws Exception { public void shouldDoSwitchCheckboxList_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createCheckBoxMultipleFormField()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createCheckBoxMultipleFormField());
assertThat(widget).isNotNull().isInstanceOf(CheckBoxMultipleFormField.class); assertThat(widget).isNotNull().isInstanceOf(CheckBoxMultipleFormField.class);
verify(initializer).init_CheckBoxMultipleFormField_3120((CheckBoxMultipleFormField) widget); verify(initializer).init_CheckBoxMultipleFormField_3120((CheckBoxMultipleFormField) widget);
} }
@Test @Test
public void shouldDoSwitchFileWidget_InitializeWidget() throws Exception { public void shouldDoSwitchFileWidget_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createFileWidget()); Widget widget = createWidgetSwitch.doSwitch(formFactory.createFileWidget());
assertThat(widget).isNotNull().isInstanceOf(FileWidget.class); assertThat(widget).isNotNull().isInstanceOf(FileWidget.class);
assertThat(((FileWidget) widget).getInputType()).isEqualTo(FileWidgetInputType.DOCUMENT);
verify(initializer).init_FileWidget_3119((FileWidget) widget); verify(initializer).init_FileWidget_3119((FileWidget) widget);
createWidgetSwitch = new CreateWidgetSwitch(PoolBuilder.create().build(), initializer);
widget = createWidgetSwitch.doSwitch(formFactory.createFileWidget());
assertThat(((FileWidget) widget).getInputType()).isEqualTo(FileWidgetInputType.RESOURCE);
} }
@Test @Test
public void shouldDoSwitchDurationFormField_InitializeWidget() throws Exception { public void shouldDoSwitchDurationFormField_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createDurationFormField()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createDurationFormField());
assertThat(widget).isNotNull().isInstanceOf(DurationFormField.class); assertThat(widget).isNotNull().isInstanceOf(DurationFormField.class);
verify(initializer).init_DurationFormField_3121((DurationFormField) widget); verify(initializer).init_DurationFormField_3121((DurationFormField) widget);
} }
@Test @Test
public void shouldDoSwitchRadioFormField_InitializeWidget() throws Exception { public void shouldDoSwitchRadioFormField_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createRadioFormField()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createRadioFormField());
assertThat(widget).isNotNull().isInstanceOf(RadioFormField.class); assertThat(widget).isNotNull().isInstanceOf(RadioFormField.class);
verify(initializer).init_RadioFormField_3110((RadioFormField) widget); verify(initializer).init_RadioFormField_3110((RadioFormField) widget);
} }
@Test @Test
public void shouldDoSwitchMessageInfo_InitializeWidget() throws Exception { public void shouldDoSwitchMessageInfo_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createMessageInfo()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createMessageInfo());
assertThat(widget).isNotNull().isInstanceOf(MessageInfo.class); assertThat(widget).isNotNull().isInstanceOf(MessageInfo.class);
verify(initializer).init_MessageInfo_3124((MessageInfo) widget); verify(initializer).init_MessageInfo_3124((MessageInfo) widget);
} }
@Test @Test
public void shouldDoSwitchTextInfo_InitializeWidget() throws Exception { public void shouldDoSwitchTextInfo_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createTextInfo()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createTextInfo());
assertThat(widget).isNotNull().isInstanceOf(TextInfo.class); assertThat(widget).isNotNull().isInstanceOf(TextInfo.class);
verify(initializer).init_TextInfo_3125((TextInfo) widget); verify(initializer).init_TextInfo_3125((TextInfo) widget);
} }
@Test @Test
public void shouldDoSwitchRichTextArea_InitializeWidget() throws Exception { public void shouldDoSwitchRichTextArea_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createRichTextAreaFormField()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createRichTextAreaFormField());
assertThat(widget).isNotNull().isInstanceOf(RichTextAreaFormField.class); assertThat(widget).isNotNull().isInstanceOf(RichTextAreaFormField.class);
verify(initializer).init_RichTextAreaFormField_3128((RichTextAreaFormField) widget); verify(initializer).init_RichTextAreaFormField_3128((RichTextAreaFormField) widget);
} }
@Test @Test
public void shouldDoSwitchGroup_InitializeWidget() throws Exception { public void shouldDoSwitchGroup_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createGroup()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createGroup());
assertThat(widget).isNotNull().isInstanceOf(Group.class); assertThat(widget).isNotNull().isInstanceOf(Group.class);
verify(initializer).init_Group_3106((Group) widget); verify(initializer).init_Group_3106((Group) widget);
} }
@Test @Test
public void shouldDoSwitchTable_InitializeWidget() throws Exception { public void shouldDoSwitchTable_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createTable()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createTable());
assertThat(widget).isNotNull().isInstanceOf(Table.class); assertThat(widget).isNotNull().isInstanceOf(Table.class);
verify(initializer).init_Table_3127((Table) widget); verify(initializer).init_Table_3127((Table) widget);
} }
@Test @Test
public void shouldDoSwitchDynamicTable_InitializeWidget() throws Exception { public void shouldDoSwitchDynamicTable_InitializeWidget() throws Exception {
Widget widget = createWidgetSwitch.doSwitch(formFactory.createDynamicTable()); final Widget widget = createWidgetSwitch.doSwitch(formFactory.createDynamicTable());
assertThat(widget).isNotNull().isInstanceOf(DynamicTable.class); assertThat(widget).isNotNull().isInstanceOf(DynamicTable.class);
verify(initializer).init_DynamicTable_3129((DynamicTable) widget); verify(initializer).init_DynamicTable_3129((DynamicTable) widget);
} }
......
...@@ -195,7 +195,7 @@ public class CreateFormCommand extends AbstractTransactionalCommand { ...@@ -195,7 +195,7 @@ public class CreateFormCommand extends AbstractTransactionalCommand {
protected Widget createWidgetFromMapping(final WidgetContainer container, final WidgetMapping mapping, final int horizontalSpan) { protected Widget createWidgetFromMapping(final WidgetContainer container, final WidgetMapping mapping, final int horizontalSpan) {
if(mapping.isGenerated()){ if(mapping.isGenerated()){
final Widget widget = new CreateWidgetSwitch(ElementInitializers.getInstance()).doSwitch(mapping.getWidgetType()); final Widget widget = new CreateWidgetSwitch(pageFlow, ElementInitializers.getInstance()).doSwitch(mapping.getWidgetType());
widget.setInjectWidgetScript(createInsertWidgetIfScript()); widget.setInjectWidgetScript(createInsertWidgetIfScript());
if(supportReadOnly(widget)){ if(supportReadOnly(widget)){
widget.setReadOnly(mapping.isReadOnly()); widget.setReadOnly(mapping.isReadOnly());
......
...@@ -37,6 +37,8 @@ import org.bonitasoft.studio.model.form.TextFormField; ...@@ -37,6 +37,8 @@ import org.bonitasoft.studio.model.form.TextFormField;
import org.bonitasoft.studio.model.form.TextInfo; import org.bonitasoft.studio.model.form.TextInfo;
import org.bonitasoft.studio.model.form.Widget; import org.bonitasoft.studio.model.form.Widget;
import org.bonitasoft.studio.model.form.util.FormSwitch; import org.bonitasoft.studio.model.form.util.FormSwitch;
import org.bonitasoft.studio.model.process.Element;
import org.bonitasoft.studio.model.process.Pool;
import org.bonitasoft.studio.model.process.diagram.form.providers.ElementInitializers; import org.bonitasoft.studio.model.process.diagram.form.providers.ElementInitializers;
/** /**
...@@ -45,151 +47,160 @@ import org.bonitasoft.studio.model.process.diagram.form.providers.ElementInitial ...@@ -45,151 +47,160 @@ import org.bonitasoft.studio.model.process.diagram.form.providers.ElementInitial
*/ */
public class CreateWidgetSwitch extends FormSwitch<Widget> { public class CreateWidgetSwitch extends FormSwitch<Widget> {
private FormFactory factory ; private final FormFactory factory ;
private ElementInitializers initializer; private final ElementInitializers initializer;
private final Element pageFlow;
public CreateWidgetSwitch(ElementInitializers initializer){ public CreateWidgetSwitch(final Element pageFlow, final ElementInitializers initializer) {
factory = FormFactory.eINSTANCE; factory = FormFactory.eINSTANCE;
this.initializer = initializer; this.initializer = initializer;
this.pageFlow = pageFlow;
} }
@Override @Override
public Widget caseTextFormField(TextFormField object) { public Widget caseTextFormField(final TextFormField object) {
TextFormField widget = factory.createTextFormField(); final TextFormField widget = factory.createTextFormField();
initializer.init_TextFormField_3112(widget); initializer.init_TextFormField_3112(widget);
return widget; return widget;
} }
@Override @Override
public Widget caseTextAreaFormField(TextAreaFormField object) { public Widget caseTextAreaFormField(final TextAreaFormField object) {
TextAreaFormField widget = factory.createTextAreaFormField(); final TextAreaFormField widget = factory.createTextAreaFormField();
initializer.init_TextAreaFormField_3113(widget); initializer.init_TextAreaFormField_3113(widget);
return widget ; return widget ;
} }
@Override @Override
public Widget caseDateFormField(DateFormField object) { public Widget caseDateFormField(final DateFormField object) {
DateFormField widget = factory.createDateFormField(); final DateFormField widget = factory.createDateFormField();
initializer.init_DateFormField_3105(widget); initializer.init_DateFormField_3105(widget);
return widget ; return widget ;
} }
@Override @Override
public Widget caseCheckBoxSingleFormField(CheckBoxSingleFormField object) { public Widget caseCheckBoxSingleFormField(final CheckBoxSingleFormField object) {
CheckBoxSingleFormField widget = factory.createCheckBoxSingleFormField(); final CheckBoxSingleFormField widget = factory.createCheckBoxSingleFormField();
initializer.init_CheckBoxSingleFormField_3118(widget); initializer.init_CheckBoxSingleFormField_3118(widget);
return widget ; return widget ;
} }
@Override @Override
public Widget caseListFormField(ListFormField object) { public Widget caseListFormField(final ListFormField object) {
ListFormField widget = factory.createListFormField(); final ListFormField widget = factory.createListFormField();
initializer.init_ListFormField_3107(widget); initializer.init_ListFormField_3107(widget);
return widget ; return widget ;
} }
@Override @Override
public Widget caseCheckBoxMultipleFormField(CheckBoxMultipleFormField object) { public Widget caseCheckBoxMultipleFormField(final CheckBoxMultipleFormField object) {
CheckBoxMultipleFormField widget = factory.createCheckBoxMultipleFormField(); final CheckBoxMultipleFormField widget = factory.createCheckBoxMultipleFormField();
initializer.init_CheckBoxMultipleFormField_3120(widget); initializer.init_CheckBoxMultipleFormField_3120(widget);
return widget ; return widget ;
} }
@Override @Override
public Widget caseFileWidget(FileWidget object) { public Widget caseFileWidget(final FileWidget object) {
FileWidget widget = factory.createFileWidget(); final FileWidget widget = factory.createFileWidget();
initializer.init_FileWidget_3119(widget); initializer.init_FileWidget_3119(widget);
widget.setInputType(FileWidgetInputType.DOCUMENT); widget.setInputType(getDefaultFileWidgetInputType(widget));
return widget ; return widget ;
} }
private FileWidgetInputType getDefaultFileWidgetInputType(final FileWidget widget) {
if (pageFlow instanceof Pool) {
return FileWidgetInputType.RESOURCE;
}
return FileWidgetInputType.DOCUMENT;
}
@Override @Override
public Widget caseDurationFormField(DurationFormField object) { public Widget caseDurationFormField(final DurationFormField object) {
DurationFormField widget = factory.createDurationFormField(); final DurationFormField widget = factory.createDurationFormField();
initializer.init_DurationFormField_3121(widget); initializer.init_DurationFormField_3121(widget);
return widget ; return widget ;
} }
@Override @Override
public Widget caseRadioFormField(RadioFormField object) { public Widget caseRadioFormField(final RadioFormField object) {
RadioFormField widget = factory.createRadioFormField(); final RadioFormField widget = factory.createRadioFormField();
initializer.init_RadioFormField_3110(widget); initializer.init_RadioFormField_3110(widget);
return widget ; return widget ;
} }
@Override @Override
public Widget casePasswordFormField(PasswordFormField object) { public Widget casePasswordFormField(final PasswordFormField object) {
PasswordFormField widget = factory.createPasswordFormField(); final PasswordFormField widget = factory.createPasswordFormField();
initializer.init_PasswordFormField_3109(widget); initializer.init_PasswordFormField_3109(widget);
return widget ; return widget ;
} }
@Override @Override
public Widget caseSelectFormField(SelectFormField object) { public Widget caseSelectFormField(final SelectFormField object) {
SelectFormField widget = factory.createSelectFormField(); final SelectFormField widget = factory.createSelectFormField();
initializer.init_SelectFormField_3111(widget); initializer.init_SelectFormField_3111(widget);
return widget ; return widget ;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.bonitasoft.studio.model.form.util.FormSwitch#caseMessageInfo(org.bonitasoft.studio.model.form.MessageInfo) * @see org.bonitasoft.studio.model.form.util.FormSwitch#caseMessageInfo(org.bonitasoft.studio.model.form.MessageInfo)
*/ */
@Override @Override
public Widget caseMessageInfo(MessageInfo object) { public Widget caseMessageInfo(final MessageInfo object) {
MessageInfo messageInfo = factory.createMessageInfo(); final MessageInfo messageInfo = factory.createMessageInfo();
initializer.init_MessageInfo_3124(messageInfo); initializer.init_MessageInfo_3124(messageInfo);
return messageInfo; return messageInfo;
} }
/* (non-Javadoc) /* (non-Javadoc)