Commit e99b8217 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

fix(data) classcast in DataWizardPage

Closes STUDIO-3609
parent 5399fa85
...@@ -79,6 +79,8 @@ import org.bonitasoft.studio.model.process.XMLType; ...@@ -79,6 +79,8 @@ import org.bonitasoft.studio.model.process.XMLType;
import org.bonitasoft.studio.model.process.util.ProcessSwitch; import org.bonitasoft.studio.model.process.util.ProcessSwitch;
import org.bonitasoft.studio.pics.Pics; import org.bonitasoft.studio.pics.Pics;
import org.bonitasoft.studio.pics.PicsConstants; import org.bonitasoft.studio.pics.PicsConstants;
import org.bonitasoft.studio.ui.converter.ConverterBuilder;
import org.bonitasoft.studio.ui.databinding.UpdateStrategyFactory;
import org.bonitasoft.studio.xml.repository.XSDFileStore; import org.bonitasoft.studio.xml.repository.XSDFileStore;
import org.bonitasoft.studio.xml.repository.XSDRepositoryStore; import org.bonitasoft.studio.xml.repository.XSDRepositoryStore;
import org.eclipse.core.databinding.UpdateValueStrategy; import org.eclipse.core.databinding.UpdateValueStrategy;
...@@ -229,7 +231,7 @@ public class DataWizardPage extends WizardPage implements IBonitaVariableContext ...@@ -229,7 +231,7 @@ public class DataWizardPage extends WizardPage implements IBonitaVariableContext
private boolean isOverviewContext = false; private boolean isOverviewContext = false;
final private Set<String> availableDataNames = new HashSet<>(); private final Set<String> availableDataNames = new HashSet<>();
private final ViewerFilter typeViewerFilter = new ViewerFilter() { private final ViewerFilter typeViewerFilter = new ViewerFilter() {
...@@ -252,39 +254,42 @@ public class DataWizardPage extends WizardPage implements IBonitaVariableContext ...@@ -252,39 +254,42 @@ public class DataWizardPage extends WizardPage implements IBonitaVariableContext
@Override @Override
public void handleValueChange(final ValueChangeEvent event) { public void handleValueChange(final ValueChangeEvent event) {
final DataType newType = (DataType) event.diff.getNewValue(); if (updateDataType) {
if (newType instanceof JavaType && !(data instanceof JavaObjectData)) { final DataType newType = (DataType) event.diff.getNewValue();
final JavaObjectData javaData = ProcessFactory.eINSTANCE.createJavaObjectData(); if (newType instanceof JavaType && !(data instanceof JavaObjectData)) {
javaData.setDataType(newType); final JavaObjectData javaData = ProcessFactory.eINSTANCE.createJavaObjectData();
javaData.setClassName(List.class.getName()); javaData.setDataType(newType);
copyDataFeature(javaData); javaData.setClassName(List.class.getName());
data = javaData; copyDataFeature(javaData);
} else if (newType instanceof XMLType && !(data instanceof XMLData)) { data = javaData;
final XMLData xmlData = ProcessFactory.eINSTANCE.createXMLData(); } else if (newType instanceof XMLType && !(data instanceof XMLData)) {
xmlData.setDataType(newType); final XMLData xmlData = ProcessFactory.eINSTANCE.createXMLData();
copyDataFeature(xmlData); xmlData.setDataType(newType);
data = xmlData; copyDataFeature(xmlData);
} else { data = xmlData;
if (!data.eClass().equals(ProcessPackage.Literals.DATA)) {
Data simpleData = ProcessFactory.eINSTANCE.createData();
simpleData.setDataType(newType);
copyDataFeature(simpleData);
data = simpleData;
} else { } else {
data.setDataType(newType); if (!data.eClass().equals(ProcessPackage.Literals.DATA)) {
Data simpleData = ProcessFactory.eINSTANCE.createData();
simpleData.setDataType(newType);
copyDataFeature(simpleData);
data = simpleData;
} else {
data.setDataType(newType);
}
} }
}
updateMoreSection(newType); updateMoreSection(newType);
updateBrowseXMLButton(newType); updateBrowseXMLButton(newType);
if (mainComposite != null && !mainComposite.isDisposed()) { if (mainComposite != null && !mainComposite.isDisposed()) {
final Composite parent = mainComposite.getParent(); final Composite parent = mainComposite.getParent();
final Point defaultSize = parent.getSize(); final Point defaultSize = parent.getSize();
final Point size = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); final Point size = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
parent.setSize(defaultSize.x, size.y); parent.setSize(defaultSize.x, size.y);
parent.layout(true, true); parent.layout(true, true);
}
updateDatabinding();
updateDataType = false;
} }
updateDatabinding();
} }
}; };
...@@ -300,6 +305,8 @@ public class DataWizardPage extends WizardPage implements IBonitaVariableContext ...@@ -300,6 +305,8 @@ public class DataWizardPage extends WizardPage implements IBonitaVariableContext
private CLabel transientDataWarning; private CLabel transientDataWarning;
private boolean updateDataType;
public DataWizardPage(final Data data, final EObject container, final boolean allowXML, final boolean allowEnum, public DataWizardPage(final Data data, final EObject container, final boolean allowXML, final boolean allowEnum,
final boolean showIsTransient, final boolean showIsTransient,
final boolean showAutoGenerateform, final Set<EStructuralFeature> featureToCheckForUniqueID, final boolean showAutoGenerateform, final Set<EStructuralFeature> featureToCheckForUniqueID,
...@@ -659,7 +666,19 @@ public class DataWizardPage extends WizardPage implements IBonitaVariableContext ...@@ -659,7 +666,19 @@ public class DataWizardPage extends WizardPage implements IBonitaVariableContext
modelObservable.addValueChangeListener(typeChangeListener); modelObservable.addValueChangeListener(typeChangeListener);
observeSingleSelectionTypeCombo = ViewersObservables.observeSingleSelection(typeCombo); observeSingleSelectionTypeCombo = ViewersObservables.observeSingleSelection(typeCombo);
emfDatabindingContext.bindValue(observeSingleSelectionTypeCombo, modelObservable, null, null); emfDatabindingContext.bindValue(observeSingleSelectionTypeCombo,
modelObservable,
UpdateStrategyFactory.updateValueStrategy()
.withConverter(ConverterBuilder.<DataType, DataType> newConverter()
.fromType(DataType.class)
.toType(DataType.class)
.withConvertFunction(dataType -> {
updateDataType = true;
return dataType;
})
.create())
.create(),
null);
} }
protected void bindDefaultValueViewer() { protected void bindDefaultValueViewer() {
......
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