Skip to main content
Version: QB11

Write Custom Gadget

In this example, we will enhance the plugin in tutorial Write Your First Plugin to add a custom gadget to display a specified message. Firstable, we create our gadget class as below:

package com.example.myplugin;

import org.apache.wicket.Component;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.basic.Label;
import org.hibernate.validator.constraints.NotEmpty;

import com.pmease.quickbuild.annotation.Editable;
import com.pmease.quickbuild.extensionpoint.support.Gadget;
import com.pmease.quickbuild.extensionpoint.support.GadgetCategory;

@Editable(name="My Message", order=100001, category=GadgetCategory.OTHERS)
public class MyMessageGadget extends Gadget {

private static final long serialVersionUID = 1L;

private String message;

@Editable(name="Message", description="Specify a message to display.")
@NotEmpty
public String getMessage() {
return message;
}

@Override
public String getCssClass() {
return "window";
}

public void setMessage(String message) {
this.message = message;
}

@Override
public Component renderBody(String componentId) {
return new Label(componentId, getMessage()).add(new AttributeAppender("class", "p8p"));
}

}

Then modify class MyPlugin to contribute the message gadget:

package com.example.myplugin;

import com.pmease.quickbuild.extensionpoint.StepProvider;
import com.pmease.quickbuild.extensionpoint.GadgetProvider;
import com.pmease.quickbuild.pluginsupport.AbstractPlugin;
import com.pmease.quickbuild.stepsupport.Step;
import com.pmease.quickbuild.extensionpoint.support.Gadget;

public class MyPlugin extends AbstractPlugin {

@Override
public Object[] getExtensions() {
return new Object[] {
new StepProvider() {

@Override
public Class<? extends Step> getStepClass() {
return MyStep.class;
}

},
new GadgetProvider() {

@Override
public Class<? extends Gadget> getGadgetClass() {
return MyMessageGadget.class;
}

};
}

}

With this change, the custom gadget will appear in the OTHERS category after running QuickBuild.

Besides the common gadget class, QuickBuild provides BuildBasedGadget and ConfigurationBasedGadget to facilitate creating gadgets displaying build or configuration info. Refer to the Javadoc for these classes in Eclipse for details.