Showing command on toolbar based on perspective - eclipse-plugin

I want to show a command on the toolbar based on the perspective. I have used core expressions to achieve this as below.
<extension point="org.eclipse.core.expressions.definitions">
<definition id="onValidationPerspective">
<with variable="activeWorkbenchWindow.activePerspective">
<equals value="com.sample.perspective1"/>
</with>
</definition>
</extension>
and I have used this in the command tag as below.
<command
commandId="com.sample.run.root"
icon="icons/run_exc.gif"
label="Reset Card"
style="pulldown">
<visibleWhen checkEnabled="false">
<reference
definitionId="onValidationPerspective">
</reference>
</visibleWhen>
</command>
The above code is working fine.
But I want to extend this for mutiple perspectives, i.e. I want to show the commands on the toolbar in 2 perspectives namely com.sample.perspective1 and com.sample.perspective2.
How can I achieve this using core expressions?

You can use the OR operation element:
<definition id="onValidationPerspective">
<or>
<with ...
<with ...
</or>
</definition>

<definition id="onValidationPerspective">
<with variable="activeWorkbenchWindow.activePerspective">
<or>
<equals value="com.sample.perspective1"/>
<equals value="com.sample.perspective2"/>
</or>
</with>
</definition>

Related

How to remove Eclipse Move from context menu and refactor main menu

I want to remove move command for specific resource type. To achieve it, I thought to using org.eclipse.ui.activities
I tried below configuration, but it didn't work.
<extension
point="org.eclipse.ui.activities">
<activity
id="refactormovehiding.id"
name="refactormovehiding">
<enabledWhen>
<not>
<instanceof
value="com.shashwat.resource.PResource">
</instanceof>
</not>
</enabledWhen>
</activity>
<activityPatternBinding
activityId="refactormovehiding.id"
pattern=".*/org.eclipse.jdt.ui.actions.Move">
</activityPatternBinding>
</extension>
I even used different pattern thinking pattern which I am providing is incorrect
<extension
point="org.eclipse.ui.activities">
<activity
id="refactormovehiding.id"
name="refactormovehiding">
<enabledWhen>
<not>
<instanceof
value="com.shashwat.resource.PResource">
</instanceof>
</not>
</enabledWhen>
</activity>
<activityPatternBinding
activityId="refactormovehiding.id"
pattern=".*/org.eclipse.ltk.ui.refactoring.commands.moveResources">
</activityPatternBinding>
</extension>
I even tried without enabledWhen configuration, but no luck.

Project explorer Delete Action not working as expected

Eclipse Default Delete action on the project explorer (context menu, key binding) not working as expected.
In Project explorer I do have 2 different files let's assume ".pc" and ".tc" files.
I want to restrict the user from deleting the ".tc" files from project explorer for that I have written custom handlers to restrict it. Actions are configured as below.
<handler
class="MyTCFileDeleteHandler"
commandId="org.eclipse.ui.edit.delete">
<activeWhen>
<with
variable="selection">
<iterate
ifEmpty="false">
<instanceof
value="org.eclipse.core.resources.IResource">
</instanceof>
<test
property="org.eclipse.core.resources.extension"
value="tc">
</test>
</iterate>
</with>
</activeWhen>
</handler>
<handler
class="MyTCFileDeleteHandler"
commandId="org.eclipse.ltk.ui.refactoring.commands.deleteResource">
<activeWhen>
<with variable="selection">
<iterate
ifEmpty="false">
<instanceof
value="org.eclipse.core.resources.IResource">
</instanceof>
<test
property="org.eclipse.core.resources.extension"
value="tc">
</test>
</iterate>
</with>
</activeWhen>
</handler>
But due to this DeleleParticepent wrote are not getting calls for ".pc" file deletion.
Also, this misbehaves for shortcuts, context menus differently.
What I want to achieve, I should restrict the deleting of some files according to extension and some not, and my participant should call if the file is deleting. And this should work for the context menu, shortcut.

MSBuild XmlPeek task help required

My sample.xml file is below
<deployment>
<definition type="xpath">
<xpath>configuration/Settings/add[#key='NetworkPath'][#value]</xpath>
<attribute>value</attribute>
<value>http://www.google.com</value>
</definition>
</deployment>
I want to fetch the value "http://www.google.com" corresponsing to xpath "configuration/Settings/add[#key='NetworkPath'][#value]". I am writing below XmlPeek task but it is not working
<XmlPeek XmlInputPath="C:\Sample.xml"
Query="configuration/Settings/add[#key='NetworkPath'][#value]">
<Output TaskParameter="Result" ItemName="Peeked" />
</XmlPeek>
<Message Text="Peeked value is #(Peeked)"/>
There might be some confusion about XPath.
If you want to retrieve htttp://www.google.com from Sample.xml you need to apply this query:
<XmlPeek XmlInputPath="Sample.xml"
Query="/deployment/definition/value/text()">
<Output TaskParameter="Result" ItemName="Peeked" />
</XmlPeek>
If you want to extract the path configuration/Settings/add[#key='NetworkPath'][#value]/#value it corresponds to another Xml file having this form:
<configuration>
<Settings>
<add key="NetworkPath" value="http://www.google.com"/>
</Settings>
</configuration>
Check out some XPath examples.

delete popup working fine over project explorer view but not working over navigator view

I am trying to hide 'delete' popup-menu for some files. I used following plugin.xml entry.
<extension point="org.eclipse.ui.activities">
<activity id="hidedeletepopupmenuID" name="hidedeletepopupmenu">
<enabledWhen>
<with variable="selection">
<iterate operator="and">
<adapt type="org.eclipse.core.resources.IResource" >
<or>
<test property="org.eclipse.core.resources.name" value="*.java"/>
</or>
</adapt>
</iterate>
</with>
</enabledWhen>
</activity>
<activityPatternBinding activityId="hidedeletepopupmenuID"
isEqualityPattern="false" pattern="org.eclipse.ui.edit.delete">
</activityPatternBinding>
</extension>
This seems to be working fine over project explorer view, but navigator view its not wokring. Can anyone help on this?
Thanks,
darshan
Actions in Navigator view context menu are hard-coded, see ResourceNavigator.fillContextMenu(IMenuManager menu).
Note that the action in popup menu is not the only way to delete a resource (there's also a menu item in Edit menu and key-binding).

How can I apply all the sql files in a directory?

We currently run a specific SQL script as part of our Ant deploy process.
What we'd like to do is change this so we run all SQL scripts in a given directory. We can't figure out how to get this directory listing in Ant and iterate through the list and run each SQL script. Does anyone know how to do this?
Note: we currently run the sql file by using the Ant exec task that runs "call sqlplus ${id}/${pw}#${db.instance} #${file}"
I would recommend using the Ant SQL task. You can then specify with the following:
<sql
driver="org.database.jdbcDriver"
url="jdbc:database-url"
userid="sa"
password="pass">
<path>
<fileset dir=".">
<include name="data*.sql"/>
</fileset>
<path>
</sql>
i am doing basically the same thing on an oracle database.. but using sqlplus and the apply task. this allows the scripts to contain DDL statements.
would obviously only work where you have a command line program to use.
using ant 1.8.2 and antcontrib.
i have defined a few macros for use.. (see below) and then just call like
<compile_sql connectstring="${db.connect_string}" >
<filelist dir="${db_proc.dir}" files="specific_file.sql" />
<fileset dir="${db_proc.dir}" includes="wildcard*.pks" />
<fileset dir="${db_proc.dir}" includes="wildcard*.pkb" />
</compile_sql>
the macros are as follows
<macrodef name="compile_sql">
<attribute name="connectstring" />
<attribute name="dirtostart" default=""/>
<attribute name="arg1" default=""/>
<element name="sqllist" implicit="true" description="filesetlist of sql to run"/>
<sequential>
<check_missing_files>
<sqllist/>
</check_missing_files>
<apply executable="${sqlplus.exe}" failonerror="true" verbose="true" skipemptyfilesets="true" ignoremissing="false" dir="#{dirtostart}">
<arg value="-L"/>
<arg value="#{connectstring}"/>
<srcfile prefix="#" />
<sqllist/>
<arg value="#{arg1}"/>
<redirector>
<globmapper id="sqlout.mapper"
from="*"
to="*.out"/>
</redirector>
</apply>
</sequential>
</macrodef>
and
<macrodef name="check_missing_files">
<element name="checkfilelist" implicit="true" description="filelist of files to check for existance"/>
<sequential>
<restrict id="missing.files" xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors">
<resources>
<checkfilelist/>
</resources>
<rsel:not>
<rsel:exists/>
</rsel:not>
</restrict>
<fail message="These files are missing: ${ant.refid:missing.files}" >
<condition >
<length string="${ant.refid:missing.files}" when="greater" length="0" />
</condition>
</fail>
</sequential>
</macrodef>