java action on multiple checkboxMenuItems at the same time - java

I'm working on a java project in NetBeans. I have put 5 checkboxMenuItems in 1 Menu (First Class) (see picture). Now I want to be able to check or uncheck multiple items at the same time. Meaning that I want to open the menu once, check and uncheck what I want & then use a function that looks which are selected or not. I know I can do 'actionPerformed' on each separate checkboxMenuItem, but that's not what I need here.
How should I handle this instead?

Related

IntelliJ - View a *single* method in a class full of many methods

Is there a way to just see one method of a class in the IntelliJ IDEA editor and hide everything else, and/or toggle between this and the regular view.
Please note, I'm not looking to fold/collapse other methods, which is certainly a way to minimize getting lost in a large file.
I am looking for a way to only view a specific method I'm working on within a class.
e.g. If there is a legacy code where an existing class has 10 long
methods (each ~50 lines long), and I'm working on one of them and don't wish to be lost in
the 500 lines of code and need to focus on a single method thereby narrowing my view to 50
lines of code.
I do remember a few versions back that this was possible, but am not able to find that setting now.
Further clarifying my question. Consider the method selected in the image below
I am interested in a view that'll show just the method like below (with all the java capabilities like code highlighting, refactoring etc., enabled of course):
In IntelliJ IDEA 2019.3.3 (Community Edition) there's a fold option 'Fold Selection' that hides even the signature.
Select / highlight the code above the method you want to focus on
Right click > Folding > Fold Selection. Shortcut = cmd + .
It might be in earlier versions but I haven't checked.
Fold selection menu option

JCheckBoxes inside JComboBox

I have added checkboxes inside combo box in Java. But when I open drop down menu and check one check box, the drop down menu closes. So to select each check box I have to open it every time.
Is there any way so that I can keep the drop down list opened till the time I dont click outside so that I can select any number of check boxes at one time only.
Please help!!
I have added checkboxes inside combo box in Java. But when I open drop
down menu and check one check box, the drop down menu closes. So to
select each check box I have to open it every time. Is there any way
so that I can keep the drop down list opened till the time I dont
click outside so that I can select any number of check boxes at one
time only.
no there isn't, this is default property of (BasicXxx)Popup implemented in Swing API, workaround for series of Bugs in Java1.4_xxx
no_way, only by using dirty hacks, usage of can be Java Version sensitive, or required left mouse button as accelerator
don't do that, another way (and proper of possible ways) is usage of JWindow/undecorated JDialog but required to override ESC Key and Focus lost in Windows three (as you can see in good Java JCalandars/JDatePickers),
I recommend that you to use the Japura API to deal with this, check this link:
http://www.japura.org/checkcombobox
Best Regards :)

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.

CNF: Remove SOME popup options (from the ones that are platform contributions)

I need to modify popup menus using CNF. I already read documentation about using action providers and about using "allowsPlatformContribution" to restrict options that are platform contributions. I already used some of these concepts sucessfully to add/remove popup options. But there is one thing I need to do and I don't know how:
Related to PLATFORM CONTRIBUTIONS, I mean declared by org.eclipse.ui.popupMenus (in my case they are standard options: "Validate", "Run As", "Debug As", "Profile As",
"Team", "Compare With", "Restore from Local History...", "Java EE Tools", "Source", "Configure") I just want to show two of them: "Team" and "Compare With" (with all their suboptions).
If using "allowsPlatformContribution=false", then ALL options are removed !. The only idea I have right know is to set this to false and to create an actionProvider for each of both options I need to show, but it seems a bit hard, because I have to add all the suboptions
in it (invoking the appropriate Eclipse action) !. Is that a good way to solve my problem ?. There is another way easier and better ?... I hope so.
Please help. Thanks a lot.
Rosa.
You can use Activities to show/hide elements in the user interface (including menus).
What you have to do is create an Activity and bind it to the UI element. Then, when you enable/disable your activity the platform will automatically show/hide the element bind to it.
For more details on the exact implementation, check out this page:
Eclipse Activities – Hide / Display certain UI elements

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.

Categories

Resources