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 3, 2023
1 parent 4d9c791 commit 614aa88
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Expand Up @@ -92,6 +92,7 @@ image:doc/images/Diagram_closed_arrow_with_dots.png[closed arrow with dots]
+

- https://github.com/eclipse-sirius/sirius-components/issues/2098[#2098] [forms] Enable vertical scrolling on the Reference widget's when showing more than a few values.
- 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.services.EditingContext;
import org.eclipse.sirius.components.representations.Failure;
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,9 @@ const useTreeItemStyle = makeStyles((theme) => ({
backgroundColor: 'var(--blue-lagoon-lighten-90)',
},
},
nonSelectable: {
fontStyle: 'italic',
},
arrow: {
cursor: 'pointer',
},
Expand Down Expand Up @@ -191,7 +194,11 @@ export const TreeItem = ({
onExpand={onExpand}
onExpandAll={onExpandAll}
selection={selection}
setSelection={setSelection}
setSelection={(selection) => {
if (item.selectable) {
setSelection(selection);
}
}}
enterEditingMode={enterEditingMode}
onClose={closeContextMenu}
/>
Expand All @@ -213,7 +220,11 @@ export const TreeItem = ({
onExpand={onExpand}
onExpandAll={onExpandAll}
selection={selection}
setSelection={setSelection}
setSelection={(selection) => {
if (childItem.selectable) {
setSelection(selection);
}
}}
readOnly={readOnly}
textToHighlight={textToHighlight}
isFilterEnabled={isFilterEnabled}
Expand Down Expand Up @@ -289,7 +300,11 @@ export const TreeItem = ({
);
}
text = (
<Typography variant="body2" className={`${classes.label} ${selected ? classes.selectedLabel : ''}`}>
<Typography
variant="body2"
className={`${classes.label} ${selected ? classes.selectedLabel : ''} ${
item.selectable ? '' : classes.nonSelectable
}`}>
{itemLabel}
</Typography>
);
Expand All @@ -301,6 +316,9 @@ export const TreeItem = ({

if (event.ctrlKey || event.metaKey) {
event.stopPropagation();
if (!item.selectable) {
return;
}
const isItemInSelection = selection.entries.find((entry) => entry.id === item.id);
if (isItemInSelection) {
const newSelection: Selection = { entries: selection.entries.filter((entry) => entry.id !== item.id) };
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 614aa88

Please sign in to comment.