use of org.eclipse.emf.transaction.RecordingCommand 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.emf.transaction.RecordingCommand in project InformationSystem by ObeoNetwork.
the class ScaffoldingOperation method execute.
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
if (scaffoldInfo.eResource() == null) {
// We have to create a scaffold model
Resource scaffoldResource = createScaffoldResource();
EObject newInfo = scaffoldResource.getContents().get(0);
if (newInfo instanceof ScaffoldInfo) {
scaffoldInfo = (ScaffoldInfo) newInfo;
}
}
final Transformation transformation = createTransformation();
try {
RecordingCommand transformCommand = new RecordingCommand(session.getTransactionalEditingDomain(), "Scaffolding transformation") {
@Override
protected void doExecute() {
success = transformation.transform(scaffoldInfo, scaffoldType);
}
};
session.getTransactionalEditingDomain().getCommandStack().execute(transformCommand);
} catch (RuntimeException e) {
logError("An error occured during the transformation", e);
return;
}
}
use of org.eclipse.emf.transaction.RecordingCommand in project InformationSystem by ObeoNetwork.
the class ViewQueryChangeTrigger method localChangesAboutToCommit.
@Override
public Option<Command> localChangesAboutToCommit(Collection<Notification> notifications) {
Iterable<Notification> querySetNotification = Iterables.filter(notifications, IS_QUERY_SET);
for (Notification notification : querySetNotification) {
view = (View) notification.getNotifier();
query = view.getQuery();
final Session session = SessionManager.INSTANCE.getSession(view);
final TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
if (!Strings.isNullOrEmpty(query)) {
final Command result = new RecordingCommand(domain) {
@Override
protected void doExecute() {
if (view.getColumns() != null) {
view.getColumns().clear();
}
if (view.getTables() != null) {
view.getTables().clear();
}
// Parse new query
ViewContentProvider viewContentProvider = new ViewContentProvider();
viewContentProvider.parseViewQuery(query);
List<ColObject> listOfColumns = viewContentProvider.getColumns();
if (listOfColumns != null) {
for (ColObject column : listOfColumns) {
ViewElement elem = DatabaseFactory.eINSTANCE.createViewElement();
elem.setName(column.getName());
elem.setAlias(column.getAlias());
view.getColumns().add(elem);
}
}
List<String> listOfTables = viewContentProvider.getTables();
if (listOfTables != null) {
for (String table : listOfTables) {
ViewElement elem = DatabaseFactory.eINSTANCE.createViewElement();
elem.setName(table);
view.getTables().add(elem);
}
}
}
};
return Options.newSome(result);
} else if (Strings.isNullOrEmpty(query)) {
final Command result = new RecordingCommand(domain) {
@Override
protected void doExecute() {
if (view.getColumns() != null) {
view.getColumns().clear();
}
if (view.getTables() != null) {
view.getTables().clear();
}
}
};
return Options.newSome(result);
}
}
return Options.newNone();
}
use of org.eclipse.emf.transaction.RecordingCommand 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.emf.transaction.RecordingCommand in project gemoc-studio by eclipse.
the class FsmTraceStateManager method restoreState.
@Override
public void restoreState(State<?, ?> state) {
if (modelResource != null && state instanceof fsmTrace.States.SpecificState) {
try {
final TransactionalEditingDomain ed = TransactionUtil.getEditingDomain(modelResource);
if (ed != null) {
final RecordingCommand command = new RecordingCommand(ed, "") {
protected void doExecute() {
restoreStateExecute((fsmTrace.States.SpecificState) state);
}
};
CommandExecution.execute(ed, command);
}
} catch (Exception e) {
throw e;
}
}
}
Aggregations