Commit e5c6631b authored by azara's avatar azara
Browse files

BS-13234 generate input contract from selected business data field

parent 81c0f99b
......@@ -42,9 +42,12 @@ removeInputErrorTitle=Remove failed
removeInputErrorMsg=An error occurred when removing contract input.
severalCompilationErrors={0} compilation errors found.
SelectBusinessDataWizardPageTitle=Select business data
selectBusinessDataWizardPageDescription=Select business data from wich contract input will be generated.
generate=Generate...
contractInputGenerationTitle=Contract input generation
rootContractInputName=Root input name
selectFieldToGenerateTitle=Select business object fields to generate
selectBusinessDataWizardPageDescription=Select business variable from wich contract input will be generated.
generate=Add from data...
contractInputGenerationTitle=Contract input
rootContractInputName=Input name
selectFieldToGenerateTitle=Select {0} attributes to add to contract
selectFieldToGenerateDescription=Choose the fields you want to reuse in your contract.
inputOfType=of type COMPLEX
inputType=Input type
attributetype=Attribute type
/**
* Copyright (C) 2015 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.contract.ui.wizard.labelProvider;
import static org.assertj.core.api.Assertions.assertThat;
import org.bonitasoft.engine.bdm.model.field.RelationField;
import org.bonitasoft.engine.bdm.model.field.SimpleField;
import org.bonitasoft.studio.contract.core.mapping.RelationFieldToContractInputMapping;
import org.bonitasoft.studio.contract.core.mapping.SimpleFieldToContractInputMapping;
import org.bonitasoft.studio.model.businessObject.BusinessObjectBuilder;
import org.bonitasoft.studio.model.businessObject.FieldBuilder.RelationFieldBuilder;
import org.bonitasoft.studio.model.businessObject.FieldBuilder.SimpleFieldBuilder;
import org.junit.Test;
public class FieldNameColumnLabelProviderTest {
@Test
public void should_return_a_simpleField_name() {
final SimpleFieldToContractInputMapping mapping = new SimpleFieldToContractInputMapping((SimpleField) SimpleFieldBuilder.aSimpleField()
.withName("employee").build());
final FieldNameColumnLabelProvider provider = new FieldNameColumnLabelProvider();
assertThat(provider.getText(mapping)).isEqualTo("employee");
}
@Test
public void should_return_a_RelationField_name() {
final RelationFieldToContractInputMapping mapping = new RelationFieldToContractInputMapping((RelationField) RelationFieldBuilder.anAggregationField(
"employee",
BusinessObjectBuilder.aBO("Employee").build()));
final FieldNameColumnLabelProvider provider = new FieldNameColumnLabelProvider();
assertThat(provider.getText(mapping)).isEqualTo("employee");
}
}
......@@ -33,7 +33,6 @@ public class FieldToContractInputMappingFactory {
public FieldToContractInputMappingFactory(final BusinessObjectModelRepositoryStore businessObjectStore) {
this.businessObjectStore = businessObjectStore;
}
public List<FieldToContractInputMapping> createMappingForBusinessObjectType(final String className) {
......@@ -59,7 +58,7 @@ public class FieldToContractInputMappingFactory {
private FieldToContractInputMapping createRelationFieldToContractInputMapping(final RelationField field) {
final RelationFieldToContractInputMapping relationFieldMapping = new RelationFieldToContractInputMapping(field);
if (((RelationField) relationFieldMapping.getField()).getType().equals(Type.COMPOSITION)) {
if (Type.COMPOSITION.equals(((RelationField) relationFieldMapping.getField()).getType())) {
for (final Field child : field.getReference().getFields()) {
relationFieldMapping.addChild(createFieldToContractInputMapping(child));
}
......
......@@ -77,5 +77,8 @@ public class Messages extends NLS {
public static String rootContractInputName;
public static String selectFieldToGenerateTitle;
public static String selectFieldToGenerateDescription;
public static String inputOfType;
public static String inputType;
public static String attributetype;
}
......@@ -42,7 +42,6 @@ public class ContractContainerAdaptableSelectionProvider extends EObjectAdaptabl
} else if (unwrapSelection instanceof EObject) {
return asContractContainer((EObject) unwrapSelection);
}
}
return null;
}
......
/**
* Copyright (C) 2015 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.contract.ui.provider;
import java.util.Collection;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.field.Field;
import org.bonitasoft.engine.bdm.model.field.RelationField;
import org.bonitasoft.engine.bdm.model.field.RelationField.Type;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
/**
* @author aurelie
*/
public class BusinessObjectFieldsContentProvider implements ITreeContentProvider {
public BusinessObjectFieldsContentProvider() {
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
@Override
public void dispose() {
// TODO Auto-generated method stub
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
// TODO Auto-generated method stub
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
*/
@Override
public Object[] getElements(final Object inputElement) {
final String message = "input must be a instance of " + Collection.class.getName() + "<" + Field.class.getName() + ">";
Assert.isLegal(inputElement instanceof Collection, message);
final Collection<?> collection = Collection.class.cast(inputElement);
if (!collection.isEmpty()) {
Assert.isLegal(collection.iterator().next() instanceof Field, message);
}
return collection.toArray();
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
*/
@Override
public Object[] getChildren(final Object parentElement) {
if (parentElement instanceof RelationField && ((RelationField) parentElement).getType().equals(Type.COMPOSITION)) {
final BusinessObject bo = ((RelationField) parentElement).getReference();
return Collection.class.cast(bo.getFields()).toArray();
}
return null;
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
*/
@Override
public Object getParent(final Object element) {
// TODO Auto-generated method stub
return null;
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
*/
@Override
public boolean hasChildren(final Object element) {
if (element instanceof RelationField && ((RelationField) element).getType().equals(Type.COMPOSITION)) {
return true;
}
return false;
}
}
......@@ -66,6 +66,7 @@ public class ContractInputGenerationWizard extends Wizard {
addPage(new SelectBusinessDataWizardPage(availableBusinessData, selectedDataObservable, businessObjectStore));
contractInputFromBusinessObjectWizardPage = new CreateContractInputFromBusinessObjectWizardPage(contractContainer.getContract(),
selectedDataObservable, new FieldToContractInputMappingFactory(businessObjectStore));
contractInputFromBusinessObjectWizardPage.setTitle();
addPage(contractInputFromBusinessObjectWizardPage);
}
......
......@@ -26,36 +26,32 @@ import java.util.List;
import org.bonitasoft.studio.common.NamingUtils;
import org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMapping;
import org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMappingFactory;
import org.bonitasoft.studio.contract.core.mapping.RelationFieldToContractInputMapping;
import org.bonitasoft.studio.contract.i18n.Messages;
import org.bonitasoft.studio.contract.ui.wizard.labelProvider.FieldNameColumnLabelProvider;
import org.bonitasoft.studio.contract.ui.wizard.labelProvider.FieldTypeColumnLabelProvider;
import org.bonitasoft.studio.contract.ui.wizard.labelProvider.InputTypeColumnLabelProvider;
import org.bonitasoft.studio.model.process.BusinessObjectData;
import org.bonitasoft.studio.model.process.Contract;
import org.bonitasoft.studio.model.process.ContractInput;
import org.bonitasoft.studio.model.process.Element;
import org.bonitasoft.studio.model.process.ProcessPackage;
import org.eclipse.core.databinding.beans.PojoObservables;
import org.eclipse.core.databinding.conversion.Converter;
import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.emf.databinding.EMFDataBindingContext;
import org.eclipse.emf.databinding.EMFObservables;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider;
import org.eclipse.jface.databinding.viewers.TreeStructureAdvisor;
import org.eclipse.jface.databinding.viewers.ViewersObservables;
import org.eclipse.jface.databinding.wizard.WizardPageSupport;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ICheckStateProvider;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
......@@ -68,7 +64,7 @@ import com.google.common.base.Function;
/**
* @author aurelie
*/
public class CreateContractInputFromBusinessObjectWizardPage extends WizardPage implements ICheckStateListener, ICheckStateProvider {
public class CreateContractInputFromBusinessObjectWizardPage extends WizardPage {
private final WritableValue selectedDataObservable;
private CheckboxTreeViewer treeViewer;
......@@ -85,13 +81,26 @@ public class CreateContractInputFromBusinessObjectWizardPage extends WizardPage
protected CreateContractInputFromBusinessObjectWizardPage(final Contract contract, final WritableValue selectedDataObservable,
final FieldToContractInputMappingFactory fieldToContractInputMappingFactory) {
super(CreateContractInputFromBusinessObjectWizardPage.class.getName());
setTitle(Messages.selectFieldToGenerateTitle);
setDescription(Messages.selectFieldToGenerateDescription);
this.selectedDataObservable = selectedDataObservable;
this.fieldToContractInputMappingFactory = fieldToContractInputMappingFactory;
this.contract = contract;
}
public void setTitle() {
if (selectedDataObservable.getValue() != null) {
setTitle(Messages.bind(Messages.selectFieldToGenerateTitle, ((Element) selectedDataObservable.getValue()).getName()));
EMFObservables.observeDetailValue(Realm.getDefault(), selectedDataObservable, ProcessPackage.Literals.ELEMENT__NAME).addValueChangeListener(
new IValueChangeListener() {
@Override
public void handleValueChange(final ValueChangeEvent event) {
setTitle(Messages.bind(Messages.selectFieldToGenerateTitle, event.diff.getNewValue()));
}
});
}
};
/*
* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
......@@ -114,13 +123,15 @@ public class CreateContractInputFromBusinessObjectWizardPage extends WizardPage
*/
private void createRootNameControl(final EMFDataBindingContext dbc, final Composite composite) {
final Composite rootNameComposite = new Composite(composite, SWT.NONE);
rootNameComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).create());
rootNameComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).create());
rootNameComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
final Label label = new Label(rootNameComposite, SWT.NONE);
label.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
label.setText(Messages.rootContractInputName);
final Text prefixText = new Text(rootNameComposite, SWT.BORDER);
prefixText.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
final Label typeLabel = new Label(rootNameComposite, SWT.NONE);
typeLabel.setText(Messages.inputOfType);
final IObservableValue prefixObservable = PojoObservables.observeValue(this, "rootName");
dbc.bindValue(prefixObservable,
EMFObservables.observeDetailValue(Realm.getDefault(), selectedDataObservable, ProcessPackage.Literals.ELEMENT__NAME),
......@@ -163,39 +174,11 @@ public class CreateContractInputFromBusinessObjectWizardPage extends WizardPage
treeViewer = new CheckboxTreeViewer(composite, SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL);
treeViewer.getTree().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 200).create());
treeViewer.getTree().setHeaderVisible(true);
treeViewer.addCheckStateListener(this);
treeViewer.setCheckStateProvider(this);
treeViewer.setContentProvider(new ObservableListTreeContentProvider(new IObservableFactory() {
@Override
public IObservable createObservable(final Object target) {
if (target instanceof List<?>) {
return new WritableList((List<?>) target, FieldToContractInputMapping.class);
} else if (target instanceof RelationFieldToContractInputMapping) {
return new WritableList(((RelationFieldToContractInputMapping) target).getChildren(), FieldToContractInputMapping.class);
}
return new WritableList();
}
}, new TreeStructureAdvisor() {
/*
* (non-Javadoc)
* @see org.eclipse.jface.databinding.viewers.TreeStructureAdvisor#getParent(java.lang.Object)
*/
@Override
public Object getParent(final Object element) {
return ((FieldToContractInputMapping) element).getParent();
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.databinding.viewers.TreeStructureAdvisor#hasChildren(java.lang.Object)
*/
@Override
public Boolean hasChildren(final Object element) {
return !((FieldToContractInputMapping) element).getChildren().isEmpty();
}
}));
final FieldToContractInputMappingViewerCheckStateManager manager = new FieldToContractInputMappingViewerCheckStateManager();
treeViewer.addCheckStateListener(manager);
treeViewer.setCheckStateProvider(manager);
treeViewer.setContentProvider(new ObservableListTreeContentProvider(new FieldToContractInputMappingObservableFactory(),
new FieldToContractInputMappingTreeStructureAdvisor()));
final TreeViewerColumn nameTreeViewerColumn = new TreeViewerColumn(treeViewer, SWT.FILL);
nameTreeViewerColumn.getColumn().setText(Messages.name);
......@@ -203,10 +186,15 @@ public class CreateContractInputFromBusinessObjectWizardPage extends WizardPage
nameTreeViewerColumn.setLabelProvider(new FieldNameColumnLabelProvider());
final TreeViewerColumn typeTreeViewerColumn = new TreeViewerColumn(treeViewer, SWT.FILL);
typeTreeViewerColumn.getColumn().setText(Messages.type);
typeTreeViewerColumn.getColumn().setWidth(250);
typeTreeViewerColumn.getColumn().setText(Messages.attributetype);
typeTreeViewerColumn.getColumn().setWidth(150);
typeTreeViewerColumn.setLabelProvider(new FieldTypeColumnLabelProvider());
final TreeViewerColumn inputTypeTreeViewerColumn = new TreeViewerColumn(treeViewer, SWT.FILL);
inputTypeTreeViewerColumn.getColumn().setText(Messages.inputType);
inputTypeTreeViewerColumn.getColumn().setWidth(150);
inputTypeTreeViewerColumn.setLabelProvider(new InputTypeColumnLabelProvider());
dbc.bindValue(ViewersObservables.observeInput(treeViewer),
selectedDataObservable,
null,
......@@ -231,60 +219,6 @@ public class CreateContractInputFromBusinessObjectWizardPage extends WizardPage
return mappings;
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent)
*/
@Override
public void checkStateChanged(final CheckStateChangedEvent event) {
final FieldToContractInputMapping mapping = (FieldToContractInputMapping) event.getElement();
mapping.setGenerated(event.getChecked());
// SELECT/DESELECT ALL CHILDREN
final CheckboxTreeViewer checkboxTreeViewer = (CheckboxTreeViewer) event.getSource();
checkboxTreeViewer.setSubtreeChecked(mapping, event.getChecked());
//SELECT PARENT IF CHILD IS SELECTED
if (event.getChecked()) {
if (mapping.getParent() != null) {
checkboxTreeViewer.setChecked(mapping.getParent(), true);
}
}
// DESELECT PARENT IF NO CHILD SELECTED
if (!event.getChecked() && mapping.getParent() != null) {
boolean deselect = true;
for (final FieldToContractInputMapping m : mapping.getParent().getChildren()) {
if (checkboxTreeViewer.getChecked(m)) {
deselect = false;
}
}
// ALL CHILD ARE UNCHECKED
if (deselect) {
checkboxTreeViewer.setChecked(mapping.getParent(), false);
}
}
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.ICheckStateProvider#isChecked(java.lang.Object)
*/
@Override
public boolean isChecked(final Object element) {
return ((FieldToContractInputMapping) element).isGenerated();
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.ICheckStateProvider#isGrayed(java.lang.Object)
*/
@Override
public boolean isGrayed(final Object element) {
return false;
}
public String getRootName() {
return rootName;
}
......
/**
* Copyright (C) 2015 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.contract.ui.wizard;
import java.util.List;
import org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMapping;
import org.bonitasoft.studio.contract.core.mapping.RelationFieldToContractInputMapping;
import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
/**
* @author aurelie
*/
public class FieldToContractInputMappingObservableFactory implements IObservableFactory {
/*
* (non-Javadoc)
* @see org.eclipse.core.databinding.observable.masterdetail.IObservableFactory#createObservable(java.lang.Object)
*/
@Override
public IObservable createObservable(final Object target) {
if (target instanceof List<?>) {
return new WritableList((List<?>) target, FieldToContractInputMapping.class);
} else if (target instanceof RelationFieldToContractInputMapping) {
return new WritableList(((RelationFieldToContractInputMapping) target).getChildren(), FieldToContractInputMapping.class);
}
return new WritableList();
}
}
/**
* Copyright (C) 2015 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.contract.ui.wizard;
import org.bonitasoft.studio.contract.core.mapping.FieldToContractInputMapping;
import org.eclipse.jface.databinding.viewers.TreeStructureAdvisor;
/**
* @author aurelie
*/
public class FieldToContractInputMappingTreeStructureAdvisor extends TreeStructureAdvisor {
/*
* (non-Javadoc)
* @see org.eclipse.jface.databinding.viewers.TreeStructureAdvisor#getParent(java.lang.Object)
*/
@Override
public Object getParent(final Object element) {
return ((FieldToContractInputMapping) element).getParent();
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.databinding.viewers.TreeStructureAdvisor#hasChildren(java.lang.Object)
*/
@Override
public Boolean hasChildren(final Object element) {
return !((FieldToContractInputMapping) element).getChildren().isEmpty();
}
}
/**
* Copyright (C) 2015 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.