左侧的菜单栏在使用场所和活动进行导航时消失

时间:2014-04-16 14:26:12

标签: java gwt

在我的应用程序中,我希望将菜单保留在所有页面的左侧,但是当我点击左侧的按钮时,我的菜单就会消失。我在这里附上我的代码。

启动器类:

public class SmartEBRM implements EntryPoint {

//private Place defaultPlace = new SmartEBRMViewPlace("World!");
//private SimplePanel appWidget = new SimplePanel();

@SuppressWarnings("deprecation")
@Override
public void onModuleLoad() {
    // TODO Auto-generated method stub

    ClientFactory clientFactory = GWT.create(ClientFactory.class);
    EventBus eventBus = clientFactory.getEventBus();
    PlaceController placeController = clientFactory.getPlaceController();

    // Start ActivityManager for the main widget with our ActivityMapper
    ActivityMapper activityMapper = new AppActivityMapper(clientFactory);
    ActivityManager activityManager = new ActivityManager(activityMapper, eventBus);
    SmartEBRMViewImpl smartViewImpl = new SmartEBRMViewImpl();
    activityManager.setDisplay (smartViewImpl.getHTMLPannel());


    // Start PlaceHistoryHandler with our PlaceHistoryMapper
    AppPlaceHistoryMapper historyMapper= GWT.create(AppPlaceHistoryMapper.class);
    PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
    SmartEBRMViewPlace smartViewPlace = new SmartEBRMViewPlace();
    //ClearPannelPlace smartViewPlace = new ClearPannelPlace();
    historyHandler.register(placeController, eventBus, smartViewPlace);
    historyHandler.handleCurrentHistory();

    RootPanel.get().add(smartViewImpl.getHTMLPannel());
}
}

主要观点:

public class SmartEBRMViewImpl extends Composite implements SmartEBRMView{

private static SmartEBRMViewImplUiBinder uiBinder = GWT
        .create(SmartEBRMViewImplUiBinder.class);

@UiField DockLayoutPanel docLayoutPanel;
@UiField StackPanel stackPanel;
@UiField Button enterpriseView;
@UiField Button testComponent;
@UiField SimplePanel centerPanel;
@UiField SimplePanel westPanel;
@UiField SimplePanel northPanel;

private Presenter listener;

interface SmartEBRMViewImplUiBinder extends
        UiBinder<Widget, SmartEBRMViewImpl> {
}

public SmartEBRMViewImpl() {
    initWidget(uiBinder.createAndBindUi(this));
}

public SmartEBRMViewImpl(String firstName) {
    initWidget(uiBinder.createAndBindUi(this));
}

@Override
public void setPresenter(Presenter listener) {
    // TODO Auto-generated method stub
    this.listener = listener;

}

public SimplePanel getHTMLPannel () {
    return centerPanel;
}

public SimplePanel getNorthPanel () {
    return northPanel;
}

public SimplePanel getWestPanel () {
    return westPanel;
}

@UiHandler("enterpriseView")
public void onClearButtonClick(ClickEvent e)
{
    listener.goTo(new EnterpriseInvoiceCompareViewPlace());
}

这是我去的地方..左侧不变:

public class EnterpriseInvoiceCompareViewImpl extends Composite implements EnterpriseInvoiceCompareView{

private static EnterpriseInvoiceCompareViewImplUiBinder uiBinder = GWT
        .create(EnterpriseInvoiceCompareViewImplUiBinder.class);
@UiField VerticalPanel verticalPannel;
@UiField HorizontalPanel invoiceNumberPanel;
@UiField Label invoiceNumberLabel;
@UiField TextBox invoiceNumberBox;
private Presenter listener;


interface EnterpriseInvoiceCompareViewImplUiBinder extends
        UiBinder<Widget, EnterpriseInvoiceCompareViewImpl> {
}

public EnterpriseInvoiceCompareViewImpl() {
    initWidget(uiBinder.createAndBindUi(this));
}

@Override
public void setPresenter(Presenter listener) {
    // TODO Auto-generated method stub
    this.listener = listener;
}

的活动:

public class SmartEBRMViewActivity extends AbstractActivity implements
SmartEBRMView.Presenter {

private ClientFactory clientFactory;

public SmartEBRMViewActivity(SmartEBRMViewPlace place, ClientFactory clientFactory) {
    //this.place = place;
    this.clientFactory = clientFactory;
}

@Override
public void start(AcceptsOneWidget containerWidget, EventBus eventBus) {
    // TODO Auto-generated method stub
    SmartEBRMView smartEBRMView = clientFactory.getSmartEBRMView();
    smartEBRMView.setPresenter(this);
    containerWidget.setWidget(smartEBRMView.asWidget());

}

@Override
public void goTo(Place place) {
    // TODO Auto-generated method stub
    clientFactory.getPlaceController().goTo(place);
}

}

public class EnterpriseInvoiceCompareActivity extends AbstractActivity implements EnterpriseInvoiceCompareView.Presenter{

private ClientFactory clientFactory;

public EnterpriseInvoiceCompareActivity(EnterpriseInvoiceCompareViewPlace place, ClientFactory clientFactory) {
    //this.name = place.getHelloName();
    this.clientFactory = clientFactory;
}

@Override
public void start(AcceptsOneWidget containerWidget, EventBus eventBus) {
    // TODO Auto-generated method stub
    EnterpriseInvoiceCompareView entInvoiceCompareView = clientFactory.getEnterpriseInvoiceCompareView();
    entInvoiceCompareView.setPresenter(this);
    containerWidget.setWidget(entInvoiceCompareView.asWidget());
}

@Override
public void goTo(Place place) {
    // TODO Auto-generated method stub
    clientFactory.getPlaceController().goTo(place);
}

}

映射器:

public class AppActivityMapper implements ActivityMapper{

private ClientFactory clientFactory;

/**
 * AppActivityMapper associates each Place with its corresponding
 * {@link Activity}
 * 
 * @param clientFactory
 *            Factory to be passed to activities
 */
public AppActivityMapper(ClientFactory clientFactory) {
    super();
    this.clientFactory = clientFactory;
}

/**
 * Map each Place to its corresponding Activity. This would be a great use
 * for GIN.
 */
@Override
public Activity getActivity(Place place) {
    if (place instanceof EnterpriseInvoiceCompareViewPlace){
        return new EnterpriseInvoiceCompareActivity((EnterpriseInvoiceCompareViewPlace) place, clientFactory);
    }
    else if (place instanceof SmartEBRMViewPlace)
        return new SmartEBRMViewActivity((SmartEBRMViewPlace) place, clientFactory);

    return null;
}

}

地点:

public class EnterpriseInvoiceCompareViewPlace extends Place{

public EnterpriseInvoiceCompareViewPlace()
{
}

public static class Tokenizer implements PlaceTokenizer<EnterpriseInvoiceCompareViewPlace>
{

    @Override
    public String getToken(EnterpriseInvoiceCompareViewPlace place)
    {
        return "EntInvoiceCompare";
    }

    @Override
    public EnterpriseInvoiceCompareViewPlace getPlace(String token)
    {
        return new EnterpriseInvoiceCompareViewPlace();
    }

}

}

public class SmartEBRMViewPlace extends Place{

public SmartEBRMViewPlace()
{
}

public static class Tokenizer implements PlaceTokenizer<SmartEBRMViewPlace>
{

    @Override
    public String getToken(SmartEBRMViewPlace place)
    {
        return "SmartView";
    }

    @Override
    public SmartEBRMViewPlace getPlace(String token)
    {
        return new SmartEBRMViewPlace();
    }

}

}

enter image description here

1 个答案:

答案 0 :(得分:0)

如果您想要左侧的静态菜单,那么它不应该是一个活动(如果需要,它仍然可以对PlaceChangeEvent个事件作出反应),或者左边应该有2 ActivityManager个区域(ActivityMapper始终返回您的菜单活动,无论哪个地方)和中心区域(ActivityMapper根据当前位置返回相应的活动)。


顺便说一句,我觉得奇怪的是你将smartViewImpl.getHTMLPannel()添加到RootPanel,而不是smartViewImpl