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.
Related
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?
I have to complete a Java 7/8 project for a client with a requirement regarding four (4) checkboxes on a Java GUI form. I would rather not use the latest Java 8 feature, if there exists such a new feature, and stick with what works for older Java versions, as well.
I am having trouble with the logic regarding how the checkboxes are supposed to work together, and I am hoping someone might be able to help me solve this. I do not have trouble selecting and unselecting a checkbox, only in the logic governing all four, as such:
Consider the checkboxes named:
userCheckBoxA, userCheckBoxB, userCheckBoxC, and userCheckBoxD
At this point, neither is selected on GUI startup, but I am willing to change that to selecting CheckBoxA at startup, if that helps the logic here.
What I need to accomplish is if CheckBoxA is selected, then the other three are cleared, and if either B, C, or D is selected, then A is cleared. As it is supposed to work, B, C, or D might be selected after A is selected, which means that A selected would make no sense. If A is selected, then B, C, or D selected would make no sense.
I am currently using a public class ActionHandler implementing ActionListener with each checkbox registered with (eg.) userCheckBoxA.addActionListener( checkBoxListener) The checkboxes are in a panel, but (currently) they are not grouped in another manner.
With every attempt that I have made, I have (basically) created an infinite loop (of sorts) when certain checkboxes are selected in a certain order.
I am hoping that someone with more experience that I can look this over and solve this logic puzzle for me.
I have a class called EntitiesContainer that holds multiple compartments.
What I did is basically, when you right click on the compartment or compartmentName to listen to this event through a double click listener that is applied to both the compartmentXEditpart and compartmentXNameEditpart.
Now, I would like to achieve something like expanding or collapsing this compartment based on the double click but I havent found any way to do this. How can I approach it through the EditPart of this compartment?
Also would it be possible to close all other compartments when one opens, and if so this has to be done with AddSemanticListeners-listenerFilters ?
Any clues will be appreciated.
To expand/collapse compartment you'd need to create ChangePropertyValueRequest, get the command for that request from your compartment editpart and then execute that command on the command stack (expand is a boolean):
ChangePropertyValueRequest request = new ChangePropertyValueRequest(
DiagramUIMessages.PropertyDescriptorFactory_CollapseCompartment,
Properties.ID_COLLAPSED, expand);
getDomain().getCommandStack().execute(command);
Yes you could also open/close other compartments buy creating the same request and creating extra commands (exactly as shown above) for sibling compartment editparts. The only complication is that you'd have to find those sibling compartment editoarts in the editparts tree.
Also once you have a number of these commands wrap them in the GEF's CompoundCommand or GMF's CompositeCommand such that a number of commands is executed as one command and undo/redo actions would treat this case correctly.
(Have a look at org.eclipse.gmf.runtime.diagram.ui.internal.tools.CompartmentCollapseTracker)
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.
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.