use of org.osate.ge.internal.ui.LtkRenameAction in project osate2 by osate.
the class EditorRenameUtil method rename.
public static void rename(final DiagramElement de, final String value, final InternalDiagramEditor editor) {
final ReferenceBuilderService referenceBuilder = Objects.requireNonNull(editor.getAdapter(ReferenceBuilderService.class), "Unable to retrieve reference builder service");
final DiagramService diagramService = Objects.requireNonNull(editor.getAdapter(DiagramService.class), "Unable to retrieve diagram service");
final AadlModificationService aadlModService = Objects.requireNonNull(editor.getAdapter(AadlModificationService.class), "Unable to retrieve AADL modification service");
final ProjectProvider projectProvider = Objects.requireNonNull(editor.getAdapter(ProjectProvider.class), "Unable to retrieve project provider");
final ActionExecutor actionExecutor = editor.getActionExecutor();
final ModelChangeNotifier modelChangeNotifier = Objects.requireNonNull(editor.getAdapter(ModelChangeNotifier.class), "Unable to retrieve model change notifier");
final EObject bo = (EObject) de.getBusinessObject();
final BusinessObjectHandler handler = de.getBusinessObjectHandler();
final String initialValue = getCurrentName(de);
// If the business object handler provides a Rename method, then use it to rename the element instead of using LTK refactoring.
if (RenameUtil.supportsNonLtkRename(handler)) {
final CanonicalBusinessObjectReference canonicalRef = referenceBuilder.getCanonicalReference(bo);
final IProject project = ProjectUtil.getProjectOrNull(EcoreUtil.getURI(bo));
final ReferenceCollection references;
if (canonicalRef == null || project == null) {
references = null;
} else {
final Set<IProject> relevantProjects = ProjectUtil.getAffectedProjects(project, new HashSet<>());
references = diagramService.getReferences(relevantProjects, Collections.singleton(canonicalRef));
}
aadlModService.modify(bo, (boToModify) -> {
RenameUtil.performNonLtkRename(boToModify, handler, value);
// Update diagram references. This is done in the modify block because the project is build and the diagram is updated before the modify()
// function returns.
final CanonicalBusinessObjectReference newCanonicalRef = referenceBuilder.getCanonicalReference(boToModify);
final RelativeBusinessObjectReference newRelRef = referenceBuilder.getRelativeReference(boToModify);
if (newCanonicalRef != null && newRelRef != null) {
references.update(new UpdatedReferenceValueProvider() {
@Override
public CanonicalBusinessObjectReference getNewCanonicalReference(final CanonicalBusinessObjectReference originalCanonicalReference) {
if (originalCanonicalReference.equals(canonicalRef)) {
return newCanonicalRef;
}
return null;
}
@Override
public RelativeBusinessObjectReference getNewRelativeReference(final CanonicalBusinessObjectReference originalCanonicalReference) {
if (originalCanonicalReference.equals(canonicalRef)) {
return newRelRef;
}
return null;
}
});
}
});
} else {
// Rename using LTK
actionExecutor.execute("Rename Element " + initialValue + " to " + value, ActionExecutor.ExecutionMode.NORMAL, new LtkRenameAction(projectProvider, modelChangeNotifier, new BoSupplier(de), value, initialValue));
}
}
Aggregations