Skip to content

Commit

Permalink
[3950] Activate multiple selection on the Selection Dialog
Browse files Browse the repository at this point in the history
This commit allows the specifier to indicate if the selection dialog
should allow multiple selection.

Bug: #3950
Signed-off-by: Florian Barbin <[email protected]>
  • Loading branch information
florianbarbin authored and sbegaudeau committed Oct 11, 2024
1 parent 5a5b92f commit 836448e
Show file tree
Hide file tree
Showing 20 changed files with 212 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ description (optional).
** deleteProject (`POST /api/rest/projects/{projectId}`): Delete the project with the given id (projectId).
** updateProject (`PUT /projects/{projectId}`): Update the project with the given id (projectId).
- https://github.com/eclipse-sirius/sirius-web/issues/3873[#3873] [diagram] Make the Selection Dialog available for the EdgeTool
- https://github.com/eclipse-sirius/sirius-web/issues/3950[#3950] [diagram] Have the multiple selection on the Selection Dialog

=== Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type SelectionDescription implements RepresentationDescription {
label: String!
message(variables: [SelectionDialogVariable!]!): String!
treeDescription: TreeDescription!
multiple: Boolean!
}

input SelectionDialogVariable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public final class SelectionDescription implements IRepresentationDescription {

private Predicate<VariableManager> canCreatePredicate;

private boolean multiple;

private TreeDescription treeDescription;

private SelectionDescription() {
Expand Down Expand Up @@ -90,6 +92,10 @@ public TreeDescription getTreeDescription() {
return this.treeDescription;
}

public boolean isMultiple() {
return this.multiple;
}

@Override
public String toString() {
String pattern = "{0} '{'id: {1}, label: {2}'}'";
Expand Down Expand Up @@ -120,6 +126,8 @@ public static final class Builder {

private TreeDescription treeDescription;

private boolean multiple;

private Builder(String id) {
this.id = Objects.requireNonNull(id);
}
Expand Down Expand Up @@ -159,6 +167,11 @@ public Builder treeDescription(TreeDescription treeDescription) {
return this;
}

public Builder multiple(boolean multiple) {
this.multiple = multiple;
return this;
}

public SelectionDescription build() {
SelectionDescription selectionDescription = new SelectionDescription();
selectionDescription.id = Objects.requireNonNull(this.id);
Expand All @@ -169,6 +182,7 @@ public SelectionDescription build() {
selectionDescription.messageProvider = Objects.requireNonNull(this.messageProvider);
selectionDescription.canCreatePredicate = Objects.requireNonNull(this.canCreatePredicate);
selectionDescription.treeDescription = Objects.requireNonNull(this.treeDescription);
selectionDescription.multiple = this.multiple;
return selectionDescription;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Obeo - initial API and implementation
*******************************************************************************/
import { Selection, SelectionContext } from '@eclipse-sirius/sirius-components-core';
import { DiagramDialogComponentProps } from '@eclipse-sirius/sirius-components-diagrams';
import { DiagramDialogComponentProps, GQLToolVariable } from '@eclipse-sirius/sirius-components-diagrams';
import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
Expand Down Expand Up @@ -44,15 +44,23 @@ export const SelectionDialog = ({

const message: string = selectionDescription?.message ?? '';
const treeDescriptionId: string | null = selectionDescription?.treeDescription.id ?? null;
const multiple: boolean = selectionDescription?.multiple ?? false;

const setDialogSelection = (selection: Selection) => {
setState((prevState) => ({ ...prevState, selectedObjects: [...selection.entries] }));
};

const handleClick = () => {
let variables: GQLToolVariable[] = [];
if (state.selectedObjects.length > 0) {
const selectedObjectId = state.selectedObjects[0]?.id ?? '';
onFinish([{ name: 'selectedObject', value: selectedObjectId, type: 'OBJECT_ID' }]);
if (multiple) {
const selectedObjectIds = state.selectedObjects.map((selectedObject) => selectedObject.id).join(',');
variables = [{ name: 'selectedObjects', value: selectedObjectIds, type: 'OBJECT_ID_ARRAY' }];
} else {
const selectedObjectId = state.selectedObjects[0]?.id ?? '';
variables = [{ name: 'selectedObject', value: selectedObjectId, type: 'OBJECT_ID' }];
}
onFinish(variables);
}
};

Expand All @@ -63,6 +71,7 @@ export const SelectionDialog = ({
editingContextId={editingContextId}
variables={variables}
treeDescriptionId={treeDescriptionId}
enableMultiSelection={multiple}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const SelectionDialogTreeView = ({
editingContextId,
treeDescriptionId,
variables,
enableMultiSelection,
}: SelectionDialogTreeViewProps) => {
const { classes } = useTreeStyle();
const [state, setState] = useState<SelectionDialogTreeViewState>(initialState);
Expand All @@ -57,7 +58,7 @@ export const SelectionDialogTreeView = ({
editingContextId={editingContextId}
readOnly={true}
treeId={treeId}
enableMultiSelection={false}
enableMultiSelection={enableMultiSelection}
synchronizedWithSelection={true}
tree={tree}
textToFilter={''}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface SelectionDialogTreeViewProps {
editingContextId: string;
treeDescriptionId: string;
variables: DiagramDialogVariable[];
enableMultiSelection: boolean;
}

export interface SelectionDialogTreeViewState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const getSelectionDescription = gql`
treeDescription {
id
}
multiple
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface GetSelectionDescriptionVariables {
export interface GQLSelectionDescription {
message: string;
treeDescription: GQLTreeDescription;
multiple: boolean;
}

export interface GQLTreeDescription {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@

import org.eclipse.sirius.components.collaborative.selection.dto.SelectionDialogTreeEventInput;
import org.eclipse.sirius.components.collaborative.trees.dto.TreeRefreshedEventPayload;
import org.eclipse.sirius.components.core.api.IObjectService;
import org.eclipse.sirius.components.graphql.api.URLConstants;
import org.eclipse.sirius.components.graphql.tests.api.IGraphQLRequestor;
import org.eclipse.sirius.components.trees.Tree;
import org.eclipse.sirius.components.trees.TreeItem;
import org.eclipse.sirius.components.trees.tests.graphql.ExpandAllTreePathQueryRunner;
import org.eclipse.sirius.components.view.diagram.SelectionDialogDescription;
import org.eclipse.sirius.components.view.diagram.SelectionDialogTreeDescription;
import org.eclipse.sirius.web.AbstractIntegrationTests;
import org.eclipse.sirius.web.data.PapayaIdentifiers;
import org.eclipse.sirius.web.services.selection.SelectionDescriptionProvider;
Expand Down Expand Up @@ -74,6 +77,7 @@ query getSelectionDescription($editingContextId: ID!, $representationId: ID!, $v
treeDescription {
id
}
multiple
}
}
}
Expand Down Expand Up @@ -118,6 +122,9 @@ subscription selectionDialogTreeEvent($input: SelectionDialogTreeEventInput!) {
@Autowired
private RepresentationIdBuilder representationIdBuilder;

@Autowired
private IObjectService objectService;

@BeforeEach
public void beforeEach() {
this.givenInitialServerState.initialize();
Expand Down Expand Up @@ -405,6 +412,24 @@ public void givenSemanticObjectWhenWeSubscribeToItsSelectionEventsThenTheURLOfIt
.verify(Duration.ofSeconds(10));
}

@Test
@DisplayName("given a selectionDescription then the image and the label are the expected ones")
@Sql(scripts = { "/scripts/papaya.sql" }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED))
public void givenASelectionDescriptionThenTheImageAndLabelAreTheExpectedOnes() {
SelectionDialogDescription selectionDRialogDescription = this.selectionDescriptionProvider.getSelectionDialog();
String selectionDialogLabel = this.objectService.getLabel(selectionDRialogDescription);
assertThat(selectionDialogLabel).isEqualTo(selectionDRialogDescription.getSelectionMessage());
List<String> imagePath = this.objectService.getImagePath(selectionDRialogDescription);
assertThat(imagePath).hasSize(1).first().isEqualTo("/icons/full/obj16/SelectionDialogDescription.svg");

SelectionDialogTreeDescription selectionDialogTreeDescription = selectionDRialogDescription.getSelectionDialogTreeDescription();
String selectionDialogTreeDescriptionLabel = this.objectService.getLabel(selectionDialogTreeDescription);
assertThat(selectionDialogTreeDescriptionLabel).isEqualTo(selectionDialogTreeDescription.getElementsExpression());
List<String> selectionDialogTreeDescriptionImagePath = this.objectService.getImagePath(selectionDialogTreeDescription);
assertThat(selectionDialogTreeDescriptionImagePath).hasSize(1).first().isEqualTo("/icons/full/obj16/SelectionDialogTreeDescription.svg");
}

private Consumer<Object> getTreeSubscriptionConsumer(Consumer<Tree> treeConsumer) {
return object -> Optional.of(object)
.filter(DataFetcherResult.class::isInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public String getSelectionDialogDescriptionId() {
return this.diagramIdProvider.getId(this.selectionDialog);
}

public SelectionDialogDescription getSelectionDialog() {
return this.selectionDialog;
}

private View createView() {
ViewBuilder viewBuilder = new ViewBuilder();
View unsynchronizedView = viewBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,15 @@ public SelectionDialogDescriptionBuilder selectionDialogTreeDescription(org.ecli
return this;
}

/**
* Setter for Multiple.
*
* @generated
*/
public SelectionDialogDescriptionBuilder multiple(java.lang.Boolean value) {
this.getSelectionDialogDescription().setMultiple(value);
return this;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
super.getPropertyDescriptors(object);

this.addSelectionMessagePropertyDescriptor(object);
this.addMultiplePropertyDescriptor(object);
}
return this.itemPropertyDescriptors;
}
Expand All @@ -69,6 +70,18 @@ protected void addSelectionMessagePropertyDescriptor(Object object) {
DiagramPackage.Literals.SELECTION_DIALOG_DESCRIPTION__SELECTION_MESSAGE, true, false, false, ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null));
}

/**
* This adds a property descriptor for the Multiple feature. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
protected void addMultiplePropertyDescriptor(Object object) {
this.itemPropertyDescriptors.add(this.createItemPropertyDescriptor(((ComposeableAdapterFactory) this.adapterFactory).getRootAdapterFactory(), this.getResourceLocator(),
this.getString("_UI_SelectionDialogDescription_multiple_feature"),
this.getString("_UI_PropertyDescriptor_description", "_UI_SelectionDialogDescription_multiple_feature", "_UI_SelectionDialogDescription_type"),
DiagramPackage.Literals.SELECTION_DIALOG_DESCRIPTION__MULTIPLE, true, false, false, ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE, null, null));
}

/**
* This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an
* {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or
Expand Down Expand Up @@ -143,6 +156,7 @@ public void notifyChanged(Notification notification) {

switch (notification.getFeatureID(SelectionDialogDescription.class)) {
case DiagramPackage.SELECTION_DIALOG_DESCRIPTION__SELECTION_MESSAGE:
case DiagramPackage.SELECTION_DIALOG_DESCRIPTION__MULTIPLE:
this.fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
case DiagramPackage.SELECTION_DIALOG_DESCRIPTION__SELECTION_DIALOG_TREE_DESCRIPTION:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ _UI_CreateView_containmentKind_feature=Containment Kind
_UI_DeleteView_viewExpression_feature=View Expression
_UI_SelectionDialogDescription_selectionMessage_feature=Selection Message
_UI_SelectionDialogDescription_selectionDialogTreeDescription_feature=Selection Dialog Tree Description
_UI_SelectionDialogDescription_multiple_feature = Multiple
_UI_ToolSection_name_feature=Name
_UI_DiagramToolSection_nodeTools_feature=Node Tools
_UI_NodeToolSection_nodeTools_feature=Node Tools
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3149,14 +3149,22 @@ public interface DiagramPackage extends EPackage {
*/
int SELECTION_DIALOG_DESCRIPTION__SELECTION_DIALOG_TREE_DESCRIPTION = DIALOG_DESCRIPTION_FEATURE_COUNT + 1;

/**
* The feature id for the '<em><b>Multiple</b></em>' attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
* @ordered
*/
int SELECTION_DIALOG_DESCRIPTION__MULTIPLE = DIALOG_DESCRIPTION_FEATURE_COUNT + 2;

/**
* The number of structural features of the '<em>Selection Dialog Description</em>' class. <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
* @ordered
*/
int SELECTION_DIALOG_DESCRIPTION_FEATURE_COUNT = DIALOG_DESCRIPTION_FEATURE_COUNT + 2;
int SELECTION_DIALOG_DESCRIPTION_FEATURE_COUNT = DIALOG_DESCRIPTION_FEATURE_COUNT + 3;

/**
* The number of operations of the '<em>Selection Dialog Description</em>' class. <!-- begin-user-doc --> <!--
Expand Down Expand Up @@ -5316,6 +5324,18 @@ public interface DiagramPackage extends EPackage {
*/
EReference getSelectionDialogDescription_SelectionDialogTreeDescription();

/**
* Returns the meta object for the attribute
* '{@link org.eclipse.sirius.components.view.diagram.SelectionDialogDescription#isMultiple <em>Multiple</em>}'.
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @return the meta object for the attribute '<em>Multiple</em>'.
* @see org.eclipse.sirius.components.view.diagram.SelectionDialogDescription#isMultiple()
* @see #getSelectionDialogDescription()
* @generated
*/
EAttribute getSelectionDialogDescription_Multiple();

/**
* Returns the meta object for class '{@link org.eclipse.sirius.components.view.diagram.ToolSection <em>Tool
* Section</em>}'. <!-- begin-user-doc --> <!-- end-user-doc -->
Expand Down Expand Up @@ -6948,6 +6968,14 @@ interface Literals {
*/
EReference SELECTION_DIALOG_DESCRIPTION__SELECTION_DIALOG_TREE_DESCRIPTION = eINSTANCE.getSelectionDialogDescription_SelectionDialogTreeDescription();

/**
* The meta object literal for the '<em><b>Multiple</b></em>' attribute feature. <!-- begin-user-doc --> <!--
* end-user-doc -->
*
* @generated
*/
EAttribute SELECTION_DIALOG_DESCRIPTION__MULTIPLE = eINSTANCE.getSelectionDialogDescription_Multiple();

/**
* The meta object literal for the '{@link org.eclipse.sirius.components.view.diagram.impl.ToolSectionImpl
* <em>Tool Section</em>}' class. <!-- begin-user-doc --> <!-- end-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Message</em>}</li>
* <li>{@link org.eclipse.sirius.components.view.diagram.SelectionDialogDescription#getSelectionDialogTreeDescription
* <em>Selection Dialog Tree Description</em>}</li>
* <li>{@link org.eclipse.sirius.components.view.diagram.SelectionDialogDescription#isMultiple <em>Multiple</em>}</li>
* </ul>
*
* @see org.eclipse.sirius.components.view.diagram.DiagramPackage#getSelectionDialogDescription()
Expand Down Expand Up @@ -79,4 +80,26 @@ public interface SelectionDialogDescription extends DialogDescription {
*/
void setSelectionDialogTreeDescription(SelectionDialogTreeDescription value);

/**
* Returns the value of the '<em><b>Multiple</b></em>' attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @return the value of the '<em>Multiple</em>' attribute.
* @see #setMultiple(boolean)
* @see org.eclipse.sirius.components.view.diagram.DiagramPackage#getSelectionDialogDescription_Multiple()
* @model
* @generated
*/
boolean isMultiple();

/**
* Sets the value of the '{@link org.eclipse.sirius.components.view.diagram.SelectionDialogDescription#isMultiple
* <em>Multiple</em>}' attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @param value
* the new value of the '<em>Multiple</em>' attribute.
* @see #isMultiple()
* @generated
*/
void setMultiple(boolean value);

} // SelectionDialogDescription
Loading

0 comments on commit 836448e

Please sign in to comment.