diff options
author | Benoit Maggi | 2016-12-16 13:04:06 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2017-01-03 15:26:36 +0000 |
commit | af4d73d59c3a8593ce43950e67b404fbccf13669 (patch) | |
tree | 8a9ec70f84bd681b2f42d73ad355e45a6642f298 | |
parent | f9943b0e1c05b80168047b396578186da74c203d (diff) | |
download | org.eclipse.papyrus-af4d73d59c3a8593ce43950e67b404fbccf13669.tar.gz org.eclipse.papyrus-af4d73d59c3a8593ce43950e67b404fbccf13669.tar.xz org.eclipse.papyrus-af4d73d59c3a8593ce43950e67b404fbccf13669.zip |
Bug 509346 - [Facet] Order of loaded facet should be saved
- store the facet in an Array
- reload the facet order
- remove very old commented code
Change-Id: I199d824a3cccc8ebee26a139b5ee22648ca47815
Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
2 files changed, 43 insertions, 154 deletions
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/internal/emf/Activator.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/internal/emf/Activator.java index 8f725ffb90f..9dd1c198dca 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/internal/emf/Activator.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/internal/emf/Activator.java @@ -10,13 +10,17 @@ * Camille Letavernier (camille.letavernier@cea.fr) - Initial API and implementation * Christian W. Damus - bug 485220 * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation - * + * Benoit Maggi - Bug 509346 *****************************************************************************/ package org.eclipse.papyrus.infra.ui.internal.emf; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -44,11 +48,19 @@ import org.osgi.framework.ServiceRegistration; */ public class Activator extends AbstractUIPlugin { + + /** * The plug-in ID */ public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.ui.emf"; //$NON-NLS-1$ - + + /** + * Key to store the facet order + */ + private static final String LOADED_FACET_ORDER = PLUGIN_ID+".facet.order"; + + // The shared instance private static Activator plugin; @@ -108,48 +120,44 @@ public class Activator extends AbstractUIPlugin { public void saveCustomizationManagerState() { IDialogSettings dialogSettings = getBrowserCustomizationDialogSettings(); List<Customization> appliedCustomizations = getCustomizationManager().getManagedCustomizations(); - final List<Customization> registeredCustomizations = ICustomizationCatalogManagerFactory.DEFAULT.getOrCreateCustomizationCatalogManager(getCustomizationManager().getResourceSet()).getRegisteredCustomizations(); - for (Customization customization : registeredCustomizations) { - boolean isApplied = appliedCustomizations.contains(customization); String settingKey = getSettingKey(customization); - - dialogSettings.put(settingKey, isApplied); + dialogSettings.put(settingKey, isApplied); } + + // We have to use a temporary list since CustomizationsDelegatingList is buggy (missing a lot of methods) + List<Customization> customizationList = new ArrayList<>(); + customizationList.addAll(appliedCustomizations); + String[] loadedCustomizationArray = customizationList.stream().map(customization -> customization.eResource().getURI().toString()).toArray(size -> new String[size]); + dialogSettings.put(LOADED_FACET_ORDER, loadedCustomizationArray); + } private String getSettingKey(Customization customization) { // do not exist anymore return customization.eResource().getURI().toString(); - // return ""; } protected IDialogSettings getBrowserCustomizationDialogSettings() { - String sectionId = CUSTOMIZATION_MANAGER_SECTION; - - IDialogSettings settings = Activator.getDefault().getDialogSettings().getSection(sectionId); + IDialogSettings settings = Activator.getDefault().getDialogSettings().getSection(CUSTOMIZATION_MANAGER_SECTION); if (settings == null) { - settings = Activator.getDefault().getDialogSettings().addNewSection(sectionId); + settings = Activator.getDefault().getDialogSettings().addNewSection(CUSTOMIZATION_MANAGER_SECTION); } return settings; } private void init(final ICustomizationManager customizationManager) { // the appearance can be customized here: - IDialogSettings settings = getBrowserCustomizationDialogSettings(); - try { - // load customizations defined as default through the customization // extension ICustomizationCatalogManager customCatalog = ICustomizationCatalogManagerFactory.DEFAULT.getOrCreateCustomizationCatalogManager(customizationManager.getResourceSet()); // no possibility to get default customization - List<Customization> registryAllCustomizations = customCatalog.getRegisteredCustomizations(); - ArrayList<Customization> orderedCustomizationList = new ArrayList<Customization>(); + List<Customization> orderedCustomizationList = new ArrayList<>(); for (Customization customization : registryAllCustomizations) { String settingKey = getSettingKey(customization); @@ -163,11 +171,21 @@ public class Activator extends AbstractUIPlugin { if (isActive) { orderedCustomizationList.add(customization); - } } - - Collections.sort(orderedCustomizationList, new CustomizationComparator()); + String[] loadedFacetOrder = settings.getArray(LOADED_FACET_ORDER); + if (loadedFacetOrder != null && loadedFacetOrder.length > 0){ + + Map<String, Customization> mapProp = registryAllCustomizations.stream().collect( + Collectors.toMap(e -> getSettingKey(e),e -> e)); + + Stream<String> stream = Arrays.stream(loadedFacetOrder); + Stream<Customization> map = stream.map(id -> mapProp.get(id)); + orderedCustomizationList = map.collect(Collectors.toList()); + } else { + Collections.sort(orderedCustomizationList, new CustomizationComparator()); + } + customizationManager.getManagedCustomizations().addAll(orderedCustomizationList); } catch (Throwable e) { @@ -184,18 +202,8 @@ public class Activator extends AbstractUIPlugin { * Restores the default Customization Manager configuration */ public void restoreDefaultCustomizationManager() { - // ICustomizationManager manager = getCustomizationManager(); - DialogSettings settings = (DialogSettings) getDialogSettings(); settings.removeSection(CUSTOMIZATION_MANAGER_SECTION); - - // List<MetamodelView> registryDefaultCustomizations = CustomizationsCatalog.getInstance().getRegistryDefaultCustomizations(); - // - // manager.clearCustomizations(); - // for(MetamodelView customization : registryDefaultCustomizations) { - // manager.registerCustomization(customization); - // } - // manager.loadCustomizations(); } public ICustomizationManager getCustomizationManager() { diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/LoadBrowserCustomization.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/LoadBrowserCustomization.java index 21409f56a11..8cf0fbd2a1f 100644 --- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/LoadBrowserCustomization.java +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/LoadBrowserCustomization.java @@ -9,7 +9,7 @@ * Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
* Christian W. Damus - bug 485220
- *
+ * Benoit Maggi - Bug 509346
*****************************************************************************/
package org.eclipse.papyrus.views.modelexplorer.handler;
@@ -23,13 +23,6 @@ import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
-//import org.eclipse.papyrus.emf.facet.infra.browser.Messages;
-//import org.eclipse.papyrus.emf.facet.infra.browser.custom.MetamodelView;
-//import org.eclipse.papyrus.emf.facet.infra.browser.custom.TypeView;
-//import org.eclipse.papyrus.emf.facet.infra.browser.uicore.CustomizationManager;
-//import org.eclipse.papyrus.emf.facet.infra.facet.Facet;
-//import org.eclipse.papyrus.emf.facet.infra.facet.FacetSet;
-//import org.eclipse.papyrus.emf.facet.infra.facet.core.FacetSetCatalog;
import org.eclipse.jface.window.Window;
import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationCatalogManagerFactory;
import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationManager;
@@ -38,8 +31,6 @@ import org.eclipse.papyrus.emf.facet.custom.ui.internal.exported.dialog.ILoadCus import org.eclipse.papyrus.emf.facet.custom.ui.internal.exported.dialog.ILoadCustomizationsDialogFactory;
import org.eclipse.papyrus.emf.facet.util.ui.internal.exported.dialog.IDialogCallback;
import org.eclipse.papyrus.emf.facet.util.ui.internal.exported.dialog.IDialogCallbackWithPreCommit;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.resource.ModelUtils;
import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
@@ -47,7 +38,6 @@ import org.eclipse.papyrus.infra.core.utils.ServiceUtils; import org.eclipse.papyrus.infra.services.semantic.service.SemanticService;
import org.eclipse.papyrus.views.modelexplorer.Activator;
import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPageBookView;
-import org.eclipse.papyrus.views.modelexplorer.dialog.PapyrusLoadBrowserCustomizationDialog;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IViewPart;
@@ -71,7 +61,7 @@ public class LoadBrowserCustomization extends AbstractHandler { if (part instanceof ModelExplorerPageBookView) {
IViewPart page = ((ModelExplorerPageBookView) part).getActiveView();
if (page instanceof CommonNavigator) {
- return ((CommonNavigator) page);
+ return (CommonNavigator) page;
}
}
return null;
@@ -82,26 +72,19 @@ public class LoadBrowserCustomization extends AbstractHandler { */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
-
if (Activator.getDefault().getCustomizationManager() != null) {
ICustomizationManager customizationManager = Activator.getDefault().getCustomizationManager();
final List<Customization> registeredCustomizations = ICustomizationCatalogManagerFactory.DEFAULT.getOrCreateCustomizationCatalogManager(customizationManager.getResourceSet()).getRegisteredCustomizations();
- PapyrusLoadBrowserCustomizationDialog loadCustomizationsDialog;
-
-
Shell shell = HandlerUtil.getActiveShell(event);
IDialogCallbackWithPreCommit<List<Customization>, Boolean, Dialog> dialogCallBack = new IDialogCallbackWithPreCommit<List<Customization>, Boolean, Dialog>() {
@Override
public void committed(List<Customization> result, Boolean precommitResult) {
- // TODO Auto-generated method stub
-
}
@Override
public Dialog openPrecommitDialog(List<Customization> result, IDialogCallback<Boolean> precommitCallback) {
- // TODO Auto-generated method stub
return null;
}
};
@@ -110,14 +93,11 @@ public class LoadBrowserCustomization extends AbstractHandler { if (Window.OK == dialog.open()) {
customizationManager.getManagedCustomizations().clear();
customizationManager.getManagedCustomizations().addAll(dialog.getSelectedCustomizations());
-
-
// Save the current state of the customizations
org.eclipse.papyrus.infra.ui.internal.emf.Activator.getDefault().saveCustomizationManagerState();
}
- // // load customizations defined as default through the customization
- // // extension
+ // load customizations defined as default through the customization extension
if (getCommonNavigator() != null) {
getCommonNavigator().getCommonViewer().refresh();
}
@@ -126,87 +106,9 @@ public class LoadBrowserCustomization extends AbstractHandler { return null;
}
- /**
- *
- * @return the RessourceSet
- */
- private ModelSet getModelSet() {
- return ModelUtils.getModelSet();
- }
-
- // /**
- // * load the facets
- // *
- // * @param customizations
- // * list of customization
- // * @param customizationManager
- // * the Customization Manager
- // */
- // protected void loadFacetsForCustomizations(final List<MetamodelView> customizations, final CustomizationManager customizationManager) {
- // final Set<Facet> referencedFacets = new HashSet<Facet>();
- // final Collection<FacetSet> facetSets = FacetSetCatalog.getSingleton().getAllFacetSets();
- //
- // for(MetamodelView customization : customizations) {
- // String metamodelURI = customization.getMetamodelURI();
- // // find customized FacetSet
- // FacetSet customizedFacetSet = null;
- // if(metamodelURI != null) {
- // for(FacetSet facetSet : facetSets) {
- // if(metamodelURI.equals(facetSet.getNsURI())) {
- // customizedFacetSet = facetSet;
- // break;
- // }
- // }
- // }
- // if(customizedFacetSet == null) {
- // continue;
- // }
- //
- // // find customized Facets
- // EList<TypeView> types = customization.getTypes();
- // for(TypeView typeView : types) {
- // String metaclassName = typeView.getMetaclassName();
- // Facet facet = findFacetWithFullyQualifiedName(metaclassName, customizedFacetSet);
- // if(facet != null) {
- // referencedFacets.add(facet);
- // } else {
- // Activator.log.warn(NLS.bind(Messages.BrowserActionBarContributor_missingRequiredFacet, new Object[]{ metaclassName, customizedFacetSet.getName(), customization.getName() }));
- // }
- // }
- //
- // for(Facet referencedFacet : referencedFacets) {
- // customizationManager.loadFacet(referencedFacet);
- // }
- // }
-
- //
- // for modified facets
- // customizationManager.getInstancesForMetaclasses().buildDerivationTree();
- // customizationManager.getAppearanceConfiguration().touch();
- // customizationManager.refreshDelayed(true);
- // }
-
- // /**
- // * fin a facet from
- // *
- // * @param metaclassName
- // * @param customizedFacetSet
- // * @return
- // */
- // private Facet findFacetWithFullyQualifiedName(final String metaclassName, final FacetSet customizedFacetSet) {
- // EList<Facet> facets = customizedFacetSet.getFacets();
- // for(Facet facet : facets) {
- // String facetName = getMetaclassQualifiedName(facet);
- // if(metaclassName.equals(facetName)) {
- // return facet;
- // }
- // }
- // return null;
- // }
-
/** @return the qualified name of the given metaclass */
public static String getMetaclassQualifiedName(final EClassifier eClass) {
- final ArrayList<String> qualifiedNameParts = new ArrayList<String>();
+ final ArrayList<String> qualifiedNameParts = new ArrayList<>();
final StringBuilder builder = new StringBuilder();
EPackage ePackage = eClass.getEPackage();
@@ -224,32 +126,11 @@ public class LoadBrowserCustomization extends AbstractHandler { return builder.toString();
}
- // /**
- // * Get the metmodel URI
- // * **/
- // @Unused
- // private String getMetamodelURI() {
- //
- // try {
- // EList<EObject> contents = UmlUtils.getUmlResource(getModelSet()).getContents();
- // if(contents.size() > 0) {
- // EObject eObject = contents.get(0);
- // EClass eClass = eObject.eClass();
- // if(eClass != null) {
- // return eClass.getEPackage().getNsURI();
- // }
- // }
- // } catch (Exception e) {
- // Activator.log.error(e);
- // }
- // return ""; //$NON-NLS-1$
- // }
-
/**
* Get the metmodel URI
**/
protected List<EPackage> getMetamodels(ServicesRegistry serviceRegistry) {
- List<EPackage> ePackages = new ArrayList<EPackage>();
+ List<EPackage> ePackages = new ArrayList<>();
/*
* we look for the current editors, because their are represented in the model explorer
|