I am very interested in that, too. I can construct a nice looking menu but have no clue how to trigger a method if the user chooses an entry. I have the feeling that this is not possible. Does anyone have an idea?
Somehow I doubt it is possible to make javabeans trigger any Servoy method due to the very nature of the thing.
You can talk TO it…but it doesn’t talk back (with Javascript that is..).
Unless you use the bean to create a Servoy plugin that provides for the callbacks.
But I am sure Jan Blok or others can tell you for sure.
To Johan: You are right, we still want that real menu bar!
The jmenu comes in handy for example when creating a menu let’s say in the header of a list. There I could offer things that only apply to the items in the list. Apple does menus like this for example with their “action” menu. In an OS X finder window you can access file/folder related functions in such an action menu. Basically we are talking about a replacement/enhancement for a contextual menu that is visible to the user.
My impression is the same as Robert’s though: you can talk to the bean but the bean won’t talk to you? Is that right? All I see is a listener in the bean, but I don’t really see how I can put this to work.
a javabean or servoy plugin can talk back to servoy. But then it does need to know about servoy methods (that plugins do anyway) So if you make a bean then you can give that bean a method where you can give a javascript method as a parameter. Then that bean can call that javascript method on a specific time or event. That is how the Scheduler Plugin works.
So if you had a MenuBarPlugin (that is being build by paul bakker i believe) you should be able to attach a special menu that can call back any javascript method you want.
Those listeners interfaces are pure java. That you can also do in javascript but this is for the very advanced programmeurs…
that sounds really great! As far as I understand this, though, it will be “limited” to the main menu bar of a window, right? The question here was related to a menu that can be placed anywhere.
Two more questions:
Will this plugin be free or are you planning to sell it (if yes, how much will it more or less be)?
Since you already offer all required features for a custom menu bar, Servoy will not offer that themselves?
I am excited to see what wwe can do with your plugin! It does sound really great!
for now it will be limited to the Main MenuBar and MenuBars on forms in Dialogs.
I’ll have a look if i can add the feature requested here in the future.
The plugin will not be free of charge (spent a lot of time getting it to work properly ). The exact prizing is yet to be determined, but will be a lot less then comparable products in the FM world…
as for what Servoy will include or not: I do not have influence on that, but from what I hear is that if there is a plugin available that does the trick, they will work on other requests first.
Am I correct in thinking this plugin will allow methods to be assigned to keystrokes and/or a combination of keystrokes? There are a few basic methods that I would really like to be able to assign keystrokes to instead of having the user have to hit a button for. If your plugin will allow that I too will be in the queue! Any update as to when it will be available?
jcompagner:
…So if you make a bean then you can give that bean a method where you can give a javascript method as a parameter. Then that bean can call that javascript method on a specific time or event…
Let me make sure I got this right. I assume the method you are talking about would run on any change to the bean UI, for example movement of the slider in jslider. This would then run some javascript passed as a parameter and this would have access to Servoy methods??? Interesting interface. What would this javascript passed as a parameter look like?
Now if Servoy can read and write properties of a bean and execute its methods, can it also set a change listener method of the bean to do the above passing the javascript needed along the way?
What’s it take to do this? I’m not a java coder, but have friends who could help but they are clueless on servoy. Any guidance appreciated.
yes this all is possible
If you make the bean/plugin in java then you can let java call a javascript method on any kind of event
Please let youre friends look at the scheduler plugin. The src is included
yes this all is possible
If you make the bean/plugin in java then you can let java call a javascript method on any kind of event
Please let youre friends look at the scheduler plugin. The src is included
Please could someone show me a really simple example of how to call a Servoy method from a Java Bean? I’ve looked at the Scheduler example and just can’t see how its done…
I’m not really a java programmer, but have managed to create a java bean and include it Servoy, just need to do this bit.
Hi Nick, it is a combination of different bits and pieces. It is not at all that difficult but also not too simple to ‘write it down’. The easiest way imho is that scheduler plugin…
I think I saw that the plugin API in Servoy 3.0 eta’s now includes a function to execute a method. If I saw correctly, this will probably simplify things a lot.
nick:
Please could someone show me a really simple example of how to call a Servoy method from a Java Bean? I’ve looked at the Scheduler example and just can’t see how its done…
I’m not really a java programmer, but have managed to create a java bean and include it Servoy, just need to do this bit.
Thanks,
Nick
Hi Nick,
The following is a bit of code that when called from your bean will invoke a method in Javascript within Servoy:
// ... inside your Java bean class.
private org.mozilla.javascript.Function jsClickyFunction;
/**
* This has a js_ prefix so that the Servoy Javascript can see it and
* call it to pass in the name of your callback method.
* Ex: (In Servoy Javascript)
* elements.mybean.setClickyCallback(myCallbackMethod);
*/
public void js_setClickyCallback(Function f) {
this.jsClickyFunction = f;
}
/**
* When something is clicked in your bean, or whenever you want to
* call Javascript.
* Remember, jsClickyFunction is set to the value of your javascript
* method (called by javascript above).
*/
private void somethingWasClicked() {
if (jsClickyFunction == null) return;
Context context = Context.enter();
try {
// This is where the javascript method is actually invoked.
jsClickyFunction.call(
context,
jsClickyFunction.getParentScope(),
jsClickyFunction.getParentScope(),
new Object[] {
"first string parameter passed to Javascript.",
"The objects in this array will be passed",
"to your javascript method as arguments...",
"eg. var arg1 = arguments[0];",
"eg. var arg2 = arguments[1];",
"... ",
new Integer(25)
});
}
catch (JavaScriptException jse) {
jse.printStackTrace();
}
finally {
// Important to ALWAYS include this finally block!
Context.exit();
}
}
This is the basic structure of calling a javascript method. If you don’t want to pass any parameters to the javascript method, just leave the Object array empty… (new Object {}).