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 3, 2024
1 parent fc4f6d6 commit 2dd3526
Show file tree
Hide file tree
Showing 18 changed files with 195 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Introduce new `IRewriteProxiesResourceFilter` interface, to register resource fi
+
image:doc/screenshots/treeItemLabelStyled.jpg[StyledString, 70%]
- 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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,16 @@ public EReference getSelectionDialogDescription_SelectionDialogTreeDescription()
return (EReference) this.selectionDialogDescriptionEClass.getEStructuralFeatures().get(1);
}

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
public EAttribute getSelectionDialogDescription_Multiple() {
return (EAttribute) this.selectionDialogDescriptionEClass.getEStructuralFeatures().get(2);
}

/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
Expand Down Expand Up @@ -2565,6 +2575,7 @@ public void createPackageContents() {
this.selectionDialogDescriptionEClass = this.createEClass(SELECTION_DIALOG_DESCRIPTION);
this.createEAttribute(this.selectionDialogDescriptionEClass, SELECTION_DIALOG_DESCRIPTION__SELECTION_MESSAGE);
this.createEReference(this.selectionDialogDescriptionEClass, SELECTION_DIALOG_DESCRIPTION__SELECTION_DIALOG_TREE_DESCRIPTION);
this.createEAttribute(this.selectionDialogDescriptionEClass, SELECTION_DIALOG_DESCRIPTION__MULTIPLE);

this.toolSectionEClass = this.createEClass(TOOL_SECTION);
this.createEAttribute(this.toolSectionEClass, TOOL_SECTION__NAME);
Expand Down Expand Up @@ -2983,6 +2994,8 @@ public void initializePackageContents() {
!IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
this.initEReference(this.getSelectionDialogDescription_SelectionDialogTreeDescription(), this.getSelectionDialogTreeDescription(), null, "selectionDialogTreeDescription", null, 0, 1,
SelectionDialogDescription.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
this.initEAttribute(this.getSelectionDialogDescription_Multiple(), this.ecorePackage.getEBoolean(), "multiple", null, 0, 1, SelectionDialogDescription.class, !IS_TRANSIENT, !IS_VOLATILE,
IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);

this.initEClass(this.toolSectionEClass, ToolSection.class, "ToolSection", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
this.initEAttribute(this.getToolSection_Name(), theViewPackage.getIdentifier(), "name", "Tool Section", 1, 1, ToolSection.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE,
Expand Down
Loading

0 comments on commit 2dd3526

Please sign in to comment.