How to rename the eclipse plugin menu programmatically - java

I am developing an eclipse plugin.I have given my menu,sub menu names and plugin id in plugin.xml.
I want to dynamically rename my plugin id as well my menu and sub menu name.I came across this SOF link.I am using the below code.
MenuManager menuManager = ((WorkbenchWindow)window).getMenuManager();
Menu menu = menuManager.getMenu();
String itemId = "plugin_menu_id";
IContributionItem item = menuManager.find(itemId);
System.out.println("item.getId() --> " + item.getId());
//gives the plugin_menu_id
System.out.println( "menu.getItemCount() ==> "+ menu.getItemCount());
//gives no of menus in eclipse
But unfortunately I am unable to find an option to rename the menu from IContributionItem.
So is there any other way to modify things in eclipse plugin?

I found a temporary solution .Instead of using a MenuManager,I created a dynamic menu using Actions Framework instead of Command Framework though the former is deprecated.
So each time , I create a Menu,I am able to change the Menu name,icon etc.
I am searching for an equivalent in the Command Framework and will post as soon as I found that.

Related

Eclipse plugin dev - How to show default IResource context menu in non-text custom editor?

I´m writing an Eclipse plugin to show the contents of an own file type in an own custom editor.
This file basically consists of 1..n IFile´s from the Project Explorer which are shown in a SWT TreeView.
The entries in this TreeView are some Beans organized in a flat List, but i provide an adapter to convert them to IFile´s.
<extension
point="org.eclipse.core.runtime.adapters">
<factory
adaptableType="de.dstg.delta.collections.model.Collection$Member"
class="de.dstg.delta.collections.CollectionMemberAdapterFactory">
<adapter
type="org.eclipse.ui.views.properties.IPropertySource2">
</adapter>
<adapter
type="org.eclipse.core.resources.IFile">
</adapter>
</factory>
</extension>
Eclipse Screenshot
It´s no problem to show a custom SWT menu but i think the right way is using the Eclipse menu structure, especially by providing default behaviour for Resources.
How can i show the default context popup menu, which is used by right-clicking resources in the Project Explorer, in my SWT TableView?
EDIT second question removed
EDIT2
According to the answer from greg-449, the problem remains that the context menu shows no entries i would like to have for this type of selection.
f.e. i need delete or open with or something like that 'file basics' without implementing it on my own.
We have also some other menus from additional plugins that should be visible here when the appropriate file type is selected. This works in Project Explorer but not in my table view.
I think the problem is the type of the selected element.
Plugin spy shows the following in my table view:
type of the selected element: Collection$Member,
interfaces valid for the selected element: IAdaptable
whereas the Project Explorer shows File and IFile, respectively.
My adapter works generally and delivers the related IFile while being triggered from an unknown Eclipse source.
I think i have to explicitely say, that the context menu should use the IFile type to get the correct menu entries but i dont´t know how.
Or did i miss something?
There isn't really a 'default' menu. Some menu items are defined to be added to all popup menus that define a specific place holder.
To use the place holder you must register your context menu with Eclipse, something like:
private void createContextMenu(Viewer viewer) {
Control menuControl = viewer.getControl();
MenuManager menuMgr = new MenuManager("#PopUp");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
#Override
public void menuAboutToShow(IMenuManager mgr) {
fillContextMenu(mgr);
}
});
Menu menu = menuMgr.createContextMenu(menuControl);
menuControl.setMenu(menu);
// register the context menu such that other plugins may contribute to it
getSite().registerContextMenu(menuMgr, viewer);
}
private void fillContextMenu(IMenuManager menu) {
// TODO add your actions
// Standard additions
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
You will probably also need to set your viewer as the 'selection provider':
getSite().setSelectionProvider(viewer);
Many menu items will check this to see what the type of the current selection is.
There is nothing that will automatically give you things like Open With or Delete, you have to add these yourself in the 'fillContextMenu' section.
You can use org.eclipse.ui.actions.OpenWithMenu for Open With.
IFile file = ... currently selected file
IMenuManager submenu = new MenuManager("Open With...");
submenu.add(new OpenWithMenu(getSite().getPage(), file);
menu.append(submenu);

Winium - how to access tool bar item if that bar doesn't have child

I am using Winium + Java for automation testing of Windows application, and trying to access tool bar menu.
When I tried to detect elements using UI Automation Verify, I couldn't see child elements under tool bar element like below screenshot.
enter image description here
But my tool bar definitely has sub menu items like screenshot and I need to access them.
enter image description here
I tried below java code, but it didn't work
WebElement el = driver.findElement(By.id('59398'));
el.click();
WebElement child = el.findElement(By.name('Start'));
child.click();
when I tried
driver.findElement(By.name"Start').click();
it clicked my windows start menu, not my application's menu.
Is there any way to access items under this tool bar?
You can try use another UI Inspector
eg. UI SPY or Inspector.exe
Probably your ID is not a AutomationID (process id?)
You should find a main window (parent of your app) (Example for calc) and get a parameter like AutomationId, ClassName or Name
I see this is MFC application, and this is an app side MFC library problem. If you hover mouse over toolbar button using Inspect.exe, the info is available but you can't reach this button from the hierarchy (the buttons have no parent somehow). Possible workaround involves combined Win32 API and UI Automation approach:
get button rectangle using Win32 API (but there is no text).
use ElementFromPoint method of UI Automation API and get actual texts to choose the right button.
P.S. My suggestion is applicable for Java + Winium in theory. But I can't estimate the complexity because I'm not a Java expert. So below is Python solution.
We have plans to implemented this mixed way in pywinauto. See issue #413. It contains Python code sample how to do that. We've had no chance to integrate it yet.
from ctypes.wintypes import tagPOINT
import pywinauto
app = pywinauto.Application().start(r'.\apps\MFC_samples\RebarTest.exe')
menu_bar = app.RebarTest.MenuBar.wrapper_object()
point = menu_bar.button(0).rectangle().mid_point()
point = menu_bar.client_to_screen(point)
elem = pywinauto.uia_defines.IUIA().iuia.ElementFromPoint(tagPOINT(point[0], point[1]))
element = pywinauto.uia_element_info.UIAElementInfo(elem)
print(element.name)

Eclipse RCP application Active Title Bar

I am working in an RCP application similar to Eclipse where the user can navigate in Project Explorer tree and opens any file in the Editor
i am Setting the RCP application title in a class which extends "WorkbenchWindowAdvisor" as the following:
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setTitle("My RCP Application title");
But what i need to show up in title bar the perspective name and the opened file path like in normal eclipse:
any suggestions
Thanks
This is requires listening to a lot of events in your WorkbenchWindowAdvisor.
In the preWindowOpen method you need to add listeners for:
Page activation and closing using configurer.getWindow().addPageListener(listener) The pageActivated and pageClosed listener methods need to update the title.
Perspective changes using configurer.getWindow().addPerspectiveListener(listener). The perspectiveActivated, perspectiveSavedAs, perspectiveDeactivated methods need to update the title.
Part activations using configurer.getWindow().getPartService().addPartListener(listener). This need to use an IPartListener2. The partActivated, partBroughtToTop, partClosed, partHidden, partVisible methods need to update the title.
You get the open file path from the active editor:
IWorkbenchPage currentPage = configurer.getWindow().getActivePage();
IEditorPart activeEditor = currentPage.getActiveEditor();
if (activeEditor != null) {
path = activeEditor.getTitleToolTip();
}
and the perspective name:
IPerspectiveDescriptor persp = currentPage.getPerspective();
if (persp != null) {
label = persp.getLabel();
}
The full, even more complex, code for this is in org.eclipse.ui.internal.ide.application.IDEWorkbenchWindowAdvisor

Eclipse RCP: Set active part programmatically or get selection of inactive part

in my Eclipse Plugin I have this workflow:
Get the currently selected project in the Package Explorer
Do something
Get the currently selected project in the Package Explorer (same as 1)
Do something different
1 (and 3) are realized like that:
ISelectionService selectionService = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
[...]
Now, the problem is that before 1, the Package Explorer is selected, because that's the only way to trigger the workflow. But step 2 changes the active part because it refreshes a TreeView which makes it the active part. When I now try to run 3, which is the same method as 1, I have a problem: The Package Explorer is no longer the activePart of the selectionService and therefore selection is null.
My questions are: Is there any way to get the ISelectionService for a particular View which is not the active one? If not, is there a way to programmatically set the active part before executing step 3?
Btw that's an Eclipse 3.x plugin.
If you find the IViewPart for the package explorer you can access its ISelectionProvider directly using:
IViewPart part = .. find package explorer view part
IViewSite viewSite = part.getViewSite();
ISelectionProvider provider = viewSite.getSelectionProvider();
ISelection selection = provider.getSelection();

Eclipse RCP 4.x - Defining workspace location

I know that this question was asked many times, but I didn't find an exact answer which would fulfill my desires :)
Long story short:
I've got simple E4 application, product project, feature and main plugin with simple trim window.
Works, after exporting works too.
Now. I add lifeCycleURI property, create bundleclass for it and create simple dialog with Text area and a Button. Run it\export it and it works, before running main Trim Window dialog is shown. Fine.. Cool etc.
But I want to enter location eg. C:\TEST and after clicking button I want it to be my workspace area for the application (with .metedata and so on). HOW ???
Of course I've tried with :
Location instanceLocation = Platform.getInstanceLocation();
instanceLocation.set(new URL("file", null, "C:\TEST"), false);
But... It says that I can't change location cause it is already set... Tried to use above in Activator. The same. Tried to add
-data #noDefault in products Launching Arguments ... The same...
I always try to accomplish my tasks by myself but this.... this... ehh... Help ?
You should be able to do this in the #PostContextCreate method of the life cycle class. Don't specify the '-data' argument
#PostContextCreate
public void postContextCreate()
{
Location instanceLoc = Platform.getInstanceLocation();
// Stop if location is set
if (instanceLoc.isSet())
return;
File file = new File("C:\\TEST");
instanceLocation.set(file.toURL(), false);
}
Note: You need '\\' in your file path.
This is adapted from code which I use in my e4 RCP.
If you are currently testing the application from within Eclipse you will need to clear the workspace location in the 'Run Configuration' for the application. Open 'Run > Run Configurations', find your application and clear the 'Location' field on the 'Main' tab.

Categories

Resources