GWT plugin archetype: Open GWT dialog box from menu
Instead of adding a button that opens a GWT dialog box,
have a top menu from which the GWT dialog box is opened.
Change-Id: Ie62f04609958c4e1bdf4f30ada08f42579a42961
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/gerrit-plugin-gwt-archetype/src/main/resources/archetype-resources/src/main/java/HelloMenu.java b/gerrit-plugin-gwt-archetype/src/main/resources/archetype-resources/src/main/java/HelloMenu.java
new file mode 100644
index 0000000..546381b
--- /dev/null
+++ b/gerrit-plugin-gwt-archetype/src/main/resources/archetype-resources/src/main/java/HelloMenu.java
@@ -0,0 +1,39 @@
+// Copyright (C) 2013 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package ${package};
+
+import com.google.gerrit.extensions.annotations.Listen;
+import com.google.gerrit.extensions.webui.TopMenu;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+@Listen
+public class HelloMenu implements TopMenu {
+ public final static String MENU_ID = "hello_open-dialog-box";
+ private final List<MenuEntry> menuEntries;
+
+ public HelloMenu() {
+ menuEntries = new ArrayList<TopMenu.MenuEntry>();
+ menuEntries.add(new MenuEntry("Hello", Collections
+ .singletonList(new MenuItem("Open Dialog Box", "", "", MENU_ID))));
+ }
+
+ @Override
+ public List<MenuEntry> getEntries() {
+ return menuEntries;
+ }
+}
diff --git a/gerrit-plugin-gwt-archetype/src/main/resources/archetype-resources/src/main/java/client/HelloPlugins.java b/gerrit-plugin-gwt-archetype/src/main/resources/archetype-resources/src/main/java/client/HelloPlugins.java
index 8d716a9..4c1c29a 100644
--- a/gerrit-plugin-gwt-archetype/src/main/resources/archetype-resources/src/main/java/client/HelloPlugins.java
+++ b/gerrit-plugin-gwt-archetype/src/main/resources/archetype-resources/src/main/java/client/HelloPlugins.java
@@ -22,6 +22,8 @@
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
+import ${package}.HelloMenu;
+
/**
* HelloWorld Plugins.
*/
@@ -29,15 +31,6 @@
@Override
public void onModuleLoad() {
- Button button = new Button("Click me");
-
- VerticalPanel vPanel = new VerticalPanel();
- vPanel.setWidth("100%");
- vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
- vPanel.add(button);
-
- RootPanel.get().add(vPanel);
-
// Create the dialog box
final DialogBox dialogBox = new DialogBox();
@@ -59,11 +52,14 @@
// Set the contents of the Widget
dialogBox.setWidget(dialogVPanel);
- button.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent event) {
- dialogBox.center();
- dialogBox.show();
- }
- });
+ 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());
}
}
diff --git a/gerrit-plugin-gwt-archetype/src/main/resources/archetype-resources/src/main/java/public/hello.css b/gerrit-plugin-gwt-archetype/src/main/resources/archetype-resources/src/main/java/public/hello.css
index 73bf5c6..13c5177 100644
--- a/gerrit-plugin-gwt-archetype/src/main/resources/archetype-resources/src/main/java/public/hello.css
+++ b/gerrit-plugin-gwt-archetype/src/main/resources/archetype-resources/src/main/java/public/hello.css
@@ -101,3 +101,6 @@
zoom: 1;
}
+#hello_open-dialog-box {
+ cursor: pointer;
+}