diff --git a/Documentation/dev-plugins.txt b/Documentation/dev-plugins.txt index 1745e67236..c30310d4df 100644 --- a/Documentation/dev-plugins.txt +++ b/Documentation/dev-plugins.txt @@ -1049,6 +1049,193 @@ is described in the link:#getting-started[Getting started] section. The generated GWT plugin has a link:#top-menu-extensions[top menu] that opens a GWT dialog box when the user clicks on it. +In addition to the Gerrit-Plugin API a GWT plugin depends on +`gerrit-plugin-gwtui`. This dependency must be specified in the +`pom.xml`: + +[source,xml] +---- + + com.google.gerrit + gerrit-plugin-gwtui + ${Gerrit-ApiVersion} + +---- + +A GWT plugin must contain a GWT module file, e.g. `HelloPlugin.gwt.xml`, +that bundles together all the configuration settings of the GWT plugin: + +[source,xml] +---- + + + + + + + + + + + + + + +---- + +The GWT module must inherit `com.google.gerrit.Plugin` and +`com.google.gwt.http.HTTP`. + +To register the GWT module a `GwtPlugin` needs to be bound. + +If no Guice modules are declared in the manifest, the GWT plugin may +use auto-registration by using the `@Listen` annotation: + +[source,java] +---- +@Listen +public class MyExtension extends GwtPlugin { + public MyExtension() { + super("hello_gwt_plugin"); + } +} +---- + +Otherwise the binding must be done in an `HttpModule`: + +[source,java] +---- +public class HttpModule extends HttpPluginModule { + + @Override + protected void configureServlets() { + DynamicSet.bind(binder(), WebUiPlugin.class) + .toInstance(new GwtPlugin("hello_gwt_plugin")); + } +} +---- + +The HTTP module above must be declared in the `pom.xml` for Maven +driven plugins: + +[source,xml] +---- + + com.googlesource.gerrit.plugins.myplugin.HttpModule + +---- + +It is important that the module name that is provided to the +`GwtPlugin` matches the GWT module contained in the plugin. The name +of the GWT module can be explicitly set in the GWT module file by +specifying the `rename-to` attribute on the module. + +[source,xml] +---- + +---- + +The actual GWT code must be implemented in a class that extends +`com.google.gerrit.plugin.client.Plugin`: + +[source,java] +---- +public class HelloPlugin extends Plugin { + + @Override + public void onModuleLoad() { + // Create the dialog box + final DialogBox dialogBox = new DialogBox(); + + // The content of the dialog comes from a User specified Preference + dialogBox.setText("Hello from GWT Gerrit UI plugin"); + dialogBox.setAnimationEnabled(true); + Button closeButton = new Button("Close"); + VerticalPanel dialogVPanel = new VerticalPanel(); + dialogVPanel.setWidth("100%"); + dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER); + dialogVPanel.add(closeButton); + + closeButton.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent event) { + dialogBox.hide(); + } + }); + + // Set the contents of the Widget + dialogBox.setWidget(dialogVPanel); + + RootPanel rootPanel = RootPanel.get(HelloMenu.MENU_ID); + rootPanel.getElement().removeAttribute("href"); + rootPanel.addDomHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + dialogBox.center(); + dialogBox.show(); + } + }, ClickEvent.getType()); + } +} +---- + +This class must be set as entry point in the GWT module: + +[source,xml] +---- + +---- + +In addition this class must be defined as module in the `pom.xml` for the +`gwt-maven-plugin` and the `webappDirectory` option of `gwt-maven-plugin` +must be set to `${project.build.directory}/classes/static`: + +[source,xml] +---- + + org.codehaus.mojo + gwt-maven-plugin + 2.5.1 + + com.googlesource.gerrit.plugins.myplugin.HelloPlugin + true + true + ${project.build.directory}/classes/static + + + + + compile + + + + +---- + +To attach a GWT widget defined by the plugin to the Gerrit core UI +`com.google.gwt.user.client.ui.RootPanel` can be used to manipulate the +Gerrit core widgets: + +[source,java] +---- +RootPanel rootPanel = RootPanel.get(HelloMenu.MENU_ID); +rootPanel.getElement().removeAttribute("href"); +rootPanel.addDomHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + dialogBox.center(); + dialogBox.show(); + } +}, ClickEvent.getType()); +---- + +GWT plugins can come with their own css file. This css file must have a +unique name and must be registered in the GWT module: + +[source,xml] +---- + +---- + [[http]] HTTP Servlets -------------