From b4954feb594b8659a1553f0464bdae866fdbfb3a Mon Sep 17 00:00:00 2001 From: Uwe Stieber Date: Tue, 2 Oct 2012 12:31:54 +0200 Subject: Target Explorer: Bug 377506 - [UI] "Show In > Properties" is visible for category nodes --- .../runtime/services/interfaces/IMenuService.java | 29 +++++++++++++++ .../internal/MenuServicePropertyTester.java | 42 ++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/interfaces/IMenuService.java create mode 100644 target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/internal/MenuServicePropertyTester.java (limited to 'target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src') diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/interfaces/IMenuService.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/interfaces/IMenuService.java new file mode 100644 index 000000000..7b8da18c1 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/interfaces/IMenuService.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 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.services.interfaces; + +/** + * Menu services. + *
+ * Allows to control specific menu contributions for a selection.
+ */
+public interface IMenuService extends IService {
+
+ /**
+ * Tests if or if not the menu contribution identified by the given id is
+ * visible for the given context.
+ *
+ * @param context The context. Must be not null
.
+ * @param contributionID The contribution ID. Must be not null
.
+ *
+ * @return True
if the contribution is visible, false
otherwise.
+ */
+ public boolean isVisible(Object context, String contributionID);
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/internal/MenuServicePropertyTester.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/internal/MenuServicePropertyTester.java
new file mode 100644
index 000000000..6c2f9e8f7
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.services/src/org/eclipse/tcf/te/runtime/services/internal/MenuServicePropertyTester.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.tcf.te.runtime.services.internal;
+
+import org.eclipse.tcf.te.runtime.services.ServiceManager;
+import org.eclipse.tcf.te.runtime.services.interfaces.IMenuService;
+
+
+/**
+ * Services plug-in property tester implementation.
+ */
+public class MenuServicePropertyTester 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) {
+ // Get the menu service instance for the given receiver
+ IMenuService service = ServiceManager.getInstance().getService(receiver, IMenuService.class);
+ if (service != null) {
+
+ // "isVisible": Checks if a given menu contribution shall be visible for the given receiver.
+ if ("isVisible".equals(property)) { //$NON-NLS-1$
+ // The menu contribution ID is the first argument
+ String contributionID = args.length > 0 && args[0] instanceof String ? (String)args[0] : null;
+ boolean isVisible = service.isVisible(receiver, contributionID);
+ return expectedValue instanceof Boolean ? ((Boolean)expectedValue).booleanValue() == isVisible : false;
+ }
+ }
+
+ return false;
+ }
+
+}
--
cgit v1.2.3