Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbrun2014-06-26 14:00:46 +0000
committercbrun2014-06-26 14:00:46 +0000
commit41fdd5c4a1bd21a572ecc59a8970616a8daecc25 (patch)
tree8da1ba9e978d7ae7a7ee0b11def0f540989a17ab
parenta011e88d4f792c95f66939645f5754eb106667c3 (diff)
downloadorg.eclipse.ecoretools-41fdd5c4a1bd21a572ecc59a8970616a8daecc25.tar.gz
org.eclipse.ecoretools-41fdd5c4a1bd21a572ecc59a8970616a8daecc25.tar.xz
org.eclipse.ecoretools-41fdd5c4a1bd21a572ecc59a8970616a8daecc25.zip
[438126] If the ecore model is in a Modeling Project, reuse it.
-rw-r--r--org.eclipse.emf.ecoretools.design/src/org/eclipse/emf/ecoretools/design/action/EcoreInitDiagramFileAction.java51
1 files changed, 46 insertions, 5 deletions
diff --git a/org.eclipse.emf.ecoretools.design/src/org/eclipse/emf/ecoretools/design/action/EcoreInitDiagramFileAction.java b/org.eclipse.emf.ecoretools.design/src/org/eclipse/emf/ecoretools/design/action/EcoreInitDiagramFileAction.java
index ab48cf2..ef868ff 100644
--- a/org.eclipse.emf.ecoretools.design/src/org/eclipse/emf/ecoretools/design/action/EcoreInitDiagramFileAction.java
+++ b/org.eclipse.emf.ecoretools.design/src/org/eclipse/emf/ecoretools/design/action/EcoreInitDiagramFileAction.java
@@ -11,6 +11,7 @@
package org.eclipse.emf.ecoretools.design.action;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
@@ -22,8 +23,10 @@ import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.sirius.business.api.modelingproject.ModelingProject;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.business.api.session.SessionManager;
+import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ui.business.api.session.IEditingSession;
import org.eclipse.sirius.ui.business.api.session.SessionUIManager;
import org.eclipse.sirius.ui.business.api.viewpoint.ViewpointSelectionCallback;
@@ -41,6 +44,8 @@ public class EcoreInitDiagramFileAction implements IObjectActionDelegate {
private URI domainModelURI;
+ private IProject containingProject;
+
private IStructuredSelection selection;
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
@@ -55,11 +60,13 @@ public class EcoreInitDiagramFileAction implements IObjectActionDelegate {
return;
}
this.selection = (IStructuredSelection) selection;
- IFile file = (IFile) ((IStructuredSelection) selection)
- .getFirstElement();
- domainModelURI = URI.createPlatformResourceURI(file.getFullPath()
- .toString(), true);
- action.setEnabled(true);
+ if (this.selection.getFirstElement() instanceof IFile) {
+ IFile file = (IFile) this.selection.getFirstElement();
+ containingProject = file.getProject();
+ domainModelURI = URI.createPlatformResourceURI(file.getFullPath()
+ .toString(), true);
+ action.setEnabled(true);
+ }
}
private Shell getShell() {
@@ -68,6 +75,7 @@ public class EcoreInitDiagramFileAction implements IObjectActionDelegate {
public void run(IAction action) {
Session existingSession = null;
+
for (Session session : SessionManager.INSTANCE.getSessions()) {
ResourceSet set = session.getTransactionalEditingDomain()
.getResourceSet();
@@ -83,6 +91,39 @@ public class EcoreInitDiagramFileAction implements IObjectActionDelegate {
}
}
if (existingSession == null) {
+ /*
+ * we could not find a session already having this file in its
+ * resources. We will use the containing project if it is a modeling
+ * project but we have to add the resource as a semantic resource.
+ */
+ final Option<ModelingProject> prj = ModelingProject
+ .asModelingProject(containingProject);
+ if (prj.some()) {
+ existingSession = prj.get().getSession();
+ existingSession
+ .getTransactionalEditingDomain()
+ .getCommandStack()
+ .execute(
+ new RecordingCommand(existingSession
+ .getTransactionalEditingDomain()) {
+
+ @Override
+ protected void doExecute() {
+ prj.get()
+ .getSession()
+ .addSemanticResource(
+ domainModelURI,
+ new NullProgressMonitor());
+
+ }
+ });
+ existingSession.addSemanticResource(domainModelURI,
+ new NullProgressMonitor());
+
+ }
+ }
+
+ if (existingSession == null) {
existingSession = createSession();
}

Back to the top