[304559] Need extensible mechanism to override menu enablement in WTP
diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.wst.common.frameworks.ui/META-INF/MANIFEST.MF
index 4162f10..4a9fe89 100644
--- a/plugins/org.eclipse.wst.common.frameworks.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.wst.common.frameworks.ui/META-INF/MANIFEST.MF
@@ -17,6 +17,7 @@
org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,2.0.0)";visibility:=reexport,
org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.wst.common.environment;bundle-version="[1.0.200,2.0.0)",
- org.eclipse.wst.common.core;bundle-version="[1.2.0,2.0.0)"
+ org.eclipse.wst.common.core;bundle-version="[1.2.0,2.0.0)",
+ org.eclipse.core.expressions;bundle-version="[3.4.100,4.0.0)"
Eclipse-LazyStart: true
Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/plugin.xml b/plugins/org.eclipse.wst.common.frameworks.ui/plugin.xml
index 6301a00..d40590f 100644
--- a/plugins/org.eclipse.wst.common.frameworks.ui/plugin.xml
+++ b/plugins/org.eclipse.wst.common.frameworks.ui/plugin.xml
@@ -7,7 +7,21 @@
<extension-point id="extendableWizard" name="%Extendable_Wizard" schema="schema/extendableWizard.exsd"/>
<extension-point id="wizardPageGroup" name="%Extendable_Wizard_Page" schema="schema/extendableWizardPage.exsd"/>
<extension-point id="DataModelWizardExtension" name="%DataModelWizard" schema="schema/DataModelWizardExtension.exsd"/>
-
+
+ <extension-point id="MenuEnabler"
+ name="MenuEnabler"
+ schema="schema/MenuEnabler.exsd"/>
+
+ <extension point="org.eclipse.core.expressions.propertyTesters">
+ <propertyTester
+ class="org.eclipse.wst.common.frameworks.internal.ui.MenuEnablementPropertyTester"
+ id="org.eclipse.wst.common.frameworks.internal.ui.MenuEnablementPropertyTester"
+ namespace="org.eclipse.wst.common.frameworks.actions"
+ properties="show"
+ type="org.eclipse.core.resources.IResource">
+ </propertyTester>
+ </extension>
+
<extension
id="UITester"
point="org.eclipse.wst.common.core.uiTester">
diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/schema/menuEnabler.exsd b/plugins/org.eclipse.wst.common.frameworks.ui/schema/menuEnabler.exsd
new file mode 100644
index 0000000..332f105
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.frameworks.ui/schema/menuEnabler.exsd
@@ -0,0 +1,106 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.wst.common.frameworks.ui" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.wst.common.frameworks.ui" id="MenuEnabler" name="MenuEnabler"/>
+ </appInfo>
+ <documentation>
+ Defines extension point for setting enablement condition for a menu item. This extension point is used in
+org.eclipse.wst.common.frameworks.internal.ui.MenuEnablementPropertyTester.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="menuenabler"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ Optional name for the extension point
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="menuenabler">
+ <complexType>
+ <attribute name="className" type="string" use="required">
+ <annotation>
+ <documentation>
+ The className is an implementation of interface IPropertyTester
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ 3.2 M6
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ <extension
+ point="org.eclipse.wst.common.frameworks.ui.MenuEnabler">
+ <menuenabler
+ className="org.eclipse.foo.BarPropertyTester">
+ </menuenabler>
+</extension>
+
+The class specified in className should implement IPropertyTester interface
+ </documentation>
+ </annotation>
+
+
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (c) 2010 IBM Corporation 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:
+ IBM Corporation - initial API and implementation
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/MenuEnablementPropertyTester.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/MenuEnablementPropertyTester.java
new file mode 100644
index 0000000..dc1afbf
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/MenuEnablementPropertyTester.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.wst.common.frameworks.internal.ui;
+
+import java.util.List;
+
+import org.eclipse.core.expressions.IPropertyTester;
+import org.eclipse.core.expressions.PropertyTester;
+
+public class MenuEnablementPropertyTester extends PropertyTester{
+
+ static private List<MenuEnablerExtension> list = MenuEnablerExtensionReader.getInstance().getMenuEnabler();
+ public boolean test(Object receiver, String property, Object[] args,
+ Object expectedValue) {
+
+ if( list != null && list.size() > 0 ){
+ MenuEnablerExtension menuEnablerExtension = list.get( 0 );
+ IPropertyTester tester = menuEnablerExtension.getInstance();
+ if( tester != null ){
+ return tester.test( receiver, property, args, expectedValue );
+ }
+ return true;
+ }
+ return true;
+ }
+
+}
diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/MenuEnablerExtension.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/MenuEnablerExtension.java
new file mode 100644
index 0000000..2c1dbbd
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/MenuEnablerExtension.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.wst.common.frameworks.internal.ui;
+
+import org.eclipse.core.expressions.IPropertyTester;
+import org.eclipse.core.runtime.IConfigurationElement;
+
+
+public class MenuEnablerExtension {
+
+ public static final String ATT_ID = "id"; //$NON-NLS-1$
+ public static final String MENU_ENABLER_EXTENSION = "menuenabler"; //$NON-NLS-1$
+
+ private String id = null;
+ private IConfigurationElement element;
+ //private IMenuEnabler instance;
+ private IPropertyTester instance;
+ private boolean errorCondition = false;
+
+ public MenuEnablerExtension(){
+ super();
+ }
+
+ private void init() {
+ id = element.getAttribute(ATT_ID);
+ }
+
+ /**
+ * @return Returns the id.
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @param id
+ * The id to set.
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public MenuEnablerExtension(IConfigurationElement element) {
+ this.element = element;
+ init();
+ }
+
+ public IPropertyTester getInstance() {
+ try {
+ if (instance == null && !errorCondition)
+ instance = (IPropertyTester) element.createExecutableExtension("className"); //$NON-NLS-1$
+ } catch (Throwable e) {
+ errorCondition = true;
+ }
+ return instance;
+ }
+}
diff --git a/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/MenuEnablerExtensionReader.java b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/MenuEnablerExtensionReader.java
new file mode 100644
index 0000000..684b964
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.frameworks.ui/wtp_ui/org/eclipse/wst/common/frameworks/internal/ui/MenuEnablerExtensionReader.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.wst.common.frameworks.internal.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.wst.common.core.util.RegistryReader;
+
+
+
+public class MenuEnablerExtensionReader extends RegistryReader {
+
+ private static MenuEnablerExtensionReader instance = null;
+ private List<MenuEnablerExtension> pageExtenders = null;
+
+ public MenuEnablerExtensionReader(){
+ super("org.eclipse.wst.common.frameworks.ui", "MenuEnabler"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+
+ public static MenuEnablerExtensionReader getInstance() {
+ if (instance == null) {
+ instance = new MenuEnablerExtensionReader();
+ instance.readRegistry();
+ }
+ return instance;
+ }
+
+ @Override
+ public boolean readElement(IConfigurationElement element) {
+ if (MenuEnablerExtension.MENU_ENABLER_EXTENSION.equals(element.getName())) {
+ addExtension(element);
+ return true;
+ }
+ return false;
+ }
+
+ protected void addExtension(IConfigurationElement newExtension) {
+ getMenuEnabler().add(new MenuEnablerExtension(newExtension));
+ }
+
+ public List<MenuEnablerExtension> getMenuEnabler() {
+ if (pageExtenders == null)
+ pageExtenders = new ArrayList<MenuEnablerExtension>();
+ return pageExtenders;
+ }
+
+}