Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2012-09-03 07:09:40 -0400
committerUwe Stieber2012-09-03 07:09:40 -0400
commit6bd5e0dd5737805c1485034c639a74bd04bd689e (patch)
treea90fea2f080395b93164e99b7880b81af61f9f8f /target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence
parent1928fde3fd9fe25968628e5c5240af64b91a7374 (diff)
downloadorg.eclipse.tcf-6bd5e0dd5737805c1485034c639a74bd04bd689e.tar.gz
org.eclipse.tcf-6bd5e0dd5737805c1485034c639a74bd04bd689e.tar.xz
org.eclipse.tcf-6bd5e0dd5737805c1485034c639a74bd04bd689e.zip
Target Explorer: Persistence bindings can have a priority
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBinding.java146
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/internal/PersistenceDelegateBindingExtensionPointManager.java46
2 files changed, 126 insertions, 66 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 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 <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$
- 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 <code>null</code>.
- */
- 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 <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$
+ 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 <code>null</code>.
+ */
+ public String getPriority() {
+ return priority;
+ }
+
+ /**
+ * Returns the enablement expression which is associated with this binding.
+ *
+ * @return The enablement expression or <code>null</code>.
+ */
+ 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,10 +148,54 @@ 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<PersistenceDelegateBinding> {
+
+ /* (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.
*
* @return The list of contributed persistence delegate bindings, or an empty array.

Back to the top