我有一个带有Back
/Forward
按钮的导航面板(功能不重要,只是想了解一下在 GWT 页面内外交换面板)
导航按钮面板
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 使用它。我从 ABC 到 BA 的导航工作正常。我现在模拟用户在转到面板 B 之前更改某些内容。在这种情况下,面板 B 中的标签。我的最终应用程序显然会比这更复杂,但这是否是应用程序工作方式的典型特征。您通过用户在同一面板或不同面板中的交互来修改面板中的某些字段,加载新面板,更多交互,在不同面板中加载等?我只希望用户使用定义非常明确的导航路径,因此某个面板只有一条路径。
面板A
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;
}
}
面板B
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;
}
}
面板C
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;
}
}