diff options
author | Nicolas FAUVERGUE | 2018-08-23 09:07:31 +0000 |
---|---|---|
committer | Patrick Tessier | 2018-08-29 14:30:02 +0000 |
commit | f63d85196dc9c8b040c01ef3bd6459fb5f5f524d (patch) | |
tree | c837bc471271e107691cd5d42207733a347b3227 /plugins/uml | |
parent | 7fb01ba74afc2fa646aea7cc2d0a8982dc929d12 (diff) | |
download | org.eclipse.papyrus-f63d85196dc9c8b040c01ef3bd6459fb5f5f524d.tar.gz org.eclipse.papyrus-f63d85196dc9c8b040c01ef3bd6459fb5f5f524d.tar.xz org.eclipse.papyrus-f63d85196dc9c8b040c01ef3bd6459fb5f5f524d.zip |
Bug 538193: [Profile] Profile application will be faster when there is
only one profile in selected model
- Check if there is only one profile in model for profile application
Change-Id: I37cc393230c2abe3c717656b674d90328ae78481
Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
Diffstat (limited to 'plugins/uml')
3 files changed, 92 insertions, 36 deletions
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/dialogs/RegisteredProfileSelectionDialog.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/dialogs/RegisteredProfileSelectionDialog.java index 8b890cfc6ae..94ae1e05df9 100644 --- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/dialogs/RegisteredProfileSelectionDialog.java +++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/dialogs/RegisteredProfileSelectionDialog.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2008, 2014 CEA LIST and others. + * Copyright (c) 2008, 2014, 2018 CEA LIST and others. * * * All rights reserved. This program and the accompanying materials @@ -14,12 +14,14 @@ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification * Christian W. Damus (CEA) - Refactoring package/profile import/apply UI for CDO * Christian W. Damus (CEA) - bug 422257 + * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 538193 * *****************************************************************************/ package org.eclipse.papyrus.uml.properties.profile.ui.dialogs; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -34,6 +36,7 @@ import org.eclipse.papyrus.uml.extensionpoints.standard.FilteredRegisteredElemen import org.eclipse.papyrus.uml.extensionpoints.utils.Util; import org.eclipse.papyrus.uml.profile.ui.dialogs.ElementImportTreeSelectionDialog.ImportSpec; import org.eclipse.papyrus.uml.profile.ui.dialogs.ProfileTreeSelectionDialog; +import org.eclipse.papyrus.uml.tools.utils.ProfileUtil; import org.eclipse.swt.widgets.Composite; import org.eclipse.uml2.uml.Package; import org.eclipse.uml2.uml.Profile; @@ -55,7 +58,7 @@ public class RegisteredProfileSelectionDialog extends FilteredRegisteredElements * @param parent */ public RegisteredProfileSelectionDialog(Composite parent, Package umlPackage) { - super(parent.getShell(), true, Registry.getRegisteredProfiles().toArray(new IRegisteredProfile[0]), new ArrayList<Object>(), "Apply profiles from Papyrus repository :", ""); + super(parent.getShell(), true, Registry.getRegisteredProfiles().toArray(new IRegisteredProfile[0]), new ArrayList<>(), "Apply profiles from Papyrus repository :", ""); currentPackage = umlPackage; } @@ -79,7 +82,7 @@ public class RegisteredProfileSelectionDialog extends FilteredRegisteredElements // dialog.open(); this.open(); - List<Profile> result = new LinkedList<Profile>(); + List<Profile> result = new LinkedList<>(); ResourceSet resourceSet = Util.createTemporaryResourceSet(); try { @@ -106,16 +109,16 @@ public class RegisteredProfileSelectionDialog extends FilteredRegisteredElements Object[] selection = this.getResult(); if (selection == null) { // Cancel was selected - return new ArrayList<Profile>(); + return new ArrayList<>(); } // This first list (listOfProfileToApply) contain every selected profile // which owns sub-profiles (it is possible to select a set of sub-profiles) // The list is used to build a profile selection tree - List<Package> listOfProfileToApply = new ArrayList<Package>(); + List<Package> listOfProfileToApply = new ArrayList<>(); // try to parse the qualified names - List<String> subprofilesList = new ArrayList<String>(); + List<String> subprofilesList = new ArrayList<>(); for (int i = 0; i < selection.length; i++) { IRegisteredProfile currentProfile = (IRegisteredProfile) (selection[i]); @@ -150,22 +153,28 @@ public class RegisteredProfileSelectionDialog extends FilteredRegisteredElements } if (!listOfProfileToApply.isEmpty()) { - // Open package/profile selection tree selection - ProfileTreeSelectionDialog profileDialog = new ProfileTreeSelectionDialog(getShell(), listOfProfileToApply, subprofilesList); - int returnValue = profileDialog.open(); - - // Apply selected profile if ok was selected - if (Window.OK == returnValue) { - Collection<ImportSpec<Profile>> dlgResult = profileDialog.getResult(); - List<Profile> result = new java.util.ArrayList<Profile>(dlgResult.size()); - for (ImportSpec<Profile> next : dlgResult) { - result.add(next.getElement()); + final Profile onlyOneProfile = ProfileUtil.getTheOnlyOneProfile(listOfProfileToApply); + if (null == onlyOneProfile) { + + // Open package/profile selection tree selection + ProfileTreeSelectionDialog profileDialog = new ProfileTreeSelectionDialog(getShell(), listOfProfileToApply, subprofilesList); + int returnValue = profileDialog.open(); + + // Apply selected profile if ok was selected + if (Window.OK == returnValue) { + Collection<ImportSpec<Profile>> dlgResult = profileDialog.getResult(); + List<Profile> result = new java.util.ArrayList<>(dlgResult.size()); + for (ImportSpec<Profile> next : dlgResult) { + result.add(next.getElement()); + } + return result; + } else { + return new ArrayList<Profile>(); } - return result; } else { - new ArrayList<Profile>(); + return Collections.singletonList(onlyOneProfile); } } - return new ArrayList<Profile>(); + return new ArrayList<>(); } } diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/ProfileApplicationEditor.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/ProfileApplicationEditor.java index f4b2db7a4c9..f4cd3208c38 100644 --- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/ProfileApplicationEditor.java +++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/ProfileApplicationEditor.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2011, 2014 CEA LIST, Christian W. Damus, and others. + * Copyright (c) 2011, 2014, 2018 CEA LIST, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -12,6 +12,7 @@ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation * Christian W. Damus (CEA) - Refactoring package/profile import/apply UI for CDO * Christian W. Damus - bug 399859 + * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 538193 * *****************************************************************************/ package org.eclipse.papyrus.uml.properties.widgets; @@ -234,6 +235,7 @@ public class ProfileApplicationEditor extends MultipleReferenceEditor { reapplyProfile = createButton(org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("/icons/refresh.gif"), "Reapply profile"); treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { + @Override public void selectionChanged(SelectionChangedEvent event) { updateControls(); } @@ -255,7 +257,7 @@ public class ProfileApplicationEditor extends MultipleReferenceEditor { // ResourceSelectionDialog dialog = // new ResourceSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), "Apply Profiles"); - Map<String, String> extensionFilters = new LinkedHashMap<String, String>(); + Map<String, String> extensionFilters = new LinkedHashMap<>(); extensionFilters.put("*.profile.uml", "UML Profiles (*.profile.uml)"); extensionFilters.put("*.uml", "UML (*.uml)"); extensionFilters.put("*", "All (*)"); @@ -268,21 +270,27 @@ public class ProfileApplicationEditor extends MultipleReferenceEditor { } if (packages.size() > 0) { - ProfileTreeSelectionDialog profileDialog = new ProfileTreeSelectionDialog(getShell(), packages); + final Collection<Profile> profilesToApply = new LinkedList<>(); + final Profile onlyOneProfile = ProfileUtil.getTheOnlyOneProfile(packages); + if (null == onlyOneProfile) { - if (profileDialog.open() != Window.OK) { - return; - } + ProfileTreeSelectionDialog profileDialog = new ProfileTreeSelectionDialog(getShell(), packages); - if (profileDialog.getResult().isEmpty()) { - return; - } + if (profileDialog.open() != Window.OK) { + return; + } - Collection<ImportSpec<Profile>> profilesImportToApply = profileDialog.getResult(); + if (profileDialog.getResult().isEmpty()) { + return; + } + + Collection<ImportSpec<Profile>> profilesImportToApply = profileDialog.getResult(); - Collection<Profile> profilesToApply = new LinkedList<Profile>(); - for (ImportSpec<Profile> importProfile : profilesImportToApply) { - profilesToApply.add(importProfile.getElement()); + for (ImportSpec<Profile> importProfile : profilesImportToApply) { + profilesToApply.add(importProfile.getElement()); + } + } else { + profilesToApply.add(onlyOneProfile); } if (!ProfileValidationHelper.checkApplicableProfiles(getShell(), profilesToApply)) { @@ -316,7 +324,7 @@ public class ProfileApplicationEditor extends MultipleReferenceEditor { ISelection selectedElements = treeViewer.getSelection(); // Filter profiles - List<Profile> profilesToRefresh = new LinkedList<Profile>(); + List<Profile> profilesToRefresh = new LinkedList<>(); if (!selectedElements.isEmpty() && selectedElements instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) selectedElements; Iterator<?> iterator = selection.iterator(); diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ProfileUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ProfileUtil.java index 08ba7bc56c9..824d41541fc 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ProfileUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ProfileUtil.java @@ -16,6 +16,7 @@ * Christian W. Damus - bug 474610 * Calin Glitia (Esterel Technologies SAS) - bug 497699 * Camille Letavernier (EclipseSource) - bug 530156 + * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 538193 * *****************************************************************************/ package org.eclipse.papyrus.uml.tools.utils; @@ -258,6 +259,44 @@ public class ProfileUtil extends org.eclipse.uml2.uml.util.UMLUtil { } /** + * This allows to the profile of the packages if there is only one profile. + * + * @param packages + * The collection of packages to check. + * @return The profile if there is only one profile, otherwise <code>null</code>. + */ + public static Profile getTheOnlyOneProfile(final Collection<Package> packages) { + int numberOfProfiles = 0; + Profile onlyOneProfile = null; + + // Loop on all packages + final List<Package> allPackages = new ArrayList<>(packages); + int index = 0; + while (index < allPackages.size() && numberOfProfiles <= 1) { + final Package currentPackage = allPackages.get(index); + + // If this is a profile, save and count it + if (currentPackage instanceof Profile) { + numberOfProfiles++; + onlyOneProfile = (Profile) currentPackage; + } + + if (numberOfProfiles <= 1) { + for (final PackageableElement packagesElement : currentPackage.getPackagedElements()) { + if (packagesElement instanceof Package) { + allPackages.add((Package) packagesElement); + } + } + } + + index++; + } + + // If there is more than one profile, return null + return numberOfProfiles == 1 ? onlyOneProfile : null; + } + + /** * Finds the profile application, if any, in the context of an {@code element} that supplies the given * stereotype Ecore definition. * @@ -266,7 +305,7 @@ public class ProfileUtil extends org.eclipse.uml2.uml.util.UMLUtil { * @param stereotypeDefinition * the Ecore definition of a stereotype * @param stereotype - * The stereotype from which the stereotypeDefinition was derived + * The stereotype from which the stereotypeDefinition was derived * * @return the providing profile application, or {@code null} if none can be determined * @since 3.4 @@ -275,7 +314,7 @@ public class ProfileUtil extends org.eclipse.uml2.uml.util.UMLUtil { if (stereotype == null) { NamedElement umlDefinition = getNamedElement(stereotypeDefinition, element); if (umlDefinition instanceof Stereotype) { - stereotype = (Stereotype)umlDefinition; + stereotype = (Stereotype) umlDefinition; } else { return null; } @@ -301,7 +340,7 @@ public class ProfileUtil extends org.eclipse.uml2.uml.util.UMLUtil { * * @return the providing profile application, or {@code null} if none can be determined * @deprecated since 3.4 Use {@link #getProfileApplication(Element, EClass, Stereotype)} instead, - * which is more efficient. + * which is more efficient. */ @Deprecated public static ProfileApplication getProfileApplication(Element element, EClass stereotypeDefinition) { |