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 <florian.barbin@obeo.fr>
  • Loading branch information
florianbarbin committed Sep 5, 2024
1 parent 2d00ebd commit fef399d
Show file tree
Hide file tree
Showing 20 changed files with 223 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Introduce new `IRewriteProxiesResourceFilter` interface, to register resource fi
image:doc/screenshots/treeItemLabelStyled.jpg[StyledString, 70%]
- https://github.com/eclipse-sirius/sirius-web/issues/3963[#3963] [core] Add support for optional GraphQLCodeRegistry post-processing/transformation.
- 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 @@ -3,6 +3,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,11 @@
* Obeo - initial API and implementation
*******************************************************************************/
import { Selection, SelectionContext } from '@eclipse-sirius/sirius-components-core';
import { DiagramDialogComponentProps, DiagramDialogVariable } from '@eclipse-sirius/sirius-components-diagrams';
import {
DiagramDialogComponentProps,
DiagramDialogVariable,
GQLToolVariable,
} from '@eclipse-sirius/sirius-components-diagrams';
import { TreeItemActionProps, TreeView } from '@eclipse-sirius/sirius-components-trees';
import UnfoldMoreIcon from '@mui/icons-material/UnfoldMore';
import Button from '@mui/material/Button';
Expand Down Expand Up @@ -48,6 +52,7 @@ export const SelectionDialog = ({
treeDescriptionId: '',
message: '',
selectedObjects: [],
multiple: false,
};
const { classes } = useTreeStyle();
const [state, setState] = useState<DiagramDialogComponentState>(initialState);
Expand All @@ -68,6 +73,7 @@ export const SelectionDialog = ({
...prevState,
message: selectionDescription.message,
treeDescriptionId: selectionDescription.treeDescription.id,
multiple: selectionDescription.multiple,
}));
}
}, [loading, selectionDescription]);
Expand All @@ -82,7 +88,7 @@ export const SelectionDialog = ({
treeId={`selection://?treeDescriptionId=${encodeURIComponent(state.treeDescriptionId)}${encodeVariables(
variables
)}`}
enableMultiSelection={false}
enableMultiSelection={state.multiple}
synchronizedWithSelection={true}
activeFilterIds={[]}
textToFilter={''}
Expand All @@ -92,6 +98,21 @@ export const SelectionDialog = ({
</div>
);
}

const handleFinish = () => {
let variables: GQLToolVariable[] = [];
if (state.selectedObjects.length > 0) {
if (state.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);
}
};

return (
<SelectionContext.Provider
value={{ selection: { entries: [...state.selectedObjects] }, setSelection: setDialogSelection }}>
Expand All @@ -113,12 +134,7 @@ export const SelectionDialog = ({
disabled={state.selectedObjects.length == 0}
data-testid="finish-action"
color="primary"
onClick={() => {
if (state.selectedObjects.length > 0) {
const selectedObjectId = state.selectedObjects[0]?.id ?? '';
onFinish([{ name: 'selectedObject', value: selectedObjectId, type: 'OBJECT_ID' }]);
}
}}>
onClick={handleFinish}>
Finish
</Button>
</DialogActions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface SelectionDialogProps {
export interface DiagramDialogComponentState {
treeDescriptionId: string;
message: string;
multiple: boolean;
selectedObjects: DiagramDialogComponentSelectedObject[];
}

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 SelectionDescription {
message: string;
treeDescription: TreeDescription;
multiple: boolean;
}

export interface TreeDescription {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@
import org.eclipse.sirius.components.collaborative.selection.dto.SelectionDialogVariable;
import org.eclipse.sirius.components.collaborative.trees.dto.TreeEventInput;
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.trees.tests.graphql.TreeEventSubscriptionRunner;
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 @@ -120,6 +123,9 @@ subscription treeEvent($input: TreeEventInput!) {
@Autowired
private ObjectMapper objectMapper;

@Autowired
private IObjectService objectService;

@BeforeEach
public void beforeEach() {
this.givenInitialServerState.initialize();
Expand Down Expand Up @@ -401,6 +407,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 @@ -89,6 +89,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 @@ -90,15 +90,8 @@ protected static String extensionFor(String key) {
int index = key.lastIndexOf('.');
if (index != -1) {
String extension = key.substring(index + 1);
if ("png".equalsIgnoreCase(extension)
|| "gif".equalsIgnoreCase(extension)
|| "bmp".equalsIgnoreCase(extension)
|| "ico".equalsIgnoreCase(extension)
|| "jpg".equalsIgnoreCase(extension)
|| "jpeg".equalsIgnoreCase(extension)
|| "tif".equalsIgnoreCase(extension)
|| "tiff".equalsIgnoreCase(extension)
|| "svg".equalsIgnoreCase(extension)) {
if ("png".equalsIgnoreCase(extension) || "gif".equalsIgnoreCase(extension) || "bmp".equalsIgnoreCase(extension) || "ico".equalsIgnoreCase(extension) || "jpg".equalsIgnoreCase(extension)
|| "jpeg".equalsIgnoreCase(extension) || "tif".equalsIgnoreCase(extension) || "tiff".equalsIgnoreCase(extension) || "svg".equalsIgnoreCase(extension)) {
result = "";
}
}
Expand Down
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 @@ -3222,14 +3222,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 @@ -5400,6 +5408,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 @@ -7022,6 +7042,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 fef399d

Please sign in to comment.