List of usage examples for org.apache.wicket.mock MockHomePage MockHomePage
MockHomePage
From source file:org.efaps.ui.wicket.components.modalwindow.ModalWindowContainer.java
License:Apache License
/** * Method creates a JavaScript to reload the parent page. * * @param _uiObject uiObject of the page that was opened in the current modal * @return JavaScript// w w w .j a v a 2 s . co m * @throws EFapsException */ public String getReloadJavaScript(final ICmdUIObject _uiObject) { final StringBuilder javascript = new StringBuilder(); if (getPage() instanceof GridPage) { final UIGrid uiGrid = (UIGrid) getPage().getDefaultModelObject(); final GridPage gridPage = new GridPage(Model.of(UIGrid.get(uiGrid.getCmdUUID()))); final IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(gridPage)); final String url = getRequestCycle().urlFor(handler).toString(); javascript.append(DojoWrapper.require( new StringBuilder().append(" top.dijit.registry.byId(\"mainPanel\").set(\"content\",") .append(" domConstruct.create(\"iframe\",{").append("\"id\": \"") .append(MainPage.IFRAME_ID).append("\",\"src\": \"./wicket/").append(url) .append("\",\"style\": \"border: 0; width: 100%; height: 99%\" }").append("))"), DojoClasses.domConstruct)); } else { final AbstractUIPageObject uiObject = (AbstractUIPageObject) getPage().getDefaultModelObject(); if (uiObject != null) { try { PageReference calledByPageRef = ((AbstractContentPage) getPage()).getCalledByPageReference(); if (calledByPageRef != null && calledByPageRef.getPage() instanceof AbstractContentPage) { calledByPageRef = ((AbstractContentPage) calledByPageRef.getPage()) .getCalledByPageReference(); } final String href = _uiObject.getCommand().getReference(); final Page page; boolean tree = false; if ("TREE?".equalsIgnoreCase(href) && _uiObject.getInstance() != null && _uiObject.getInstance().isValid()) { final Menu menu = Menu.getTypeTreeMenu(_uiObject.getInstance().getType()); if (menu == null) { final Exception ex = new Exception( "no tree menu defined for type " + _uiObject.getInstance().getType().getName()); throw new RestartResponseException(new ErrorPage(ex)); } page = new ContentContainerPage(menu.getUUID(), _uiObject.getInstance().getKey()); tree = true; } else { uiObject.resetModel(); if (uiObject instanceof UITable) { page = new TablePage(Model.of((UITable) uiObject), calledByPageRef); } else if (uiObject instanceof UIForm) { page = new FormPage(Model.of((UIForm) uiObject), calledByPageRef); } else if (uiObject instanceof UIStructurBrowser) { page = new StructurBrowserPage(Model.of((UIStructurBrowser) uiObject), calledByPageRef); } else { page = new MockHomePage(); } } final IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page)); // touch the page to ensure that the pagemanager stores it to be accessible getSession().getPageManager().touchPage(page); final String url = getRequestCycle().urlFor(handler).toString(); if (calledByPageRef != null && calledByPageRef.getPage() instanceof ContentContainerPage && !tree) { final String panelId = ((ContentContainerPage) calledByPageRef.getPage()) .getCenterPanelId(); javascript.append("require([\"dojo/dom-construct\"], function(domConstruct){") .append("var mF = top.dojo.doc.getElementById(\"").append(MainPage.IFRAME_ID) .append("\");").append("if (mF != null) {") .append("mF.contentWindow.dijit.registry.byId(\"").append(panelId) .append("\").set(\"content\",").append(" domConstruct.create(\"iframe\", {") .append("\"src\": \"").append(url) .append("\",\"style\": \"border: 0; width: 100%; height: 99%\"}").append(")); ") .append("mF.contentWindow.").append(MenuUpdateBehavior.FUNCTION_NAME).append("(\"") .append(MenuUpdateBehavior.PARAMETERKEY4UPDATE).append("\");").append("}") .append("});"); } else { javascript.append("require([\"dojo/dom-construct\"], function(domConstruct){") .append(" top.dijit.registry.byId(\"mainPanel\").set(\"content\",") .append(" domConstruct.create(\"iframe\",{").append("\"id\": \"") .append(MainPage.IFRAME_ID).append("\",\"src\": \"./wicket/").append(url) .append("\",\"style\": \"border: 0; width: 100%; height: 99%\" }").append("))") .append("});"); } } catch (final EFapsException e) { throw new RestartResponseException(new ErrorPage(e)); } } else if (getPage() instanceof MainPage) { try { // this was called by the DashBoard final DashboardPage page = new DashboardPage(getPage().getPageReference()); final IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page)); // touch the page to ensure that the pagemanager stores it to be accessible getSession().getPageManager().touchPage(page); final String url = getRequestCycle().urlFor(handler).toString(); javascript.append("require([\"dojo/dom-construct\"], function(domConstruct){") .append(" top.dijit.registry.byId(\"mainPanel\").set(\"content\",") .append(" domConstruct.create(\"iframe\",{").append("\"id\": \"") .append(MainPage.IFRAME_ID).append("\",\"src\": \"./wicket/").append(url) .append("\",\"style\": \"border: 0; width: 100%; height: 99%\" }").append("))") .append("});"); } catch (final EFapsException e) { throw new RestartResponseException(new ErrorPage(e)); } } } return javascript.toString(); }