diff options
| author | Laurent Fasani | 2017-07-28 15:10:30 +0000 |
|---|---|---|
| committer | Laurent Fasani | 2017-08-01 14:56:17 +0000 |
| commit | 6aeef97372b9fea424afde4ae0f7c16883b41d04 (patch) | |
| tree | c628494714ddc497a62ad0beecad1d82b2290d74 | |
| parent | 1172e363c75c5d2d8e46a53859221b4038cb81ca (diff) | |
| download | org.eclipse.sirius-6aeef97372b9fea424afde4ae0f7c16883b41d04.tar.gz org.eclipse.sirius-6aeef97372b9fea424afde4ae0f7c16883b41d04.tar.xz org.eclipse.sirius-6aeef97372b9fea424afde4ae0f7c16883b41d04.zip | |
[516669] Use DRepresentationLocationManager to move a representation
* DRepresentationLocationManager allows to determine the representation
resource in which the representation will be moved.
* In case the resource target is not a platform resource, we display
only "Move
to <scheme>" to avoid displaying the full target URI which is technical
, in any case, more than before. Before the target URI was
<scheme>:/xxx.aird now it is
<scheme>:/xxx/.representation/yyy.srm id representation resource split
is activated.
Bug: 516669
Change-Id: I7395b1763fc3cd63b8a19518b6e7ea51815ae743
Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
3 files changed, 53 insertions, 14 deletions
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/MoveRepresentationAction.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/MoveRepresentationAction.java index de587306f8..ed5dc1e48d 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/MoveRepresentationAction.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/MoveRepresentationAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2016 Obeo and others. + * Copyright (c) 2015, 2017 Obeo 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 @@ -13,12 +13,14 @@ package org.eclipse.sirius.ui.tools.internal.views.common.action; import java.text.MessageFormat; import java.util.Collection; +import org.eclipse.core.runtime.Assert; import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.action.Action; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.sirius.business.api.dialect.command.MoveRepresentationCommand; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.business.api.session.danalysis.DAnalysisSessionHelper; +import org.eclipse.sirius.business.internal.representation.DRepresentationLocationManager; import org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority; import org.eclipse.sirius.ecore.extender.business.api.permission.PermissionAuthorityRegistry; import org.eclipse.sirius.ui.business.api.session.IEditingSession; @@ -40,6 +42,8 @@ import com.google.common.collect.Iterables; * @author <a href="mailto:mickael.lanoe@obeo.fr">Mickael LANOE</a> */ public class MoveRepresentationAction extends Action { + private static final String PLATFORM_SCHEME = "platform"; //$NON-NLS-1$ + private final Collection<DRepresentationDescriptor> repDescriptors; private final DAnalysis targetAnalysis; @@ -61,11 +65,19 @@ public class MoveRepresentationAction extends Action { this.targetAnalysis = targetAnalysis; this.session = session; this.repDescriptors = selection; + Assert.isTrue(!repDescriptors.isEmpty()); final ImageDescriptor descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(SiriusEditPlugin.ID, "/icons/full/others/forward.gif"); //$NON-NLS-1$ this.setImageDescriptor(descriptor); - this.setText(MessageFormat.format(Messages.MoveRepresentationAction_text, targetAnalysis.eResource().getURI().toString())); + DRepresentationDescriptor firstRepDesc = repDescriptors.iterator().next(); + String uriString = new DRepresentationLocationManager().getRepresentationResourceURI(firstRepDesc.getRepresentation(), targetAnalysis.eResource()).map(uri -> { + if (uri.scheme().equals(PLATFORM_SCHEME)) { + return uri.toString(); + } + return uri.scheme(); + }).orElse(""); //$NON-NLS-1$ + this.setText(MessageFormat.format(Messages.MoveRepresentationAction_text, uriString)); // Disable the action if the selection is not valid if (!isValidSelection()) { diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepresentationLocationManager.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepresentationLocationManager.java index f89cfbe503..54fe520ffc 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepresentationLocationManager.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/representation/DRepresentationLocationManager.java @@ -40,7 +40,7 @@ public class DRepresentationLocationManager { ResourceSet resourceSet = airdResource != null ? airdResource.getResourceSet() : null; if (resourceSet != null) { // Get the fragment of the URI - resource = getURIFromExtensionPoint(representation, airdResource).map(repResourceURI -> { + resource = getRepresentationResourceURI(representation, airdResource).map(repResourceURI -> { // get or create resource Resource res = resourceSet.getResource(repResourceURI, false); if (res == null) { @@ -57,7 +57,16 @@ public class DRepresentationLocationManager { return resource; } - private Optional<URI> getURIFromExtensionPoint(DRepresentation representation, Resource airdResource) { + /** + * Get the URI of the resource in which the representation will be stored. + * + * @param representation + * the DRepresentation + * @param airdResource + * the airdResource the representation wil be reference from + * @return the URI + */ + public Optional<URI> getRepresentationResourceURI(DRepresentation representation, Resource airdResource) { Optional<DRepresentationLocationRule> representationLocationRule = DRepresentationLocationRuleRegistry.getInstance().getRepresentationLocationRule(representation, airdResource); return representationLocationRule.map(r -> r.getResourceURI(representation, airdResource)); diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java index eb0e72390d..7ef50143fa 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.sirius.business.internal.session.danalysis; +import java.io.IOException; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; @@ -68,6 +69,7 @@ import org.eclipse.sirius.business.api.session.danalysis.DAnalysisSelectorServic import org.eclipse.sirius.business.api.session.danalysis.DAnalysisSession; import org.eclipse.sirius.business.api.session.danalysis.DAnalysisSessionHelper; import org.eclipse.sirius.business.api.session.danalysis.DAnalysisSessionService; +import org.eclipse.sirius.business.internal.representation.DRepresentationLocationManager; import org.eclipse.sirius.business.internal.resource.ResourceModifiedFieldUpdater; import org.eclipse.sirius.business.internal.session.IsModifiedSavingPolicy; import org.eclipse.sirius.business.internal.session.ReloadingPolicyImpl; @@ -501,16 +503,32 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements final IPermissionAuthority receiverAuthority = PermissionAuthorityRegistry.getDefault().getPermissionAuthority(receiverDView); if (receiverAuthority.canCreateIn(receiverDView)) { DRepresentation dRepresentation = repDescriptor.getRepresentation(); - receiverDView.eResource().getContents().add(dRepresentation); - // We call updateRepresentation to update the new path. We need to update the path before updating the - // repDescritor's parent which triggers the model explorer refresh with a wrong repPath attribute. - repDescriptor.updateRepresentation(dRepresentation); - receiverDView.getOwnedRepresentationDescriptors().add(repDescriptor); - // Add all semantic root elements pointed by the target of all - // DSemanticDecorator of this representation (except of this root is - // a root of a referencedAnalysis) - if (receiverDView.eContainer() instanceof DAnalysis) { - DAnalysisSessionHelper.updateModelsReferences(receiverDView); + Resource sourceRepResource = dRepresentation.eResource(); + + // move representation + Resource targetRepResource = new DRepresentationLocationManager().getOrCreateRepresentationResource(dRepresentation, receiverDView.eResource()); + if (targetRepResource != null) { + targetRepResource.getContents().add(dRepresentation); + + // We call updateRepresentation to update the new path. We need to update the path before updating the + // repDescritor's parent which triggers the model explorer refresh with a wrong repPath attribute. + repDescriptor.updateRepresentation(dRepresentation); + receiverDView.getOwnedRepresentationDescriptors().add(repDescriptor); + // Add all semantic root elements pointed by the target of all + // DSemanticDecorator of this representation (except of this root is + // a root of a referencedAnalysis) + if (receiverDView.eContainer() instanceof DAnalysis) { + DAnalysisSessionHelper.updateModelsReferences(receiverDView); + } + + // delete the resource if it is empty + Arrays.asList(sourceRepResource, targetRepResource).stream().filter(res -> res.getContents().isEmpty()).forEach(res -> { + try { + res.delete(Collections.emptyMap()); + } catch (IOException e) { + SiriusPlugin.getDefault().error(Messages.SiriusUncontrolCommand_resourceDeletionFailedMsg, e); + } + }); } } else { throw new LockedInstanceException(receiverDView); |
