From 6bd5e0dd5737805c1485034c639a74bd04bd689e Mon Sep 17 00:00:00 2001 From: Uwe Stieber Date: Mon, 3 Sep 2012 13:09:40 +0200 Subject: Target Explorer: Persistence bindings can have a priority --- .../internal/PersistenceDelegateBinding.java | 146 +++++++++++---------- ...stenceDelegateBindingExtensionPointManager.java | 46 +++++++ 2 files changed, 126 insertions(+), 66 deletions(-) (limited to 'target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence') 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 9d3bfc863..7cf2390d0 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 @@ -1,66 +1,80 @@ -/******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. 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: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.tcf.te.runtime.persistence.internal; - -import org.eclipse.core.expressions.Expression; -import org.eclipse.core.expressions.ExpressionConverter; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.tcf.te.runtime.extensions.ExecutableExtension; - -/** - * Persistence delegate binding implementation. - */ -public class PersistenceDelegateBinding extends ExecutableExtension { - // The mandatory delegate identifier - private String delegateId; - // The converted expression - private Expression expression; - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.runtime.extensions.ExecutableExtension#doSetInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object) - */ - @Override - public void doSetInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { - super.doSetInitializationData(config, propertyName, data); - - // Initialize the delegate id field by reading the 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$ - throw createMissingMandatoryAttributeException("delegateId", config.getContributor().getName()); //$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) { - expression = ExpressionConverter.getDefault().perform(children[0]); - } - } - - /** - * Returns the delegate id which is associated with this binding. - * - * @return The delegate id. - */ - public String getDelegateId() { - return delegateId; - } - - /** - * Returns the enablement expression which is associated with this binding. - * - * @return The enablement expression or null. - */ - public Expression getEnablement() { - return expression; - } -} +/******************************************************************************* + * Copyright (c) 2011, 2012 Wind River Systems, Inc. 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.runtime.persistence.internal; + +import org.eclipse.core.expressions.Expression; +import org.eclipse.core.expressions.ExpressionConverter; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.tcf.te.runtime.extensions.ExecutableExtension; + +/** + * Persistence delegate binding implementation. + */ +public class PersistenceDelegateBinding extends ExecutableExtension { + // The mandatory delegate identifier + private String delegateId; + // The converted expression + private Expression expression; + // The binding priority + private String priority; + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.extensions.ExecutableExtension#doSetInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object) + */ + @Override + public void doSetInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { + super.doSetInitializationData(config, propertyName, data); + + // Initialize the delegate id field by reading the 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$ + throw createMissingMandatoryAttributeException("delegateId", config.getContributor().getName()); //$NON-NLS-1$ + } + + // Initialize the priority field + priority = config != null ? config.getAttribute("priority") : 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) { + expression = ExpressionConverter.getDefault().perform(children[0]); + } + } + + /** + * Returns the delegate id which is associated with this binding. + * + * @return The delegate id. + */ + public String getDelegateId() { + return delegateId; + } + + /** + * Returns the priority of this binding. + * + * @return The priority or null. + */ + public String getPriority() { + return priority; + } + + /** + * Returns the enablement expression which is associated with this binding. + * + * @return The enablement expression or null. + */ + public Expression getEnablement() { + return expression; + } +} 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 2e25b1cc1..72b25d049 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 @@ -11,6 +11,8 @@ package org.eclipse.tcf.te.runtime.persistence.internal; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import org.eclipse.core.expressions.EvaluationContext; @@ -146,9 +148,53 @@ public class PersistenceDelegateBindingExtensionPointManager extends AbstractExt } } + // Sort the applicable bindings by priority + Collections.sort(applicable, new SortByPriority()); + return applicable.toArray(new PersistenceDelegateBinding[applicable.size()]); } + /** + * Persistence delegate binding sort by priority comparator implementation. + */ + /* default */ static class SortByPriority implements Comparator { + + /* (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; + } + } + /** * Returns the list of all contributed persistence delegate bindings. * -- cgit v1.2.3