Use extension screens in cookbook example
Instead of replacing the menu entry's anchor to open a dialog,
register a screen to hold the form and allow Gerrit to navigate.
Change-Id: I2a7c4addf1833784c7df5c5b50ef6bbb933ed93d
diff --git a/src/main/java/com/googlesource/gerrit/plugins/cookbook/HelloForm.gwt.xml b/src/main/java/com/googlesource/gerrit/plugins/cookbook/HelloForm.gwt.xml
index 1d2805e..6616bca 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/cookbook/HelloForm.gwt.xml
+++ b/src/main/java/com/googlesource/gerrit/plugins/cookbook/HelloForm.gwt.xml
@@ -25,6 +25,6 @@
<!-- resources to the plugin. No theme inherits lines were -->
<!-- added in order to make this plugin as simple as possible -->
<!-- Specify the app entry point class. -->
- <entry-point class="com.googlesource.gerrit.plugins.cookbook.client.HelloForm"/>
+ <entry-point class="com.googlesource.gerrit.plugins.cookbook.client.CookBookPlugin"/>
<stylesheet src="cookbook.css"/>
</module>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/cookbook/HelloTopMenu.java b/src/main/java/com/googlesource/gerrit/plugins/cookbook/HelloTopMenu.java
index 5e11b03..4d98601 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/cookbook/HelloTopMenu.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/cookbook/HelloTopMenu.java
@@ -23,13 +23,12 @@
public class HelloTopMenu implements TopMenu {
private final List<MenuEntry> menuEntries;
- public final static String MENU_ID = "cookbook-plugin_hello-form";
@Inject
public HelloTopMenu(@PluginName String pluginName) {
String baseUrl = "/plugins/" + pluginName + "/";
List<MenuItem> menuItems = Lists.newArrayListWithCapacity(2);
- menuItems.add(new MenuItem("Greeting", "", "", MENU_ID));
+ menuItems.add(new MenuItem("Greeting", "#/x/" + pluginName + "/", ""));
menuItems.add(new MenuItem("Documentation", baseUrl));
menuEntries = Lists.newArrayListWithCapacity(2);
menuEntries.add(new MenuEntry("Cookbook", menuItems));
diff --git a/src/main/java/com/googlesource/gerrit/plugins/cookbook/client/CookBookPlugin.java b/src/main/java/com/googlesource/gerrit/plugins/cookbook/client/CookBookPlugin.java
new file mode 100644
index 0000000..e9ace38
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/cookbook/client/CookBookPlugin.java
@@ -0,0 +1,25 @@
+// 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 com.googlesource.gerrit.plugins.cookbook.client;
+
+import com.google.gerrit.plugin.client.Plugin;
+import com.google.gerrit.plugin.client.PluginEntryPoint;
+
+public class CookBookPlugin extends PluginEntryPoint {
+ @Override
+ public void onPluginLoad() {
+ Plugin.get().screen("", new IndexScreen.Factory());
+ }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/cookbook/client/HelloForm.java b/src/main/java/com/googlesource/gerrit/plugins/cookbook/client/IndexScreen.java
similarity index 68%
rename from src/main/java/com/googlesource/gerrit/plugins/cookbook/client/HelloForm.java
rename to src/main/java/com/googlesource/gerrit/plugins/cookbook/client/IndexScreen.java
index 5600406..c50dc36 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/cookbook/client/HelloForm.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/cookbook/client/IndexScreen.java
@@ -14,7 +14,7 @@
package com.googlesource.gerrit.plugins.cookbook.client;
-import com.google.gerrit.plugin.client.PluginEntryPoint;
+import com.google.gerrit.plugin.client.screen.Screen;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.dom.client.ClickEvent;
@@ -24,29 +24,26 @@
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
-import com.google.gwt.user.client.ui.DialogBox;
-import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
-import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
-import com.googlesource.gerrit.plugins.cookbook.HelloTopMenu;
-public class HelloForm extends PluginEntryPoint {
- private DialogBox dialogBox;
+class IndexScreen extends VerticalPanel {
+ static class Factory implements Screen.EntryPoint {
+ @Override
+ public void onLoad(Screen screen) {
+ screen.setPageTitle("cookbook index");
+ screen.show(new IndexScreen());
+ }
+ }
+
private TextBox usernameTxt;
private TextArea greetingTxt;
- @Override
- public void onPluginLoad() {
- dialogBox = new DialogBox(false, false);
- dialogBox.setText("Greetings dialog");
- dialogBox.setAnimationEnabled(true);
-
- Panel p = new VerticalPanel();
- p.setStyleName("panel");
+ IndexScreen() {
+ setStyleName("cookbook-panel");
Panel usernamePanel = new VerticalPanel();
usernamePanel.add(new Label("Username:"));
@@ -75,7 +72,7 @@
usernameTxt.sinkEvents(Event.ONPASTE);
usernameTxt.setVisibleLength(40);
usernamePanel.add(usernameTxt);
- p.add(usernamePanel);
+ add(usernamePanel);
Panel messagePanel = new VerticalPanel();
messagePanel.add(new Label("Message:"));
@@ -90,43 +87,18 @@
greetingTxt.setCharacterWidth(80);
greetingTxt.getElement().setPropertyBoolean("spellcheck", false);
messagePanel.add(greetingTxt);
- p.add(messagePanel);
+ add(messagePanel);
- HorizontalPanel buttons = new HorizontalPanel();
- p.add(buttons);
-
- final Button helloButton = new Button("Say Hello");
- helloButton.addStyleName("helloButton");
+ Button helloButton = new Button("Say Hello");
+ helloButton.addStyleName("cookbook-helloButton");
helloButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(final ClickEvent event) {
sayHello();
}
});
- buttons.add(helloButton);
+ add(helloButton);
helloButton.setEnabled(true);
-
- Button closeButton = new Button("Close");
- closeButton.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent event) {
- hide();
- }
- });
- buttons.add(closeButton);
-
- dialogBox.setWidget(p);
-
- RootPanel rootPanel = RootPanel.get(HelloTopMenu.MENU_ID);
- rootPanel.getElement().removeAttribute("href");
- rootPanel.addDomHandler(new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- dialogBox.center();
- dialogBox.show();
- usernameTxt.setFocus(true);
- helloButton.setEnabled(true);
- }
- }, ClickEvent.getType());
}
private void sayHello() {
@@ -149,10 +121,4 @@
sb.append(greeting.isEmpty() ? "what's up?" : greeting);
Window.alert(sb.toString());
}
-
- private void hide() {
- dialogBox.hide();
- usernameTxt.setValue("");
- greetingTxt.setValue("");
- }
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/cookbook/public/cookbook.css b/src/main/java/com/googlesource/gerrit/plugins/cookbook/public/cookbook.css
index c820fdd..dd4f2a4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/cookbook/public/cookbook.css
+++ b/src/main/java/com/googlesource/gerrit/plugins/cookbook/public/cookbook.css
@@ -1,108 +1,8 @@
-body, table td, select {
- font-family: sans-serif;
- font-size: small;
-}
-pre {
- font-family: "courier new", courier;
- font-size: small;
-}
-body {
- color: black;
- margin: 0px;
- border: 0px;
- padding: 0px;
- background: #fff;
- direction: ltr;
-}
-a, a:visited, a:hover {
- color: #0000AA;
-}
-
-/**
- * The reference theme can be used to determine when this style sheet has
- * loaded. Create a hidden div element with absolute position, assign the style
- * name below, and attach it to the DOM. Use a timer to detect when the
- * element's height and width are set to 5px.
- */
-.gwt-Reference-standard {
- height: 5px;
- width: 5px;
- zoom: 1;
-}
-
-.gwt-Button {
- margin: 0;
- padding: 3px 5px;
- text-decoration: none;
- font-size: small;
- cursor: pointer;
- border: 1px outset #ccc;
-}
-.gwt-Button:active {
- border: 1px inset #ccc;
-}
-.gwt-Button:hover {
- border-color: #9cf #69e #69e #7af;
-}
-.gwt-Button[disabled] {
- cursor: default;
- color: #888;
-}
-.gwt-Button[disabled]:hover {
- border: 1px outset #ccc;
-}
-
-.gwt-DialogBox .Caption {
- background: #e3e8f3;
- padding: 4px 4px 4px 8px;
- cursor: default;
- border-bottom: 1px solid #bbbbbb;
- border-top: 5px solid #d0e4f6;
- border-left: 5px solid #d0e4f6;
- border-right: 5px solid #d0e4f6;
-}
-
-.gwt-DialogBox .dialogContent {
-}
-
-.gwt-DialogBox .dialogMiddleCenter {
- padding: 3px;
- background: white;
- border-left: 5px solid #d0e4f6;
- border-right: 5px solid #d0e4f6;
- border-bottom: 5px solid #d0e4f6;
-}
-
-.gwt-DialogBox .dialogTopLeftInner {
- width: 5px;
- zoom: 1;
-}
-.gwt-DialogBox .dialogTopRightInner {
- width: 8px;
- zoom: 1;
-}
-.gwt-DialogBox .dialogBottomLeftInner {
- width: 5px;
- height: 8px;
- zoom: 1;
-}
-
-.gwt-DialogBox .dialogBottomRightInner {
- width: 5px;
- height: 8px;
- zoom: 1;
-}
-
-#cookbook-plugin_hello-form {
- cursor: pointer;
-}
-
-.panel {
+.cookbook-panel {
border-spacing: 0px 5px;
}
-.helloButton {
+.cookbook-helloButton {
margin-left: 35px !important;
margin-right: 450px !important;
}
-