Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Fasani2017-05-11 16:22:08 +0000
committerLaurent Fasani2017-07-07 15:55:36 +0000
commit07e9ce2a6fc7f5dd72959a1f1b3a6d95d3c8bcdb (patch)
tree9415ef0587277cf206590e4beb06c8f6b9f1e9d4
parent5d116f886358def2c6ed6db700bb908788e1acf9 (diff)
downloadorg.eclipse.sirius-07e9ce2a6fc7f5dd72959a1f1b3a6d95d3c8bcdb.tar.gz
org.eclipse.sirius-07e9ce2a6fc7f5dd72959a1f1b3a6d95d3c8bcdb.tar.xz
org.eclipse.sirius-07e9ce2a6fc7f5dd72959a1f1b3a6d95d3c8bcdb.zip
[516669] Allow representation load on demand
* Update the Sirius crossReferencer, when loading the representation. * Explicitly load the representation for the following action: ** opening ** export Bug: 516669 Change-Id: I902e5633e831b551f655a94095c49943f0c729b3 Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/export/AbstractExportRepresentationsAction.java33
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/export/ExportRepresentationsAction.java14
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/session/OpenRepresentationsAction.java41
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepLocationRuleForLocalResource.java15
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepresentationDescriptorToDRepresentationLinkManager.java16
5 files changed, 70 insertions, 49 deletions
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/export/AbstractExportRepresentationsAction.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/export/AbstractExportRepresentationsAction.java
index 2171928797..32edfc1db9 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/export/AbstractExportRepresentationsAction.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/export/AbstractExportRepresentationsAction.java
@@ -13,7 +13,9 @@ package org.eclipse.sirius.ui.tools.internal.actions.export;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.List;
+import java.util.Objects;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -40,7 +42,6 @@ import org.eclipse.sirius.viewpoint.provider.Messages;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
-import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@@ -52,8 +53,7 @@ import com.google.common.collect.Lists;
public abstract class AbstractExportRepresentationsAction extends Action {
/**
- * Creates a new AbstractExportRepresentationsAction with the given text and
- * image.
+ * Creates a new AbstractExportRepresentationsAction with the given text and image.
*
* @param text
* the action's text, or <code>null</code> if there is no text
@@ -67,32 +67,34 @@ public abstract class AbstractExportRepresentationsAction extends Action {
}
/**
- * Collect the diagrams to export, get the corresponding session, compute
- * the export path and then show the path and file format dialog to the user
- * before exporting export the diagrams.
+ * Collect the diagrams to export, get the corresponding session, compute the export path and then show the path and
+ * file format dialog to the user before exporting export the diagrams.
*/
@Override
public void run() {
- Collection<DRepresentationDescriptor> collectedRepDescriptors = getRepresentationToExport();
- Iterable<DRepresentationDescriptor> dRepresentationsToExport = Iterables.filter(collectedRepDescriptors, Predicates.notNull());
- if (!Iterables.isEmpty(dRepresentationsToExport)) {
- DRepresentationDescriptor firstDRepDescriptorToExport = dRepresentationsToExport.iterator().next();
+ Collection<DRepresentationDescriptor> repDescriptorsToExport = getRepresentationToExport().stream().filter(Objects::nonNull).collect(Collectors.toList());
+
+ if (!repDescriptorsToExport.isEmpty()) {
+ DRepresentationDescriptor firstDRepDescriptorToExport = repDescriptorsToExport.iterator().next();
+ // Make sure the representation is loaded
+ firstDRepDescriptorToExport.getRepresentation();
Session session = getSession(firstDRepDescriptorToExport);
if (session != null) {
IPath exportPath = getExportPath(firstDRepDescriptorToExport, session);
-
if (exportPath != null) {
- exportRepresentation(exportPath, dRepresentationsToExport, session);
+ exportRepresentation(exportPath, repDescriptorsToExport, session);
}
}
+ } else {
+ MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.ExportRepresentationsAction_noRepresentationsDialog_title,
+ Messages.ExportRepresentationsAction_noRepresentationsDialog_message);
}
}
/**
* Collect the representations to export.
*
- * @return the {@link DRepresentationDescriptor} corresponding to the
- * representation to export.
+ * @return the {@link DRepresentationDescriptor} corresponding to the representation to export.
*/
protected abstract Collection<DRepresentationDescriptor> getRepresentationToExport();
@@ -106,8 +108,7 @@ public abstract class AbstractExportRepresentationsAction extends Action {
protected abstract Session getSession(DRepresentationDescriptor repDescriptor);
/**
- * Display the export path and file format dialog and then export the
- * representations.
+ * Display the export path and file format dialog and then export the representations.
*
* @param exportPath
* the default export path.
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/export/ExportRepresentationsAction.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/export/ExportRepresentationsAction.java
index 74c804fe97..5087e98e61 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/export/ExportRepresentationsAction.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/export/ExportRepresentationsAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2016 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2009, 2017 THALES GLOBAL SERVICES and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -16,7 +16,6 @@ import java.util.LinkedHashSet;
import java.util.Set;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.sirius.business.api.dialect.DialectManager;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager;
@@ -25,7 +24,6 @@ import org.eclipse.sirius.ui.business.api.dialect.ExportFormat.ExportDocumentFor
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.eclipse.sirius.viewpoint.provider.Messages;
import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import com.google.common.base.Predicate;
@@ -71,16 +69,6 @@ public class ExportRepresentationsAction extends AbstractExportRepresentationsAc
}
@Override
- public void run() {
- if (!getRepresentationToExport().isEmpty()) {
- super.run();
- } else {
- MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.ExportRepresentationsAction_noRepresentationsDialog_title,
- Messages.ExportRepresentationsAction_noRepresentationsDialog_message);
- }
- }
-
- @Override
protected Collection<DRepresentationDescriptor> getRepresentationToExport() {
Collection<DRepresentationDescriptor> dRepDescriptorsToExport = Sets.newLinkedHashSet(selectedRepDescriptors);
if (dRepDescriptorsToExport.isEmpty()) {
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/session/OpenRepresentationsAction.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/session/OpenRepresentationsAction.java
index 63452881c5..4bbdd21921 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/session/OpenRepresentationsAction.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/session/OpenRepresentationsAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2016 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2011, 2017 THALES GLOBAL SERVICES and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -15,7 +15,7 @@ import java.util.Collection;
import java.util.Collections;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableContext;
@@ -37,8 +37,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
- * Action to open the given representations and init/update the corresponding ui
- * session(s).
+ * Action to open the given representations and init/update the corresponding ui session(s).
*
* @author mporhel
*/
@@ -79,7 +78,7 @@ public class OpenRepresentationsAction extends Action {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor pm) {
- openRepresentations(representationsToOpen, pm);
+ openRepresentations(pm);
}
};
PlatformUI.getWorkbench().getProgressService().runInUI(context, runnable, null);
@@ -93,28 +92,42 @@ public class OpenRepresentationsAction extends Action {
}
}
- private void openRepresentations(final Collection<DRepresentationDescriptor> selection, final IProgressMonitor monitor) {
+ /**
+ * Open the representations associated to {@link DRepresentationDescriptor}.
+ *
+ * @param monitor
+ * the progress monitor to use for reporting progress to the user, or null indicating that no progress
+ * should be reported and the operation cannot be cancelled.
+ */
+ private void openRepresentations(final IProgressMonitor monitor) {
String taskName = Messages.OpenRepresentationsAction_openRepresentationTask;
- if (selection.size() > 1) {
+ if (representationsToOpen.size() > 1) {
taskName = Messages.OpenRepresentationsAction_openRepresentationsTask;
}
try {
- monitor.beginTask(taskName, 5 * selection.size());
-
- for (DRepresentationDescriptor repDesc : selection) {
+ int nbRepToLoad = (int) representationsToOpen.stream().filter(repDesc -> !repDesc.isLoadedRepresentation()).count();
+ SubMonitor subMonitor = SubMonitor.convert(monitor, taskName, 6 * representationsToOpen.size() + 4 * nbRepToLoad);
+
+ for (DRepresentationDescriptor repDesc : representationsToOpen) {
+ // force representation resource loading if needed
+ if (!repDesc.isLoadedRepresentation()) {
+ repDesc.getRepresentation();
+ subMonitor.worked(4);
+ }
+
Session session = new EObjectQuery(repDesc.getTarget()).getSession();
- monitor.worked(1);
+ subMonitor.worked(1);
if (session != null) {
- IEditorPart part = DialectUIManager.INSTANCE.openEditor(session, repDesc.getRepresentation(), new SubProgressMonitor(monitor, 3));
+ IEditorPart part = DialectUIManager.INSTANCE.openEditor(session, repDesc.getRepresentation(), subMonitor.split(4));
if (part instanceof DialectEditor) {
updateUISession((DialectEditor) part, session);
- monitor.worked(1);
+ subMonitor.worked(1);
}
}
}
} finally {
- monitor.done();
+ SubMonitor.done(monitor);
}
}
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepLocationRuleForLocalResource.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepLocationRuleForLocalResource.java
index 8ca5654c15..7eb83dcf2c 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepLocationRuleForLocalResource.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepLocationRuleForLocalResource.java
@@ -18,10 +18,12 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.sirius.business.api.dialect.DialectManager;
import org.eclipse.sirius.business.api.helper.SiriusUtil;
import org.eclipse.sirius.business.api.query.URIQuery;
import org.eclipse.sirius.business.api.session.danalysis.DRepresentationLocationRule;
import org.eclipse.sirius.viewpoint.DRepresentation;
+import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
/**
* This implementation to {@link DRepresentationLocationRule} give a behavior for representation resources in local
@@ -58,7 +60,7 @@ public class DRepLocationRuleForLocalResource implements DRepresentationLocation
* @return the representation URI
*/
protected URI getDedicatedRepResourceURI(DRepresentation representation, Resource airdResource) {
- int count = 0;
+ int count = 1;
ResourceSet resourceSet = airdResource.getResourceSet();
URI repUri = createRepURI(airdResource, representation, count++);
while (!isUsableURI(repUri, resourceSet, representation)) {
@@ -106,7 +108,8 @@ public class DRepLocationRuleForLocalResource implements DRepresentationLocation
}
/**
- * Create the representation URI based on the aird resource URI. Only the last part of the segment is changed.
+ * Create the representation URI based on the aird resource URI.</br>
+ * Only the last part of the segment is changed. It will include the name of the RepresentationDescription
*
* @param airdResource
* the aird resource
@@ -117,10 +120,10 @@ public class DRepLocationRuleForLocalResource implements DRepresentationLocation
*/
private URI createRepURI(Resource airdResource, DRepresentation representation, int count) {
// get the representation URI fragment
- String repName = representation.getName().replace(' ', '_');
- if (count > 0) {
- repName += String.valueOf(count);
- }
+ RepresentationDescription description = DialectManager.INSTANCE.getDescription(representation);
+ String repName = description.getName().replace(' ', '_');
+ repName += "_" + String.valueOf(count); //$NON-NLS-1$
+
URI airdURI = airdResource.getURI();
List<String> srmFileSegments = new ArrayList<>(airdURI.segmentsList());
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepresentationDescriptorToDRepresentationLinkManager.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepresentationDescriptorToDRepresentationLinkManager.java
index 0eddfcd1ec..24bb527ed0 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepresentationDescriptorToDRepresentationLinkManager.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepresentationDescriptorToDRepresentationLinkManager.java
@@ -16,7 +16,9 @@ import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.sirius.business.api.query.EObjectQuery;
import org.eclipse.sirius.business.api.resource.ResourceDescriptor;
+import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.common.tools.api.util.EclipseUtil;
import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
@@ -81,6 +83,20 @@ public class DRepresentationDescriptorToDRepresentationLinkManager {
* @return an Optional DRepresentation.
*/
public Optional<DRepresentation> getRepresentation(boolean loadOnDemand) {
+ Optional<DRepresentation> representation = getRepresentationInternal(false);
+ if (loadOnDemand && !representation.isPresent()) {
+ representation = getRepresentationInternal(true);
+
+ representation.ifPresent(rep -> Optional.ofNullable(new EObjectQuery(repDescriptor).getSession()).map(Session::getSemanticCrossReferencer).ifPresent(crossRef -> {
+ crossRef.setTarget(repDescriptor);
+ rep.eAdapters().add(crossRef);
+ }));
+ }
+
+ return representation;
+ }
+
+ private Optional<DRepresentation> getRepresentationInternal(boolean loadOnDemand) {
Optional<DRepresentationURIFragmentStrategy> fragmentStrategy = EclipseUtil
.getExtensionPlugins(DRepresentationURIFragmentStrategy.class, DRepresentationURIFragmentStrategy.ID, DRepresentationURIFragmentStrategy.CLASS_ATTRIBUTE).stream()
.filter(strategy -> strategy.providesGetter(repDescriptor)).findFirst();

Back to the top