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

Fix FileWidget Initialization

parent c90d56b7
......@@ -148,7 +148,11 @@ public class ModelHelper {
}
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.DOCUMENT;
......
......@@ -26,6 +26,7 @@ import org.bonitasoft.studio.model.form.DateFormField;
import org.bonitasoft.studio.model.form.DurationFormField;
import org.bonitasoft.studio.model.form.DynamicTable;
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.Group;
import org.bonitasoft.studio.model.form.ListFormField;
......@@ -39,6 +40,8 @@ import org.bonitasoft.studio.model.form.TextAreaFormField;
import org.bonitasoft.studio.model.form.TextFormField;
import org.bonitasoft.studio.model.form.TextInfo;
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.junit.After;
import org.junit.Before;
......@@ -55,10 +58,10 @@ import org.mockito.runners.MockitoJUnitRunner;
public class CreateWidgetSwitchTest {
private CreateWidgetSwitch createWidgetSwitch;
@Mock
private ElementInitializers initializer;
private FormFactory formFactory;
/**
......@@ -67,7 +70,7 @@ public class CreateWidgetSwitchTest {
@Before
public void setUp() throws Exception {
formFactory = FormFactory.eINSTANCE;
createWidgetSwitch = new CreateWidgetSwitch(initializer);
createWidgetSwitch = new CreateWidgetSwitch(TaskBuilder.createTaskBuilder().build(), initializer);
}
/**
......@@ -76,122 +79,127 @@ public class CreateWidgetSwitchTest {
@After
public void tearDown() throws Exception {
}
@Test
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);
verify(initializer).init_TextFormField_3112((TextFormField) widget);
}
@Test
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);
verify(initializer).init_TextAreaFormField_3113((TextAreaFormField) widget);
}
@Test
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);
verify(initializer).init_DateFormField_3105((DateFormField) widget);
}
@Test
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);
verify(initializer).init_SelectFormField_3111((SelectFormField) widget);
}
@Test
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);
verify(initializer).init_PasswordFormField_3109((PasswordFormField) widget);
}
@Test
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);
verify(initializer).init_ListFormField_3107((ListFormField) widget);
}
@Test
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);
verify(initializer).init_CheckBoxSingleFormField_3118((CheckBoxSingleFormField) widget);
}
@Test
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);
verify(initializer).init_CheckBoxMultipleFormField_3120((CheckBoxMultipleFormField) widget);
}
@Test
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(((FileWidget) widget).getInputType()).isEqualTo(FileWidgetInputType.DOCUMENT);
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
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);
verify(initializer).init_DurationFormField_3121((DurationFormField) widget);
}
@Test
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);
verify(initializer).init_RadioFormField_3110((RadioFormField) widget);
}
@Test
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);
verify(initializer).init_MessageInfo_3124((MessageInfo) widget);
}
@Test
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);
verify(initializer).init_TextInfo_3125((TextInfo) widget);
}
@Test
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);
verify(initializer).init_RichTextAreaFormField_3128((RichTextAreaFormField) widget);
}
@Test
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);
verify(initializer).init_Group_3106((Group) widget);
}
@Test
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);
verify(initializer).init_Table_3127((Table) widget);
}
@Test
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);
verify(initializer).init_DynamicTable_3129((DynamicTable) widget);
}
......
......@@ -195,7 +195,7 @@ public class CreateFormCommand extends AbstractTransactionalCommand {
protected Widget createWidgetFromMapping(final WidgetContainer container, final WidgetMapping mapping, final int horizontalSpan) {
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());
if(supportReadOnly(widget)){
widget.setReadOnly(mapping.isReadOnly());
......
......@@ -37,6 +37,8 @@ import org.bonitasoft.studio.model.form.TextFormField;
import org.bonitasoft.studio.model.form.TextInfo;
import org.bonitasoft.studio.model.form.Widget;
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;
/**
......@@ -45,151 +47,160 @@ import org.bonitasoft.studio.model.process.diagram.form.providers.ElementInitial
*/
public class CreateWidgetSwitch extends FormSwitch<Widget> {
private FormFactory factory ;
private ElementInitializers initializer;
private final FormFactory factory ;
private final ElementInitializers initializer;
private final Element pageFlow;
public CreateWidgetSwitch(ElementInitializers initializer){
public CreateWidgetSwitch(final Element pageFlow, final ElementInitializers initializer) {
factory = FormFactory.eINSTANCE;
this.initializer = initializer;
this.pageFlow = pageFlow;
}
@Override
public Widget caseTextFormField(TextFormField object) {
TextFormField widget = factory.createTextFormField();
public Widget caseTextFormField(final TextFormField object) {
final TextFormField widget = factory.createTextFormField();
initializer.init_TextFormField_3112(widget);
return widget;
}
@Override
public Widget caseTextAreaFormField(TextAreaFormField object) {
TextAreaFormField widget = factory.createTextAreaFormField();
public Widget caseTextAreaFormField(final TextAreaFormField object) {
final TextAreaFormField widget = factory.createTextAreaFormField();
initializer.init_TextAreaFormField_3113(widget);
return widget ;
}
@Override
public Widget caseDateFormField(DateFormField object) {
DateFormField widget = factory.createDateFormField();
public Widget caseDateFormField(final DateFormField object) {
final DateFormField widget = factory.createDateFormField();
initializer.init_DateFormField_3105(widget);
return widget ;
}
@Override
public Widget caseCheckBoxSingleFormField(CheckBoxSingleFormField object) {
CheckBoxSingleFormField widget = factory.createCheckBoxSingleFormField();
public Widget caseCheckBoxSingleFormField(final CheckBoxSingleFormField object) {
final CheckBoxSingleFormField widget = factory.createCheckBoxSingleFormField();
initializer.init_CheckBoxSingleFormField_3118(widget);
return widget ;
}
@Override
public Widget caseListFormField(ListFormField object) {
ListFormField widget = factory.createListFormField();
public Widget caseListFormField(final ListFormField object) {
final ListFormField widget = factory.createListFormField();
initializer.init_ListFormField_3107(widget);
return widget ;
}
@Override
public Widget caseCheckBoxMultipleFormField(CheckBoxMultipleFormField object) {
CheckBoxMultipleFormField widget = factory.createCheckBoxMultipleFormField();
public Widget caseCheckBoxMultipleFormField(final CheckBoxMultipleFormField object) {
final CheckBoxMultipleFormField widget = factory.createCheckBoxMultipleFormField();
initializer.init_CheckBoxMultipleFormField_3120(widget);
return widget ;
}
@Override
public Widget caseFileWidget(FileWidget object) {
FileWidget widget = factory.createFileWidget();
public Widget caseFileWidget(final FileWidget object) {
final FileWidget widget = factory.createFileWidget();
initializer.init_FileWidget_3119(widget);
widget.setInputType(FileWidgetInputType.DOCUMENT);
widget.setInputType(getDefaultFileWidgetInputType(widget));
return widget ;
}
private FileWidgetInputType getDefaultFileWidgetInputType(final FileWidget widget) {
if (pageFlow instanceof Pool) {
return FileWidgetInputType.RESOURCE;
}
return FileWidgetInputType.DOCUMENT;
}
@Override
public Widget caseDurationFormField(DurationFormField object) {
DurationFormField widget = factory.createDurationFormField();
public Widget caseDurationFormField(final DurationFormField object) {
final DurationFormField widget = factory.createDurationFormField();
initializer.init_DurationFormField_3121(widget);
return widget ;
}
@Override
public Widget caseRadioFormField(RadioFormField object) {
RadioFormField widget = factory.createRadioFormField();
public Widget caseRadioFormField(final RadioFormField object) {
final RadioFormField widget = factory.createRadioFormField();
initializer.init_RadioFormField_3110(widget);
return widget ;
}
@Override
public Widget casePasswordFormField(PasswordFormField object) {
PasswordFormField widget = factory.createPasswordFormField();
public Widget casePasswordFormField(final PasswordFormField object) {
final PasswordFormField widget = factory.createPasswordFormField();
initializer.init_PasswordFormField_3109(widget);
return widget ;
}
@Override
public Widget caseSelectFormField(SelectFormField object) {
SelectFormField widget = factory.createSelectFormField();
public Widget caseSelectFormField(final SelectFormField object) {
final SelectFormField widget = factory.createSelectFormField();
initializer.init_SelectFormField_3111(widget);
return widget ;
}
/* (non-Javadoc)
* @see org.bonitasoft.studio.model.form.util.FormSwitch#caseMessageInfo(org.bonitasoft.studio.model.form.MessageInfo)
*/
@Override
public Widget caseMessageInfo(MessageInfo object) {
MessageInfo messageInfo = factory.createMessageInfo();
public Widget caseMessageInfo(final MessageInfo object) {
final MessageInfo messageInfo = factory.createMessageInfo();
initializer.init_MessageInfo_3124(messageInfo);
return messageInfo;
}
/* (non-Javadoc)
* @see org.bonitasoft.studio.model.form.util.FormSwitch#caseTextInfo(org.bonitasoft.studio.model.form.TextInfo)
*/
@Override
public Widget caseTextInfo(TextInfo object) {
TextInfo textInfo = factory.createTextInfo();
public Widget caseTextInfo(final TextInfo object) {
final TextInfo textInfo = factory.createTextInfo();
initializer.init_TextInfo_3125(textInfo);
return textInfo;
}
/* (non-Javadoc)
* @see org.bonitasoft.studio.model.form.util.FormSwitch#caseRichTextAreaFormField(org.bonitasoft.studio.model.form.RichTextAreaFormField)
*/
@Override
public Widget caseRichTextAreaFormField(RichTextAreaFormField object) {
RichTextAreaFormField richTextArea = factory.createRichTextAreaFormField();
public Widget caseRichTextAreaFormField(final RichTextAreaFormField object) {
final RichTextAreaFormField richTextArea = factory.createRichTextAreaFormField();
initializer.init_RichTextAreaFormField_3128(richTextArea);
return richTextArea;
}
/* (non-Javadoc)
* @see org.bonitasoft.studio.model.form.util.FormSwitch#caseTable(org.bonitasoft.studio.model.form.Table)
*/
@Override
public Widget caseTable(Table object) {
Table table = factory.createTable();
public Widget caseTable(final Table object) {
final Table table = factory.createTable();
initializer.init_Table_3127(table);
return table;
}
/* (non-Javadoc)
* @see org.bonitasoft.studio.model.form.util.FormSwitch#caseDynamicTable(org.bonitasoft.studio.model.form.DynamicTable)
*/
@Override
public Widget caseDynamicTable(DynamicTable object) {
DynamicTable table = factory.createDynamicTable();
public Widget caseDynamicTable(final DynamicTable object) {
final DynamicTable table = factory.createDynamicTable();
initializer.init_DynamicTable_3129(table);
return table;
}
/* (non-Javadoc)
* @see org.bonitasoft.studio.model.form.util.FormSwitch#caseGroup(org.bonitasoft.studio.model.form.Group)
*/
@Override
public Widget caseGroup(Group object) {
Group group = factory.createGroup();
public Widget caseGroup(final Group object) {
final Group group = factory.createGroup();
initializer.init_Group_3106(group);
return group;
}
}
......@@ -7,7 +7,7 @@ Bundle-ClassPath: .
Bundle-Activator: org.bonitasoft.studio.model.process.diagram.form.part.FormDiagramEditorPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.bonitasoft.studio.model.process.diagram.form.edit.parts,
Export-Package: org.bonitasoft.studio.model.process.diagram.form.edit.parts,
org.bonitasoft.studio.model.process.diagram.form.part,
org.bonitasoft.studio.model.process.diagram.form.providers
Require-Bundle: org.eclipse.core.runtime,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment