use of org.osate.ge.internal.services.ModelChangeNotifier.Lock in project osate2 by osate.
the class DefaultAadlModificationService method performModifications.
// Assumes that the modification notifier is already locked
private void performModifications(final List<? extends Modification<?, ?>> modifications, final ModificationPostprocessor postProcessor) {
class ModificationAction implements AgeAction {
@Override
public boolean canExecute() {
return true;
}
@Override
public AgeAction execute() {
try (Lock lock = modelChangeNotifier.lock()) {
final Set<IProject> projectsToBuild = new HashSet<>();
boolean allSuccessful = true;
final List<ModificationResult> modificationResults = new ArrayList<>();
// Iterate over the input objects
for (final Modification<?, ?> modification : modifications) {
final ModificationResult modificationResult = performModification(modification, projectsToBuild);
allSuccessful = modificationResult.modificationSuccessful;
if (!allSuccessful) {
break;
}
modificationResults.add(modificationResult);
}
// Build projects before unlocking. This will cause the post build notifications to be sent out before the lock is released.
// This is desired to avoid multiple diagram updates for the same change.
buildProjects(projectsToBuild);
if (postProcessor != null) {
postProcessor.modificationCompleted(allSuccessful);
}
return modificationResults.isEmpty() ? null : new UndoAction(modificationResults);
}
}
}
actionService.execute("Modify Model", ActionExecutor.ExecutionMode.NORMAL, new ModificationAction());
}
use of org.osate.ge.internal.services.ModelChangeNotifier.Lock in project osate2 by osate.
the class LtkRenameAction method renameWithLtk.
/**
* Renames the specified model element using an LTK rename refactoring.
* @param bo the model element to rename
* @param value the new name for the model element
* @return true if the rename occurred
*/
private boolean renameWithLtk(final EObject bo, final String value) {
// Prevent model notification changes from being sent until after the refactoring
try (Lock lock = modelChangeNotifier.lock()) {
// Rename the element using LTK
final ProcessorBasedRefactoring renameRefactoring = RenameUtil.getRenameRefactoring(bo);
final RefactoringStatus refactoringStatus = prepareAndCheck(renameRefactoring, value);
if (!refactoringStatus.isOK()) {
final Dialog dlg = RefactoringUI.createRefactoringStatusDialog(refactoringStatus, Display.getCurrent().getActiveShell(), "Refactoring", false);
if (dlg.open() != Window.OK) {
// Abort
return false;
}
}
try {
final Change change = renameRefactoring.createChange(new NullProgressMonitor());
new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException {
// Perform the modification
change.perform(monitor);
// Build the project, reconcile all open AADL text editors and then build again.
// This seems to be the best way to ensure that all the model change events have been
// queued before the model change notification lock is released
buildProject();
ensureReconciled();
buildProject();
}
}.run(null);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new GraphicalEditorException(e);
} catch (final RuntimeException | InvocationTargetException | CoreException e) {
throw new GraphicalEditorException(e);
}
}
return true;
}
Aggregations