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>
This commit is contained in:
committed by
Edwin Kempin
parent
9323223d2f
commit
1d2d9bf746
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ import com.google.gwt.user.client.ui.DialogBox;
|
||||
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 @@ public class HelloPlugins extends Plugin {
|
||||
|
||||
@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 @@ public class HelloPlugins extends Plugin {
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,3 +101,6 @@ a, a:visited, a:hover {
|
||||
zoom: 1;
|
||||
}
|
||||
|
||||
#hello_open-dialog-box {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user