How to show the Eclipse Move context menu in project explorer - eclipse

I have noticed that by default Eclipse "Move" context menu is not shown when a folder and a file is multi selected at once.
My scenario is i want to show the my context menu -Move for certain type of files and folders when multi selected.
<and>
<iterate
operator="or">
<with
variable="org.eclipse.ui.selection">
<adapt
type="org.eclipse.core.resources.IResource">
<or>
<test property="com.sap.ndb.studio.dwb.team.ui.expressions.isContainedInSharedProject" value = "true"/>
<test property="com.sap.ndb.studio.dwb.team.ui.expressions.isFile" value="true"/>
<test property="com.sap.ndb.studio.dwb.team.ui.expressions.isFolder" value="true"/>
</or>
</adapt>
</with>
</iterate>
</and>
How can i enable my context menu for the type folder and a file in multi select?
Regards,
Pavitra

in Project explorer, select those files that you want to move,
right click on one of them, select Refactor, by default Move... option is available.
or simply you can use shortcut to move: Alt+Shift+V.
if it wasn't enabled or doesn't exist, in eclipse go to Window menu,
select Customize perspective...
a windows with for tabs will appear.
select Menu visibility tab then expand Refactor, then tic the Move... checkbox.

Related

Is it possible to find out whether the code written in Eclipse editor is valid and disable/enable context menu button accordingly?

I'm creating Eclipse plugin for my DSL, using Xtext and need to add context menu item for my editor (what I did already), but need to find out whether the code in editor is valid, if yes -> this menu item should be enabled, otherwise disabled. Is it somethow possible to check whether the whole code is valid and update the state of this context menu item accordingly ?
I added this context menu item by adding this fragment to the plugin.xml file in .ui project in Xtext.
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:#TextEditorContext?after=additions">
<command commandId="org.first.langu.ui.handler.InterpreterCommand" style="push">
<enabledWhen checkEnabled="true">
<reference definitionId="org.first.langu.Program.XtextEditor.opened"/>
</enabledWhen>
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.commands">
<command id="org.first.langu.ui.handler.InterpreterCommand" name="Interpret Code"/>
</extension>
<extension point="org.eclipse.ui.handlers">
<handler
class="org.first.langu.ui.ProgramExecutableExtensionFactory:org.first.langu.ui.handler.InterpretCodeHandler"
commandId="org.first.langu.ui.handler.InterpreterCommand"/>
</extension>
Basically I need to check whether code in editor is valid, instead of if editor is just opened.
you can use the editors annotation model to find out if there are any errors.
see org.eclipse.xtext.ui.editor.XtextEditorErrorTickUpdater.getSeverity(XtextEditor)
for an example on how to retrieve and filter the annotations. that class is used to display the red x in the editor icon if there are errors

Eclipse 4.x popup menu visibility based on tree viewer selection

I'm creating an eclipse 4 plugin project. I have a tree viewer that shows model elements.
Problem:
I need to show a popup menu based on the selection that I'm doing on the tree viewer.
I tired to use core expression as explained in the link:
http://www.vogella.com/tutorials/EclipseRCP/article.html#menuadvanced_popup
But whenever I attach the core expression with my popup menu it disappears.
The popup menu appears for all the elements if i don't attach the core expression.
Is there something else that i'm supposed to do to get things right ?
or Should i use a different approach ?
Please find the below snap of my Application.e4xmi file
My plugin.xml file definition for the core expression
<definition
id="xxx.abc.project.addchilddefinition">
<with variable="org.eclipse.ui.selection">
<iterate
ifEmpty="false"
operator="or">
<instanceof
value="xxx.abc.project.model.ObjectName">
</instanceof>
</iterate>
</with>
</definition>
I've registered my popup menu using the below code snippet:
menuService.registerContextMenu(treeviewer.getControl(),
"xxx.abc.project.popupmenu.addchild");
menuService is the EMenuService object and "xxx.abc.project.popupmenu.addchild" is my popupmenu id
You need to use a with element to specify that the selection should be used:
<definition
id="xxx.abc.project.addchilddefinition">
<with
variable="org.eclipse.ui.selection">
<iterate
ifEmpty="false"
operator="or">
<instanceof
value="xxx.abc.project.model.ObjectName">
</instanceof>
</iterate>
</with>
You must also call the ESelectionService setSelection(Object) method when the tree selection changes.
The selection variable org.eclipse.ui.selection is defined in IServiceConstants.ACTIVE_SELECTION

Hide unhide toolbars based on the editors open

In eclipse there are certain toolbars which becomes visible when I open java editor. It goes invisible when I close the editor (only one editor was open.)
Here opening the java editor is not changing the perspective.
How to achieve this functionality in eclipse rcp application?
Pre-3.3 this can be accomplished through a org.eclipse.ui.IEditorActionBarContributor, defined in your editor extension with the contributorClass attribute.
Since 3.3 a core expression definition can be used in a visiblewhen expression.
For example, a re-usable core expression for an editor can be defined as follows
<extension point = "org.eclipse.core.expressions.definitions">
<definition id="org.eclipse.ui.examples.contributions.activeEditor">
<with variable="activeEditorId">
<equals value="org.eclipse.ui.examples.contributions.editor"/>
</with>
</definition>
</extension>
Then the following expression can be used to control whether a menu or toolbar is visible
<visibleWhen>
<reference definitionId=""org.eclipse.ui.examples.contributions.activeEditor"/>
</visibleWhen>
You need to look at Activities and Contexts to hide/unhide contributions
http://www.vogella.com/blog/2009/07/13/eclipse-activities/

Add popup menu to Eclipse Problems view

I wish to add a popup menu to the Eclipse Problem View. I can add the menu but I want it to only appear under certain condition. Like for example when a certain type of problem is selected in the problems view.
Assuming you are using the "org.eclipse.ui.menus" extension point and the command framework, you can set the visibleWhen part of the menu definition to something like;
<visibleWhen>
<with variable="selection">
<iterate>
<and>
<instanceof value="com.example.MyClass">
</instanceof>
</and>
</iterate>
</with>
</visibleWhen>
This should only make the option visible when the selected items are of the correct instance.
It is also possible to set enabled and active states on command handlers in a similar way.

Override Eclipse File > Save Action

I am trying to override the Eclipse File > Save menu action to add some functionality.
I have tried the following things
a) Create a new action and add it to the global action handler
actionBars.setGlobalActionHandler(ActionFactory.SAVE.getId(), mySaveAction);
actionRegistry.registerAction(action);
b) Create a new handler and override the save command
<extension point="org.eclipse.ui.handlers">
<handler commandId="org.eclipse.ui.file.save"
class="com.diagrams.ui.SaveFileHandler">
<enabledWhen>
<with variable="activePartId">
<equals
value="com.diagrams.editors.MultiPageEditor" />
</with>
</enabledWhen>
<activeWhen>
<with variable="activePartId">
<equals
value="com.diagrams.editors.MultiPageEditor" />
</with>
</activeWhen>
</handler>
</extension>
With both these approaches I have been able to override the Keyboard Ctrl+S functionality but the "File > Save" menu seem to work differently.
Would really appreciate any help, Thanks
In an RCP application, you can contribute the Save action in your ActionBarAdvisor. This also registers the action so it is available from the save command.
But as a plugin in the Eclipse IDE, the IDE provides the ActionBarAdvisor and hooks up the Save action in the File menu. Because that's not technically a command (Actions are a step above an SWT.Selection listener) that's why you can't override the File>Save action.
However, each part provides its own save implementation, so you can do whatever you want in your MultiPageEditor.
The other option is to use org.eclipse.ui.commands.ICommandService.addExecutionListener(IExecutionListener) and add an IExecutionListener (or IEL2). That can listen for the save command, the ID is declared in org.eclipse.ui.IWorkbenchCommandConstants.
It might have something to do with the activePartId being different when the main menu is selected versus a keystroke or using the right-click menu. Have you looked at other extension points?