Create conditions in Eclipse plugin.xml - eclipse

Is there a way to create conditions (similar to if/else blocks) in the Eclipse plugin.xml's files.
I'm creating a Eclipse plugins in which I need to set a different value depending on the project facet, I'm getting the project facet using:
<with variable="projectFacet">
<test property="org.eclipse.wst.common.project.facet.core.projectFacet" value="projectFacet" forcePluginActivation="true"/>
</with>
And then I have this code:
<item
label="test"
visible="false"
id="test.test1"
category="category1"
description="test description">
</item>
At this momment I'm hardcoding "category1", what I need is to select the correct category depending on the variable I got before, for example:
facet1 should be on the category1
facet2 should be on the category2
Someone knows how to do that? Thanks.

Related

Magento 2 - Copy price block to another location in product layout

I am trying to find a way to duplicate the price block so that it appears in two locations of the product page for specific products, by using the Layout Update XML field inside the design tab of the product edit page (Magento Admin).
I have successfully copied the price block by creating a modified layout XML file for specific products, for example:
theme_folder\Magento_Catalog\layout\catalog_product_view_id_178.xml
Inside this file I added the following in the required location:
<block class="Magento\Catalog\Pricing\Render" name="product.price.final.second.location" after="product.info.options.wrapper">
<arguments>
<argument name="price_render" xsi:type="string">product.price.render.default</argument>
<argument name="price_type_code" xsi:type="string">final_price</argument>
<argument name="zone" xsi:type="string">item_view</argument>
</arguments>
</block>
However there are too many products that use this modified layout and it would be easier to manage the product catalog if I could achieve the same thing just using the Layout Update XML field and entering a simple instruction like:
<copy element="product.price.final" destination="second.price.container">
Except there is no copy instruction, only a move instruction which is not what I want.
A different solution would be to have a way to select which layout XML to use from the product edit page, for example a yes/no attribute.
Is there a way to achieve this result?
I found the solution. The following XML inserted into the Layout Update XML field will copy the price block to a referenceBlock (or referenceContainer):
<referenceBlock name="my.reference.block">
<block class="Magento\Catalog\Pricing\Render" name="product.price.final.lower">
<arguments>
<argument name="price_render" xsi:type="string">product.price.render.default</argument>
<argument name="price_type_code" xsi:type="string">final_price</argument>
<argument name="zone" xsi:type="string">item_view</argument>
</arguments>
</block>
</referenceBlock>

Visibility in popup menus

I have created an eclipse plugin project. I want this plugin to be available as a popup. Therefore I have created an extension point with "org.eclipse.ui.popupMenus" (I know it is deprecated now, ours is an old project.)
I want this popup option to appear only at the file level with certain extension (say xml). Currently, it is appearing anywhere on right click.
I have looked around the internet and got to know that I can add a "visibility" tag that can set rules where this popup should be visible. However, I do not know the syntax for that.
Can someone please help me out? How to set the visibility of the popup menu so that it is visible only when I right click ON the filename with extension xml?
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.*"
id="org.eclipse.lyo.tools.codegenerator.ui.popupMenus.contribution.IFile">
<menu id="org.eclipse.acceleo.module.menu" label="Acceleo Model Code Generator" path="additionsAcceleo">
<groupMarker name="acceleo"/>
</menu>
<action
class="org.eclipse.lyo.tools.codegenerator.ui.popupMenus.AcceleoGenerateCodegeneratorAction"
enablesFor="+"
id="org.eclipse.lyo.tools.codegenerator.ui.popupMenus.AcceleoGenerateCodegeneratorAction"
icon="icons/default.gif"
label="Generate Java Code from Model"
menubarPath="org.eclipse.acceleo.module.menu/acceleo"/>
<visibility>
//what should come here?
</visibility>
</objectContribution>
</extension>
</plugin>
(http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_ui_popupMenus.html)
Regards,
Yash
visibility can only be a child of objectContribution not action.
In any case you can use the namefilter attribute to restrict the file name matching. You would only use visiblity to do more complex checks.
For example this is one of the JDT items:
<objectContribution
adaptable="true"
objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.xml"
id="org.eclipse.jdt.internal.ui.javadocexport.JavadocWizard">
<visibility>
<objectState name="contentTypeId" value="org.eclipse.ant.core.antBuildFile"/>
</visibility>
In this
adaptable="true"
objectClass="org.eclipse.core.resources.IFile"
restricts the actions to a workspace file
nameFilter="*.xml"
restricts the actions to files ending in .xml
<visibility>
<objectState name="contentTypeId" value="org.eclipse.ant.core.antBuildFile"/>
</visibility>
further restricts the actions to files with a 'content type' of 'Ant build file'
To match multiple name patterns remove the nameFilter and use a visibility like:
<visibility>
<or>
<objectState name="name" value="*.xml"/>
<objectState name="name" value="*.java"/>
</or>
</visibility>

Checking for null selection variable value in the command framework of Eclipse RCP

How can I check whether the selection variable value is null when I open the editor?
I want to activate a context menu command when the certain editor is opened, it is not dirty and nothing was selected by the user. First two coditions are working fine:
<and>
<with
variable="activePartId">
<equals
value="com.eclipse.someeditor">
</equals>
</with>
<with
variable="activePart">
<not>
<test
property="com.eclipse.isEditorDirty">
</test>
</not>
</with>
<and>
My current problem is that the straightforward solution would be to include another condition:
<with variable="selection">
<count value="0" />
</with>
Unfortunately when the editor is first opened, the count is not 0. It probably is null. If the user selects something and then deselects, it becomes 0. Any ideas how to check whether the value of selection is null or similar?
UPDATE
I also tried creating a property tester that checks whether the value of the selection is null, but the code is not executed. I think that it happens, because it does not even go inside the selection if the user did not select/deselect anything.
<with variable="selection">
<test
property="com.eclipse.isSelectionNullOrEmpty">
</test>
</with>
Try using 'instanceof' and 'and'. Like:
<and>
<instanceof value="fully_qualified_class_name_of_your_selection_class"/>
<equals value="0" />
</and>
Hope this helps.
The following solution worked:
I made the Editor a SelectionProvider that is capable of delegating to another SelectionProvider to be able to switch between them (e.g. when I have an inner table that provides selection as well and take procedence.
Then I set the getSelection() to return an empty StructuredSelection when there is no delegate (opposite to returning null). Thanks to that there is always a StructuredSelection being returned, but sometimes it is empty.
public ISelection getSelection() {
return delegate == null ? new StructuredSelection() : delegate.getSelection();
}
After that I could add the simple condition that I mentioned earlier:
<with variable="selection">
<count value="0" />
</with>
Some people may find this useful.

netbeans, xml autocomplete for attributes fails for default namespace

I've defined two namespaces: beans, aop.
If you cut & paste into a Netbeans the tag that i've written below, and you try to edit a tag inside beans:beans you should observe this behavior:
<beans:import />
typing this the autocomplete assists you, and after the element name, it proposes the list of attributes (in this case just one).
<aspectj-autoproxy />
typing this the autocomplete dosn't propose the list of attributes (there are two attributes: proxy-target-class, expose-proxy)
It happens for the attributes of the default namespace's elements.
Is it a bug? Am I doing something wrong?
I've tested on NB 6.9 and NB 7.0
thanks in advance
<beans:beans
xmlns:beans ="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
try here
</beans:beans>

phing nested if conditions

I am having trouble understanding the Phing documentation regarding multiple conditions for a given <if> tag. It implies you cannot have multiple conditions unless you use the <and> tag, but there are no examples of how to use it. Consequently I nested two <if> tags, however I feel silly doing this when I know there is a better way. Does anyone know how I can use the <and> tag to accomplish the following:
<if><equals arg1="${deployment.host.type}" arg2="unrestricted" /><then>
<if><equals arg1="${db.adapter}" arg2="PDO_MYSQL"/><then>
<!-- Code Here -->
</then></if>
</then></if>
I find it very surprising that no one has had any experience with this. Phing is an implementation of the 'ANT' build tool in PHP instead of Java. It is very useful for PHP developers who feel a lack of a simple and powerful deployment tool. Java's ability to package self contained web projects into a single file or package multiple web project files into a yet bigger file is an amazing capability. ANT or Phing does not get PHP to that point, but its a definite step in the right direction and leaps and bounds easier to understand and use than GNU Make ever was or will be.
According to the Phing documentation:
The <or> element doesn't have any attributes and accepts an arbitrary number of conditions as nested elements. This condition is true if at least one of its contained conditions is, conditions will be evaluated in the order they have been specified in the build file.
It may sound confusing at first, especially with no handy examples available, but the keywords to note are, "accepts an arbitrary number of conditions as nested elements." If you try the following build snippet out, you should easily realize how to use <or> and <and> conditions:
<if>
<or>
<equals arg1="foo" arg2="bar" />
<equals arg1="baz" arg2="baz" />
</or>
<then>
<echo message="Foo equals bar, OR baz equals baz!" />
</then>
</if>
<if>
<or>
<equals arg1="foo" arg2="bar" />
<equals arg1="baz" arg2="bam" />
</or>
<then>
<echo message="Foo equals bar, OR baz equals baz!" />
</then>
<else>
<echo message="No match to OR found." />
</else>
</if>
<fail />