Commit 8056a3d9 authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub

fix(property) fix property selection provider (#539)

Closes BS-16729
parent a1af659c
......@@ -19,8 +19,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.bonitasoft.studio.common.emf.tools.ModelHelper;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.diagram.custom.repository.DiagramRepositoryStore;
......@@ -30,17 +28,14 @@ import org.bonitasoft.studio.model.process.CallActivity;
import org.bonitasoft.studio.model.process.ContractInput;
import org.bonitasoft.studio.model.process.Data;
import org.bonitasoft.studio.model.process.Pool;
import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.emf.ecore.EObject;
@Creatable
public class CallActivityHelper {
private final RepositoryAccessor repositoryAccessor;
private final CallActivitySelectionProvider selectionProvider;
@Inject
public CallActivityHelper(RepositoryAccessor repositoryAccessor, CallActivitySelectionProvider selectionProvider) {
this.repositoryAccessor = repositoryAccessor;
this.selectionProvider = selectionProvider;
......
......@@ -14,8 +14,6 @@
*/
package org.bonitasoft.studio.properties.sections.callActivity;
import javax.inject.Singleton;
import org.bonitasoft.studio.common.jface.selection.EObjectAdaptableSelectionProvider;
import org.bonitasoft.studio.model.process.CallActivity;
import org.eclipse.core.runtime.IAdaptable;
......@@ -23,7 +21,6 @@ import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.emf.ecore.EObject;
@Creatable
@Singleton
public class CallActivitySelectionProvider extends EObjectAdaptableSelectionProvider {
/*
......@@ -37,8 +34,9 @@ public class CallActivitySelectionProvider extends EObjectAdaptableSelectionProv
final Object object = unwrap(selection);
if (object instanceof EObject) {
return asCallActivity((EObject) object);
} else if (object != null) {
return asCallActivity((EObject) ((IAdaptable) object).getAdapter(EObject.class));
}
return asCallActivity((EObject) ((IAdaptable) object).getAdapter(EObject.class));
}
return null;
}
......
......@@ -29,6 +29,7 @@ import org.bonitasoft.studio.common.jface.SWTBotConstants;
import org.bonitasoft.studio.common.jface.databinding.CustomEMFEditObservables;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.properties.AbstractBonitaDescriptionSection;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.widgets.MagicComposite;
import org.bonitasoft.studio.expression.editor.filter.AvailableExpressionTypeFilter;
import org.bonitasoft.studio.expression.editor.viewer.ExpressionViewer;
......@@ -75,15 +76,10 @@ import org.eclipse.ui.progress.IProgressService;
public class InputParametersMappingSection extends AbstractBonitaDescriptionSection {
@Inject
private FetchContractOperation fetchContractOperation;
@Inject
private IProgressService progressService;
@Inject
private ISharedImages sharedImages;
@Inject
private CallActivitySelectionProvider selectionProvider;
@Inject
private CallActivityHelper callActivityHelper;
private MagicComposite inputMappingControl;
......@@ -92,6 +88,19 @@ public class InputParametersMappingSection extends AbstractBonitaDescriptionSect
private EMFDataBindingContext dbc;
@Inject
public InputParametersMappingSection(RepositoryAccessor repositoryAccessor,
FetchContractOperation fetchContractOperation,
IProgressService progressService,
ISharedImages sharedImages,
CallActivitySelectionProvider selectionProvider) {
this.fetchContractOperation = fetchContractOperation;
this.progressService = progressService;
this.sharedImages = sharedImages;
this.selectionProvider = selectionProvider;
this.callActivityHelper = new CallActivityHelper(repositoryAccessor, selectionProvider);
}
@Override
public void refresh() {
super.refresh();
......@@ -138,7 +147,8 @@ public class InputParametersMappingSection extends AbstractBonitaDescriptionSect
createInputMapping(null, InputMappingAssignationType.CONTRACT_INPUT, input.getName());
}
} catch (final InvocationTargetException ex) {
MessageDialogWithLink.openWarning(mainComposite.getShell(), Messages.fetchContract, ex.getCause().getMessage());
MessageDialogWithLink.openWarning(mainComposite.getShell(), Messages.fetchContract,
ex.getCause().getMessage());
} catch (final InterruptedException e1) {
BonitaStudioLog.error(e1);
}
......@@ -202,8 +212,10 @@ public class InputParametersMappingSection extends AbstractBonitaDescriptionSect
neverUpdateValueStrategy().create(), updateValueStrategy().withConverter(hideIfEmpty()).create());
final Button addLineButton = getWidgetFactory().createButton(composite, Messages.Add, SWT.FLAT);
addLineButton.setLayoutData(GridDataFactory.swtDefaults().hint(IDialogConstants.BUTTON_WIDTH, SWT.DEFAULT).indent(15, 0).create());
addLineButton.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, SWTBotConstants.SWTBOT_ID_CALLACTIVITY_MAPPING_ADD_INPUT);
addLineButton.setLayoutData(
GridDataFactory.swtDefaults().hint(IDialogConstants.BUTTON_WIDTH, SWT.DEFAULT).indent(15, 0).create());
addLineButton.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY,
SWTBotConstants.SWTBOT_ID_CALLACTIVITY_MAPPING_ADD_INPUT);
addLineButton.addListener(SWT.Selection, new Listener() {
@Override
......@@ -228,16 +240,19 @@ public class InputParametersMappingSection extends AbstractBonitaDescriptionSect
};
}
protected void createInputMapping(final Data source, final InputMappingAssignationType assignationType, final String target) {
protected void createInputMapping(final Data source, final InputMappingAssignationType assignationType,
final String target) {
final InputMapping mapping = ProcessFactory.eINSTANCE.createInputMapping();
mapping.setProcessSource(
source == null ? ExpressionHelper.createConstantExpression("", String.class.getName()) : ExpressionHelper.createVariableExpression(source));
source == null ? ExpressionHelper.createConstantExpression("", String.class.getName())
: ExpressionHelper.createVariableExpression(source));
if (target != null) {
mapping.setSubprocessTarget(target);
}
mapping.setAssignationType(assignationType);
final CallActivity callActivity = (CallActivity) selectionProvider.getAdapter(EObject.class);
getEditingDomain().getCommandStack().execute(new AddCommand(getEditingDomain(), callActivity.getInputMappings(), mapping));
getEditingDomain().getCommandStack()
.execute(new AddCommand(getEditingDomain(), callActivity.getInputMappings(), mapping));
addInputMappingLine(inputMappingControl, mapping);
}
......@@ -258,7 +273,8 @@ public class InputParametersMappingSection extends AbstractBonitaDescriptionSect
}
if (newValue != mapping.getAssignationType()) {
getEditingDomain().getCommandStack().execute(
new SetCommand(getEditingDomain(), mapping, ProcessPackage.Literals.INPUT_MAPPING__ASSIGNATION_TYPE, newValue));
new SetCommand(getEditingDomain(), mapping,
ProcessPackage.Literals.INPUT_MAPPING__ASSIGNATION_TYPE, newValue));
targetCombo.removeAll();
updateAvailableValuesInputMappingTargetCombo(targetCombo, newValue);
}
......@@ -266,14 +282,16 @@ public class InputParametersMappingSection extends AbstractBonitaDescriptionSect
});
final Button deleteButton = getWidgetFactory().createButton(outputMappingControl, null, SWT.FLAT);
deleteButton.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, SWTBotConstants.SWTBOT_ID_CALLACTIVITY_MAPPING_DELETE_INPUT);
deleteButton.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY,
SWTBotConstants.SWTBOT_ID_CALLACTIVITY_MAPPING_DELETE_INPUT);
deleteButton.setImage(sharedImages.getImage(ISharedImages.IMG_TOOL_DELETE));
deleteButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(final Event event) {
final CallActivity callActivity = (CallActivity) selectionProvider.getAdapter(EObject.class);
final RemoveCommand command = new RemoveCommand(getEditingDomain(), callActivity.getInputMappings(), mapping);
final RemoveCommand command = new RemoveCommand(getEditingDomain(), callActivity.getInputMappings(),
mapping);
getEditingDomain().getCommandStack().execute(command);
srcCombo.getControl().setData(MagicComposite.HIDDEN, true);
srcCombo.getControl().setVisible(false);
......@@ -300,17 +318,20 @@ public class InputParametersMappingSection extends AbstractBonitaDescriptionSect
@Override
public void handleEvent(final Event event) {
getEditingDomain().getCommandStack().execute(
new SetCommand(getEditingDomain(), mapping, ProcessPackage.Literals.INPUT_MAPPING__SUBPROCESS_TARGET, targetCombo.getText()));
new SetCommand(getEditingDomain(), mapping, ProcessPackage.Literals.INPUT_MAPPING__SUBPROCESS_TARGET,
targetCombo.getText()));
}
});
if (mapping.getSubprocessTarget() != null) {
targetCombo.setText(mapping.getSubprocessTarget());
}
targetCombo.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, SWTBotConstants.SWTBOT_ID_CALLACTIVITY_MAPPING_INPUT_CALLEDTARGET);
targetCombo.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY,
SWTBotConstants.SWTBOT_ID_CALLACTIVITY_MAPPING_INPUT_CALLEDTARGET);
return targetCombo;
}
protected void updateAvailableValuesInputMappingTargetCombo(final CCombo targetCombo, final InputMappingAssignationType assignationType) {
protected void updateAvailableValuesInputMappingTargetCombo(final CCombo targetCombo,
final InputMappingAssignationType assignationType) {
if (InputMappingAssignationType.DATA == assignationType) {
for (final String subprocessData : callActivityHelper.getCallActivityData()) {
targetCombo.add(subprocessData);
......@@ -338,21 +359,27 @@ public class InputParametersMappingSection extends AbstractBonitaDescriptionSect
break;
}
assignationTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
assignationTypeCombo.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, SWTBotConstants.SWTBOT_ID_CALLACTIVITY_MAPPING_INPUT_ASSIGNATIONTYPE);
assignationTypeCombo.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY,
SWTBotConstants.SWTBOT_ID_CALLACTIVITY_MAPPING_INPUT_ASSIGNATIONTYPE);
return assignationTypeCombo;
}
private ExpressionViewer createInputMappingExpressionViewer(final Composite outputMappingControl, final InputMapping mapping) {
private ExpressionViewer createInputMappingExpressionViewer(final Composite outputMappingControl,
final InputMapping mapping) {
final ExpressionViewer srcCombo = new ExpressionViewer(outputMappingControl, SWT.BORDER, getWidgetFactory());
srcCombo.getControl().setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).hint(250, SWT.DEFAULT).create());
srcCombo.addFilter(new AvailableExpressionTypeFilter(ExpressionConstants.CONSTANT_TYPE, ExpressionConstants.VARIABLE_TYPE,
ExpressionConstants.SCRIPT_TYPE, ExpressionConstants.PARAMETER_TYPE, ExpressionConstants.DOCUMENT_TYPE));
srcCombo.getControl().setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
.hint(250, SWT.DEFAULT).create());
srcCombo.addFilter(
new AvailableExpressionTypeFilter(ExpressionConstants.CONSTANT_TYPE, ExpressionConstants.VARIABLE_TYPE,
ExpressionConstants.SCRIPT_TYPE, ExpressionConstants.PARAMETER_TYPE,
ExpressionConstants.DOCUMENT_TYPE));
dbc.bindValue(ViewersObservables.observeInput(srcCombo),
ViewersObservables.observeSingleSelection(selectionProvider));
if (mapping.getProcessSource() == null) {
getEditingDomain().getCommandStack().execute(SetCommand.create(getEditingDomain(), mapping, ProcessPackage.Literals.INPUT_MAPPING__PROCESS_SOURCE,
ExpressionHelper.createConstantExpression("", String.class.getName())));
getEditingDomain().getCommandStack().execute(
SetCommand.create(getEditingDomain(), mapping, ProcessPackage.Literals.INPUT_MAPPING__PROCESS_SOURCE,
ExpressionHelper.createConstantExpression("", String.class.getName())));
}
dbc.bindValue(ViewersObservables.observeSingleSelection(srcCombo),
EMFObservables.observeValue(mapping, ProcessPackage.Literals.INPUT_MAPPING__PROCESS_SOURCE));
......
......@@ -26,6 +26,7 @@ import org.bonitasoft.studio.common.jface.EMFFeatureLabelProvider;
import org.bonitasoft.studio.common.jface.SWTBotConstants;
import org.bonitasoft.studio.common.jface.databinding.CustomEMFEditObservables;
import org.bonitasoft.studio.common.properties.AbstractBonitaDescriptionSection;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.widgets.MagicComposite;
import org.bonitasoft.studio.model.process.CallActivity;
import org.bonitasoft.studio.model.process.Data;
......@@ -70,11 +71,10 @@ import org.eclipse.ui.IWorkbenchPart;
public class OutputParametersMappingSection extends AbstractBonitaDescriptionSection {
@Inject
private ISharedImages sharedImages;
@Inject
private CallActivitySelectionProvider selectionProvider;
@Inject
private CallActivityHelper callActivityHelper;
private MagicComposite outputMappingControl;
......@@ -83,6 +83,13 @@ public class OutputParametersMappingSection extends AbstractBonitaDescriptionSec
private EMFDataBindingContext dbc;
@Inject
public OutputParametersMappingSection(RepositoryAccessor repositoryAccessor,
CallActivitySelectionProvider selectionProvider, ISharedImages sharedImages) {
this.selectionProvider = selectionProvider;
this.callActivityHelper = new CallActivityHelper(repositoryAccessor, selectionProvider);
this.sharedImages = sharedImages;
}
/*
* (non-Javadoc)
......@@ -130,6 +137,7 @@ public class OutputParametersMappingSection extends AbstractBonitaDescriptionSec
mainComposite = getWidgetFactory().createComposite(parent);
doCreateControls(mainComposite);
}
/*
* (non-Javadoc)
* @see org.bonitasoft.studio.properties.sections.subprocess.ParametersMappingSection#doCreateControls(org.eclipse.swt.widgets.Composite)
......@@ -151,9 +159,11 @@ public class OutputParametersMappingSection extends AbstractBonitaDescriptionSec
getWidgetFactory().adapt(outputMappingControl);
outputMappingControl.setLayout(GridLayoutFactory.fillDefaults().numColumns(4).margins(0, 0).create());
final Label targetParameterLabel = getWidgetFactory().createLabel(outputMappingControl, Messages.dataFromCalledProcess);
final Label targetParameterLabel = getWidgetFactory().createLabel(outputMappingControl,
Messages.dataFromCalledProcess);
targetParameterLabel.setLayoutData(GridDataFactory.swtDefaults().span(2, 1).indent(15, 0).create());
final Control sourceParameterLabel = getWidgetFactory().createLabel(outputMappingControl, Messages.dataInRootProcess);
final Control sourceParameterLabel = getWidgetFactory().createLabel(outputMappingControl,
Messages.dataInRootProcess);
sourceParameterLabel.setLayoutData(GridDataFactory.swtDefaults().span(2, 1).create());
final IObservableValue inputMappibngsObservable = CustomEMFEditObservables.observeDetailValue(Realm.getDefault(),
......@@ -163,10 +173,12 @@ public class OutputParametersMappingSection extends AbstractBonitaDescriptionSec
neverUpdateValueStrategy().create(), updateValueStrategy().withConverter(hideIfEmpty()).create());
dbc.bindValue(SWTObservables.observeVisible(targetParameterLabel), inputMappibngsObservable,
neverUpdateValueStrategy().create(), updateValueStrategy().withConverter(hideIfEmpty()).create());
final Button addLineButton = getWidgetFactory().createButton(composite, Messages.Add, SWT.FLAT);
addLineButton.setLayoutData(GridDataFactory.swtDefaults().hint(IDialogConstants.BUTTON_WIDTH, SWT.DEFAULT).indent(15, 0).create());
addLineButton.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, SWTBotConstants.SWTBOT_ID_CALLACTIVITY_MAPPING_ADD_OUTPUT);
addLineButton.setLayoutData(
GridDataFactory.swtDefaults().hint(IDialogConstants.BUTTON_WIDTH, SWT.DEFAULT).indent(15, 0).create());
addLineButton.setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY,
SWTBotConstants.SWTBOT_ID_CALLACTIVITY_MAPPING_ADD_OUTPUT);
addLineButton.addListener(SWT.Selection, new Listener() {
@Override
......@@ -200,11 +212,11 @@ public class OutputParametersMappingSection extends AbstractBonitaDescriptionSec
outputMapping.setSubprocessSource(source);
}
final CallActivity callActivity = (CallActivity) selectionProvider.getAdapter(EObject.class);
getEditingDomain().getCommandStack().execute(new AddCommand(getEditingDomain(), callActivity.getOutputMappings(), outputMapping));
getEditingDomain().getCommandStack()
.execute(new AddCommand(getEditingDomain(), callActivity.getOutputMappings(), outputMapping));
addOutputMappingLine(outputMappingControl, outputMapping);
}
protected void addOutputMappingLine(final Composite outputMappingControl, final OutputMapping mapping) {
final CCombo subprocessSourceCombo = createSubprocessSourceCombo(outputMappingControl, mapping);
final Label assignToLabel = getWidgetFactory().createLabel(outputMappingControl, Messages.assignTo);
......@@ -217,7 +229,8 @@ public class OutputParametersMappingSection extends AbstractBonitaDescriptionSec
@Override
public void handleEvent(final Event event) {
final CallActivity callActivity = (CallActivity) selectionProvider.getAdapter(EObject.class);
final RemoveCommand command = new RemoveCommand(getEditingDomain(), callActivity.getOutputMappings(), mapping);
final RemoveCommand command = new RemoveCommand(getEditingDomain(), callActivity.getOutputMappings(),
mapping);
getEditingDomain().getCommandStack().execute(command);
processTargetCombo.getControl().setData(MagicComposite.HIDDEN, true);
processTargetCombo.getControl().setVisible(false);
......@@ -245,8 +258,9 @@ public class OutputParametersMappingSection extends AbstractBonitaDescriptionSec
public void handleEvent(final Event event) {
getEditingDomain().getCommandStack()
.execute(
new SetCommand(getEditingDomain(), mapping, ProcessPackage.Literals.OUTPUT_MAPPING__SUBPROCESS_SOURCE, subprocessSourceCombo
.getText()));
new SetCommand(getEditingDomain(), mapping,
ProcessPackage.Literals.OUTPUT_MAPPING__SUBPROCESS_SOURCE, subprocessSourceCombo
.getText()));
}
});
if (mapping.getSubprocessSource() != null) {
......@@ -256,7 +270,8 @@ public class OutputParametersMappingSection extends AbstractBonitaDescriptionSec
}
private ComboViewer createProcessTargetCombo(final Composite outputMappingControl, final OutputMapping mapping) {
final ComboViewer processTargetCombo = new ComboViewer(getWidgetFactory().createCCombo(outputMappingControl, SWT.READ_ONLY | SWT.BORDER));
final ComboViewer processTargetCombo = new ComboViewer(
getWidgetFactory().createCCombo(outputMappingControl, SWT.READ_ONLY | SWT.BORDER));
processTargetCombo.setContentProvider(new IStructuredContentProvider() {
@Override
......@@ -279,8 +294,9 @@ public class OutputParametersMappingSection extends AbstractBonitaDescriptionSec
@Override
public void selectionChanged(final SelectionChangedEvent event) {
getEditingDomain().getCommandStack().execute(
new SetCommand(getEditingDomain(), mapping, ProcessPackage.Literals.OUTPUT_MAPPING__PROCESS_TARGET, ((IStructuredSelection) event
.getSelection()).getFirstElement()));
new SetCommand(getEditingDomain(), mapping, ProcessPackage.Literals.OUTPUT_MAPPING__PROCESS_TARGET,
((IStructuredSelection) event
.getSelection()).getFirstElement()));
}
});
final CallActivity callActivity = (CallActivity) selectionProvider.getAdapter(EObject.class);
......
......@@ -14,8 +14,6 @@
*/
package org.bonitasoft.studio.properties.sections.operation;
import javax.inject.Singleton;
import org.bonitasoft.studio.common.jface.selection.EObjectAdaptableSelectionProvider;
import org.bonitasoft.studio.model.process.OperationContainer;
import org.eclipse.core.runtime.IAdaptable;
......@@ -23,7 +21,6 @@ import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.emf.ecore.EObject;
@Creatable
@Singleton
public class OperationContainerSelectionProvider extends EObjectAdaptableSelectionProvider {
/*
......
......@@ -24,6 +24,7 @@ import org.bonitasoft.studio.expression.editor.operation.OperationGroupViewer;
import org.bonitasoft.studio.model.process.ProcessPackage;
import org.bonitasoft.studio.properties.i18n.Messages;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.emf.databinding.EMFDataBindingContext;
import org.eclipse.jface.databinding.viewers.ViewersObservables;
import org.eclipse.jface.layout.GridDataFactory;
......@@ -56,11 +57,12 @@ public class OperationsPropertySection extends AbstractBonitaDescriptionSection
operationComposite = createViewer(mainComposite);
operationComposite.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
operationComposite.setContext(context);
IObservableValue diagramSelectionObservable = ViewersObservables.observeSingleSelection(selectionProvider);
operationComposite.setInput(CustomEMFEditObservables.observeDetailList(Realm.getDefault(),
ViewersObservables.observeSingleSelection(selectionProvider), ProcessPackage.Literals.OPERATION_CONTAINER__OPERATIONS));
context.bindValue(ViewersObservables.observeSingleSelection(selectionProvider), ViewersObservables.observeSingleSelection(operationComposite));
diagramSelectionObservable, ProcessPackage.Literals.OPERATION_CONTAINER__OPERATIONS));
context.bindValue(diagramSelectionObservable, ViewersObservables.observeSingleSelection(operationComposite));
}
protected OperationGroupViewer createViewer(final Composite parent) {
......
......@@ -14,8 +14,6 @@
*/
package org.bonitasoft.studio.properties.sections.userxp;
import javax.inject.Singleton;
import org.bonitasoft.studio.common.jface.selection.EObjectAdaptableSelectionProvider;
import org.bonitasoft.studio.model.process.Task;
import org.eclipse.core.runtime.IAdaptable;
......@@ -23,7 +21,6 @@ import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.emf.ecore.EObject;
@Creatable
@Singleton
public class TaskSelectionProvider extends EObjectAdaptableSelectionProvider {
/*
......
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