Skip to content

Commit

Permalink
[694] Provide a representation to display representations
Browse files Browse the repository at this point in the history
Projects that depends on Sirius Components should now provide:

- a Spring service that implements IRepresentationsDescriptionProvider
- a Subscription data fetcher to subscribe to the "representationsEvent"

Providing these components will make possible the display of a
representation that display representations for the current selection.

This contribution comes with significant changes to the behavior of the
left and right sides in order to prevent layout issues during the expand
and collapse. It also provides some improvements to the Success object
in order to provide additional information. Those pieces of information
will be used to compute the ChangeDescription. It is a first step to help
users create representations which do not display only semantic elements.

Bug: #694
Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
  • Loading branch information
gcoutable authored and sbegaudeau committed Nov 10, 2021
1 parent f3a64ac commit 2c8ee26
Show file tree
Hide file tree
Showing 57 changed files with 1,928 additions and 137 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@

- https://github.com/eclipse-sirius/sirius-components/issues/818[#818] [workbench] The concept of `Selection` will be restructured, as described in the ADR-036. Every part of the code involved in the manipulation of the selection of the workbench will be impacted. This includes concepts as remote as the representation descriptions which are used to computed fields like `kind`. For example, the behavior of the `TreeDescription#getKindProvider` and `NodeDescription#getTargetObjectKindProvider` will have to be updated for all the providers. Failure to update to the new behavior will make the selection fail in the workbench

=== Deprecation warning

[core] The Success parameterless contructor will be removed soon.

=== Breaking Changes

- https://github.com/eclipse-sirius/sirius-components/issues/804[#804] [core] Update the name of our configuration properties. The configuration property `sirius.web.graphql.websocket.allowed.origins` will now be `sirius.components.cors.allowedOriginPatterns` and it will support complex patterns on top of regular origins. The default value will be restored to nothing since it has temporarily been set to `*`. In a development environment, the recommended value would be both patterns `https://localhost:[*]` and `http://localhost:[*]` in order to accept requests from any application hosted on the same machine. The configuration property `org.eclipse.sirius.web.editingContextEventProcessorRegistry.disposeDelay` will now be `sirius.components.editingContext.disposeDelay`. Its default value will be 1s since it is the only realistic option with domain and view support.

=== New features

- https://github.com/eclipse-sirius/sirius-components/issues/773[#773] [compatibility] Add support for both `createView` and `deleteView` model operations which can be used to support unsynchronized diagrams from Sirius Desktop.
- https://github.com/eclipse-sirius/sirius-components/issues/694[#694] [core] Add `IRepresentationRefreshPolicyRegistry` to contribute `IRepresentationRefreshPolicyProvider`s in order to customize on which kind of change description, representations will be refreshed.

=== Improvements

- https://github.com/eclipse-sirius/sirius-components/issues/799[#799] [diagram] The buttons in the diagram's toolbar now have proper tooltips
- [core] Add a task to display TypeScript errors in the VS Code problems view
- https://github.com/eclipse-sirius/sirius-components/issues/773[#773] [compatibility] The synchronization policy of the node descriptions is now properly computed from the `AbstractNodeMapping`
- https://github.com/eclipse-sirius/sirius-components/issues/694[#694] [core] Data can be provided to Success in order to notify changment made by operation made on the editing context.


== v0.5.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 2021 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 All @@ -14,12 +14,14 @@

import java.text.MessageFormat;
import java.util.Objects;
import java.util.function.Supplier;

import org.eclipse.sirius.web.annotations.Immutable;
import org.eclipse.sirius.web.annotations.graphql.GraphQLField;
import org.eclipse.sirius.web.annotations.graphql.GraphQLID;
import org.eclipse.sirius.web.annotations.graphql.GraphQLNonNull;
import org.eclipse.sirius.web.annotations.graphql.GraphQLObjectType;
import org.eclipse.sirius.web.representations.IStatus;

/**
* The list item.
Expand All @@ -33,8 +35,14 @@ public final class ListItem {

private String label;

private String kind;

private String imageURL;

private boolean deletable;

private Supplier<IStatus> deleteHandler;

private ListItem() {
// Prevent instantiation
}
Expand All @@ -52,20 +60,36 @@ public String getLabel() {
return this.label;
}

@GraphQLField
@GraphQLNonNull
public String getKind() {
return this.kind;
}

@GraphQLField
@GraphQLNonNull
public String getImageURL() {
return this.imageURL;
}

@GraphQLField
@GraphQLNonNull
public boolean isDeletable() {
return this.deletable;
}

public Supplier<IStatus> getDeleteHandler() {
return this.deleteHandler;
}

public static Builder newListItem(String id) {
return new Builder(id);
}

@Override
public String toString() {
String pattern = "{0} '{'id: {1}, label: {2}, imageURL: {3}'}'"; //$NON-NLS-1$
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.label, this.imageURL);
String pattern = "{0} '{'id: {1}, label: {2}, kind: {3}, deletable: {4}, imageURL: {5}'}'"; //$NON-NLS-1$
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.label, this.kind, this.deletable, this.imageURL);
}

/**
Expand All @@ -79,8 +103,14 @@ public static final class Builder {

private String label;

private String kind;

private String imageURL;

private boolean deletable;

private Supplier<IStatus> deleteHandler;

private Builder(String id) {
this.id = Objects.requireNonNull(id);
}
Expand All @@ -90,15 +120,33 @@ public Builder label(String label) {
return this;
}

public Builder kind(String kind) {
this.kind = Objects.requireNonNull(kind);
return this;
}

public Builder imageURL(String imageURL) {
this.imageURL = Objects.requireNonNull(imageURL);
return this;
}

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

public Builder deleteHandler(Supplier<IStatus> deleteHandler) {
this.deleteHandler = Objects.requireNonNull(deleteHandler);
return this;
}

public ListItem build() {
ListItem listItem = new ListItem();
listItem.id = Objects.requireNonNull(this.id);
listItem.label = Objects.requireNonNull(this.label);
listItem.kind = Objects.requireNonNull(this.kind);
listItem.deletable = Objects.requireNonNull(this.deletable);
listItem.deleteHandler = Objects.requireNonNull(this.deleteHandler);
listItem.imageURL = Objects.requireNonNull(this.imageURL);
return listItem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;

import org.eclipse.sirius.web.components.Element;
import org.eclipse.sirius.web.components.IComponent;
Expand All @@ -23,6 +25,7 @@
import org.eclipse.sirius.web.forms.elements.ListElementProps;
import org.eclipse.sirius.web.forms.validation.DiagnosticComponent;
import org.eclipse.sirius.web.forms.validation.DiagnosticComponentProps;
import org.eclipse.sirius.web.representations.IStatus;
import org.eclipse.sirius.web.representations.VariableManager;

/**
Expand Down Expand Up @@ -58,12 +61,21 @@ public Element render() {

String itemId = listDescription.getItemIdProvider().apply(itemVariableManager);
String itemLabel = listDescription.getItemLabelProvider().apply(itemVariableManager);
String itemKind = listDescription.getItemKindProvider().apply(itemVariableManager);
String itemImageURL = listDescription.getItemImageURLProvider().apply(itemVariableManager);
boolean isItemDeletable = listDescription.getItemDeletableProvider().apply(itemVariableManager);
Function<VariableManager, IStatus> genericHandler = listDescription.getItemDeleteHandlerProvider();
Supplier<IStatus> specializedHandler = () -> {
return genericHandler.apply(itemVariableManager);
};

// @formatter:off
ListItem item = ListItem.newListItem(itemId)
.label(itemLabel)
.kind(itemKind)
.imageURL(itemImageURL)
.deletable(isItemDeletable)
.deleteHandler(specializedHandler)
.build();
// @formatter:on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.function.Function;

import org.eclipse.sirius.web.annotations.Immutable;
import org.eclipse.sirius.web.representations.IStatus;
import org.eclipse.sirius.web.representations.VariableManager;

/**
Expand All @@ -38,8 +39,14 @@ public final class ListDescription extends AbstractWidgetDescription {

private Function<VariableManager, String> itemLabelProvider;

private Function<VariableManager, String> itemKindProvider;

private Function<VariableManager, String> itemImageURLProvider;

private Function<VariableManager, Boolean> itemDeletableProvider;

private Function<VariableManager, IStatus> itemDeleteHandlerProvider;

private ListDescription() {
// Prevent instantiation
}
Expand All @@ -64,10 +71,22 @@ public Function<VariableManager, String> getItemLabelProvider() {
return this.itemLabelProvider;
}

public Function<VariableManager, String> getItemKindProvider() {
return this.itemKindProvider;
}

public Function<VariableManager, String> getItemImageURLProvider() {
return this.itemImageURLProvider;
}

public Function<VariableManager, Boolean> getItemDeletableProvider() {
return this.itemDeletableProvider;
}

public Function<VariableManager, IStatus> getItemDeleteHandlerProvider() {
return this.itemDeleteHandlerProvider;
}

public static Builder newListDescription(String id) {
return new Builder(id);
}
Expand Down Expand Up @@ -97,8 +116,14 @@ public static final class Builder {

private Function<VariableManager, String> itemLabelProvider;

private Function<VariableManager, String> itemKindProvider;

private Function<VariableManager, String> itemImageURLProvider;

private Function<VariableManager, Boolean> itemDeletableProvider;

private Function<VariableManager, IStatus> itemDeleteHandlerProvider;

private Function<VariableManager, List<Object>> diagnosticsProvider;

private Function<Object, String> kindProvider;
Expand Down Expand Up @@ -134,11 +159,26 @@ public Builder itemLabelProvider(Function<VariableManager, String> itemLabelProv
return this;
}

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

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

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

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

public Builder diagnosticsProvider(Function<VariableManager, List<Object>> diagnosticsProvider) {
this.diagnosticsProvider = Objects.requireNonNull(diagnosticsProvider);
return this;
Expand All @@ -162,7 +202,10 @@ public ListDescription build() {
listDescription.itemsProvider = Objects.requireNonNull(this.itemsProvider);
listDescription.itemIdProvider = Objects.requireNonNull(this.itemIdProvider);
listDescription.itemLabelProvider = Objects.requireNonNull(this.itemLabelProvider);
listDescription.itemKindProvider = Objects.requireNonNull(this.itemKindProvider);
listDescription.itemImageURLProvider = Objects.requireNonNull(this.itemImageURLProvider);
listDescription.itemDeletableProvider = Objects.requireNonNull(this.itemDeletableProvider);
listDescription.itemDeleteHandlerProvider = Objects.requireNonNull(this.itemDeleteHandlerProvider);
listDescription.diagnosticsProvider = Objects.requireNonNull(this.diagnosticsProvider);
listDescription.kindProvider = Objects.requireNonNull(this.kindProvider);
listDescription.messageProvider = Objects.requireNonNull(this.messageProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,36 @@
*******************************************************************************/
package org.eclipse.sirius.web.representations;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
* The status to return when the representation description handler success.
*
* @author gcoutable
*/
public class Success implements IStatus {

private final Map<String, Object> parameters;

private final String changeKind;

public Success() {
this("", new HashMap<>()); //$NON-NLS-1$
}

public Success(String changeKind, Map<String, Object> parameters) {
this.changeKind = Objects.requireNonNull(changeKind);
this.parameters = Objects.requireNonNull(parameters);
}

public String getChangeKind() {
return this.changeKind;
}

public Map<String, Object> getParameters() {
return this.parameters;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public Diagram create(String label, Object targetObject, DiagramDescription diag
@Override
public Optional<Diagram> refresh(IEditingContext editingContext, IDiagramContext diagramContext) {
Diagram previousDiagram = diagramContext.getDiagram();

var optionalObject = this.objectService.getObject(editingContext, previousDiagram.getTargetObjectId());
// @formatter:off
var optionalDiagramDescription = this.representationDescriptionSearchService.findById(editingContext, previousDiagram.getDescriptionId())
Expand Down
Loading

0 comments on commit 2c8ee26

Please sign in to comment.