|
|
@@ -14,15 +14,22 @@ import java.util.Collection;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import org.eclipse.core.resources.IFile;
|
|
|
import org.eclipse.debug.core.model.DebugElement;
|
|
|
import org.eclipse.debug.ui.sourcelookup.ISourceDisplay;
|
|
|
import org.eclipse.emf.ecore.EObject;
|
|
|
import org.eclipse.emf.ecore.resource.Resource;
|
|
|
+import org.eclipse.emf.ecore.resource.URIConverter;
|
|
|
import org.eclipse.emf.ecore.util.EcoreUtil;
|
|
|
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
|
|
|
import org.eclipse.gmf.runtime.notation.Diagram;
|
|
|
import org.eclipse.gmf.runtime.notation.NotationPackage;
|
|
|
+import org.eclipse.ui.IEditorDescriptor;
|
|
|
import org.eclipse.ui.IEditorPart;
|
|
|
import org.eclipse.ui.IWorkbenchPage;
|
|
|
+import org.eclipse.ui.PartInitException;
|
|
|
+import org.eclipse.ui.PlatformUI;
|
|
|
+import org.eclipse.ui.part.FileEditorInput;
|
|
|
import org.yakindu.sct.simulation.core.engine.ISimulationEngine;
|
|
|
import org.yakindu.sct.ui.editor.partitioning.DiagramPartitioningUtil;
|
|
|
|
|
|
@@ -73,17 +80,35 @@ public class SCTSourceDisplay implements ISourceDisplay {
|
|
|
|
|
|
private IEditorPart openEditor(DebugElement debugElement, IWorkbenchPage page) {
|
|
|
EObject semanticObject = (EObject) debugElement.getAdapter(EObject.class);
|
|
|
+
|
|
|
Diagram diagram = DiagramPartitioningUtil.getDiagramContaining(semanticObject);
|
|
|
- Resource sharedDomainResource = DiagramPartitioningUtil.getSharedDomain().getResourceSet()
|
|
|
- .getResource(semanticObject.eResource().getURI(), true);
|
|
|
- Collection<Diagram> contents = EcoreUtil.getObjectsByType(sharedDomainResource.getContents(),
|
|
|
- NotationPackage.Literals.DIAGRAM);
|
|
|
- for (Diagram diag : contents) {
|
|
|
- if (EcoreUtil.equals(diag.getElement(), diagram.getElement())) {
|
|
|
- return DiagramPartitioningUtil.openEditor((Diagram) diag);
|
|
|
+ if (diagram != null) {
|
|
|
+ if (URIConverter.INSTANCE.exists(semanticObject.eResource().getURI(), null)) {
|
|
|
+ Resource sharedDomainResource = DiagramPartitioningUtil.getSharedDomain().getResourceSet()
|
|
|
+ .getResource(semanticObject.eResource().getURI(), true);
|
|
|
+
|
|
|
+ Collection<Diagram> contents = EcoreUtil.getObjectsByType(sharedDomainResource.getContents(),
|
|
|
+ NotationPackage.Literals.DIAGRAM);
|
|
|
+ for (Diagram diag : contents) {
|
|
|
+ if (EcoreUtil.equals(diag.getElement(), diagram.getElement())) {
|
|
|
+ return DiagramPartitioningUtil.openEditor((Diagram) diag);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // No diagram for the semantic element -> open the default editor
|
|
|
+ // for the file
|
|
|
+ } else {
|
|
|
+ IFile file = (IFile) debugElement.getAdapter(IFile.class);
|
|
|
+ if (file == null)
|
|
|
+ file = WorkspaceSynchronizer.getFile(semanticObject.eResource());
|
|
|
+ IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
|
|
|
+ try {
|
|
|
+ return page.openEditor(new FileEditorInput(file), desc.getId());
|
|
|
+ } catch (PartInitException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- throw new RuntimeException("No Diagram found for semantic object " + semanticObject);
|
|
|
+ throw new RuntimeException("No editor found for semantic element " + semanticObject);
|
|
|
}
|
|
|
|
|
|
}
|