Project explorer Delete Action not working as expected - eclipse-plugin

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.

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.

TestNG XML with groups and packages not working

I am working on a set of selenium tests I want to run using a TestNG XML.
<suite name="MATS">
<parameter name="browser" value="firefox" />
<parameter name="platform" value="windows" />
<test name="mats_test">
<groups>
<run>
<include name = "mats" />
</run>
</groups>
<packages>
<package name="com.sel.tests.app.set1.*" />
<package name="com.sel.tests.app.set2.*" />
<package name="com.sel.tests.app.set3.*" />
</packages>
</test>
</suite>
Directly under each of those packages there are multiple classes with the #Test(groups = { "mats" }) annotation on top. However, I get this output:
MATS
Total tests run: 0, Failures: 0, Skips: 0
Update: Ok, so cleaning the project didn't work so I imported it again in a new workspace after which it seems to be working. Closing the question. Thanks everyone.
If you're working in IntelliJ Idea try to select in main menu Run -> Edit Configurations. On left side select "TestNG" configuration, on right side select "In whole project" radio button and Working Directory: as $MODULE_DIR$ (or play with that)

How to limit visibility of a popup menu item only to project which contains a specific file?

I am looking to limit my popup entry to be only displayed when the project has a specific file
at its root directory.
I am currently using this code to only have the popup entry shown when a project is clicked on.
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="or">
<adapt
type="org.eclipse.core.resources.IProject">
<test
property="ProjectSharing.test2">
</test>
</adapt>
</iterate>
</visibleWhen>
How can I check for a specific file?

Showing command on toolbar based on perspective

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>

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).