Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2011-10-18 11:06:20 -0400
committerUwe Stieber2011-10-18 11:06:20 -0400
commitfff238bb207b1bb78b1da0901c368fc7fb2709b9 (patch)
tree6431bb181de545124aee5e7668a1abe8c688934b
parent2e4b42ff5c84c9566b5b0c0c018e55977dc0f106 (diff)
downloadorg.eclipse.tcf-fff238bb207b1bb78b1da0901c368fc7fb2709b9.tar.gz
org.eclipse.tcf-fff238bb207b1bb78b1da0901c368fc7fb2709b9.tar.xz
org.eclipse.tcf-fff238bb207b1bb78b1da0901c368fc7fb2709b9.zip
Target Explorer: Complete the enablement evaluation for launcher delegates
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.tcf.terminals.ui/META-INF/MANIFEST.MF1
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.tcf.terminals.ui/plugin.xml8
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals/plugin.xml15
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/interfaces/ILauncherDelegate.java8
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/internal/PropertyTester.java34
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/internal/dialogs/LaunchTerminalSettingsDialog.java2
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/launcher/AbstractLauncherDelegate.java28
-rw-r--r--target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/launcher/LauncherDelegateManager.java54
8 files changed, 149 insertions, 1 deletions
diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.terminals.ui/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tm.te.tcf.terminals.ui/META-INF/MANIFEST.MF
index 438225cf7..634cdd15d 100644
--- a/target_explorer/plugins/org.eclipse.tm.te.tcf.terminals.ui/META-INF/MANIFEST.MF
+++ b/target_explorer/plugins/org.eclipse.tm.te.tcf.terminals.ui/META-INF/MANIFEST.MF
@@ -6,6 +6,7 @@ Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.eclipse.tm.te.tcf.terminals.ui.activator.UIPlugin
Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
+ org.eclipse.core.expressions;bundle-version="3.4.300",
org.eclipse.ui;bundle-version="3.7.0",
org.eclipse.ui.forms;bundle-version="3.5.100",
org.eclipse.tm.te.runtime;bundle-version="1.0.0",
diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.terminals.ui/plugin.xml b/target_explorer/plugins/org.eclipse.tm.te.tcf.terminals.ui/plugin.xml
index 634e7e919..4493100a9 100644
--- a/target_explorer/plugins/org.eclipse.tm.te.tcf.terminals.ui/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tm.te.tcf.terminals.ui/plugin.xml
@@ -7,6 +7,14 @@
class="org.eclipse.tm.te.tcf.terminals.ui.launcher.LauncherDelegate"
id="org.eclipse.tm.te.ui.terminals.launcher.tcf"
label="%launcherDelegate.label">
+ <enablement>
+ <with variable="selection">
+ <count value="1"/>
+ <iterate operator="and" ifEmpty="false">
+ <instanceof value="org.eclipse.tm.te.tcf.locator.interfaces.nodes.IPeerModel"/>
+ </iterate>
+ </with>
+ </enablement>
</delegate>
</extension>
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/plugin.xml b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/plugin.xml
index 5c80e9455..dd766873e 100644
--- a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/plugin.xml
@@ -44,6 +44,16 @@
<initializer class="org.eclipse.tm.te.ui.terminals.internal.PreferenceInitializer"/>
</extension>
+<!-- Eclipse core expressions property tester -->
+ <extension point="org.eclipse.core.expressions.propertyTesters">
+ <propertyTester
+ class="org.eclipse.tm.te.ui.terminals.internal.PropertyTester"
+ id="org.eclipse.tm.te.ui.terminals.PropertyTester"
+ namespace="org.eclipse.tm.te.ui.terminals"
+ properties="hasApplicableLauncherDelegates"
+ type="java.lang.Object">
+ </propertyTester>
+ </extension>
<!-- Service contributions -->
<extension point="org.eclipse.tm.te.runtime.services.services">
@@ -80,6 +90,11 @@
label="%command.launch.label"
style="push"
tooltip="%command.launch.tooltip">
+ <visibleWhen checkEnabled="false">
+ <with variable="selection">
+ <test property="org.eclipse.tm.te.ui.terminals.hasApplicableLauncherDelegates" value="true"/>
+ </with>
+ </visibleWhen>
</command>
</menuContribution>
</extension>
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/interfaces/ILauncherDelegate.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/interfaces/ILauncherDelegate.java
index 8d6d17360..55ed14e52 100644
--- a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/interfaces/ILauncherDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/interfaces/ILauncherDelegate.java
@@ -9,6 +9,7 @@
*******************************************************************************/
package org.eclipse.tm.te.ui.terminals.interfaces;
+import org.eclipse.core.expressions.Expression;
import org.eclipse.tm.te.runtime.interfaces.callback.ICallback;
import org.eclipse.tm.te.runtime.interfaces.extensions.IExecutableExtension;
import org.eclipse.tm.te.runtime.interfaces.properties.IPropertiesContainer;
@@ -21,6 +22,13 @@ import org.eclipse.tm.te.ui.controls.interfaces.IWizardConfigurationPanel;
public interface ILauncherDelegate extends IExecutableExtension {
/**
+ * Returns the enablement expression.
+ *
+ * @return The enablement expression or <code>null</code>.
+ */
+ public Expression getEnablement();
+
+ /**
* Returns the configuration panel instance to present to the
* user. The instance must be always the same on subsequent calls
* until disposed.
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/internal/PropertyTester.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/internal/PropertyTester.java
new file mode 100644
index 000000000..545802bb1
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/internal/PropertyTester.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.tm.te.ui.terminals.internal;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.tm.te.ui.terminals.launcher.LauncherDelegateManager;
+
+
+/**
+ * Terminals property tester implementation.
+ */
+public class PropertyTester extends org.eclipse.core.expressions.PropertyTester {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
+ */
+ @Override
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if ("hasApplicableLauncherDelegates".equals(property)) { //$NON-NLS-1$
+ ISelection selection = receiver instanceof ISelection ? (ISelection)receiver : new StructuredSelection(receiver);
+ return expectedValue.equals(Boolean.valueOf(LauncherDelegateManager.getInstance().getApplicableLauncherDelegates(selection).length > 0));
+ }
+ return false;
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/internal/dialogs/LaunchTerminalSettingsDialog.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/internal/dialogs/LaunchTerminalSettingsDialog.java
index 451881f41..7f2f014b0 100644
--- a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/internal/dialogs/LaunchTerminalSettingsDialog.java
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/internal/dialogs/LaunchTerminalSettingsDialog.java
@@ -197,7 +197,7 @@ public class LaunchTerminalSettingsDialog extends CustomTrayDialog {
List<String> items = new ArrayList<String>();
- ILauncherDelegate[] delegates = LauncherDelegateManager.getInstance().getLauncherDelegates(false);
+ ILauncherDelegate[] delegates = LauncherDelegateManager.getInstance().getApplicableLauncherDelegates(selection);
for (ILauncherDelegate delegate : delegates) {
String label = delegate.getLabel();
if (label == null || "".equals(label.trim())) label = delegate.getId(); //$NON-NLS-1$
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/launcher/AbstractLauncherDelegate.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/launcher/AbstractLauncherDelegate.java
index c339eb404..253977a19 100644
--- a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/launcher/AbstractLauncherDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/launcher/AbstractLauncherDelegate.java
@@ -9,6 +9,10 @@
*******************************************************************************/
package org.eclipse.tm.te.ui.terminals.launcher;
+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.tm.te.runtime.extensions.ExecutableExtension;
import org.eclipse.tm.te.ui.terminals.interfaces.ILauncherDelegate;
@@ -16,5 +20,29 @@ import org.eclipse.tm.te.ui.terminals.interfaces.ILauncherDelegate;
* Abstract launcher delegate implementation.
*/
public abstract class AbstractLauncherDelegate extends ExecutableExtension implements ILauncherDelegate {
+ // The converted expression
+ private Expression expression;
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.runtime.extensions.ExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
+ */
+ @Override
+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
+ super.setInitializationData(config, propertyName, data);
+
+ // 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]);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tm.te.ui.terminals.interfaces.ILauncherDelegate#getEnablement()
+ */
+ @Override
+ public Expression getEnablement() {
+ return expression;
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/launcher/LauncherDelegateManager.java b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/launcher/LauncherDelegateManager.java
index 50bbf06a0..384de99b1 100644
--- a/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/launcher/LauncherDelegateManager.java
+++ b/target_explorer/plugins/org.eclipse.tm.te.ui.terminals/src/org/eclipse/tm/te/ui/terminals/launcher/LauncherDelegateManager.java
@@ -13,9 +13,18 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import org.eclipse.core.expressions.EvaluationContext;
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.ISelection;
import org.eclipse.tm.te.runtime.extensions.AbstractExtensionPointManager;
import org.eclipse.tm.te.runtime.extensions.ExecutableExtensionProxy;
+import org.eclipse.tm.te.ui.terminals.activator.UIPlugin;
import org.eclipse.tm.te.ui.terminals.interfaces.ILauncherDelegate;
+import org.eclipse.ui.ISources;
/**
* Terminal launcher delegate manager implementation.
@@ -99,4 +108,49 @@ public class LauncherDelegateManager extends AbstractExtensionPointManager<ILaun
return contribution;
}
+
+ /**
+ * Returns the applicable terminal launcher delegates for the given selection.
+ *
+ * @param selection The selection or <code>null</code>.
+ * @return The list of applicable terminal launcher delegates or an empty array.
+ */
+ public ILauncherDelegate[] getApplicableLauncherDelegates(ISelection selection) {
+ List<ILauncherDelegate> applicable = new ArrayList<ILauncherDelegate>();
+
+ for (ILauncherDelegate delegate : getLauncherDelegates(false)) {
+ Expression enablement = delegate.getEnablement();
+
+ // The launcher delegate is applicable by default if
+ // no expression is specified.
+ boolean isApplicable = enablement == null;
+
+ if (enablement != null) {
+ if (selection != null) {
+ // Set the default variable to selection.
+ EvaluationContext context = new EvaluationContext(null, selection);
+ // Set the "selection" variable to the selection.
+ context.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
+ // Evaluate the expression
+ try {
+ isApplicable = enablement.evaluate(context).equals(EvaluationResult.TRUE);
+ } catch (CoreException e) {
+ IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(),
+ e.getLocalizedMessage(), e);
+ UIPlugin.getDefault().getLog().log(status);
+ }
+ } else {
+ // The enablement is false by definition if
+ // there is no selection.
+ isApplicable = false;
+ }
+ }
+
+ // Add the page if applicable
+ if (isApplicable) applicable.add(delegate);
+ }
+
+ return applicable.toArray(new ILauncherDelegate[applicable.size()]);
+ }
+
}

Back to the top