Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2926] Introduce IEditingContextProcessor
Bug: #2926 Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
- Loading branch information
1 parent
241377b
commit 5ac4ef0
Showing
5 changed files
with
203 additions
and
34 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
40 changes: 40 additions & 0 deletions
40
...s-core/src/main/java/org/eclipse/sirius/components/core/api/IEditingContextProcessor.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,40 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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.components.core.api; | ||
|
||
/** | ||
* Processor for {@link IEditingContext}. | ||
* | ||
* @author arichard | ||
*/ | ||
public interface IEditingContextProcessor { | ||
|
||
void preProcess(IEditingContext editingContext); | ||
void postProcess(IEditingContext editingContext); | ||
|
||
/** | ||
* Implementation which does nothing, used for mocks in unit tests. | ||
* | ||
* @author arichard | ||
*/ | ||
class NoOp implements IEditingContextProcessor { | ||
|
||
@Override | ||
public void preProcess(IEditingContext editingContext) { | ||
} | ||
|
||
@Override | ||
public void postProcess(IEditingContext editingContext) { | ||
} | ||
} | ||
} |
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
69 changes: 69 additions & 0 deletions
69
...main/java/org/eclipse/sirius/web/services/editingcontext/ViewEditingContextProcessor.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,69 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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.services.editingcontext; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.emf.ecore.EPackage; | ||
import org.eclipse.emf.edit.domain.EditingDomain; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.core.api.IEditingContextProcessor; | ||
import org.eclipse.sirius.components.view.emf.IViewConverter; | ||
import org.eclipse.sirius.web.services.editingcontext.api.IViewLoader; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Editing context processor allowing to convert all views. | ||
* | ||
* @author arichard | ||
*/ | ||
@Service | ||
public class ViewEditingContextProcessor implements IEditingContextProcessor { | ||
|
||
private final IViewLoader viewLoader; | ||
|
||
private final IViewConverter viewConverter; | ||
|
||
public ViewEditingContextProcessor(IViewLoader viewLoader, IViewConverter viewConverter) { | ||
this.viewLoader = viewLoader; | ||
this.viewConverter = viewConverter; | ||
|
||
} | ||
@Override | ||
public void preProcess(IEditingContext editingContext) { | ||
if (editingContext instanceof EditingContext siriusWebEditingContext) { | ||
siriusWebEditingContext.getViews().addAll(this.viewLoader.load()); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void postProcess(IEditingContext editingContext) { | ||
if (editingContext instanceof EditingContext siriusWebEditingContext) { | ||
List<EPackage> accessibleEPackages = this.getAccessibleEPackages(siriusWebEditingContext.getDomain()); | ||
this.viewConverter.convert(siriusWebEditingContext.getViews(), accessibleEPackages).stream() | ||
.filter(Objects::nonNull) | ||
.forEach(representationDescription -> siriusWebEditingContext.getRepresentationDescriptions().put(representationDescription.getId(), representationDescription)); | ||
} | ||
} | ||
|
||
private List<EPackage> getAccessibleEPackages(EditingDomain editingDomain) { | ||
var packageRegistry = editingDomain.getResourceSet().getPackageRegistry(); | ||
|
||
return packageRegistry.values().stream() | ||
.filter(EPackage.class::isInstance) | ||
.map(EPackage.class::cast) | ||
.toList(); | ||
} | ||
} |
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