wip
diff --git a/plugins/org.eclipse.qvtd.sirius/.classpath b/plugins/org.eclipse.qvtd.sirius/.classpath
index 9f35ee9..5de7989 100644
--- a/plugins/org.eclipse.qvtd.sirius/.classpath
+++ b/plugins/org.eclipse.qvtd.sirius/.classpath
@@ -1,15 +1,15 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
- <attributes>
- <attribute name="annotationpath" value="/org.eclipse.qvtd.pivot.qvtbase/annotations"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
- <attributes>
- <attribute name="annotationpath" value="/org.eclipse.qvtd.pivot.qvtbase/annotations"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
+ <attributes>
+ <attribute name="annotationpath" value="/org.eclipse.qvtd.pivot.qvtbase/annotations"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
+ <attributes>
+ <attribute name="annotationpath" value="/org.eclipse.qvtd.pivot.qvtbase/annotations"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.qvtd.sirius/.project b/plugins/org.eclipse.qvtd.sirius/.project
index 69d2f4d..48f616e 100644
--- a/plugins/org.eclipse.qvtd.sirius/.project
+++ b/plugins/org.eclipse.qvtd.sirius/.project
@@ -1,28 +1,28 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.qvtd.sirius</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.pde.PluginNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.qvtd.sirius</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.qvtd.sirius/build.properties b/plugins/org.eclipse.qvtd.sirius/build.properties
index 10c88ed..18b5c3b 100644
--- a/plugins/org.eclipse.qvtd.sirius/build.properties
+++ b/plugins/org.eclipse.qvtd.sirius/build.properties
@@ -1,10 +1,10 @@
-source.. = src/
-output.. = bin/
-bin.includes = META-INF/,\
- .,\
- about.html,\
- plugin.xml,\
- build.properties,\
- plugin.properties,\
- icons/
-src.includes = about.html
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html,\
+ plugin.xml,\
+ build.properties,\
+ plugin.properties,\
+ icons/
+src.includes = about.html
diff --git a/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/InitializeDiagramDialog.java b/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/InitializeDiagramDialog.java
index 4e9b67a..b825acf 100644
--- a/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/InitializeDiagramDialog.java
+++ b/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/InitializeDiagramDialog.java
@@ -1254,11 +1254,6 @@
return new Point(800, 800);
}
- public @NonNull URI getMasterSessionURI() {
- // assert getShell() == null;
- return modelURI.trimSegments(1).appendSegment(ModelingProject.DEFAULT_REPRESENTATIONS_FILE_NAME);
- }
-
public RepresentationDescription getRegistryRepresentationDescription() {
;; assert getShell() == null;
return selectedRepresentationDescription;
@@ -1269,6 +1264,11 @@
return representationDiagramName;
}
+ public @NonNull URI getRepresentationFileURI() {
+ assert representationFileURI != null;
+ return representationFileURI;
+ }
+
protected @NonNull String getSafeLabel(@NonNull RepresentationDescription representationDescription) {
String label = representationDescription.getLabel();
return label != null ? label : "";
@@ -1304,9 +1304,9 @@
}
}
- public @NonNull URI getSlaveSessionURI() {
- assert representationFileURI != null;
- return representationFileURI;
+ public @NonNull URI getSessionURI() {
+ // assert getShell() == null;
+ return modelURI.trimSegments(1).appendSegment(ModelingProject.DEFAULT_REPRESENTATIONS_FILE_NAME);
}
protected Color getWhiteBackground() {
@@ -1470,7 +1470,7 @@
protected @Nullable String refreshDiagramNames() {
if (oldDiagramNames == null) {
- URI uri = getSlaveSessionURI();
+ URI uri = getRepresentationFileURI();
AIRDReader airdReader = new AIRDReader();
if (URIConverter.INSTANCE.exists(uri, null)) {
try {
diff --git a/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/InitializeDiagramHandler.java b/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/InitializeDiagramHandler.java
index 4671b8a..b7c8fac 100644
--- a/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/InitializeDiagramHandler.java
+++ b/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/InitializeDiagramHandler.java
@@ -83,11 +83,11 @@
if ((status == Status.OK) && (initializeDiagramDialog.getShell() == null)) { // !null for forced Eclipse exit
// Convert selection-space elements to URIs for reloading in the Sirius-space.
List<@NonNull URI> selectedElements = initializeDiagramDialog.getSelectedCheckedElements();
- URI masterSessionURI = initializeDiagramDialog.getMasterSessionURI();
+ URI sessionURI = initializeDiagramDialog.getSessionURI();
String representationDiagramName = initializeDiagramDialog.getRepresentationDiagramName();
- URI slaveSessionURI = initializeDiagramDialog.getSlaveSessionURI();
+ URI representationFileURI = initializeDiagramDialog.getRepresentationFileURI();
RepresentationDescription registryRepresentationDescription = initializeDiagramDialog.getRegistryRepresentationDescription();
- InitializeDiagramJob.scheduleNewWhenPossible(masterSessionURI, registryRepresentationDescription, slaveSessionURI, representationDiagramName, selectedElements);
+ InitializeDiagramJob.scheduleNewWhenPossible(sessionURI, registryRepresentationDescription, representationFileURI, representationDiagramName, selectedElements);
}
return null;
}
diff --git a/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/InitializeDiagramJob.java b/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/InitializeDiagramJob.java
index 8f6f41e..729bfd8 100644
--- a/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/InitializeDiagramJob.java
+++ b/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/InitializeDiagramJob.java
@@ -10,10 +10,8 @@
*******************************************************************************/
package org.eclipse.qvtd.sirius;
-import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -36,14 +34,13 @@
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.sirius.business.api.dialect.command.MoveRepresentationCommand;
import org.eclipse.sirius.business.api.helper.SiriusResourceHelper;
import org.eclipse.sirius.business.api.resource.ResourceDescriptor;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.business.api.session.SessionManager;
-import org.eclipse.sirius.business.api.session.danalysis.DAnalysisSelector;
import org.eclipse.sirius.business.api.session.danalysis.DAnalysisSession;
import org.eclipse.sirius.business.internal.session.SessionTransientAttachment;
-import org.eclipse.sirius.business.internal.session.danalysis.DAnalysisSessionServicesImpl;
import org.eclipse.sirius.diagram.business.api.query.EObjectQuery;
import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager;
import org.eclipse.sirius.ui.business.api.session.EditingSessionEvent;
@@ -54,6 +51,8 @@
import org.eclipse.sirius.ui.tools.internal.views.common.modelingproject.OpenRepresentationsFileJob;
import org.eclipse.sirius.viewpoint.DAnalysis;
import org.eclipse.sirius.viewpoint.DRepresentation;
+import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
+import org.eclipse.sirius.viewpoint.DView;
import org.eclipse.sirius.viewpoint.ViewpointFactory;
import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
import org.eclipse.sirius.viewpoint.description.Viewpoint;
@@ -135,14 +134,16 @@
return op.resource;
}
- public static @Nullable DAnalysis prepare(@NonNull IProgressMonitor monitor, @NonNull DAnalysisSession masterSession, @NonNull DAnalysisSession slaveSession, @NonNull URI representationFileURI) {
- TransactionalEditingDomain transactionalEditingDomain = masterSession.getTransactionalEditingDomain(); // XXX masterSession
+ public static @Nullable DAnalysis prepare(@NonNull IProgressMonitor monitor, @NonNull DAnalysisSession session, @NonNull URI representationFileURI) {
+ TransactionalEditingDomain transactionalEditingDomain = session.getTransactionalEditingDomain();
ResourceSet resourceSet = transactionalEditingDomain.getResourceSet();
assert resourceSet != null;
Resource resource;
DAnalysis dAnalysis = null;
+ boolean needsSave = false;
if (!resourceSet.getURIConverter().exists(representationFileURI, null)) {
resource = createResource(monitor, resourceSet, representationFileURI);
+ needsSave = true;
}
else {
resource = resourceSet.getResource(representationFileURI, true);
@@ -155,18 +156,21 @@
}
assert resource != null;
if (dAnalysis == null) {
- dAnalysis = createDAnalysis(slaveSession, resource);
+ dAnalysis = createDAnalysis(session, resource); // ?? later
+ needsSave = true;
}
assert resource.getContents().contains(dAnalysis);
- try {
- resource.save(null);
- } catch (IOException e) {
- String message = "Failed to save " + representationFileURI;
- InitializeDiagramUtils.openError(message, null, e);
- return null;
- }
+ /* if (needsSave) {
+ try {
+ resource.save(null); // XXX if needsSAve
+ } catch (IOException e) {
+ String message = "Failed to save " + representationFileURI;
+ InitializeDiagramUtils.openError(message, null, e);
+ return null;
+ }
+ } */
final DAnalysis finalDAnalysis = dAnalysis;
- ((DAnalysisSessionServicesImpl)slaveSession.getServices()).setAnalysisSelector(new DAnalysisSelector() {
+ /* ((DAnalysisSessionServicesImpl)session.getServices()).setAnalysisSelector(new DAnalysisSelector() {
@Override
public DAnalysis selectSmartlyAnalysisForAddedResource(Resource resource, Collection<DAnalysis> allAnalysis) {
@@ -177,7 +181,7 @@
public DAnalysis selectSmartlyAnalysisForAddedRepresentation(DRepresentation representation, Collection<DAnalysis> allAnalysis) {
return finalDAnalysis;//allAnalysis.iterator().next();
}
- });
+ }); */
return finalDAnalysis;
}
@@ -200,13 +204,13 @@
protected static class DiagramCreateOperation extends WorkspaceModifyOperation // ?? implements Runnable
{
- protected static void create(@NonNull DAnalysisSession masterSession, @NonNull DAnalysisSession slaveSession, @NonNull RepresentationDescription registryRepresentationDescription, @NonNull URI representationFileURI, @NonNull String representationDiagramName, @NonNull List<@NonNull EObject> modelObjects) {
+ protected static void create(@NonNull DAnalysisSession session, @NonNull RepresentationDescription registryRepresentationDescription, @NonNull URI representationFileURI, @NonNull String representationDiagramName, @NonNull List<@NonNull EObject> modelObjects) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable()
{
@Override
public void run() { // run on main
try {
- WorkspaceModifyOperation op = new DiagramCreateOperation(masterSession, slaveSession, registryRepresentationDescription, representationFileURI, representationDiagramName, modelObjects);
+ WorkspaceModifyOperation op = new DiagramCreateOperation(session, registryRepresentationDescription, representationFileURI, representationDiagramName, modelObjects);
new ProgressMonitorDialog(null).run(true, true, op);
} catch (InvocationTargetException | InterruptedException e) {
SiriusEditPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, e.getLocalizedMessage(), e));
@@ -215,16 +219,14 @@
});
}
- protected final @NonNull DAnalysisSession masterSession;
- protected final @NonNull DAnalysisSession slaveSession;
+ protected final @NonNull DAnalysisSession session;
protected final @NonNull RepresentationDescription registryRepresentationDescription;
protected final @NonNull URI representationFileURI;
protected final @NonNull List<@NonNull EObject> modelObjects;
protected final @NonNull String representationDiagramName;
- protected DiagramCreateOperation(@NonNull DAnalysisSession masterSession, @NonNull DAnalysisSession slaveSession, @NonNull RepresentationDescription registryRepresentationDescription, @NonNull URI representationFileURI, @NonNull String representationDiagramName, @NonNull List<@NonNull EObject> modelObjects) { // ctor on main
- this.masterSession = masterSession;
- this.slaveSession = slaveSession;
+ protected DiagramCreateOperation(@NonNull DAnalysisSession session, @NonNull RepresentationDescription registryRepresentationDescription, @NonNull URI representationFileURI, @NonNull String representationDiagramName, @NonNull List<@NonNull EObject> modelObjects) { // ctor on main
+ this.session = session;
this.registryRepresentationDescription = registryRepresentationDescription;
this.representationFileURI = representationFileURI;
this.representationDiagramName = representationDiagramName;
@@ -232,21 +234,21 @@
assert modelObjects.size() >= 1;
}
- protected @Nullable DRepresentation createRepresentation(@NonNull IProgressMonitor monitor, @NonNull DAnalysis zdAnalysis, @NonNull RepresentationDescription editingDomainRepresentationDescription) {
- TransactionalEditingDomain transactionalEditingDomain = masterSession.getTransactionalEditingDomain();
+ protected @Nullable DRepresentation createRepresentation(@NonNull IProgressMonitor monitor, @NonNull RepresentationDescription editingDomainRepresentationDescription) {
+ TransactionalEditingDomain transactionalEditingDomain = session.getTransactionalEditingDomain();
EObject modelObject = modelObjects.get(0);
CommandStack commandStack = transactionalEditingDomain.getCommandStack();
assert commandStack != null;
ResourceSet resourceSet = transactionalEditingDomain.getResourceSet();
assert resourceSet != null;
- IEditingSession editingSession = SessionUIManager.INSTANCE.getUISession(masterSession);
- MyCreateRepresentationCommand createRepresentationCommand = new MyCreateRepresentationCommand(masterSession, zdAnalysis, editingDomainRepresentationDescription, modelObject, representationDiagramName,
+ IEditingSession editingSession = SessionUIManager.INSTANCE.getUISession(session);
+ MyCreateRepresentationCommand createRepresentationCommand = new MyCreateRepresentationCommand(session, editingDomainRepresentationDescription, modelObject, representationDiagramName,
new SubProgressMonitor(monitor, 4));
// DAnalysis dAnalysis = getDAnalysis(resourceSet);
Session semanticSession = new EObjectQuery(modelObject).getSession();
if (semanticSession == null) { // If not (yet) known to representations.aird
- modelObject.eResource().eAdapters().add(new SessionTransientAttachment(slaveSession));
+ modelObject.eResource().eAdapters().add(new SessionTransientAttachment(session));
semanticSession = new EObjectQuery(modelObject).getSession();
assert semanticSession != null;
}
@@ -262,7 +264,7 @@
}
protected void editDiagram(@NonNull DRepresentation createdDRepresentation) throws InvocationTargetException, InterruptedException {
- IRunnableWithProgress runnable = new DiagramEditRunnable(slaveSession, createdDRepresentation);
+ IRunnableWithProgress runnable = new DiagramEditRunnable(session, createdDRepresentation);
IRunnableContext context = new ProgressMonitorDialog(null);
PlatformUI.getWorkbench().getProgressService().runInUI(context, runnable, null);
}
@@ -274,21 +276,16 @@
monitor.beginTask(org.eclipse.sirius.viewpoint.provider.Messages.CreateRepresentationAction_creationTask, 15);
EObject modelObject = modelObjects.get(0);
- if (!slaveSession.getSemanticResources().contains(modelObject.eResource())) {
- slaveSession.close(monitor);
- slaveSession.getSemanticResources();
- }
-
- DAnalysis dAnalysis = DAnalysisPreparationOperation.prepare(monitor, masterSession, slaveSession, representationFileURI);
- if (dAnalysis == null) {
- return;
+ if (!session.getSemanticResources().contains(modelObject.eResource())) {
+ session.close(monitor);
+ session.getSemanticResources();
}
Viewpoint registryViewpoint = selectViewpoint(monitor);
// XXX wrap above in a ProgressMonitorDialog cf ViewpointHelper.applyNewViewpointSelection
- Viewpoint editingDomainViewpoint = SiriusResourceHelper.getCorrespondingViewpoint(masterSession, registryViewpoint); // XXX error dialog
+ Viewpoint editingDomainViewpoint = SiriusResourceHelper.getCorrespondingViewpoint(session, registryViewpoint); // XXX error dialog
if (editingDomainViewpoint == null) {
InitializeDiagramUtils.openError(mainMessage, "Failed to localize \"" + registryViewpoint.getLabel() + "\" Viewpoint", null);
return;
@@ -301,9 +298,24 @@
}
// new ViewpointSelector(session).selectViewpoint(registryViewpoint, createNewRepresentations, monitor);
- DRepresentation createdDRepresentation = createRepresentation(monitor, dAnalysis, editingDomainRepresentationDescription);
+ DRepresentation createdDRepresentation = createRepresentation(monitor, editingDomainRepresentationDescription);
+ if (representationFileURI != session.getSessionResource().getURI()) {
+ List<DRepresentationDescriptor> repDescriptors = new ArrayList<>();;
+ DAnalysis dAnalysis = session.getSharedMainDAnalysis().get();
+ for (DView dView : dAnalysis.getOwnedViews()) {
+ for (DRepresentationDescriptor dRepresentationDescriptor : dView.getOwnedRepresentationDescriptors()) {
+ if (dRepresentationDescriptor.getRepresentation() == createdDRepresentation) {
+ repDescriptors.add(dRepresentationDescriptor);
+ }
+ }
+ }
+ DAnalysis slaveAnalysis = DAnalysisPreparationOperation.prepare(monitor, session, representationFileURI);
+ if (slaveAnalysis == null) {
+ return;
+ }
+ moveRepresentations(slaveAnalysis, repDescriptors);
+ }
- // XXX move reprfesentation
monitor.worked(1);
if (createdDRepresentation != null) {
editDiagram(createdDRepresentation);
@@ -324,8 +336,25 @@
return null;
}
+ protected void moveRepresentations(final DAnalysis slaveAnalysis, List<DRepresentationDescriptor> repDescriptors) { // from org.eclipse.sirius.ui.tools.internal.wizards.ExtractRepresentationsWizard
+ // final IRunnableWithProgress moveReps = new IRunnableWithProgress() {
+ // @Override
+ // public void run(final IProgressMonitor mon) {
+ // session.getTransactionalEditingDomain().getCommandStack().execute(new MoveRepresentationCommand(session, slaveAnalysis, repDescriptors));
+ // }
+ // };
+ // try {
+ // new ProgressMonitorDialog(null).run(false, true, moveReps);
+ session.getTransactionalEditingDomain().getCommandStack().execute(new MoveRepresentationCommand(session, slaveAnalysis, repDescriptors));
+ // } catch (final InterruptedException e) {
+ // SiriusPlugin.getDefault().warning(Messages.ExtractRepresentationsWizard_moveInterrupted, e);
+ // } catch (final InvocationTargetException e) {
+ // SiriusPlugin.getDefault().error(Messages.ExtractRepresentationsWizard_moveFailed, e);
+ // }
+ }
+
protected @NonNull Viewpoint selectViewpoint(@NonNull IProgressMonitor monitor) {
- TransactionalEditingDomain transactionalEditingDomain = masterSession.getTransactionalEditingDomain();
+ TransactionalEditingDomain transactionalEditingDomain = session.getTransactionalEditingDomain();
CommandStack commandStack = transactionalEditingDomain.getCommandStack();
assert commandStack != null;
Viewpoint registryViewpoint = (Viewpoint)registryRepresentationDescription.eContainer();
@@ -333,7 +362,7 @@
ViewpointSelectionCallback callback = new ViewpointSelectionCallback();
Set<Viewpoint> registryViewpoints = Collections.singleton(registryViewpoint);
boolean createNewRepresentations = true;
- ChangeViewpointSelectionCommand changeViewpointSelectionCommand = new ChangeViewpointSelectionCommand(masterSession, callback, registryViewpoints, Collections.EMPTY_SET, createNewRepresentations,
+ ChangeViewpointSelectionCommand changeViewpointSelectionCommand = new ChangeViewpointSelectionCommand(session, callback, registryViewpoints, Collections.EMPTY_SET, createNewRepresentations,
new SubProgressMonitor(monitor, 4));
commandStack.execute(changeViewpointSelectionCommand); // XXX canCreate should use selected elements
return registryViewpoint;
@@ -364,8 +393,8 @@
/**
* Launch this derived OpenRepresentationsFileJob job when all other OpenRepresentationsFileJob job are finished.
*/
- public static void scheduleNewWhenPossible(@NonNull URI masterSessionURI, @NonNull RepresentationDescription representationDescription, @NonNull URI representationFileURI, @NonNull String representationDiagramName, @NonNull List<@NonNull URI> modelObjectURIs) {
- Job job = new InitializeDiagramJob(masterSessionURI, representationDescription, representationFileURI, representationDiagramName, modelObjectURIs);
+ public static void scheduleNewWhenPossible(@NonNull URI sessionURI, @NonNull RepresentationDescription representationDescription, @NonNull URI representationFileURI, @NonNull String representationDiagramName, @NonNull List<@NonNull URI> modelObjectURIs) {
+ Job job = new InitializeDiagramJob(sessionURI, representationDescription, representationFileURI, representationDiagramName, modelObjectURIs);
job.setUser(true);
job.setPriority(Job.SHORT);
job.schedule();
@@ -375,14 +404,13 @@
}
}
- protected final @NonNull URI masterSessionURI;
+ protected final @NonNull URI sessionURI;
protected final @NonNull RepresentationDescription registryRepresentationDescription;
- protected final @NonNull URI slaveSessionURI; // Null for shared into ModelingProject.DEFAULT_REPRESENTATIONS_FILE_NAME
+ protected final @NonNull URI representationFileURI;
protected final @NonNull String representationDiagramName;
protected final @NonNull List<@NonNull URI> modelObjectURIs;
- private Session masterSession;
- private Session slaveSession;
+ private Session session;
/**
* Constructor to open only one representations file.
@@ -394,11 +422,11 @@
* <code>true</code> if this session opening comes from a direct user action, </code>false<code>
* otherwise
*/
- private InitializeDiagramJob(@NonNull URI masterSessionURI, @NonNull RepresentationDescription registryRepresentationDescription, @NonNull URI slaveSessionURI, @NonNull String representationDiagramName, @NonNull List<@NonNull URI> modelObjectURIs) {
- super(slaveSessionURI, true);
- this.masterSessionURI = masterSessionURI;
+ private InitializeDiagramJob(@NonNull URI sessionURI, @NonNull RepresentationDescription registryRepresentationDescription, @NonNull URI representationFileURI, @NonNull String representationDiagramName, @NonNull List<@NonNull URI> modelObjectURIs) {
+ super(sessionURI, true);
+ this.sessionURI = sessionURI;
this.registryRepresentationDescription = registryRepresentationDescription;
- this.slaveSessionURI = slaveSessionURI;
+ this.representationFileURI = representationFileURI;
this.representationDiagramName = representationDiagramName;
this.modelObjectURIs = modelObjectURIs;
assert modelObjectURIs.size() >= 1;
@@ -416,36 +444,20 @@
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) {
- this.masterSession = SessionManager.INSTANCE.getExistingSession(masterSessionURI);
- if (masterSession == null) {
- IStatus status;
- if (masterSessionURI != slaveSessionURI) {
- status = new OpenRepresentationsFileJob(masterSessionURI).runInWorkspace(monitor);
- }
- else {
- status = super.runInWorkspace(monitor);
- }
- if (!status.isOK()) {
- return status;
- }
- masterSession = SessionManager.INSTANCE.getExistingSession(masterSessionURI);
- }
- DAnalysisSession masterSession2 = (DAnalysisSession)masterSession;
- assert masterSession2 != null;
- this.slaveSession = SessionManager.INSTANCE.getExistingSession(slaveSessionURI);
- if (slaveSession == null) {
+ this.session = SessionManager.INSTANCE.getExistingSession(sessionURI);
+ if (session == null) {
IStatus status = super.runInWorkspace(monitor);
if (!status.isOK()) {
return status;
}
- slaveSession = SessionManager.INSTANCE.getExistingSession(slaveSessionURI);
+ session = SessionManager.INSTANCE.getExistingSession(sessionURI);
}
- DAnalysisSession slaveSession2 = (DAnalysisSession)slaveSession;
- assert slaveSession2 != null;
- ResourceSet resourceSet = masterSession2.getTransactionalEditingDomain().getResourceSet();
+ DAnalysisSession session2 = (DAnalysisSession)session;
+ assert session2 != null;
+ ResourceSet resourceSet = session2.getTransactionalEditingDomain().getResourceSet();
assert resourceSet != null;
List<@NonNull EObject> modelObjects = getModelObjects(resourceSet);
- DiagramCreateOperation.create(masterSession2, slaveSession2, registryRepresentationDescription, slaveSessionURI, representationDiagramName, modelObjects);
+ DiagramCreateOperation.create(session2, registryRepresentationDescription, representationFileURI, representationDiagramName, modelObjects);
return Status.OK_STATUS;
}
}
diff --git a/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/MyCreateRepresentationCommand.java b/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/MyCreateRepresentationCommand.java
index 7815b89..7b9991b 100644
--- a/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/MyCreateRepresentationCommand.java
+++ b/plugins/org.eclipse.qvtd.sirius/src/org/eclipse/qvtd/sirius/MyCreateRepresentationCommand.java
@@ -1,204 +1,156 @@
-package org.eclipse.qvtd.sirius;
-
-import java.text.MessageFormat;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.sirius.business.api.dialect.DialectManager;
-import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager;
-import org.eclipse.sirius.business.api.query.DRepresentationQuery;
-import org.eclipse.sirius.business.api.session.Session;
-import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException;
-import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter;
-import org.eclipse.sirius.common.tools.api.util.StringUtil;
-import org.eclipse.sirius.tools.api.Messages;
-import org.eclipse.sirius.viewpoint.DAnalysis;
-import org.eclipse.sirius.viewpoint.DRepresentation;
-import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
-import org.eclipse.sirius.viewpoint.description.tool.RepresentationCreationDescription;
-import org.eclipse.sirius.viewpoint.description.tool.ToolPackage;
-
-/**
- * Create representation command.
- *
- * @author mchauvin
- * @since 0.9.0
- */
-public class MyCreateRepresentationCommand extends RecordingCommand {
-
- private RepresentationDescription description;
-
- private Session masterSession;
- private DAnalysis dAnalysis;
-
- private EObject semantic;
-
- private String name;
-
- private DRepresentation representation;
-
-// private boolean isInitialOperation;
-
- private RepresentationCreationDescription creationDescription;
-
- private IProgressMonitor monitor;
-
- /**
- * Construct a new instance with {@link IProgressMonitor}.
- *
- * @param session
- * the session
- * @param description
- * the representation description
- * @param eObject
- * the semantic element on which to create the representation
- * @param name
- * the representation name
- * @param monitor
- * a {@link IProgressMonitor} to report progression of representation creation
- */
- public MyCreateRepresentationCommand(Session masterSession, @NonNull DAnalysis dAnalysis, RepresentationDescription description, EObject eObject, String name, IProgressMonitor monitor) {
- super(masterSession.getTransactionalEditingDomain(), Messages.CreateRepresentationCommand_label);
- this.masterSession = masterSession;
- this.dAnalysis = dAnalysis;
- this.description = description;
- this.semantic = eObject;
- this.name = name;
- this.monitor = monitor;
-
-/* RepresentationElementMapping mapping = dde.getMapping();
- if (mapping != null) {
- EObject sessionFinder = null;
- final EList<EObject> semanticElements = dde.getSemanticElements();
- if (semanticElements != null && !semanticElements.isEmpty()) {
- sessionFinder = semanticElements.get(0);
- } else if (dde.getTarget() != null) {
- sessionFinder = dde.getTarget();
- }
- final Session session = sessionFinder != null ? SessionManager.INSTANCE.getSession(sessionFinder) : null;
- if (session != null) {
- for (RepresentationCreationDescription desc : mapping.getDetailDescriptions()) {
- */
-
- // this.creationDescription = description.getRepresentationDescription();
- }
-
- /**
- * Set if there is an initial operation or not.
- *
- * @param creationDesc
- * the creation tool
- *
- public void setInitialOperation(final RepresentationCreationDescription creationDesc) {
- this.creationDescription = creationDesc;
- isInitialOperation = creationDesc.getInitialOperation() != null && creationDesc.getInitialOperation().getFirstModelOperations() != null;
- } */
-
- public @Nullable DRepresentation basicGetCreatedRepresentation() {
- return representation;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.common.command.AbstractCommand#canExecute()
- */
- @Override
- public boolean canExecute() {
- /*
- * if there is an initial operation an semantic element could be added and used after on precondition
- *
- if (isInitialOperation) {
- return super.canExecute();
- } */
- final EObject root = computeRepresentationRoot(masterSession.getInterpreter(), creationDescription, semantic);
- return DialectManager.INSTANCE.canCreate(root, description);
- }
-
- private void clearData() {
- this.representation = null;
- this.masterSession = null;
- this.dAnalysis = null;
- this.description = null;
- this.semantic = null;
- this.name = null;
- this.creationDescription = null;
- this.label = null;
- this.monitor = null;
- }
-
- private static EObject computeRepresentationRoot(final IInterpreter interpreter, final RepresentationCreationDescription desc, final EObject initialRoot) {
- EObject newRepresentationRoot = initialRoot;
- if (desc != null && !StringUtil.isEmpty(desc.getBrowseExpression())) {
- try {
- newRepresentationRoot = interpreter.evaluateEObject(newRepresentationRoot, desc.getBrowseExpression());
- } catch (final EvaluationException e) {
- RuntimeLoggerManager.INSTANCE.warning(newRepresentationRoot, ToolPackage.eINSTANCE.getRepresentationCreationDescription_BrowseExpression(), e);
- }
- if (newRepresentationRoot == null) {
- RuntimeLoggerManager.INSTANCE.warning(initialRoot, ToolPackage.eINSTANCE.getRepresentationCreationDescription_BrowseExpression(),
- MessageFormat.format(Messages.CreateRepresentationCommand_nullExpresionWarningMsg, desc.getBrowseExpression()));
- }
- }
- return newRepresentationRoot;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void doExecute() {
- final EObject root = computeRepresentationRoot(masterSession.getInterpreter(), creationDescription, semantic);
- representation = DialectManager.INSTANCE.createRepresentation(this.name, root, this.description, this.masterSession, monitor);
- if (representation != null) {
- new DRepresentationQuery(representation).getRepresentationDescriptor().setName(name);
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.common.command.AbstractCommand#getResult()
- */
- @Override
- public Collection<?> getResult() {
- final Set<DRepresentation> result = new HashSet<>();
- result.add(representation);
- /* do not leak */
- clearData();
- return result;
- }
-
- /**
- * Get the created representation.
- *
- * @return the created representation
- */
- public DRepresentation getCreatedRepresentation() {
- return (DRepresentation) getResult().iterator().next();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.transaction.RecordingCommand#dispose()
- */
- @Override
- public void dispose() {
- super.dispose();
- clearData();
- }
-
- @Override
- protected void postExecute() {
- assert representation != null;
- dAnalysis.eResource().getContents().add(representation);
- }
-
-}
+package org.eclipse.qvtd.sirius;
+
+import java.text.MessageFormat;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.sirius.business.api.dialect.DialectManager;
+import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager;
+import org.eclipse.sirius.business.api.query.DRepresentationQuery;
+import org.eclipse.sirius.business.api.session.Session;
+import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException;
+import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter;
+import org.eclipse.sirius.common.tools.api.util.StringUtil;
+import org.eclipse.sirius.tools.api.Messages;
+import org.eclipse.sirius.viewpoint.DRepresentation;
+import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
+import org.eclipse.sirius.viewpoint.description.tool.RepresentationCreationDescription;
+import org.eclipse.sirius.viewpoint.description.tool.ToolPackage;
+
+/**
+ * Create representation command.
+ *
+ * @author mchauvin
+ * @since 0.9.0
+ */
+public class MyCreateRepresentationCommand extends RecordingCommand {
+
+ private RepresentationDescription description;
+
+ private Session session;
+
+ private EObject semantic;
+
+ private String name;
+
+ private DRepresentation representation;
+
+// private boolean isInitialOperation;
+
+ private RepresentationCreationDescription creationDescription;
+
+ private IProgressMonitor monitor;
+
+ /**
+ * Construct a new instance with {@link IProgressMonitor}.
+ *
+ * @param session
+ * the session
+ * @param description
+ * the representation description
+ * @param eObject
+ * the semantic element on which to create the representation
+ * @param name
+ * the representation name
+ * @param monitor
+ * a {@link IProgressMonitor} to report progression of representation creation
+ */
+ public MyCreateRepresentationCommand(Session session, RepresentationDescription description, EObject eObject, String name, IProgressMonitor monitor) {
+ super(session.getTransactionalEditingDomain(), Messages.CreateRepresentationCommand_label);
+ this.session = session;
+ this.description = description;
+ this.semantic = eObject;
+ this.name = name;
+ this.monitor = monitor;
+ }
+
+ public @Nullable DRepresentation basicGetCreatedRepresentation() {
+ return representation;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.command.AbstractCommand#canExecute()
+ */
+ @Override
+ public boolean canExecute() {
+ /*
+ * if there is an initial operation an semantic element could be added and used after on precondition
+ *
+ if (isInitialOperation) {
+ return super.canExecute();
+ } */
+ final EObject root = computeRepresentationRoot(session.getInterpreter(), creationDescription, semantic);
+ return DialectManager.INSTANCE.canCreate(root, description);
+ }
+
+ private void clearData() {
+ this.representation = null;
+ this.session = null;
+ this.description = null;
+ this.semantic = null;
+ this.name = null;
+ this.creationDescription = null;
+ this.label = null;
+ this.monitor = null;
+ }
+
+ private static EObject computeRepresentationRoot(final IInterpreter interpreter, final RepresentationCreationDescription desc, final EObject initialRoot) {
+ EObject newRepresentationRoot = initialRoot;
+ if (desc != null && !StringUtil.isEmpty(desc.getBrowseExpression())) {
+ try {
+ newRepresentationRoot = interpreter.evaluateEObject(newRepresentationRoot, desc.getBrowseExpression());
+ } catch (final EvaluationException e) {
+ RuntimeLoggerManager.INSTANCE.warning(newRepresentationRoot, ToolPackage.eINSTANCE.getRepresentationCreationDescription_BrowseExpression(), e);
+ }
+ if (newRepresentationRoot == null) {
+ RuntimeLoggerManager.INSTANCE.warning(initialRoot, ToolPackage.eINSTANCE.getRepresentationCreationDescription_BrowseExpression(),
+ MessageFormat.format(Messages.CreateRepresentationCommand_nullExpresionWarningMsg, desc.getBrowseExpression()));
+ }
+ }
+ return newRepresentationRoot;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void doExecute() {
+ final EObject root = computeRepresentationRoot(session.getInterpreter(), creationDescription, semantic);
+ representation = DialectManager.INSTANCE.createRepresentation(this.name, root, this.description, this.session, monitor);
+ if (representation != null) {
+ new DRepresentationQuery(representation).getRepresentationDescriptor().setName(name);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.command.AbstractCommand#getResult()
+ */
+ @Override
+ public Collection<?> getResult() {
+ final Set<DRepresentation> result = new HashSet<>();
+ result.add(representation);
+ /* do not leak */
+ clearData();
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.transaction.RecordingCommand#dispose()
+ */
+ @Override
+ public void dispose() {
+ super.dispose();
+ clearData();
+ }
+}