-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[694] WIP: Provide a representation to display representations
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
Showing
14 changed files
with
863 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
backend/sirius-web-forms/src/main/java/org/eclipse/sirius/web/forms/ListItemAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...g/eclipse/sirius/web/spring/collaborative/forms/RepresentationsEventProcessorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...clipse/sirius/web/spring/collaborative/forms/api/IRepresentationsDescriptionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
Oops, something went wrong.