Write Custom Gadget

Version 5 by Robin Shen
on Oct 14, 2011 02:55.


compared with
Current by Robin Shen
on Oct 14, 2011 02:58.


 
Key
These lines were removed. This word was removed.
These lines were added. This word was added.

View page history


There are 1 changes. View first change.

 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:
 {code}
 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"));
  }
  
 }
 {code}
  
 Then modify class _MyPlugin_ to contribute the message gadget:
 {code}
 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;
  }
  
  };
  }
  
 }
 {code}
  
  Finally, we may run QuickBuild and the custom gadget will appear in the _OTHERS_ category.
  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.