diff options
author | Tobias Schwarz | 2012-09-07 07:08:41 +0000 |
---|---|---|
committer | Tobias Schwarz | 2012-09-07 07:08:41 +0000 |
commit | 8caf3f676c4b798261b2b08221979a6241abd505 (patch) | |
tree | 2194408aeb68cac103830a33a48f06c3752e1a75 /target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org | |
parent | 273d388e48375604e04d4ab8ac98e92cc0fb9dc4 (diff) | |
download | org.eclipse.tcf-8caf3f676c4b798261b2b08221979a6241abd505.tar.gz org.eclipse.tcf-8caf3f676c4b798261b2b08221979a6241abd505.tar.xz org.eclipse.tcf-8caf3f676c4b798261b2b08221979a6241abd505.zip |
Target Explorer: add overwrite possibility to persistence delegate
binding
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org')
2 files changed, 83 insertions, 72 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBinding.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBinding.java index 7cf2390d0..f1ab0b6e2 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBinding.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBinding.java @@ -25,6 +25,8 @@ public class PersistenceDelegateBinding extends ExecutableExtension { private Expression expression; // The binding priority private String priority; + // The overwrite + private String overwrites; /* (non-Javadoc) * @see org.eclipse.tcf.te.runtime.extensions.ExecutableExtension#doSetInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object) @@ -36,19 +38,20 @@ public class PersistenceDelegateBinding extends ExecutableExtension { // Initialize the delegate id field by reading the <delegate> extension attribute. // Throws an exception if the id is empty or null. delegateId = config != null ? config.getAttribute("delegateId") : null; //$NON-NLS-1$ - if (delegateId == null || "".equals(delegateId.trim())) { //$NON-NLS-1$ + if (delegateId == null || "".equals(delegateId.trim())) //$NON-NLS-1$ throw createMissingMandatoryAttributeException("delegateId", config.getContributor().getName()); //$NON-NLS-1$ - } // Initialize the priority field priority = config != null ? config.getAttribute("priority") : null; //$NON-NLS-1$ + // Initialize the overwrite field + overwrites = config != null ? config.getAttribute("overwrite") : null; //$NON-NLS-1$ + // Read the sub elements of the extension IConfigurationElement[] children = config != null ? config.getChildren() : null; // The "enablement" element is the only expected one - if (children != null && children.length > 0) { + if (children != null && children.length > 0) expression = ExpressionConverter.getDefault().perform(children[0]); - } } /** @@ -70,6 +73,15 @@ public class PersistenceDelegateBinding extends ExecutableExtension { } /** + * Returns the overwrite(s) of this binding. + * + * @return The overwrite(s) or <code>null</code>. + */ + public String[] getOverwrites() { + return overwrites != null && overwrites.trim().length() > 0 ? overwrites.trim().split("\\s*,\\s*") : null; //$NON-NLS-1$ + } + + /** * Returns the enablement expression which is associated with this binding. * * @return The enablement expression or <code>null</code>. diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java index 72b25d049..beb37117b 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java @@ -10,6 +10,7 @@ package org.eclipse.tcf.te.runtime.persistence.internal; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -108,49 +109,49 @@ public class PersistenceDelegateBindingExtensionPointManager extends AbstractExt // The binding is applicable by default if no expression is specified. boolean isApplicable = enablement == null; - if (enablement != null) { - if (context != null) { - // Set the default variable to the delegate context. - EvaluationContext evalContext = new EvaluationContext(null, context); - evalContext.addVariable("context", context); //$NON-NLS-1$ - if (context instanceof Class) { - evalContext.addVariable("contextClass", ((Class<?>)context).getName()); //$NON-NLS-1$ - } - else { - evalContext.addVariable("contextClass", context.getClass().getName()); //$NON-NLS-1$ - } - evalContext.addVariable("container", container); //$NON-NLS-1$ - if (container instanceof Class) { - evalContext.addVariable("containerClass", ((Class<?>)container).getName()); //$NON-NLS-1$ - } - else { - evalContext.addVariable("containerClass", container.getClass().getName()); //$NON-NLS-1$ - } - // Allow plugin activation - evalContext.setAllowPluginActivation(true); - // Evaluate the expression - try { - isApplicable = enablement.evaluate(evalContext).equals(EvaluationResult.TRUE); - } catch (CoreException e) { - IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), - e.getLocalizedMessage(), e); - Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status); - } - } else { - // The enablement is false by definition if no delegate context is given. - isApplicable = false; + if (enablement != null) if (context != null) { + // Set the default variable to the delegate context. + EvaluationContext evalContext = new EvaluationContext(null, context); + evalContext.addVariable("context", context); //$NON-NLS-1$ + if (context instanceof Class) evalContext.addVariable("contextClass", ((Class<?>)context).getName()); //$NON-NLS-1$ + else evalContext.addVariable("contextClass", context.getClass().getName()); //$NON-NLS-1$ + evalContext.addVariable("container", container); //$NON-NLS-1$ + if (container instanceof Class) evalContext.addVariable("containerClass", ((Class<?>)container).getName()); //$NON-NLS-1$ + else evalContext.addVariable("containerClass", container.getClass().getName()); //$NON-NLS-1$ + // Allow plugin activation + evalContext.setAllowPluginActivation(true); + // Evaluate the expression + try { + isApplicable = enablement.evaluate(evalContext).equals(EvaluationResult.TRUE); + } catch (CoreException e) { + IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), + e.getLocalizedMessage(), e); + Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status); } } + else // The enablement is false by definition if no delegate context is given. + isApplicable = false; // Add the binding if applicable - if (isApplicable) { - applicable.add(binding); - } + if (isApplicable) applicable.add(binding); } // Sort the applicable bindings by priority Collections.sort(applicable, new SortByPriority()); + if (applicable.size() > 1) { + List<PersistenceDelegateBinding> overwritten = new ArrayList<PersistenceDelegateBinding>(); + for (PersistenceDelegateBinding candidate : applicable) + for (PersistenceDelegateBinding overwriter : applicable) { + String[] overwrites = overwriter.getOverwrites(); + if (overwrites != null && Arrays.asList(overwrites).contains(candidate.getId())) + overwritten.add(candidate); + } + + for (PersistenceDelegateBinding toRemove : overwritten) + applicable.remove(toRemove); + } + return applicable.toArray(new PersistenceDelegateBinding[applicable.size()]); } @@ -162,37 +163,37 @@ public class PersistenceDelegateBindingExtensionPointManager extends AbstractExt /* (non-Javadoc) * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ - @Override - public int compare(PersistenceDelegateBinding o1, PersistenceDelegateBinding o2) { - - if (o1 != null && o2 != null) { - String p1 = o1.getPriority(); - if (p1 == null || "".equals(p1)) p1 = "normal"; //$NON-NLS-1$ //$NON-NLS-2$ - String p2 = o2.getPriority(); - if (p2 == null || "".equals(p1)) p2 = "normal"; //$NON-NLS-1$ //$NON-NLS-2$ - - int i1 = 0; - if ("lowest".equalsIgnoreCase(p1)) i1 = -3; //$NON-NLS-1$ - if ("lower".equalsIgnoreCase(p1)) i1 = -2; //$NON-NLS-1$ - if ("low".equalsIgnoreCase(p1)) i1 = -1; //$NON-NLS-1$ - if ("high".equalsIgnoreCase(p1)) i1 = 1; //$NON-NLS-1$ - if ("higher".equalsIgnoreCase(p1)) i1 = 2; //$NON-NLS-1$ - if ("highest".equalsIgnoreCase(p1)) i1 = 3; //$NON-NLS-1$ - - int i2 = 0; - if ("lowest".equalsIgnoreCase(p2)) i2 = -3; //$NON-NLS-1$ - if ("lower".equalsIgnoreCase(p2)) i2 = -2; //$NON-NLS-1$ - if ("low".equalsIgnoreCase(p2)) i2 = -1; //$NON-NLS-1$ - if ("high".equalsIgnoreCase(p2)) i2 = 1; //$NON-NLS-1$ - if ("higher".equalsIgnoreCase(p2)) i2 = 2; //$NON-NLS-1$ - if ("highest".equalsIgnoreCase(p2)) i2 = 3; //$NON-NLS-1$ - - if (i1 < i2) return 1; - if (i1 > i2) return -1; - } - - return 0; - } + @Override + public int compare(PersistenceDelegateBinding o1, PersistenceDelegateBinding o2) { + + if (o1 != null && o2 != null) { + String p1 = o1.getPriority(); + if (p1 == null || "".equals(p1)) p1 = "normal"; //$NON-NLS-1$ //$NON-NLS-2$ + String p2 = o2.getPriority(); + if (p2 == null || "".equals(p1)) p2 = "normal"; //$NON-NLS-1$ //$NON-NLS-2$ + + int i1 = 0; + if ("lowest".equalsIgnoreCase(p1)) i1 = -3; //$NON-NLS-1$ + if ("lower".equalsIgnoreCase(p1)) i1 = -2; //$NON-NLS-1$ + if ("low".equalsIgnoreCase(p1)) i1 = -1; //$NON-NLS-1$ + if ("high".equalsIgnoreCase(p1)) i1 = 1; //$NON-NLS-1$ + if ("higher".equalsIgnoreCase(p1)) i1 = 2; //$NON-NLS-1$ + if ("highest".equalsIgnoreCase(p1)) i1 = 3; //$NON-NLS-1$ + + int i2 = 0; + if ("lowest".equalsIgnoreCase(p2)) i2 = -3; //$NON-NLS-1$ + if ("lower".equalsIgnoreCase(p2)) i2 = -2; //$NON-NLS-1$ + if ("low".equalsIgnoreCase(p2)) i2 = -1; //$NON-NLS-1$ + if ("high".equalsIgnoreCase(p2)) i2 = 1; //$NON-NLS-1$ + if ("higher".equalsIgnoreCase(p2)) i2 = 2; //$NON-NLS-1$ + if ("highest".equalsIgnoreCase(p2)) i2 = 3; //$NON-NLS-1$ + + if (i1 < i2) return 1; + if (i1 > i2) return -1; + } + + return 0; + } } /** @@ -205,9 +206,7 @@ public class PersistenceDelegateBindingExtensionPointManager extends AbstractExt Collection<ExecutableExtensionProxy<PersistenceDelegateBinding>> persistenceDelegateBindings = getExtensions().values(); for (ExecutableExtensionProxy<PersistenceDelegateBinding> persistenceDelegateBinding : persistenceDelegateBindings) { PersistenceDelegateBinding instance = persistenceDelegateBinding.getInstance(); - if (instance != null && !contributions.contains(instance)) { - contributions.add(instance); - } + if (instance != null && !contributions.contains(instance)) contributions.add(instance); } return contributions.toArray(new PersistenceDelegateBinding[contributions.size()]); |