use of org.osate.ge.internal.ui.editor.actions.PasteAction in project osate2 by osate.
the class AgeEditor method init.
@Override
public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
setInput(input);
setSite(site);
// Register a resource change listener to handle moving and deleting the resource.
ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener);
site.getWorkbenchWindow().getSelectionService().addPostSelectionListener(toolPostSelectionListener);
site.setSelectionProvider(selectionProvider);
// Activate Context
final IContextService contextService = site.getService(IContextService.class);
if (contextService != null) {
contextService.activateContext(CONTEXT_ID);
}
// Register actions for retargatable actions
new UndoRedoActionGroup(site, DefaultActionService.CONTEXT, true).fillActionBars(site.getActionBars());
registerAction(new CopyAction());
registerAction(new PasteAction(this));
registerAction(new SelectAllAction(this));
// Load the diagram
final org.osate.ge.diagram.Diagram mmDiagram = DiagramSerialization.readMetaModelDiagram(URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true));
diagram = DiagramSerialization.createAgeDiagram(project, mmDiagram, extRegistry);
// Display warning if the diagram is stored with a newer version of the diagram file format.
if (mmDiagram.getFormatVersion() > DiagramSerialization.FORMAT_VERSION) {
MessageDialog.openWarning(Display.getCurrent().getActiveShell(), "Diagram Created with Newer Version of OSATE", "The diagram '" + diagramFile.getName() + "' was created with a newer version of the OSATE. The diagram may not be correctly displayed. Saving the diagram with this version of OSATE may result in the loss of diagram information.");
}
// Ensure the project is built. This prevents being unable to find the context due to the Xtext index not having completed.
try {
project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor());
} catch (CoreException e) {
throw new AgeGefRuntimeException(e);
}
// Update the diagram to finish initializing the diagram's fields
actionService.execute("Update on Load", ExecutionMode.HIDE, () -> {
diagram.modify("Update Diagram", m -> {
// Check the diagram's context
final DiagramContextChecker contextChecker = new DiagramContextChecker(project, projectReferenceService, systemInstanceLoader);
final boolean workbenchIsVisible = isWorkbenchVisible();
final DiagramContextChecker.Result result = contextChecker.checkContextFullBuild(diagram, workbenchIsVisible);
if (!result.isContextValid()) {
// we only prompts to relink if the workbench is visible.
if (!workbenchIsVisible) {
closeEditor();
}
final String refContextLabel = projectReferenceService.getLabel(diagram.getConfiguration().getContextBoReference());
throw new AgeGefRuntimeException("Unable to resolve context: " + refContextLabel);
}
diagramUpdater.updateDiagram(diagram);
});
return null;
});
this.modelChangeNotifier.addChangeListener(modelChangeListener);
// Set the initial selection to the diagram
selectionProvider.setSelection(new StructuredSelection(diagram));
site.getWorkbenchWindow().getPartService().addPartListener(partListener);
diagram.addModificationListener(diagramModificationListener);
}
Aggregations