Skip to content

Commit

Permalink
[694] WIP: Provide a representation to display representations
Browse files Browse the repository at this point in the history
The new representation is can display all existing representation for
the current selection.

Bug: #694
Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
  • Loading branch information
gcoutable committed Aug 20, 2021
1 parent 90d67b3 commit 7722a33
Show file tree
Hide file tree
Showing 14 changed files with 863 additions and 4 deletions.
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 Down Expand Up @@ -35,6 +35,8 @@ public final class ListItem {

private String imageURL;

private ListItemAction action;

private ListItem() {
// Prevent instantiation
}
Expand All @@ -58,6 +60,12 @@ public String getImageURL() {
return this.imageURL;
}

@GraphQLField
@GraphQLNonNull
public ListItemAction getAction() {
return this.action;
}

public static Builder newListItem(String id) {
return new Builder(id);
}
Expand All @@ -81,6 +89,8 @@ public static final class Builder {

private String imageURL;

private ListItemAction action;

private Builder(String id) {
this.id = Objects.requireNonNull(id);
}
Expand All @@ -95,11 +105,17 @@ public Builder imageURL(String imageURL) {
return this;
}

public Builder action(ListItemAction action) {
this.action = Objects.requireNonNull(action);
return this;
}

public ListItem build() {
ListItem listItem = new ListItem();
listItem.id = Objects.requireNonNull(this.id);
listItem.label = Objects.requireNonNull(this.label);
listItem.imageURL = Objects.requireNonNull(this.imageURL);
listItem.action = Objects.requireNonNull(this.action);
return listItem;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*******************************************************************************
* Copyright (c) 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
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.forms;

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

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

/**
* The action of a {@link ListItem}.
*
* @author gcoutable
*/
@Immutable
@GraphQLObjectType
public final class ListItemAction {

private String tooltip;

private String iconName;

private ListItemAction() {
// Prevent instantiation
}

@GraphQLField
@GraphQLNonNull
public String getTooltip() {
return this.tooltip;
}

@GraphQLField
@GraphQLNonNull
public String getIconName() {
return this.iconName;
}

public static Builder newListItemAction() {
return new Builder();
}

@Override
public String toString() {
String pattern = "{0} '{'tooltip: {1}, iconName: {2}'}'"; //$NON-NLS-1$
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.tooltip, this.iconName);
}

/**
* The builder used to create the list item action.
*
* @author gcoutable
*/
@SuppressWarnings("checkstyle:HiddenField")
public static final class Builder {
private String tooltip;

private String iconName;

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

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

public ListItemAction build() {
ListItemAction listItemAction = new ListItemAction();
listItemAction.tooltip = Objects.requireNonNull(this.tooltip);
listItemAction.iconName = Objects.requireNonNull(this.iconName);
return listItemAction;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.sirius.web.components.Element;
import org.eclipse.sirius.web.components.IComponent;
import org.eclipse.sirius.web.forms.ListItem;
import org.eclipse.sirius.web.forms.ListItemAction;
import org.eclipse.sirius.web.forms.description.ListDescription;
import org.eclipse.sirius.web.forms.elements.ListElementProps;
import org.eclipse.sirius.web.forms.validation.DiagnosticComponent;
Expand All @@ -32,6 +33,8 @@
*/
public class ListComponent implements IComponent {

public static final String ACTION_VARIABLE = "action"; //$NON-NLS-1$

public static final String CANDIDATE_VARIABLE = "candidate"; //$NON-NLS-1$

private ListComponentProps props;
Expand Down Expand Up @@ -60,10 +63,22 @@ public Element render() {
String itemLabel = listDescription.getItemLabelProvider().apply(itemVariableManager);
String itemImageURL = listDescription.getItemImageURLProvider().apply(itemVariableManager);

Object listItemAction = listDescription.getListItemActionProvider().apply(itemVariableManager);
VariableManager itemActionVariableManager = itemVariableManager.createChild();
itemActionVariableManager.put(ACTION_VARIABLE, listItemAction);
String listItemActionTooltip = listDescription.getListItemActionTooltipProvider().apply(itemActionVariableManager);
String listItemActionIconName = listDescription.getListItemActionIconNameProvider().apply(itemActionVariableManager);

// @formatter:off
ListItemAction itemAction = ListItemAction.newListItemAction()
.tooltip(listItemActionTooltip)
.iconName(listItemActionIconName)
.build();

ListItem item = ListItem.newListItem(itemId)
.label(itemLabel)
.imageURL(itemImageURL)
.action(itemAction)
.build();
// @formatter:on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public final class ListDescription extends AbstractWidgetDescription {

private Function<VariableManager, String> itemImageURLProvider;

private Function<VariableManager, Object> listItemActionProvider;

private Function<VariableManager, String> listItemActionTooltipProvider;

private Function<VariableManager, String> listItemActionIconNameProvider;

private ListDescription() {
// Prevent instantiation
}
Expand Down Expand Up @@ -68,6 +74,18 @@ public Function<VariableManager, String> getItemImageURLProvider() {
return this.itemImageURLProvider;
}

public Function<VariableManager, Object> getListItemActionProvider() {
return this.listItemActionProvider;
}

public Function<VariableManager, String> getListItemActionTooltipProvider() {
return this.listItemActionTooltipProvider;
}

public Function<VariableManager, String> getListItemActionIconNameProvider() {
return this.listItemActionIconNameProvider;
}

public static Builder newListDescription(String id) {
return new Builder(id);
}
Expand Down Expand Up @@ -99,6 +117,12 @@ public static final class Builder {

private Function<VariableManager, String> itemImageURLProvider;

private Function<VariableManager, Object> listItemActionProvider;

private Function<VariableManager, String> listItemActionTooltipProvider;

private Function<VariableManager, String> listItemActionIconNameProvider;

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

private Function<Object, String> kindProvider;
Expand Down Expand Up @@ -139,6 +163,21 @@ public Builder itemImageURLProvider(Function<VariableManager, String> itemImageU
return this;
}

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

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

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

public Builder diagnosticsProvider(Function<VariableManager, List<Object>> diagnosticsProvider) {
this.diagnosticsProvider = Objects.requireNonNull(diagnosticsProvider);
return this;
Expand All @@ -163,6 +202,9 @@ public ListDescription build() {
listDescription.itemIdProvider = Objects.requireNonNull(this.itemIdProvider);
listDescription.itemLabelProvider = Objects.requireNonNull(this.itemLabelProvider);
listDescription.itemImageURLProvider = Objects.requireNonNull(this.itemImageURLProvider);
listDescription.listItemActionProvider = Objects.requireNonNull(this.listItemActionProvider);
listDescription.listItemActionTooltipProvider = Objects.requireNonNull(this.listItemActionTooltipProvider);
listDescription.listItemActionIconNameProvider = Objects.requireNonNull(this.listItemActionIconNameProvider);
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
@@ -0,0 +1,91 @@
/*******************************************************************************
* Copyright (c) 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
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.spring.collaborative.forms;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import org.eclipse.sirius.web.core.api.IEditingContext;
import org.eclipse.sirius.web.core.api.IObjectService;
import org.eclipse.sirius.web.forms.description.FormDescription;
import org.eclipse.sirius.web.spring.collaborative.api.IRepresentationConfiguration;
import org.eclipse.sirius.web.spring.collaborative.api.IRepresentationEventProcessor;
import org.eclipse.sirius.web.spring.collaborative.api.IRepresentationEventProcessorFactory;
import org.eclipse.sirius.web.spring.collaborative.api.ISubscriptionManagerFactory;
import org.eclipse.sirius.web.spring.collaborative.forms.api.IFormEventHandler;
import org.eclipse.sirius.web.spring.collaborative.forms.api.IFormEventProcessor;
import org.eclipse.sirius.web.spring.collaborative.forms.api.IRepresentationsDescriptionProvider;
import org.eclipse.sirius.web.spring.collaborative.forms.api.IWidgetSubscriptionManagerFactory;
import org.eclipse.sirius.web.spring.collaborative.forms.api.RepresentationsConfiguration;
import org.springframework.stereotype.Service;

/**
* Used to create the representations event processors.
*
* @author gcoutable
*/
@Service
public class RepresentationsEventProcessorFactory implements IRepresentationEventProcessorFactory {

private final IRepresentationsDescriptionProvider representationsDescriptionProvider;

private final IObjectService objectService;

private final List<IFormEventHandler> formEventHandlers;

private final ISubscriptionManagerFactory subscriptionManagerFactory;

private final IWidgetSubscriptionManagerFactory widgetSubscriptionManagerFactory;

public RepresentationsEventProcessorFactory(IRepresentationsDescriptionProvider representationsDescriptionProvider, IObjectService objectService, List<IFormEventHandler> formEventHandlers,
ISubscriptionManagerFactory subscriptionManagerFactory, IWidgetSubscriptionManagerFactory widgetSubscriptionManagerFactory) {
this.representationsDescriptionProvider = Objects.requireNonNull(representationsDescriptionProvider);
this.objectService = Objects.requireNonNull(objectService);
this.formEventHandlers = Objects.requireNonNull(formEventHandlers);
this.subscriptionManagerFactory = Objects.requireNonNull(subscriptionManagerFactory);
this.widgetSubscriptionManagerFactory = Objects.requireNonNull(widgetSubscriptionManagerFactory);
}

@Override
public <T extends IRepresentationEventProcessor> boolean canHandle(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration) {
return IFormEventProcessor.class.isAssignableFrom(representationEventProcessorClass) && configuration instanceof RepresentationsConfiguration;
}

@Override
public <T extends IRepresentationEventProcessor> Optional<T> createRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration,
IEditingContext editingContext) {
if (IFormEventProcessor.class.isAssignableFrom(representationEventProcessorClass) && configuration instanceof RepresentationsConfiguration) {
RepresentationsConfiguration representationsConfiguration = (RepresentationsConfiguration) configuration;

FormDescription formDescription = this.representationsDescriptionProvider.getRepresentationsDescription();
Optional<Object> optionalObject = this.objectService.getObject(editingContext, representationsConfiguration.getObjectId());
if (optionalObject.isPresent()) {
Object object = optionalObject.get();
if (formDescription != null) {
FormEventProcessor formEventProcessor = new FormEventProcessor(editingContext, formDescription, representationsConfiguration.getId(), object, this.formEventHandlers,
this.subscriptionManagerFactory.create(), this.widgetSubscriptionManagerFactory.create());

// @formatter:off
return Optional.of(formEventProcessor)
.filter(representationEventProcessorClass::isInstance)
.map(representationEventProcessorClass::cast);
// @formatter:on
}
}
}

return Optional.empty();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright (c) 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
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.spring.collaborative.forms.api;

import org.eclipse.sirius.web.forms.description.FormDescription;

/**
* Interface used to contribute the form description that contains all OCP representations.
*
* @author gcoutable
*/
public interface IRepresentationsDescriptionProvider {
FormDescription getRepresentationsDescription();
}
Loading

0 comments on commit 7722a33

Please sign in to comment.