use of org.eclipse.sirius.viewpoint.DRepresentationDescriptor in project InformationSystem by ObeoNetwork.
the class DeleteInteractionHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
final Interaction interaction = extractInteraction(event);
if (interaction == null) {
return null;
}
boolean confirm = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Delete interaction", "Delete the selected interaction ?");
if (confirm) {
final Session session = SessionManager.INSTANCE.getSession(interaction);
final ModelAccessor modelAccessor = session.getModelAccessor();
final ECrossReferenceAdapter semanticCrossReferencer = session.getSemanticCrossReferencer();
TransactionalEditingDomain transactionalEditingDomain = session.getTransactionalEditingDomain();
transactionalEditingDomain.getCommandStack().execute(new RecordingCommand(transactionalEditingDomain) {
@Override
protected void doExecute() {
// Retrieve associated representations
Collection<DRepresentationDescriptor> representationDescriptors = DialectManager.INSTANCE.getRepresentationDescriptors(interaction, session);
// Delete representations
for (DRepresentationDescriptor representationDescriptor : representationDescriptors) {
closeEditor(session, representationDescriptor.getRepresentation());
DialectManager.INSTANCE.deleteRepresentation(representationDescriptor, session);
}
// Delete interaction
modelAccessor.eDelete(interaction, semanticCrossReferencer);
}
});
}
return null;
}
use of org.eclipse.sirius.viewpoint.DRepresentationDescriptor in project InformationSystem by ObeoNetwork.
the class DeleteStateMachineHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
final StateMachine stateMachine = extractStateMachine(event);
if (stateMachine == null) {
return null;
}
boolean confirm = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Delete State Machine", "Delete the selected state machine ?");
if (confirm) {
final Session session = SessionManager.INSTANCE.getSession(stateMachine);
final ModelAccessor modelAccessor = session.getModelAccessor();
final ECrossReferenceAdapter semanticCrossReferencer = session.getSemanticCrossReferencer();
TransactionalEditingDomain transactionalEditingDomain = session.getTransactionalEditingDomain();
transactionalEditingDomain.getCommandStack().execute(new RecordingCommand(transactionalEditingDomain) {
@Override
protected void doExecute() {
// Retrieve associated representations
Collection<DRepresentationDescriptor> representationDescriptors = DialectManager.INSTANCE.getRepresentationDescriptors(stateMachine, session);
// Delete representations
for (DRepresentationDescriptor representationDescriptor : representationDescriptors) {
closeEditor(session, representationDescriptor.getRepresentation());
DialectManager.INSTANCE.deleteRepresentation(representationDescriptor, session);
}
// Delete StateMachine
modelAccessor.eDelete(stateMachine, semanticCrossReferencer);
}
});
}
return null;
}
use of org.eclipse.sirius.viewpoint.DRepresentationDescriptor in project InformationSystem by ObeoNetwork.
the class BusinessProjectImporter method getImpactedReferences.
public Collection<ReferenceData> getImpactedReferences(IProgressMonitor parentMonitor) throws CoreException {
SubMonitor monitor = SubMonitor.convert(parentMonitor, 2);
saveAndCloseEditorsOnTargetProject(monitor.newChild(1));
initializeImportData();
// Compute the target existing roots that will be replaced
Collection<EObject> existingTargetSemanticRoots = getAllImpactedTargetSemanticRoots();
// Collect representations related to the existing target semantic content
Collection<DRepresentationDescriptor> existingTargetRepresentationDescriptors = ImporterUtil.getRelatedRepresentationDescriptors(targetSession, ImporterUtil.getAllElementsWithChildren(existingTargetSemanticRoots));
Collection<DRepresentation> existingTargetRepresentations = new ArrayList<DRepresentation>();
for (DRepresentationDescriptor existingTargetRepresentationDescriptor : existingTargetRepresentationDescriptors) {
existingTargetRepresentations.add(existingTargetRepresentationDescriptor.getRepresentation());
}
// Collect references
Collection<ReferenceData> allReferences = ImporterUtil.getReferencingElements(existingTargetSemanticRoots, targetSession);
// Filter references not impacted by the removal
Collection<ReferenceData> filteredReferences = filterOutOfConcernReferences(allReferences, existingTargetSemanticRoots, existingTargetRepresentations);
monitor.worked(1);
monitor.done();
return filteredReferences;
}
use of org.eclipse.sirius.viewpoint.DRepresentationDescriptor in project InformationSystem by ObeoNetwork.
the class BusinessProjectImporter method importElementsIntoTargetProject.
public void importElementsIntoTargetProject(IProgressMonitor parentMonitor) throws CoreException {
final SubMonitor monitor = SubMonitor.convert(parentMonitor, 5);
// Ensure project is closed
saveAndCloseEditorsOnTargetProject(monitor.newChild(1));
initializeImportData();
final Map<String, List<EObject>> requirementReferencesCache = cacheRequirementReferences();
// Create command
TransactionalEditingDomain editingDomain = targetSession.getTransactionalEditingDomain();
RecordingCommand command = new RecordingCommand(editingDomain) {
@Override
protected void doExecute() {
// At the end of the import, if there is no "requirement.Repository" object in the target MOE project, then create one named after the MOE project.
// This verification is done *before* importing models from the MOA otherwise they get added onto the session.
boolean repositoryExistsBeforeImporting = false;
for (Resource semanticResource : SessionManager.INSTANCE.getExistingSession(targetProject.getMainRepresentationsFileURI(monitor).get()).getSemanticResources()) {
repositoryExistsBeforeImporting = repositoryExistsBeforeImporting || EcoreUtil.getObjectByType(semanticResource.getContents(), RequirementPackage.Literals.REPOSITORY) != null;
}
// Delete the content of the impacted resources and the related representations
final Collection<EObject> existingTargetSemanticRoots = getAllImpactedTargetSemanticRoots();
if (!existingTargetSemanticRoots.isEmpty()) {
// Delete related representations
final Collection<DRepresentationDescriptor> existingRepresentationDescriptors = ImporterUtil.getRelatedRepresentationDescriptors(targetSession, ImporterUtil.getAllElementsWithChildren(existingTargetSemanticRoots));
if (!existingRepresentationDescriptors.isEmpty()) {
for (DRepresentationDescriptor dRepresentationDescriptor : existingRepresentationDescriptors) {
DialectManager.INSTANCE.deleteRepresentation(dRepresentationDescriptor, targetSession);
}
}
// Delete existing objects
for (EObject semanticRoot : existingTargetSemanticRoots) {
if (semanticRoot instanceof Repository) {
for (Requirement req : ImporterUtil.getAllContentsOfType(semanticRoot, Requirement.class)) {
req.getReferencedObject().clear();
SiriusUtil.delete(req, targetSession);
}
}
SiriusUtil.delete(semanticRoot, targetSession);
}
}
// Create semantic resources and their content
for (EObject sourceRoot : importData.getSourceRoots()) {
EObject copyRoot = importData.getCopyEObject(sourceRoot);
String targetPath = getTargetResourcePath(sourceRoot);
addToSemanticResource(copyRoot, targetPath);
}
// Add representations
for (DRepresentationDescriptor sourceRepresentationDescriptor : importData.getSourceRepresentationDescriptors()) {
DRepresentationDescriptor copyRepresentationDescriptor = (DRepresentationDescriptor) importData.getCopyEObject(sourceRepresentationDescriptor);
Viewpoint viewpoint = getViewpoint(copyRepresentationDescriptor);
addRepresentationDescriptor(copyRepresentationDescriptor, viewpoint);
}
// Restore the local requirement references
restoreRequirementReferences(requirementReferencesCache);
// }
if (!repositoryExistsBeforeImporting) {
Repository requirementsRepository = RequirementFactory.eINSTANCE.createRepository();
addToSemanticResource(requirementsRepository, targetProject.getProject().getName() + "/" + targetProject.getProject().getName() + ".requirement");
}
}
};
// Execute the command
editingDomain.getCommandStack().execute(command);
monitor.worked(3);
// Save project
targetSession.save(monitor.newChild(1));
}
use of org.eclipse.sirius.viewpoint.DRepresentationDescriptor in project InformationSystem by ObeoNetwork.
the class ImportData method initializeCopyElements.
private void initializeCopyElements() {
Collection<EObject> sourceEObjects = new ArrayList<EObject>();
sourceEObjects.addAll(sourceRoots);
sourceEObjects.addAll(sourceRepresentationDescriptors);
for (DRepresentationDescriptor dRepresentationDescriptor : sourceRepresentationDescriptors) {
sourceEObjects.add(dRepresentationDescriptor.getRepresentation());
}
Copier copier = new Copier();
copier.copyAll(sourceEObjects);
copier.copyReferences();
// Build the copy to source map
copyToSourceMap = new HashMap<EObject, EObject>();
for (EObject sourceEObject : sourceEObjects) {
copyToSourceMap.put(copier.get(sourceEObject), sourceEObject);
}
// Save the copier as the source to copy map
sourceToCopyMap = copier;
}
Aggregations