Netbeans platform and menus - java

Does anyone know how to edit the menus shown in the skeleton created by the Netbeans platform?
Thanks in advance for the time you will spend trying to help me.

Preamble: the only way to edit menu items that are present in the platform is through one of your own modules. This means that in order to remove or rename a menu item in another module you must first add a module to your application. Your application is not itself a module but a (potential) collection of modules.
The simplest way to edit the menus for an NB Platform based application is the following:
In one of your modules, expand the Important Files node
Expand the XML Layer node (assuming the module has a layer file¹)
Expand the This layer in context node
Expand the Menu Bar node
Right-click on any menu (folder node) or menu item (file node) and select Delete
This will add the necessary entries to your modules layer file (_hidden entry) and as long as this module is loaded these menus and menu items will not be loaded. If you want to restore an item in the future you can either remove the entry from the layer file or right-click the item and select Restore.
Edit
Here's a method for renaming a menu item:
Using the above technique to find the entry you want to rename
Right-click the node and select "Go to Declaration"
Look for the attribute with a name of "SystemFileSystem.localizingBundle"
Open the application's branding interface (right-click on your application's node and select Branding...)
Choose the Resource Bundles tab
Look for the Bundle node that has the value you found in step 3
The name of the menu item will be located in this Bundle's node. Just edit this and it will be changed in your application. The key here is to locate the Bundle that the menu item is named in.
Here's a method for replacing a menu item's action:
Follow steps 1 and 2 from the previous outline
Once you've gotten to the declaration, search (Ctrl + F) the same file for the originalFile value (you're only looking for the .instance declaration)²
Once you've found where the action is defined, copy the structure to your layer file
Using the delegate attribute you can redefine what action is used for this menu item
The point here is to override the menu item's action definition in your layer file, replacing the action with your own. You can also use this technique to override the display name of the action but the Branding technique is simpler if you don't need to replace the action as well.
¹If your module doesn't have a layer file you'll need to create one before you can use this technique. This requires that you create a layer.xml file in one of your module's packages. Then you need to register this file in your Modules Manifest file using the following OpenIDE-Module-Layer: com/example/mymodule/layer.xml
²For this step you can highlight the .instance name of the originalValue attribute's value and press Ctrl + F. For example, if the originalValue attribute's value is Actions/Window/org-netbeans-core-windows-actions-RecentViewListAction.instance you want to highlight only the org-netbeans-core-windows-actions-RecentViewListAction.instance part. The point here is to find where the action is defined (this part of the layer file is only adding the action to the menu).

In addition to what has been nicely explained above, here is a simple trick to add your own global menu item without even looking to the XML file content:
In your module tree go and find the file named layers.xml
click on the layers.xml node to unfold its children, these are two folders:
this layer
this layer in context
unfold the "this layer in context" node and go to the sub-folder Menu Bar
right click and add a new folder (name it History e.g) inside Menu Bar. The name of this new folder will be used as a category in the global menus of you main GUI window.
To add a sub menu item to this global menu, right click on your module, choose new->action action and when asked to select the menu to place this sub menu in, choose History.
PS: you can also add a category to the Toolbar as you did for the Menu Bar.
Thank you

I'm not sure what exactly you want to do, but the layer.xml file is usually the place to do such changes.

Related

In Intellij Idea, how to keep showing context information?

I know for sure that by clicking hot key alt + q, the context of current method or class could show up just like:
But is there any way to make the IDE keep showing the context information at the top of the edit area?
You can't keep the method definition for the 'currently active' method pinned to the top of the editor but if your goal is to display the method definition for the 'currently active' method while you are editing that method then you could use the Structure tool window and select Autoscroll from source. This will show you the definition of the method you are currently editing / your cursor is currently sitting in.
Here's a screenshot:
Autoscroll from source is the last icon on the right at the top of the Structure tool window.
You can activate the Structure tool window via keystokes (e.g. ALT 7), to identify the correct keystroke just have a look at the keystroke associated with the menu item: View > Tool Windows > Structure.
More details in the docs

In Eclipse, is there a view that shows members of the currently selected element

When I have an interface or class open in the editor, I can see all the members in the outline. The "Javadoc" view shows the docs of the element currently selected - whatever I click on.
I want a combination of these views. I want to see all members of the currently selected element. I know I can see them if I declare a variable and bring up the content assist. But that is too cumbersome. I want to click on an element, see its vivible methods and attributes in a view without loading the file into the main editor window.
Can it be done?
You can use Ctrl + F3 to open a popup with the outline of the current element, with focus in a search field. I think it's the most useful. Skike Ctrl + F3 to get also inherited members in the same popup.
You can also use F4 to quickly open a the type hierarchy view on the selected element. This view contains the subtype and/or supertype hierarchy of the element, and also the members/methods of the element (and its parents with the button 'show all inherited members').
You can expand the element in Package explore and see all the methods and variables declared

Get the order of selection from an IStructuredSelection

I wrote an Eclipse plugin which allows the user to compare SLOC counts between two projects. The plugin is kicked off simply by highlighting two projects in the Project Explorer View, right clicking, and selecting the plugin (the plugin is launched via the context menu). The plugin always compares ProjectA to ProjectB regardless of the order ProjectA and ProjectB were selected. I would like to use the order of selection to determine if the user will get a comparison of ProjectA to ProjectB or ProjectB to ProjectA.
Given an IStructuredSelection, how can I tell which project was selected first?
BTW - It seems that getFirstElement() does not give you the first element selected, just the first element in the list (which, again, is not necessarily the first element [Project in this case] selected)
You can't get the order of selection from the IStructuredSelection, but there is another option. For menu/popup actions you get the current selections by having a selectionChanged(IAction action, ISelection selection) method. This method is called whenever the selection changes. Normally you throw out the last selection and just keep the new IStructuredSelection, but if you compare the previous IStructuredSelection to the one that's been passed to you you'll see what's been added and removed since the last selection action. By tracking these changes over time you should be able to know the order of selection.
You simply should not make this depending on the order of selection events. As a user, I would be very angry, if I not only have to choose 2 projects, but must click them in the right order to get the result I want.
Instead, put a button or other UI element into your results view to "switch comparison order". That's way more easy to understand and remember for users.

How do I get the caller(s) of a method without running this system (written in JAVA)

In java, How can I get the caller(s) of a method without running this system.
My purpose is to find the callers of some methods (around 150 methods) and want to get
the name of all callers of each method. Is it possible to do that?
Is there possible way to do it ( that is not to use call hierarchy or reference in Eclipse because I need to find the callers of many methods and record it to my excel file.)?
Thank you very much.
In Eclipse, you can do this by right-clicking the method, and choosing "Open Call Hierarchy".
Also, in Eclipse, you can do this by right-clicking the method, and choosing "references" -> "XXX"
As David mentioned, this is called the Call Hierarchy. You can access it from the right-click menu, or just use the keyboard shortcut: put your cursor on the method name, then press Ctrl + Alt + H.
In Eclipse, you can do this by right-clicking the method, and choosing "Open Call Hierarchy".
See 5 options given on right side top of that panel (Refresh) (Cancel Current Search) (Show Caller Hierarchy) (Show Callee Hierarchy) (Show History List)
For You the 3rd option will work..
In eclipse you can right click on the method name and click 'Open Call Hierarchy'. Another panel opens and select 'Open caller hierarchy'
Bit late to the party, but based on your updated question and comment, you want to retrieve the names of all callers of multiple methods in one go (and not have to do the same thing, i.e. open Call Hierarchy, 150 times) and end up with something in a format you can use in a spreadsheet.
Here's how to do that with Eclipse for anyone facing the same issue (as I did recently):
Get all the methods whose callers you're interested in into the same view. If they're all in the same class, the Outline view will do, otherwise do a search and get all your methods to show in the Search results view - you can specify all sorts of interesting criteria in there, in your case you might want to search for methods in selected resources (select your classes in the Package Explorer first).
Select all the methods whose callers you're interested in in that view. Hold down Ctrl and click to multi-select, or do Ctrl+A to Select all and then de-select the ones you don't want with Ctrl+Shift+Click.
Open the Call Hierarchy on all those methods. Either drag those selected methods onto the Call Hierarchy view, or use Ctrl+Alt+H, or use the context menu. This will show all the callers of all those methods. (If you want to dive deeper, expand as required to retrieve callers of callers, etc.)
Select all in the Call Hierarchy view. Just do Ctrl+A while the view has focus.
Copy the methods' qualified names to the clipboard. There's no keyboard shortcut for this by default, but you can right-click on the selected files and select Copy Qualified Name. You'll end up with a bunch of lines of the format <package name>.<class name>.<method name>().
Paste into your favourite text editor or spreadsheet and manipulate as required.
Tested in Eclipse neon.
In Netbeans, right click on the method and go to "find usages". Alternatively, click on the method name and then hit alt+F7.
EDIT: Oops, just seen this is tagged for eclipse and not netbeans. Still, I'll leave it here in case it's useful.

How to extend Eclipse's compare context menu?

I want to create a plugin that displays additional information about Eclipse's compare results. For example, clicking a difference in Eclipse will bring up additional meta-information in my new view about who made the change, when it was made, what are the related changes, etc. I've got everything else figured out except how to call the view from the compare editor. I am thinking of using a context menu.
I was able to implement a context menu for the text editor. I used a targetID of targetID="#TextEditorContext and the action to inherit from IViewActionDelegate. But somehow the compare editor is not the same as the normal text editor. What targetID should I use? Is this even possible? Or if someone has a better idea than context menu, do share.
I was able to add additional commands (Handlers) to the compare view's context menu using the popup menu id popup:org.eclipse.compare.CompareEditor?after=additions

Categories

Resources