use of org.osate.ge.services.ReferenceBuilderService in project osate2 by osate.
the class CopyDiagramElementsHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
// Get clipboard. The clipboard service stores the clipboard weakly but this handler does not need to
// because the paste action stores a strong reference to the clipboard. This isn't stored in a field by
// the constructor because the handler is not instantiated for each editor.
final Bundle bundle = FrameworkUtil.getBundle(getClass());
final IEclipseContext context = EclipseContextFactory.getServiceContext(bundle.getBundleContext());
final Clipboard clipboard = Objects.requireNonNull(context.get(ClipboardService.class), "Unable to get clipboard service").getClipboard();
final ReferenceBuilderService refBuilder = Objects.requireNonNull(context.get(ReferenceBuilderService.class), "Unable to get reference builder service");
final List<CopiedDiagramElement> copiedElements = new ArrayList<>();
for (final DiagramElement de : AgeHandlerUtil.getSelectedDiagramElements()) {
final DiagramElement copiedElement = CopyAndPasteUtil.copyDiagramElement(de, null, de.getRelativeReference(), refBuilder);
final Point position = CopyAndPasteUtil.getPositionToCopy(de);
copiedElements.add(new CopiedDiagramElement(copiedElement, de.getBusinessObject(), position));
}
clipboard.setContents(new CopiedDiagramElements(ImmutableList.copyOf(copiedElements)));
return null;
}
use of org.osate.ge.services.ReferenceBuilderService in project osate2 by osate.
the class ShowContentsUtil method addContentsToSelectedElements.
/**
* Adds contents to the selected diagram elements. Adds all children which pass the specified filter.
* @param event is the ExecutionEvent of the handler which provides the active editor.
* @param filters determines the filters to apply to the selected elements.
*/
public static void addContentsToSelectedElements(final ExecutionEvent event, final Function<DiagramElement, ImmutableSet<ContentFilter>> filters) {
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (!(activeEditor instanceof InternalDiagramEditor)) {
throw new RuntimeException("Unexpected editor: " + activeEditor);
}
final InternalDiagramEditor diagramEditor = (InternalDiagramEditor) activeEditor;
final ExtensionRegistryService extService = Objects.requireNonNull(Adapters.adapt(diagramEditor, ExtensionRegistryService.class), "Unable to retrieve extension service");
final List<DiagramElement> selectedDiagramElements = AgeHandlerUtil.getSelectedDiagramElements();
final AgeDiagram diagram = diagramEditor.getDiagram();
if (diagram == null) {
throw new RuntimeException("Unable to retrieve diagram");
}
final DiagramUpdater diagramUpdater = Objects.requireNonNull(diagramEditor.getDiagramUpdater(), "Unable to retrieve diagram updater");
final ReferenceBuilderService referenceBuilder = Objects.requireNonNull(Adapters.adapt(diagramEditor, ReferenceBuilderService.class), "Unable to retrieve reference builder service");
if (addChildrenDuringNextUpdate(selectedDiagramElements, diagramUpdater, extService, referenceBuilder, filters)) {
diagramEditor.getActionExecutor().execute("Show Contents", ExecutionMode.NORMAL, () -> {
diagramEditor.updateDiagram();
return null;
});
}
}
use of org.osate.ge.services.ReferenceBuilderService 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