Setting methods and parameter to your bean

Hi everybody,

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).

Paul

I have checked Patrick bean example code. But it looks like he is only using Properties in his bean :roll:

public class ServoySliderBeanInfo extends SimpleBeanInfo {
	
	/* (non-Javadoc)
	 * @see java.beans.SimpleBeanInfo#getPropertyDescriptors()
	 */
	@Override
	public PropertyDescriptor[] getPropertyDescriptors() {
		try {
	    	List<PropertyDescriptor> liste = new ArrayList<PropertyDescriptor>();
	    	liste.add(new PropertyDescriptor("background", ServoySlider.class));
	    	PropertyDescriptor pd = new PropertyDescriptor("border", ServoySlider.class);
        	pd.setDisplayName("borderType");
        	liste.add(pd);
	    	pd = new PropertyDescriptor("font", ServoySlider.class);
        	pd.setDisplayName("fontType");
        	liste.add(pd);
	    	liste.add(new PropertyDescriptor("focusable", ServoySlider.class));
	    	liste.add(new PropertyDescriptor("foreground", ServoySlider.class));
	    	liste.add(new PropertyDescriptor("inverted", ServoySlider.class));
	    	pd = new PropertyDescriptor("majorTicks", ServoySlider.class);
	    	pd.setDisplayName("majorTickSpacing");
	    	liste.add(pd);
...

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.

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 managed to find the code here: http://www.servoyforge.net/projects/ser … dbtreeview

But it’s not easy to see how they declare the methods for them to be displayed in Developer :|

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 8). :)

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;
		}
	}
}

But isn’t it your BusyBean object that is relevant in Smart client? There you should add your method…

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.

I have moved the IScriptObject implementation to BusyBean but it didn’t solve the problem :(
Here is my code:

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. :roll:

That has to be done in the getPropertyDescriptors() of a BusyBeanInfo class extending SimpleBeanInfo…

What has to be done in the getPropertyDescriptors() ?
I need to do something like

public PropertyDescriptor[] getPropertyDescriptors()
	{
		try
		{
			PropertyDescriptor methodLocation = new PropertyDescriptor("methodLocation", BusyBeanFactory.class);
			PropertyDescriptor methodName = new PropertyDescriptor("methodName", BusyBeanFactory.class);
			PropertyDescriptor changeWaitCursor = new PropertyDescriptor("ChangeWaitCursor", BusyBean.class);
			PropertyDescriptor result[] = { methodLocation, methodName,changeWaitCursor };
			return result;
		}
		catch (Exception ex)
		{
			System.out.println("InMemDataGridBeanInfo: unexpected exeption: " + ex);
			return null;
		}
	}

But I was thinking that it was for the properties of the bean. Not its methods :roll:

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 :roll:

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.

:oops:

Once again a stupid mistake :x Thanks.

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?

Foobrother:
I’ll have a look at the Glasspane and JDialog, but I think both are requiring a window, aren’t they?

the busy plugin is made for that!

Harjo:
the busy plugin is made for that!

Yes but it requires to run the process:

processFunctionName: (mandatory) the name (as string) of the function that will contains the 'lengthy' process, will be called by the plugin

I don’t want that.

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!

Really? Then what is you methodLocation and methodName for?

It’s remaining code from my previous bean that I don’t use (should be deleted).

Anyway, I have solved my issue :mrgreen:
By looking at your code (thanks to open-source :D ) I discovered 2 VERY interesting functions:

  • com.servoy.j2db.plugins.IClientPluginAccess.BlockGUI()
  • com.servoy.j2db.plugins.IClientPluginAccess.ReleaseGUI()

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 :)

And it seems to work well :wink:

You should really dig into the public API: http://www.servoy.doc/docs/publi-api/
This is where all these methods are coming from ;)