Skip to content

Commit

Permalink
[2123] Add support for non-selectable tree items
Browse files Browse the repository at this point in the history
Bug: #2123
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
  • Loading branch information
pcdavid committed Jul 11, 2023
1 parent d45dcf0 commit 6a0512a
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Expand Up @@ -117,6 +117,7 @@ The existing context menu contributions now only apply to the _Explorer_ view.
- https://github.com/eclipse-sirius/sirius-components/issues/2091[#2091] [diagram] Add support for the direct edit in the diagram with nodes.
- https://github.com/eclipse-sirius/sirius-components/issues/2142[#2142] [diagram] Add support for Edge labels (begin, center, end) in sirius-components-diagrams-reactflow.
- https://github.com/eclipse-sirius/sirius-components/issues/2097[#2097] [forms] Add click handler support on the reference value of a reference widget.
- https://github.com/eclipse-sirius/sirius-components/issues/2123[#2123] [tree] Add support for non-selectable tree items

== v2023.6.0

Expand Down
Expand Up @@ -29,8 +29,8 @@
import org.eclipse.sirius.components.compatibility.services.ImageConstants;
import org.eclipse.sirius.components.core.RepresentationMetadata;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IURLParser;
import org.eclipse.sirius.components.core.api.IObjectService;
import org.eclipse.sirius.components.core.api.IURLParser;
import org.eclipse.sirius.components.core.api.SemanticKindConstants;
import org.eclipse.sirius.components.emf.ResourceMetadataAdapter;
import org.eclipse.sirius.components.emf.services.EditingContext;
Expand Down Expand Up @@ -96,6 +96,7 @@ public TreeDescription getDescription() {
.imageURLProvider(this::getImageURL)
.editableProvider(this::isEditable)
.deletableProvider(this::isDeletable)
.selectableProvider(this::isSelectable)
.elementsProvider(this::getElements)
.hasChildrenProvider(this::hasChildren)
.childrenProvider(this::getChildren)
Expand Down Expand Up @@ -186,6 +187,10 @@ private boolean isDeletable(VariableManager variableManager) {
return true;
}

private boolean isSelectable(VariableManager variableManager) {
return true;
}

private String getImageURL(VariableManager variableManager) {
Object self = variableManager.getVariables().get(VariableManager.SELF);

Expand Down
Expand Up @@ -39,6 +39,7 @@ type TreeItem {
imageURL: String!
editable: Boolean!
deletable: Boolean!
selectable: Boolean!
expanded: Boolean!
hasChildren: Boolean!
children: [TreeItem]!
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Obeo.
* Copyright (c) 2019, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -40,6 +40,8 @@ public final class TreeItem {

private boolean deletable;

private boolean selectable;

private boolean hasChildren;

private boolean expanded;
Expand Down Expand Up @@ -70,6 +72,10 @@ public boolean isDeletable() {
return this.deletable;
}

public boolean isSelectable() {
return this.selectable;
}

public String getImageURL() {
return this.imageURL;
}
Expand Down Expand Up @@ -116,6 +122,8 @@ public static final class Builder {

private boolean deletable;

private boolean selectable;

private boolean hasChildren;

private boolean expanded;
Expand All @@ -142,12 +150,17 @@ public Builder imageURL(String imageURL) {
}

public Builder editable(boolean editable) {
this.editable = Objects.requireNonNull(editable);
this.editable = editable;
return this;
}

public Builder deletable(boolean deletable) {
this.deletable = Objects.requireNonNull(deletable);
this.deletable = deletable;
return this;
}

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

Expand All @@ -172,10 +185,11 @@ public TreeItem build() {
treeItem.kind = Objects.requireNonNull(this.kind);
treeItem.label = Objects.requireNonNull(this.label);
treeItem.imageURL = Objects.requireNonNull(this.imageURL);
treeItem.editable = Objects.requireNonNull(this.editable);
treeItem.deletable = Objects.requireNonNull(this.deletable);
treeItem.expanded = Objects.requireNonNull(this.expanded);
treeItem.hasChildren = Objects.requireNonNull(this.hasChildren);
treeItem.editable = this.editable;
treeItem.deletable = this.deletable;
treeItem.selectable = this.selectable;
treeItem.expanded = this.expanded;
treeItem.hasChildren = this.hasChildren;
treeItem.children = Objects.requireNonNull(this.children);
return treeItem;
}
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Obeo.
* Copyright (c) 2019, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -49,6 +49,8 @@ public final class TreeDescription implements IRepresentationDescription {

private Function<VariableManager, Boolean> deletableProvider;

private Function<VariableManager, Boolean> selectableProvider;

private Function<VariableManager, List<?>> elementsProvider;

private Function<VariableManager, List<?>> childrenProvider;
Expand Down Expand Up @@ -103,6 +105,11 @@ public Function<VariableManager, Boolean> getDeletableProvider() {
return this.deletableProvider;
}

public Function<VariableManager, Boolean> getSelectableProvider() {
return this.selectableProvider;
}


public Function<VariableManager, List<?>> getElementsProvider() {
return this.elementsProvider;
}
Expand Down Expand Up @@ -163,6 +170,8 @@ public static final class Builder {

private Function<VariableManager, Boolean> deletableProvider;

private Function<VariableManager, Boolean> selectableProvider = (variableManager) -> true;

private Function<VariableManager, List<?>> elementsProvider;

private Function<VariableManager, List<?>> childrenProvider;
Expand Down Expand Up @@ -219,6 +228,11 @@ public Builder deletableProvider(Function<VariableManager, Boolean> deletablePro
return this;
}

public Builder selectableProvider(Function<VariableManager, Boolean> selectableProvider) {
this.selectableProvider = Objects.requireNonNull(selectableProvider);
return this;
}

public Builder elementsProvider(Function<VariableManager, List<?>> elementsProvider) {
this.elementsProvider = Objects.requireNonNull(elementsProvider);
return this;
Expand Down Expand Up @@ -260,6 +274,7 @@ public TreeDescription build() {
treeDescription.imageURLProvider = Objects.requireNonNull(this.imageURLProvider);
treeDescription.editableProvider = Objects.requireNonNull(this.editableProvider);
treeDescription.deletableProvider = Objects.requireNonNull(this.deletableProvider);
treeDescription.selectableProvider = Objects.requireNonNull(this.selectableProvider);
treeDescription.elementsProvider = Objects.requireNonNull(this.elementsProvider);
treeDescription.childrenProvider = Objects.requireNonNull(this.childrenProvider);
treeDescription.hasChildrenProvider = Objects.requireNonNull(this.hasChildrenProvider);
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Obeo.
* Copyright (c) 2019, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -66,6 +66,7 @@ private TreeItem renderTreeItem(VariableManager treeItemVariableManager) {
String label = this.treeDescription.getLabelProvider().apply(treeItemVariableManager);
boolean editable = this.treeDescription.getEditableProvider().apply(treeItemVariableManager);
boolean deletable = this.treeDescription.getDeletableProvider().apply(treeItemVariableManager);
boolean selectable = this.treeDescription.getSelectableProvider().apply(treeItemVariableManager);
String imageURL = this.treeDescription.getImageURLProvider().apply(treeItemVariableManager);
Boolean hasChildren = this.treeDescription.getHasChildrenProvider().apply(treeItemVariableManager);

Expand All @@ -85,6 +86,7 @@ private TreeItem renderTreeItem(VariableManager treeItemVariableManager) {
.label(label)
.editable(editable)
.deletable(deletable)
.selectable(selectable)
.imageURL(imageURL)
.children(childrenTreeItems)
.hasChildren(hasChildren)
Expand Down
Expand Up @@ -48,6 +48,10 @@ const useTreeItemStyle = makeStyles((theme) => ({
backgroundColor: 'var(--blue-lagoon-lighten-90)',
},
},
nonSelectable: {
fontStyle: 'italic',
opacity: 0.6,
},
arrow: {
cursor: 'pointer',
},
Expand Down Expand Up @@ -297,6 +301,9 @@ export const TreeItem = ({
const onClick: React.MouseEventHandler<HTMLDivElement> = (event) => {
if (!state.editingMode) {
refDom.current.focus();
if (!item.selectable) {
return;
}

if (event.ctrlKey || event.metaKey) {
event.stopPropagation();
Expand Down Expand Up @@ -392,7 +399,7 @@ export const TreeItem = ({
data-depth={depth}
data-expanded={item.expanded.toString()}
data-testid={dataTestid}>
<div className={classes.content}>
<div className={`${classes.content} ${item.selectable ? '' : classes.nonSelectable}`}>
<div
className={classes.imageAndLabel}
onDoubleClick={() => item.hasChildren && onExpand(item.id, depth)}
Expand Down
Expand Up @@ -50,6 +50,7 @@ export interface GQLTreeItem {
expanded: boolean;
editable: boolean;
deletable: boolean;
selectable: boolean;
}

export interface GQLGetTreePathVariables {
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Obeo.
* Copyright (c) 2019, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -43,6 +43,7 @@ const getDocumentSubscription = gql`
label
editable
deletable
selectable
kind
imageURL
}
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Obeo.
* Copyright (c) 2019, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -39,6 +39,7 @@ fragment treeItemFields on TreeItem {
label
editable
deletable
selectable
kind
imageURL
}
Expand Down

0 comments on commit 6a0512a

Please sign in to comment.