Creating Custom Controls

This topic describes how to use a custom custom control. It explains how to:

Custom control files can be located:

To Create a Custom Control

The following instruction assume you are in the J2EE perspective (Window > Open Perspective > J2EE).

  1. You cannot create a control in the default package. So the first step is to create a package for the control. For example:

    <ProjectRoot>/src/controls/myControl/
  2. Right-click the package and select New > Custom Control.
  3. In the Control name field, enter the class name for the control.

    The Java interface and implementation classes will be based on the name entered here. For example, if you enter Hello, two classes will be created:

        Hello.java (=the interface class)

            and

        HelloImpl.java (=the implementation class)
  4. Click Finish.

Default control interface and implementation classes are produced. Assuming that your control is named Hello, the following class files are produced:

Hello.java Interface Class File

package controls.myControl;
 
import org.apache.beehive.controls.api.bean.ControlInterface;
 
@ControlInterface
public interface Hello {
 
}

HelloImpl.java Implementation Class File

package controls.myControl;
 
import org.apache.beehive.controls.api.bean.ControlImplementation;
import java.io.Serializable;
 
@ControlImplementation
public class HelloImpl implements Hello, Serializable {
	private static final long serialVersionUID = 1L;
 
}

Continue the composition of the custom control by adding methods to these class files.

To Use a Custom Control in an Application

If you have an existing custom control in your project or in a utility project in the current workspace, you can add a reference to that control to a control client by right-clicking anywhere within the client's Java source file and selecting Insert > Control.

A list of available controls appears. The heading Existing Project Controls lists the controls in the same project as the client. The heading Existing Application Controls lists the controls in the utility projects in the same workspace.

When you add a control reference to a client, Workshop modifies your client's source code to include an annotation and variable declaration for the control. The annotation ensures that the control is recognized by Workshop, and the variable declaration gives you a way to work with the control from your client code. For example, if you add a new custom control named Hello, the following code will be added to your client:

    import org.apache.beehive.controls.api.bean.Control;
    import controls.myControl.Hello;
	
	@Control
	private Hello hello;
Once you have a reference to a control, your client can call methods on that control. For more detail on calling a control method, see Invoking a Control Method.

Related Topics

Invoking a Control Method

Source Files for Custom Controls


Still need help? Post a question on the Workshop newsgroup.