I want to call an RCP command in code, like this:
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IHandlerService handlerService = (IHandlerService)window.getService(IHandlerService.class);
handlerService.executeCommand(cmdID, null);
With considerably more code, I can call the command with a string argument by assembling a Parameterization object then building a ParameterizedCommand and so forth but Paramaterization only allows for string values, and can't be subclassed.
What I really want to do is call the command with an object as a parameter. How can I do this?
Use ParameterizedCommand.generateCommand(). You can pass the command object (obtained from ICommandService) and the parameters in a map.
Related
In Eclipse CDT at DefaultBinaryFileEditor class, in the method getStorage there is a comment that tells the line objdump.getOutput(limitBytes) is a UI blocking call...
How can I make it run in background without UI Blocking to process longer files than it is stated with parameter int limitBytes = 6*1024*1024;
I can access org.eclipse.cdt.utils.Objdump class' getOutput method via plugin.xml extension point "org.eclipse.cdt.core.BinaryParser"...
I tried to replace the class that is used in extension point "org.eclipse.ui.editors" in editor tag with id "org.eclipse.cdt.ui.binaryEditor" via my plugin.xml, but this did not worked.
I put a boolean flag to outer class and in inner class BinaryFileEditorInput in method getStorage I put a Job and before this job works I created an empty fStorage = new FileStorage. I return this empty fstorage. So first the editor gets blank. Then when the objdump.getOutput(limitBytes) method returns in job, I set the fStorage to the returned output. I simply call the outer class'es refresh method. I put a reference of created outer class to inner static class in outerclasses constructor. This way I can access the refresh method. Also I moved fStorage varible to outerclass because refresh method triggers creating a new inner class so it overrides the valuable fStorage variable.
Finally If you want to update the opened elf file editor when you build the project again, assign the boolean variable and fStorage to first values in method resourceChanged before calling refresh method.
I would like to dynamically change the script that is executed when a index in an array is called.
The following is valid syntax:
actions[0] = script_do_something
...
actions[n] = script_do_something_else
How do I execute the scripts stored in the array? If I cant, then how else could I replicate a function pointer in GMS?
Unfortunately this doesn't work:
actions[0]()
I would like to avoid if statements as I feel they will get too long and messy.
you should use script_execute function.
script_execute(actions[0]);
also you may pass arguments:
script_execute(actions[0], arg1, arg2);
Is it possible to dynamically create objects or modify them on run-time ?for example,on button click,another button created or change number of lines of a road?
When I write this code for a button Action,in run-time
road123.setBackwardLanesCount(3);
I get error below:
root:
road123: Markup element is already initiated and cannot be modified.Please use constructor without arguments,perform setup and finally call initialize() .function
You'll get that error with any object you attempt to create at runtime using a parameterized constructor. If you create the object with a simple constructor (just "()") and then set all of the parameters individually, you won't run into that issue. Check the Anylogic API for specific information about the object you are using, because some require you to call .initiliaze() on that object after setting all of it's parameters if you created it using a simple constructor. Furthermore, if you want to add the object to the screen at runtime you'll need to add this code to the function that creates it:
#Override
public void onDraw( Panel panel, Graphics2D graphics) {
obj.drawModel(panel, graphics, true);
}
where obj is replaced with the name of the object you created dynamically.
Having a bit of hardtime understanding coffeescript. Why is this the window object in the set_position function?
window.App = {}
$ ->
driver = new Driver if ($('#drivers_become').length >= 1)
window.App.driver = driver
class Driver
constructor: ->
#get_position()
get_position: ->
if navigator.geolocation
navigator.geolocation.getCurrentPosition(#set_position)
set_position: (pos) ->
# this refers to window object in this case. why?
#latitude = pos.coords.latitude
#longitude = pos.coords.longitude
get_latitude: ->
#latitude
get_longitude: ->
#longitude
get_latitude and get_longitude return undefined in this case.
If you are using aDriverInstance.set_position as an event handler function, the browser will invoke it as a regular function not a method. To fix that, use a "fat arrow" when defining it: set_position: (pos) =>. But more broadly it is a question of invoking via dot notation and invoking via direct reference:
aDriverInstance.set_position(pos) will have this set to aDriverInstance and all is well
set_position_reference = aDriverInstance.set_position;set_position_reference(pos) will have this set to the window object.
This is a classic binding issue, and applies as much to Javascript as Coffeescript.
You are passing a Driver method, set_position to a Windows function,
navigator.geolocation.getCurrentPosition(#set_position)
That function evaluates set_position in the global, windows, context. In effect it ends up setting global latitude and longitude variables, not the attributes of the Driver instance. In your console see if those variables are defined.
What you want to do is define set_position so #is bound to the Driver instance. To do that, use the fat arrow, =>. http://coffeescript.org/#fat-arrow
set_position: (pos) =>
# this refers to window object in this case. why?
#latitude = pos.coords.latitude
#longitude = pos.coords.longitude
If you use this, and look at the compiled Coffee, you will see a line that does:
this.set_position = __bind(this.set_position, this);
Packages like jquery and underscore also have a bind function, as do recent browsers.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
get_position: ->
if navigator.geolocation
navigator.geolocation.getCurrentPosition(#set_position.bind(this))
Uses the browser's bind
There is this $entry method that we can use in GWT to allow external javascript to execute java methods.
You can see the explanations in their documentation https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsJSNI?hl=fr#calling
However, the example there is only with static methods. I'm trying to write it for a non-static method and when I try to call it, I get an exception :
java.lang.ClassCastException: Cannot cast com.google.gwt.core.client.JavaScriptObject$ to mypackage.MyModule
Here is my code :
public native void setRefreshModuleCallback() /*-{
$wnd.refreshModule = $entry(function() {
this.#mypackage.MyModule::refreshModuleJava();
alert('test');
});
}-*/;
public void refreshModuleJava() {
logger.log(Level.WARNING, "REFRESH");
}
What I find very funny is that alert is called, I see the result in the browser, but the call just before is not performed.
Do you know if it's actually possible to do such thing ?
$entry is not about calling java, it's about ensuring a few things go well in GWT: exceptions are routed to the GWT.UncaughtExceptionHandler, and commands scheduled via Scheduler#scheduleEntry and Scheduler#scheduleFinally are correctly called.
Your problem is the this. When the function is called, this is not your MyModule class (it's most probably the $wnd object). This is why the question you linked to uses var that = this. It's about scoping.
You also need to actually call the method, not only reference it: in JSNI, the first pair of parens are for the formal parameters (to disambiguate overloads), and you need another pair passing the actual arguments: that.#mypackage.MyModule::refreshModuleJava()().