diff --git a/docs/org.eclipse.wst.doc.isv/html/facets/downloads/enablement-example.zip b/docs/org.eclipse.wst.doc.isv/html/facets/downloads/enablement-example.zip new file mode 100644 index 0000000000000000000000000000000000000000..03e7c89e4d3cf499c1422054f32740dce7ac28c7 Binary files /dev/null and b/docs/org.eclipse.wst.doc.isv/html/facets/downloads/enablement-example.zip differ diff --git a/docs/org.eclipse.wst.doc.isv/html/facets/enabling-based-on-facets.html b/docs/org.eclipse.wst.doc.isv/html/facets/enabling-based-on-facets.html new file mode 100644 index 0000000000000000000000000000000000000000..50ce36a1df450ba663a49df0d6c467500d436c21 --- /dev/null +++ b/docs/org.eclipse.wst.doc.isv/html/facets/enabling-based-on-facets.html @@ -0,0 +1,108 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" +"http://www.w3.org/TR/html4/loose.dtd"> +<html> + +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <title>Enabling UI Elements Based on Project Facets</title> + <link type="text/css" rel="stylesheet" href="tutorial/tutorial.css"/> +</head> + +<body> + +<h1 align="center">Enabling UI Elements Based on Project Facets</h1> + +<p>User interface elements often need to be selectively enabled based on the +presence of a facet in a project. The two most common examples are project +properties pages and menu actions associated with a facet. The Faceted Project +Framework provides a way to do that via a property tester that can be used in +any extension point that supports the Eclipse Platform's common expression +language.</p> + +<p> + <b>Property Name:</b> <code>org.eclipse.wst.common.project.facet.core.projectFacet</code><br/> + <b>Property Value:</b> <code>[facet.id](:[version.expr])?</code> +</p> + +<p>As you can see from the format of the property value, you can either test +using just the project facet id or you can also include a version expression if +only certain versions should be matched.</p> + +<p>The following two examples demonstrate how the facets property tester can be +used. To explore further, you can also download the +<a href="downloads/enablement-example.zip">complete runnable source</a> of these +examples.</p> + +<p><b>Example 1</b></p> + +<p>Enables a project properties page based on the presence of a facet. Note the +use of the <code>forcePluginActivation</code> attribute. This attribute makes +sure that the property tester will be invoked even if the Faceted Project +Framework plugins have not been activated yet. Omitting this attribute will cause +the test expression to return false in that situation. Also note the use of the +<code>adapt</code> operator to adapt the object to <code>IProject</code>. This +is necessary as some views may represent project entities using other types. For +instance, in the JDT's Package Explorer the projects are instances of +<code>org.eclipse.jdt.core.IJavaProject</code>.</p> + +<div class="code"> +<pre class="code-xml"><extension point="<span class="code-text">org.eclipse.ui.propertyPages</span>"> + <page + id="<span class="code-text">ExampleFacetPropertiesPage</span>" + objectClass="<span class="code-text">org.eclipse.core.resources.IProject</span>" + adaptable="<span class="code-text">true</span>" + name="<span class="code-text">Example Facet Properties</span>" + class="<span class="code-text">org.eclipse.wst.project.facet.examples.enablement.ExampleFacetPropertiesPage</span>"> + <enabledWhen> + <adapt type="<span class="code-text">org.eclipse.core.resources.IProject</span>"> + <test + forcePluginActivation="<span class="code-text">true</span>" + property="<span class="code-text">org.eclipse.wst.common.project.facet.core.projectFacet</span>" + value="<span class="code-text">example.facet1</span>"/> + </adapt> + </enabledWhen> + </page> +</extension></pre> +</div> + +<p><b>Example 2</b></p> + +<p>Enables a menu action if either one of the two facets specified is installed +in a project. Note the use of a version expression to match only certain versions.</p> + +<div class="code"> +<pre class="code-xml"><extension point="<span class="code-text">org.eclipse.ui.popupMenus</span>"> + <objectContribution + id="<span class="code-text">exampleFacetPopup</span>" + objectClass="<span class="code-text">org.eclipse.core.resources.IProject</span>" + adaptable="<span class="code-text">true</span>"> + <action + id="<span class="code-text">exampleFacetPopupAction</span>" + label="<span class="code-text">Example Facet Popup</span>" + class="<span class="code-text">org.eclipse.wst.project.facet.examples.enablement.ExampleFacetPopupAction</span>" + menubarPath="<span class="code-text">additions</span>" + enablesFor="<span class="code-text">+</span>"> + </action> + <enablement> + <adapt type="<span class="code-text">org.eclipse.core.resources.IProject</span>"> + <or> + <test + forcePluginActivation="<span class="code-text">true</span>" + property="<span class="code-text">org.eclipse.wst.common.project.facet.core.projectFacet</span>" + value="<span class="code-text">example.facet1:1.0</span>"/> + <test + forcePluginActivation="<span class="code-text">true</span>" + property="<span class="code-text">org.eclipse.wst.common.project.facet.core.projectFacet</span>" + value="<span class="code-text">example.facet2:[1.1-2.2]</span>"/> + </or> + </adapt> + </enablement> + </objectContribution> +</extension></pre> +</div> + +<br/><br/><br/><br/> + +</body> + +</html> diff --git a/docs/org.eclipse.wst.doc.isv/toc_WST.xml b/docs/org.eclipse.wst.doc.isv/toc_WST.xml index a423239efd3dd0937e495a17069502a26037d33e..3b9f19210137d13dfaac351b40f4a9b50e6e8f34 100644 --- a/docs/org.eclipse.wst.doc.isv/toc_WST.xml +++ b/docs/org.eclipse.wst.doc.isv/toc_WST.xml @@ -25,6 +25,9 @@ <topic label="Tutorial" href="html/facets/tutorial/tutorial.html"> </topic> + <topic label="Enabling UI Elements Based on Project Facets" + href="html/facets/enabling-based-on-facets.html"> + </topic> <topic label="Questions & Answers" href="html/facets/questions.html"> </topic>