use of org.eclipse.sirius.components.emf.services.EditingContext in project sirius-components by eclipse-sirius.
the class CreateInstanceOperationHandlerTests method initialize.
@BeforeEach
public void initialize() {
this.operationTestContext = new OperationTestContext();
AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
EditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
this.operationTestContext.getVariables().put(IEditingContext.EDITING_CONTEXT, editingContext);
this.createInstanceOperation = ToolFactory.eINSTANCE.createCreateInstance();
this.createInstanceOperationHandler = new CreateInstanceOperationHandler(this.operationTestContext.getObjectService(), this.operationTestContext.getRepresentationMetadataSearchService(), this.operationTestContext.getIdentifierProvider(), this.operationTestContext.getInterpreter(), new EPackageService(), new ChildModelOperationHandler(List.of()), this.createInstanceOperation);
}
use of org.eclipse.sirius.components.emf.services.EditingContext in project sirius-components by eclipse-sirius.
the class CreateViewOperationHandlerTests method initialize.
@BeforeEach
public void initialize() {
this.operationTestContext = new OperationTestContext();
// @formatter:off
DiagramDescription diagramDescription = DiagramDescription.newDiagramDescription(UUID.randomUUID()).label(// $NON-NLS-1$
"DiagramDescriptionTest").targetObjectIdProvider(// $NON-NLS-1$
variableManager -> "diagramTargetObjectId").canCreatePredicate(variableManager -> true).labelProvider(// $NON-NLS-1$
variableManager -> "Diagram").toolSections(List.of()).nodeDescriptions(List.of(this.getNodeDescription(UUID.randomUUID()))).edgeDescriptions(List.of()).dropHandler(// $NON-NLS-1$
variableManager -> new Failure("")).build();
Diagram diagram = Diagram.newDiagram(UUID.randomUUID().toString()).descriptionId(diagramDescription.getId()).targetObjectId(UUID.randomUUID().toString()).label(// $NON-NLS-1$
"DiagramTest").position(Position.at(0, 0)).size(Size.of(100, 100)).nodes(new ArrayList<>()).edges(List.of()).build();
IDiagramContext diagramContext = new IDiagramContext.NoOp() {
@Override
public List<ViewCreationRequest> getViewCreationRequests() {
return new ArrayList<>();
}
};
this.operationTestContext.getVariables().put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext);
// @formatter:on
AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
EditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
this.operationTestContext.getVariables().put(IEditingContext.EDITING_CONTEXT, editingContext);
this.operationTestContext.getVariables().put(CONTAINER_VIEW, diagram);
this.createViewOperation = org.eclipse.sirius.diagram.description.tool.ToolFactory.eINSTANCE.createCreateView();
this.createViewOperationHandler = new CreateViewOperationHandler(this.operationTestContext.getObjectService(), this.operationTestContext.getRepresentationMetadataSearchService(), this.operationTestContext.getIdentifierProvider(), this.operationTestContext.getInterpreter(), new ChildModelOperationHandler(List.of()), this.createViewOperation);
}
use of org.eclipse.sirius.components.emf.services.EditingContext in project sirius-components by eclipse-sirius.
the class DeleteViewOperationHandlerTests method initialize.
@BeforeEach
public void initialize() {
this.operationTestContext = new OperationTestContext();
// @formatter:off
DiagramDescription diagramDescription = DiagramDescription.newDiagramDescription(UUID.randomUUID()).label(// $NON-NLS-1$
"DiagramDescriptionTest").targetObjectIdProvider(// $NON-NLS-1$
variableManager -> "diagramTargetObjectId").canCreatePredicate(variableManager -> true).labelProvider(// $NON-NLS-1$
variableManager -> "Diagram").toolSections(List.of()).nodeDescriptions(List.of(this.getNodeDescription(UUID.randomUUID()))).edgeDescriptions(List.of()).dropHandler(// $NON-NLS-1$
variableManager -> new Failure("")).build();
Node node = Node.newNode(UUID.randomUUID().toString()).descriptionId(UUID.randomUUID()).type(// $NON-NLS-1$
"Node").targetObjectId(UUID.randomUUID().toString()).targetObjectKind(// $NON-NLS-1$
"ecore::EPackage").targetObjectLabel(OperationTestContext.ROOT_PACKAGE_NAME).label(Label.newLabel(UUID.randomUUID().toString()).type(// $NON-NLS-1$
"Label").text(OperationTestContext.ROOT_PACKAGE_NAME).position(Position.at(0, 0)).size(Size.of(10, 10)).alignment(Position.at(0, 0)).style(// $NON-NLS-1$ //$NON-NLS-2$
LabelStyle.newLabelStyle().color("").fontSize(0).iconURL("").build()).build()).style(// $NON-NLS-1$
ImageNodeStyle.newImageNodeStyle().imageURL("").scalingFactor(0).build()).position(Position.at(0, 0)).size(Size.of(10, 10)).borderNodes(List.of()).childNodes(List.of()).build();
Diagram diagram = Diagram.newDiagram(UUID.randomUUID().toString()).descriptionId(diagramDescription.getId()).targetObjectId(UUID.randomUUID().toString()).label(// $NON-NLS-1$
"DiagramTest").position(Position.at(0, 0)).size(Size.of(100, 100)).nodes(List.of(node)).edges(List.of()).build();
IDiagramContext diagramContext = new IDiagramContext.NoOp() {
@Override
public List<ViewDeletionRequest> getViewDeletionRequests() {
return new ArrayList<>();
}
};
this.operationTestContext.getVariables().put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext);
// @formatter:on
AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
EditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
this.operationTestContext.getVariables().put(IEditingContext.EDITING_CONTEXT, editingContext);
this.operationTestContext.getVariables().put(CONTAINER_VIEW, diagram);
this.operationTestContext.getVariables().put(VariableManager.SELF, diagram.getNodes().get(0));
this.deleteViewOperation = ToolFactory.eINSTANCE.createDeleteView();
this.deleteViewOperationHandler = new DeleteViewOperationHandler(this.operationTestContext.getObjectService(), this.operationTestContext.getRepresentationMetadataSearchService(), this.operationTestContext.getIdentifierProvider(), this.operationTestContext.getInterpreter(), new ChildModelOperationHandler(List.of()), this.deleteViewOperation);
}
use of org.eclipse.sirius.components.emf.services.EditingContext in project sirius-components by eclipse-sirius.
the class ToolInterpreter method executeCreateInstance.
private Optional<VariableManager> executeCreateInstance(VariableManager variableManager, CreateInstance creatInstanceOperation) {
var optionalSelf = variableManager.get(VariableManager.SELF, EObject.class);
var editingDomain = variableManager.get(IEditingContext.EDITING_CONTEXT, EditingContext.class).map(EditingContext::getDomain);
if (optionalSelf.isPresent() && editingDomain.isPresent()) {
var optionalNewInstance = this.createSemanticInstance(editingDomain.get(), creatInstanceOperation.getTypeName());
if (optionalNewInstance.isPresent()) {
Object container = this.ecore.eAdd(optionalSelf.get(), creatInstanceOperation.getReferenceName(), optionalNewInstance.get());
if (container != null) {
VariableManager childVariableManager = variableManager.createChild();
childVariableManager.put(creatInstanceOperation.getVariableName(), optionalNewInstance.get());
return this.executeOperations(creatInstanceOperation.getChildren(), childVariableManager);
}
}
}
return Optional.empty();
}
use of org.eclipse.sirius.components.emf.services.EditingContext in project sirius-web by eclipse-sirius.
the class EditingContextSearchService method findById.
@Override
public Optional<IEditingContext> findById(String editingContextId) {
long start = System.currentTimeMillis();
// $NON-NLS-1$
this.logger.debug("Loading the editing context {}", editingContextId);
AdapterFactoryEditingDomain editingDomain = new AdapterFactoryEditingDomain(this.composedAdapterFactory, new BasicCommandStack());
ResourceSet resourceSet = editingDomain.getResourceSet();
resourceSet.eAdapters().add(new ECrossReferenceAdapter());
EPackageRegistryImpl ePackageRegistry = new EPackageRegistryImpl();
this.globalEPackageRegistry.forEach(ePackageRegistry::put);
List<EPackage> additionalEPackages = this.editingContextEPackageService.getEPackages(editingContextId);
additionalEPackages.forEach(ePackage -> ePackageRegistry.put(ePackage.getNsURI(), ePackage));
resourceSet.setPackageRegistry(ePackageRegistry);
List<DocumentEntity> documentEntities = new IDParser().parse(editingContextId).map(this.documentRepository::findAllByProjectId).orElseGet(List::of);
for (DocumentEntity documentEntity : documentEntities) {
URI uri = URI.createURI(documentEntity.getId().toString());
JsonResource resource = new SiriusWebJSONResourceFactoryImpl().createResource(uri);
try (var inputStream = new ByteArrayInputStream(documentEntity.getContent().getBytes())) {
resourceSet.getResources().add(resource);
resource.load(inputStream, null);
resource.eAdapters().add(new DocumentMetadataAdapter(documentEntity.getName()));
} catch (IOException | IllegalArgumentException exception) {
// $NON-NLS-1$
this.logger.warn("An error occured while loading document {}: {}.", documentEntity.getId(), exception.getMessage());
resourceSet.getResources().remove(resource);
}
}
// $NON-NLS-1$
this.logger.debug("{} documents loaded for the editing context {}", resourceSet.getResources().size(), editingContextId);
long end = System.currentTimeMillis();
this.timer.record(end - start, TimeUnit.MILLISECONDS);
return Optional.of(new EditingContext(editingContextId, editingDomain));
}
Aggregations