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)
Related
Is there a keyboard shortcut I can use to jump to the method that would get run if I clicked the run button?
In this case, how can I jump my keyboard cursor to JustATest.testName()?
You can jump to a specific method or field by adding a pound character (#) when you do a class search.
Depending on your keyboard setup, a class search is done with Command+N or Ctrl+N.
So, you'd want to type in the pop-up dialog TestClassTest#testMethod, and it will take your cursor straight to it. There might be a bit of shakiness with split panes, but for the most part, this is a simple solution that works in the general case.
The other way involves placing a bookmark on that line of code, and recalling it either through the Favorites bar or through the provided shortcuts.
Outside of that, you don't have many other options. IntelliJ wouldn't be able to divine that this method will for sure be run, since any manner of exceptions could occur before it gets to that method. At that point, you're left with just breakpoints in your code.
I am making a program in Java and I have a SWT tree widget that the user is supposed to toy with via drag and drop.
Now the problem is that when the user drags and drops a branch, I want to change the branch item's parent to whichever treeItem it was dropped on, but there doesn't appear to be any way to do so. I could simply create a new treeItem, but there is no easy way to transfer the children, so I need to redefine all the children, and their grandchildren and so on recursively. It seems pretty klunky and inefficient to me that I need to remake the entire branch just to change the parent.
Is there any clean way to do this?
Well, the clean way is to separate view/widgets from model (as in MVC). In case of SWT, you should use TreeViewer and implement ITreeContentProvider. jFace will take care of creating tree nodes for you and you only need to update your model and refresh the viewer.
I just started yesterday using GWT, so maybe I'm not using the proper mechanism to solve that problem. So, I will try to explain exactly what I'm trying to do (with a simple problem) and 2 solutions I came up with to address that problem.
Problem:
Remember an index that can be updated via other widgets. Let's use focus to represent it.
[button 1]
[button 2] [button A]
[button 3]
The buttons [1..3] and [A] are not in the same class and need to find the element using the id using the DOM. The reason is that those 2 views needs to be orthogonal.
We can use up/down key to move the focus from button 1 to 3.
If we are on the buttons [1..3] and press right, we go to button A.
If we are on the button A and press left, we go to button previously focused.
What we want to do is save or set the focus index when pressing right.
Solution 1: Global variables
I'm not usually fond of global variables, but in some case it's handy. By using, for instance, a dictionary (Dictionary.getDictionary) defined globally in the javascript, I could save the current index in it using the "Focus Event" in that case.
So, in the key press event, when left would be fired, I would just read the value in the dictionary.
I haven't tested yet, but I think it should work.
Solution 2: Set the value with the Element
Element element = DOM.getElementById("button id A");
element.<setFocusLeftKey>("button id [1..3]");
Here what I would like to achieve is just in the "onFocus" Event, I would simply set the value of that button.
So is it possible to cast/find the object with the Element? I think that if there is no easy way, it's probably because it's not recommended.
Is there a simpler way/other method to achieve that?
So, any thought or solutions?
Thanks in advance.
P.S. I haven't found a better title for that, so if any suggestion, just put it in the comments and I'll update it.
Using ID is definitely not the suggested way to do this in GWT. You say you need this mechanism to keep your views orthogonal to one another. This is noble, but in GWT you would achieve by using another resource (an EventBus, implemented in SimpleEventBus) that hides the different components from one another. In fact, I would argue that looking up the element by ID strongly couples the two views and is smelly.
Armed your EventBus you simply create and fire custom events that let the views (or, better, their presenters) communcate with one another. For example here you could have: NavigateRightFromButtonsEvent and NavigagteLeftFromButtonA event.
However, depending on the size of your app (or as a first experiment) you could decide to couple your two views. In this case simply pass the view for the button list into the one for button A and vice-versa. This is not really worse than relying on a global ID.
No matter which mechanism you choose (event bus or wiring the views together), you should now have access directly to the instance of the widget you want to highlight. To focus, just call setFocus(true) on it.
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.
I have mixed some different types of command like OK,CANCEL,BACK,EXIT,SCREEN in my application.
For Example,
exit = new Command("Exit", Command.EXIT, 5);
_123=new Command("123",Command.BACK,4);
ABC=new Command("ABC",Command.CANCEL,3);
sample1=new Command("Sample1",Command.SCREEN,1);
sample2=new Command("Sample2",Command.OK,2);
The Order i need is :Sample1,Sample2,ABC,Exit. But it Display like this Sample1,Sample2,Exit,ABC are right side and 123 is placed in left side button.
Here, I also have one problem while adding one more command(Edit_Cell) using like below.... and also i need to display in the first place before Sample1.But it displayed in End of all the commands on right hand side.
I have added this new Command(Edit_Cell) in another src file constructor and call that constructor in below of my above code(adding commands).
Edit_Cell is type of SCREEN and PRIORITIES IS 1 on the other source file.
My Final Order i need is : Edit_Cell,Sample1,Sample2,ABC,Exit, on right hand side and _123 on left hand side.
First of all, and without offense, I think you should elaborate a bit more your written compositions, it took me a while to understand the issue.
Still, the way you claim commands makes sense according to this (Nokia's wiki forum):
The Command mapping to softkeys follow following rules:
Right softkey: There can be only one
"negative" Command (STOP, CANCEL,
BACK, EXIT in this priority order)
mapped to Right softkey, and the
Command mapped there is directly
invoked by softkey press.
Left softkey: Mutiple commands can be
mapped under Left softkey in which
case there is "Options" label in Left
softkey and selection of it will open
a menu of commands. If there's however
only a single "positive" Command (OK,
ITEM, SCREEN or HELP) under left
softkey it will be presented directly
on Left softkey. (Note: Some LCDUI
components have their own operations
that will be also visible under left
softkey thus forcing Options menu.) If
there's more than one negative Command
this will force Options menu on Left
softkey and the commands will be
presented in the order define below.
Middle softkey: In Series 40 only a
single context sensitive Command (OK,
ITEM) is mapped to Middle softkey. In
S60 multiple context sensitive
Commands (OK, ITEM) can be mapped to
Middle Softkey. If there's only single
Command it will be shown directly in
softkey, otherwise commands are
visible in context sensitive menu
opened from middle softkey. Normally
the same commands mapped to Middle
softkey are also available in Left
softkey (directly or via Options
menu). Note: Some UI components
override this rule and place component
specific operation directly to Middle
softkey. For example, POPUP
ChoiceGroup has "Open" operation in
Middle softkey.
Obviously this depends a lot on the platform, but it seems your midlet is assuming _123 as the negative Command, and all others are placed on the other soft key.
I would try to change the types and set the priorities as you wish... something like this
exit = new Command("Exit", Command.EXIT, 5);
_123=new Command("123",Command.BACK,0);
ABC=new Command("ABC",Command.SCREEN,3);
sample1=new Command("Sample1",Command.SCREEN,1);
sample2=new Command("Sample2",Command.OK,2);
And you can set the priority of Edit_Cell to 0 and its type to SCREEN. And just to add: ITEM commands are usually placed before.
I hope this helps.
Regards.
I reply to your comment here, it's less messy...
Maybe it's displaying the commands in the same order they were added (not using priorities). I would delete all commands when Edit_Cell is added and add them all again, after Edit_Cell is added.
If you can only modify your form's code, then you can override the addCommand method to ensure when Edit_Cell is added all previous commands are removed and added again later.
Something like this:
#Override
public void addCommand(Command cmd) {
if (cmd.getLabel().equals("Edit_Cell")){
removeCommand(sample1); // with all the previously added commands
}
super.addCommand(cmd);
if (cmd.getLabel().equals("Edit_Cell")){
addCommand(sample1); // again with all your previously added commands
}
}
It's not very elegant, but well, you can always make it more classy, as long as it works....