0
我有Back
/Forward
鍵(功能並不重要,只想讓我的頭周圍和縮小GWT頁面交換面板)GWT視圖導航基本的例子
NavigationButtonsPanel
導航面板public class NavigationButtonsPanel extends HTMLPanel
{
private Button btnA = new Button("Go back");
private Button btnB = new Button("Go forward");
public NavigationButtonsPanel()
{
super("Navigation Panel");
add(btnA);
add(btnB);
}
public void setBackHandler(ClickHandler handler)
{
btnA.addClickHandler(handler);
}
public void setForwardHandler(ClickHandler handler)
{
btnB.addClickHandler(handler);
}
}
我然後有3個基本面板,AB和C,其使用此。我從A-B-C導航回到B-A可以正常工作。他們去之前,面板B.在這種情況下PanelB一個標籤 我現在模擬用戶不斷變化的東西。 我的最終應用程序顯然會比這更復雜,但這是典型的應用程序如何工作。您可以通過同一面板或不同面板中的用戶交互來修改面板中的某些字段,加載新面板,進行更多交互,加載不同面板等? 我只希望用戶因此只有一個路徑在一定面板使用了非常明確的導航路徑。
紅砂糖
public class PanelA extends HTMLPanel
{
private static PanelA panel;
private PanelA()
{
super("Panel A");
final RootPanel rootPanel = RootPanel.get();
NavigationButtonsPanel btnPanel = new NavigationButtonsPanel();
btnPanel.setForwardHandler(new ClickHandler() {
public void onClick(ClickEvent event)
{
rootPanel.clear();
PanelB.setMessageFromPreviousPage("Message set in Panel AAAAA");
rootPanel.add(PanelB.getInstance());
}
});
add(btnPanel);
}
public static PanelA getInstance()
{
if (panel == null)
{
panel = new PanelA();
}
return panel;
}
}
PanelB
public class PanelB extends HTMLPanel
{
private static PanelB panel;
private static String messageFromPreviousPage;
private PanelB()
{
super("Panel B");
final RootPanel rootPanel = RootPanel.get();
Label messageLabel = new Label(messageFromPreviousPage);
NavigationButtonsPanel btnPanel = new NavigationButtonsPanel();
btnPanel.setBackHandler(new ClickHandler() {
public void onClick(ClickEvent event)
{
rootPanel.clear();
rootPanel.add(PanelA.getInstance());
}
});
btnPanel.setForwardHandler(new ClickHandler() {
public void onClick(ClickEvent event)
{
rootPanel.clear();
rootPanel.add(PanelC.getInstance());
}
});
add(btnPanel);
add(messageLabel);
}
public static PanelB getInstance()
{
if (panel == null)
{
panel = new PanelB();
}
return panel;
}
public static void setMessageFromPreviousPage(
String message)
{
messageFromPreviousPage = message;
}
}
PanelC
public class PanelC extends HTMLPanel
{
private static PanelC panel;
private PanelC()
{
super("Panel C");
final RootPanel rootPanel = RootPanel.get();
NavigationButtonsPanel btnPanel = new NavigationButtonsPanel();
btnPanel.setBackHandler(new ClickHandler() {
public void onClick(ClickEvent event)
{
rootPanel.clear();
PanelB.setMessageFromPreviousPage("Message set in Panel CCCCCC");
rootPanel.add(PanelB.getInstance());
}
});
add(btnPanel);
}
public static PanelC getInstance()
{
if (panel == null)
{
panel = new PanelC();
}
return panel;
}
}