diff options
author | Florian Noyrit | 2016-05-30 09:38:16 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-05-30 10:49:13 -0400 |
commit | 2fd1fc2ab6e806bdd1829ab2f7f4cba327b844c2 (patch) | |
tree | 2fc48531a76d756f94c5c34f931fa0cf23bac855 | |
parent | a184cf4e46d73cb7e5c820dcc81ae23ce7d6d0c2 (diff) | |
download | org.eclipse.papyrus-2fd1fc2ab6e806bdd1829ab2f7f4cba327b844c2.tar.gz org.eclipse.papyrus-2fd1fc2ab6e806bdd1829ab2f7f4cba327b844c2.tar.xz org.eclipse.papyrus-2fd1fc2ab6e806bdd1829ab2f7f4cba327b844c2.zip |
Bug 494921 - Improve the ElementTypesConfiguration framework to provide
ClientContext dependent advice execution ordering
Change-Id: I20eb9fc1fec583e94e919061acf622203e8000f4
7 files changed, 98 insertions, 82 deletions
diff --git a/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/providers/ElementTypesDetailsContentProvider.java b/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/providers/ElementTypesDetailsContentProvider.java index 2b919398f82..18829a02018 100644 --- a/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/providers/ElementTypesDetailsContentProvider.java +++ b/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/providers/ElementTypesDetailsContentProvider.java @@ -26,10 +26,27 @@ import org.eclipse.gmf.runtime.emf.type.core.SpecializationType; import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.papyrus.dev.types.utils.AdvicesComparator;
+import org.eclipse.papyrus.infra.types.core.utils.AdviceComparator;
public class ElementTypesDetailsContentProvider implements ITreeContentProvider {
+ String contextID;
+
+ String typeID;
+
+
+ /**
+ * @param contextID
+ * the contextID to set
+ */
+ public void setContextID(String contextID) {
+ this.contextID = contextID;
+ }
+
+ public void setTypeID(String typeID) {
+ this.typeID = typeID;
+ }
+
/**
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*
@@ -119,7 +136,7 @@ public class ElementTypesDetailsContentProvider implements ITreeContentProvider @Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof List<?>) {
- Collections.sort((List<IEditHelperAdvice>) parentElement, new AdvicesComparator());
+ Collections.sort((List<IEditHelperAdvice>) parentElement, new AdviceComparator(contextID));
return ((List<?>) parentElement).toArray();
}
diff --git a/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/utils/AdvicesComparator.java b/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/utils/AdvicesComparator.java deleted file mode 100644 index 781b4429dca..00000000000 --- a/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/utils/AdvicesComparator.java +++ /dev/null @@ -1,35 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2015 CEA LIST 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.dev.types.utils;
-
-import java.util.Comparator;
-
-import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
-
-
-public class AdvicesComparator implements Comparator<IEditHelperAdvice> {
-
- /**
- * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
- *
- * @param arg0
- * @param arg1
- * @return
- */
- @Override
- public int compare(IEditHelperAdvice o1, IEditHelperAdvice o2) {
- return o1.toString().compareTo(o2.toString());
- }
-
-}
diff --git a/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/view/RegistredElementTypesView.java b/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/view/RegistredElementTypesView.java index 37ee95d146c..627b3b86471 100644 --- a/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/view/RegistredElementTypesView.java +++ b/plugins/developer/org.eclipse.papyrus.dev.types/src/org/eclipse/papyrus/dev/types/view/RegistredElementTypesView.java @@ -44,6 +44,7 @@ public class RegistredElementTypesView extends ViewPart { SashForm sash = null;
FilteredTree elementTypesFilteredTree = null;
Combo combo = null;
+ ElementTypesDetailsContentProvider elementTypesDetailsContentProvider;
@Override
@@ -81,6 +82,7 @@ public class RegistredElementTypesView extends ViewPart { IClientContext clientContex = ClientContextManager.getInstance().getClientContext(clientContexId);
if (clientContex != null) {
IElementType[] elementTypes = ElementTypeRegistry.getInstance().getElementTypes(clientContex);
+ elementTypesDetailsContentProvider.setContextID(clientContex.getId());
elementTypesFilteredTree.getViewer().setInput(elementTypes);
}
}
@@ -102,7 +104,8 @@ public class RegistredElementTypesView extends ViewPart { elementTypesFilteredTree.getViewer().setContentProvider(new ElementTypesContentProvider());
detailsFilteredTree = new FilteredTree(sash, SWT.BORDER, new PatternFilter(), true);
detailsFilteredTree.getViewer().setLabelProvider(new ElementTypesDetailsLabelProvider());
- detailsFilteredTree.getViewer().setContentProvider(new ElementTypesDetailsContentProvider());
+ elementTypesDetailsContentProvider = new ElementTypesDetailsContentProvider();
+ detailsFilteredTree.getViewer().setContentProvider(elementTypesDetailsContentProvider);
if (index != -1) {
combo.select(index);
@@ -113,7 +116,11 @@ public class RegistredElementTypesView extends ViewPart { @Override
public void selectionChanged(SelectionChangedEvent event) {
if (event.getSelection() instanceof IStructuredSelection) {
- detailsFilteredTree.getViewer().setInput(((IStructuredSelection) event.getSelection()).getFirstElement());
+ Object selection = ((IStructuredSelection) event.getSelection()).getFirstElement();
+ if (selection instanceof IElementType) {
+ elementTypesDetailsContentProvider.setTypeID(((IElementType) selection).getId());
+ detailsFilteredTree.getViewer().setInput(selection);
+ }
}
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DefaultEditHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DefaultEditHelper.java index 62a32bb3bc2..9ea3d8d6c22 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DefaultEditHelper.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DefaultEditHelper.java @@ -25,6 +25,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.gmf.runtime.common.core.command.ICommand; import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry; +import org.eclipse.gmf.runtime.emf.type.core.IClientContext; import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor; import org.eclipse.gmf.runtime.emf.type.core.IEditHelperContext; import org.eclipse.gmf.runtime.emf.type.core.IElementType; @@ -340,35 +341,51 @@ public class DefaultEditHelper extends AbstractNotifierEditHelper { advices = (IEditHelperAdvice[]) contextMap.get(EditHelper_Advice); } } - } if (advices == null) { - if (editHelperContext instanceof EObject) { - // IElementType type = ElementTypeRegistry.getInstance().getElementType((EObject) editHelperContext, req.getClientContext()); - // advices = CacheRegistry.getInstance().getEditHelperAdvice(req.getClientContext(), type); advices = ElementTypeRegistry.getInstance().getEditHelperAdvice((EObject) editHelperContext, req.getClientContext()); + IElementType type = ElementTypeRegistry.getInstance().getElementType((EObject) editHelperContext, req.getClientContext()); + if (type != null) { + Arrays.sort(advices, new AdviceComparator(req.getClientContext().getId())); + } } else if (editHelperContext instanceof IElementType) { advices = CacheRegistry.getInstance().getEditHelperAdvice(req.getClientContext(), ((IElementType) editHelperContext)); + Arrays.sort(advices, new AdviceComparator(req.getClientContext().getId())); } else if (editHelperContext instanceof IEditHelperContext) { - IElementType type = ((IEditHelperContext) editHelperContext).getElementType(); - if (type != null) { - advices = CacheRegistry.getInstance().getEditHelperAdvice(req.getClientContext(), type); + IClientContext clientContext = ((IEditHelperContext) editHelperContext).getClientContext(); + IElementType elementType = ((IEditHelperContext) editHelperContext).getElementType(); + EObject eObject = ((IEditHelperContext) editHelperContext).getEObject(); + + if (clientContext != null) { + if (elementType != null) { + advices = CacheRegistry.getInstance().getEditHelperAdvice(req.getClientContext(), elementType); + Arrays.sort(advices, new AdviceComparator(req.getClientContext().getId())); + } else if (eObject != null) { + IElementType type = ElementTypeRegistry.getInstance().getElementType(eObject, req.getClientContext()); + if (type != null) { + advices = CacheRegistry.getInstance().getEditHelperAdvice(req.getClientContext(), type); + Arrays.sort(advices, new AdviceComparator(req.getClientContext().getId())); + } + } } else { - advices = ElementTypeRegistry.getInstance().getEditHelperAdvice(editHelperContext); + if (elementType != null) { + advices = CacheRegistry.getInstance().getEditHelperAdvice(req.getClientContext(), elementType); + Arrays.sort(advices, new AdviceComparator(req.getClientContext().getId())); + } else if (eObject != null) { + IElementType type = ElementTypeRegistry.getInstance().getElementType(eObject, req.getClientContext()); + if (type != null) { + advices = CacheRegistry.getInstance().getEditHelperAdvice(req.getClientContext(), type); + Arrays.sort(advices, new AdviceComparator(req.getClientContext().getId())); + } + } } - } else { - advices = ElementTypeRegistry.getInstance().getEditHelperAdvice(editHelperContext); } } - if(null != advices){ - Arrays.sort(advices, new AdviceComparator()); - } - return advices; } diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/ElementTypeSetConfigurationRegistry.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/ElementTypeSetConfigurationRegistry.java index 22136866b8a..5a02f86a778 100644 --- a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/ElementTypeSetConfigurationRegistry.java +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/registries/ElementTypeSetConfigurationRegistry.java @@ -66,7 +66,8 @@ public class ElementTypeSetConfigurationRegistry { /** Map of retrieved elementType sets, key is their identifier */ protected Map<String, Map<String, ElementTypeSetConfiguration>> elementTypeSetConfigurations = null; - protected OrientedGraph<String> advicesDeps = null; + /** Advice execution order dependencies per clientContextId per IElementType */ + protected Map<String, OrientedGraph<String>> advicesDeps = null; /** unique resource set to load all elementType sets models */ @@ -92,6 +93,7 @@ public class ElementTypeSetConfigurationRegistry { // 0. Resets values elementTypeSetConfigurationResourceSet = null; elementTypeSetConfigurations = new HashMap<String, Map<String, ElementTypeSetConfiguration>>(); + advicesDeps = new HashMap<String, OrientedGraph<String>>(); // 1. creates the resource set elementTypeSetConfigurationResourceSet = createResourceSet(); // 2. creates the list only when registry is acceded for the first time, @@ -165,11 +167,13 @@ public class ElementTypeSetConfigurationRegistry { return loadElementTypeSetConfigurations(clientContextID, Collections.singleton(elementTypeSetConfiguration)); } - public OrientedGraph<String> getAdvicesDeps() { - if (advicesDeps == null) { - advicesDeps = new OrientedGraph<>(); + public OrientedGraph<String> getAdvicesDeps(String clientContextID) { + OrientedGraph<String> dependencies = advicesDeps.get(clientContextID); + if (dependencies == null) { + dependencies = new OrientedGraph<String>(); + advicesDeps.put(clientContextID, dependencies); } - return advicesDeps; + return dependencies; } protected boolean isAlreadyRegistred(String elementTypeID, IClientContext context) { @@ -323,8 +327,8 @@ public class ElementTypeSetConfigurationRegistry { } // Check that there is no cyclic dependencies among advices introduced by this loading - advicesDeps = TypesConfigurationsCycleUtil.getDependenciesAmongAdvices(adviceToCheck); - Collection<Collection<Object>> cyclesAdvices = TypesConfigurationsCycleUtil.getCyclesInAdvices(advicesDeps.getVertices(), advicesDeps.getEdges()); + OrientedGraph<String> deps = TypesConfigurationsCycleUtil.getDependenciesAmongAdvices(adviceToCheck); + Collection<Collection<Object>> cyclesAdvices = TypesConfigurationsCycleUtil.getCyclesInAdvices(deps.getVertices(), deps.getEdges()); if (!cyclesAdvices.isEmpty()) { Activator.log.warn("The ElementTypesConfiguration registration has been aborted because there is at least a cyclic-dependencies in the Advices definitions: " + cyclesAdvices); return false; @@ -357,6 +361,9 @@ public class ElementTypeSetConfigurationRegistry { } } + // Store the advicesDependencies + advicesDeps.put(contexId, deps); + return true; } @@ -421,7 +428,8 @@ public class ElementTypeSetConfigurationRegistry { } } - advicesDeps = TypesConfigurationsCycleUtil.getDependenciesAmongAdvices(advices); + OrientedGraph<String> deps = TypesConfigurationsCycleUtil.getDependenciesAmongAdvices(advices); + advicesDeps.put(contextId, deps); return true; } diff --git a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/AdviceComparator.java b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/AdviceComparator.java index 5f8c3befd49..43bbcc5f2f8 100644 --- a/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/AdviceComparator.java +++ b/plugins/infra/types/org.eclipse.papyrus.infra.types.core/src/org/eclipse/papyrus/infra/types/core/utils/AdviceComparator.java @@ -21,14 +21,16 @@ import org.eclipse.papyrus.infra.types.core.registries.ElementTypeSetConfigurati public class AdviceComparator implements Comparator<IEditHelperAdvice> {
- OrientedGraph<String> dependencies;
+ protected OrientedGraph<String> dependencies;
- public AdviceComparator() {
- this.dependencies = ElementTypeSetConfigurationRegistry.getInstance().getAdvicesDeps();
+
+ public AdviceComparator(String contextId) {
+ this.dependencies = ElementTypeSetConfigurationRegistry.getInstance().getAdvicesDeps(contextId);
}
@Override
public int compare(IEditHelperAdvice arg0, IEditHelperAdvice arg1) {
+
String arg0Name = arg0.getClass().getName();
String arg1Name = arg1.getClass().getName();
if (dependencies.getEdges().containsKey(arg0Name)) {
diff --git a/tests/junit/plugins/infra/types/org.eclipse.papyrus.infra.types.tests/src/org/eclipse/papyrus/infra/types/tests/ElementEditHelperAdviceTests.java b/tests/junit/plugins/infra/types/org.eclipse.papyrus.infra.types.tests/src/org/eclipse/papyrus/infra/types/tests/ElementEditHelperAdviceTests.java index 6f910601feb..4aa4f5f723c 100644 --- a/tests/junit/plugins/infra/types/org.eclipse.papyrus.infra.types.tests/src/org/eclipse/papyrus/infra/types/tests/ElementEditHelperAdviceTests.java +++ b/tests/junit/plugins/infra/types/org.eclipse.papyrus.infra.types.tests/src/org/eclipse/papyrus/infra/types/tests/ElementEditHelperAdviceTests.java @@ -256,29 +256,29 @@ public class ElementEditHelperAdviceTests extends AbstractElementTypeTests imple try {
ElementTypeSetConfigurationRegistry.getInstance().loadElementTypeSetConfiguration(TypeContext.getContext().getId(), (ElementTypeSetConfiguration) root);
+ IEditHelperAdvice[] advicesAfterLoading = ElementTypeRegistry.getInstance().getEditHelperAdvice(classElementType);
+ Arrays.sort(advicesAfterLoading, new AdviceComparator(TypeContext.getContext().getId()));
+ int advice1Index = -1;
+ int advice2Index = -1;
+ int advice3Index = -1;
+ for (int i = 0; i < advicesAfterLoading.length; i++) {
+ IEditHelperAdvice iEditHelperAdvice = advicesAfterLoading[i];
+ if (iEditHelperAdvice.getClass().getName().equals(ADVICES_ID_1)) {
+ advice1Index = i;
+ } else if (iEditHelperAdvice.getClass().getName().equals(ADVICES_ID_2)) {
+ advice2Index = i;
+ } else if (iEditHelperAdvice.getClass().getName().equals(ADVICES_ID_3)) {
+ advice3Index = i;
+ }
+ }
+
+ Assert.assertTrue(ADVICES_ID_2 + " should be after " + ADVICES_ID_3, advice3Index < advice2Index);
+ Assert.assertTrue(ADVICES_ID_3 + " should be after " + ADVICES_ID_1, advice2Index < advice1Index);
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
- IEditHelperAdvice[] advicesAfterLoading = ElementTypeRegistry.getInstance().getEditHelperAdvice(classElementType);
- Arrays.sort(advicesAfterLoading, new AdviceComparator());
-
- int advice1Index = -1;
- int advice2Index = -1;
- int advice3Index = -1;
- for (int i = 0; i < advicesAfterLoading.length; i++) {
- IEditHelperAdvice iEditHelperAdvice = advicesAfterLoading[i];
- if (iEditHelperAdvice.getClass().getName().equals(ADVICES_ID_1)) {
- advice1Index = i;
- } else if (iEditHelperAdvice.getClass().getName().equals(ADVICES_ID_2)) {
- advice2Index = i;
- } else if (iEditHelperAdvice.getClass().getName().equals(ADVICES_ID_3)) {
- advice3Index = i;
- }
- }
- Assert.assertTrue(ADVICES_ID_2 + " should be after " + ADVICES_ID_3, advice3Index < advice2Index);
- Assert.assertTrue(ADVICES_ID_3 + " should be after " + ADVICES_ID_1, advice2Index < advice1Index);
} else {
Assert.fail("Failed to load test model: " + CYCLIC_ADVICES_CONFIGURATIONS);
}
|