I have created a bean. But now I would like to be able to call methods which are part of the bean and can be viewed in Servoy Developer Explorer (when the bean is selected). Like for the dbtreeview bean which has the “bgcolor” “fgcolor” parameter or “addRoots” “refresh” methods. How do you declare these methods into your bean code?! I have 3 classes in my bean:
Bean.java » contains the bean process/main methods.
BeanFactory.java » implements IServoyBeanFactory
BeanFactoryInfo.java » extends SimpleBeanInfo
I have tried to put my methods into Bean.java and BeanFactory.java but it doesn’t pick them up.
I think the best way is to check out Patrick Talbot’s tutorials and/or check out the source of the beans that already do this (like the DBTreeView bean you mention).
Foobrother:
And for dbtreeview bean I check the jar but it does not contain any java file. I’ll check on ServoyForge to see if there is the source code.
At this moment the dbtreeview bean is not a project on ServoyForge.
I have finally found in Patrick tutorial where he speaks about declaring these methods. It’s in the part 3 section “M. Adding JavaScript to our bean” (page .
I think I have done what he explained, I used his ServoySlider.java and ServoySliderBeanInfo.java
I think I did the same. But it doesn’t work: no method displayed in Developer.
Here is my code: BusyBeanFactory
public class BusyBeanFactory implements IServoyBeanFactory, IScriptObject {
public IClientPluginAccess icpa;
public BusyBean fdb;
public String methodName = "checkURL";
public String methodLocation = "globals";
public BusyBeanFactory() {
super();
}
@Override
public IComponent getBeanInstance(int servoy_application_type, IClientPluginAccess arg1,
Object[] arg2) {
if (servoy_application_type == IApplication.WEB_CLIENT || servoy_application_type == IApplication.HEADLESS_CLIENT)
{
return null;
}
else
{
icpa = arg1;
fdb = new BusyBean(icpa, methodLocation, methodName);
return fdb;
}
}
public void js_ChangeWaitCursor(){ //THE METHOD I WANT TO DISPLAY IN DEVELOPER
fdb.ChangeWaitCursor();
}
...
//IScriptObject methods implementation
BusyBeanFactoryInfo
public class BusyBeanFactoryInfo extends SimpleBeanInfo {
public PropertyDescriptor[] getPropertyDescriptors()
{
try
{
PropertyDescriptor methodLocation = new PropertyDescriptor("methodLocation", BusyBeanFactory.class);
PropertyDescriptor methodName = new PropertyDescriptor("methodName", BusyBeanFactory.class);
PropertyDescriptor result[] = { methodLocation, methodName };
return result;
}
catch (Exception ex)
{
System.out.println("InMemDataGridBeanInfo: unexpected exeption: " + ex);
return null;
}
}
}
Yes, for Servoy to pick it up, your js_ChangeWaitCursor() should be located in the IScriptObject implementation, in tyour case the BusyBean.
The IServoyBeanFactory is just what its name implies, it is a Factory, meaning its purpose is to create the real objects.
Ohh! I just discovered that by looking at the available methods of the bean in the code using “elements.myBean.” it pops up my method! But it still not display it in the methods explorer when you select the bean.
But I was thinking that it was for the properties of the bean. Not its methods
By the way, I’m having an issue with my bean behaviour. The bean is a JPanel. When I place the bean over buttons in my GUI. When I run the solution and click on the JPanel it clicks also the buttons behind the JPanel. I thought it would act as a pop-up window and disable the buttons covered (I need to revise my Swing!). Is there any way to make this panel non-clickable?
Foobrother:
But I was thinking that it was for the properties of the bean. Not its methods
No you are right!
The getPropertyDescriptors() is for the bean properties, not the IScriptObject methods that you see in elements.myBean in the SolutionExplorer.
So this will work if you correct the getSample() and getToolTip() methods of the BusyBean class, look closely at the argument variable you receive:
public String getSample(String arg0) {
if (methodName.equals("ChangeWaitCursor")) //$NON-NLS-1$
...
}
public String getToolTip(String arg0) {
if ("ChangeWaitCursor".equals(methodName)) //$NON-NLS-1$
...
}
You try to test methodName but it is always null, in the getToolTip() method it doesn’t generate an exception because you do it safely, but in the getSample() nethod… boom
What are you trying to do anyway? Using a JPanel to create a Popup of some kind? Or blocking the UI / rewriting the Busy plugin?
If the latter, you would better use the GlassPane of the JFrame or JDialog.
Yes indeed, I’m trying to do another Busy system. Because I would like something more sober. The user would see only the cursor in “Wait mode” and wouldn’t be able to click anywhere but the GUI would remain the same (nothing looking disabled and no grey pane).
With the JPanel I managed to do it but people can still click on the GUI behind
I’ll have a look at the Glasspane and JDialog, but I think both are requiring a window, aren’t they?
Really? Then what is you methodLocation and methodName for?
Most certainly you do something while you set your users to wait, which could be put in the processFunction couldn’t it?
As to not see any change in the display except for the cursor, you could set the opacity to 0% and put a space as a string, and no cancel button, and you would have exactly what you are trying to achieve.
BTW, I have fixed the busy plugin for 5.2 now, will publish a v2.1 soon, there was an issue with the cancel method that was called AFTER the process finished which kind of defeated the purpose. After much fiddling with different ways using Threads and other stuff, I finally managed to workaround this limitation introduced in 5.2. Stay tuned on ServoyForge for an update version!
They do exactly what I’m looking for: changing the cursor to “Wait mode” and blocking the GUI.
And, as I didn’t need to do any Swing stuff anymore, I just made a plugin instead of a bean