Skip to content

Commit

Permalink
[3562] Update displayed default model creation action
Browse files Browse the repository at this point in the history
- The action to create an empty model is displayed only when the project does not have a nature.
- Add the possibility for a project with the studio nature to create an empty model.

Bug: eclipse-sirius#3562
Signed-off-by: Guillaume Coutable <[email protected]>
  • Loading branch information
gcoutable authored and sbegaudeau committed Jun 9, 2024
1 parent a02045f commit 389819a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

=== Breaking changes

- https://github.com/eclipse-sirius/sirius-web/issues/3562[#3562] [sirius-web] Update displayed default model creation action.
+ Projects that have a nature and need the action to create an empty model will need to register the empty model action like it is done in `StudioEditingContextActionProvider`.

=== Dependency update

- https://github.com/eclipse-sirius/sirius-web/issues/3510[#3510] [releng] Switch to Spring Boot 3.2.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
package org.eclipse.sirius.web.application.project.services;

import java.util.List;
import java.util.Objects;
import java.util.Set;

import org.eclipse.sirius.components.collaborative.api.IEditingContextActionProvider;
import org.eclipse.sirius.components.collaborative.dto.EditingContextAction;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.web.application.UUIDParser;
import org.eclipse.sirius.web.domain.boundedcontexts.project.Project;
import org.eclipse.sirius.web.domain.boundedcontexts.project.services.api.IProjectSearchService;
import org.springframework.stereotype.Service;

/**
Expand All @@ -29,8 +34,22 @@ public class DefaultEditingContextActionProvider implements IEditingContextActio

public static final String EMPTY_ACTION_ID = "empty";

private final IProjectSearchService projectSearchService;

public DefaultEditingContextActionProvider(IProjectSearchService projectSearchService) {
this.projectSearchService = Objects.requireNonNull(projectSearchService);
}

@Override
public List<EditingContextAction> getEditingContextAction(IEditingContext editingContext) {
return List.of(new EditingContextAction(EMPTY_ACTION_ID, "Others..."));
var isWithoutNature = new UUIDParser().parse(editingContext.getId())
.flatMap(this.projectSearchService::findById)
.map(Project::getNatures)
.orElseGet(Set::of)
.isEmpty();
if (isWithoutNature) {
return List.of(new EditingContextAction(EMPTY_ACTION_ID, "Others..."));
}
return List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class StudioEditingContextActionProvider implements IEditingContextAction

public static final String EMPTY_VIEW_ID = "empty_view";

public static final String EMPTY_ACTION_ID = "empty";

private final IStudioCapableEditingContextPredicate studioCapableEditingContextPredicate;

public StudioEditingContextActionProvider(IStudioCapableEditingContextPredicate studioCapableEditingContextPredicate) {
Expand Down Expand Up @@ -66,6 +68,7 @@ public List<EditingContextAction> getEditingContextAction(IEditingContext editin
if (containsView) {
actions.add(new EditingContextAction(EMPTY_VIEW_ID, "View"));
}
actions.add(new EditingContextAction(EMPTY_ACTION_ID, "Others..."));
}

return actions;
Expand Down

0 comments on commit 389819a

Please sign in to comment.