package de.forsthaus.webui.blog; import java.io.Serializable; import org.apache.log4j.Logger; import org.zkoss.util.resource.Labels; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Path; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.util.Clients; import org.zkoss.zul.Borderlayout; import org.zkoss.zul.Iframe; import org.zkoss.zul.Intbox; import org.zkoss.zul.Window; import de.forsthaus.UserWorkspace; import de.forsthaus.webui.util.GFCBaseCtrl; /** * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br> * This is the controller class for the /WEB-INF/blog/blog.zul file. <br> * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br> * * @author bbruhns * @author sgerth */ public class BlogCtrl extends GFCBaseCtrl implements Serializable { private static final long serialVersionUID = 1L; private static final Logger logger = Logger.getLogger(BlogCtrl.class); /* * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * All the components that are defined here and have a corresponding * component with the same 'id' in the zul-file are getting autowired by our * 'extends GFCBaseCtrl' GenericForwardComposer. * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ protected Window windowBlog; // autowired protected Borderlayout borderLayout_blog; // autowired protected Iframe iFrameBlog; // autowired /** * default constructor.<br> */ public BlogCtrl() { super(); } @Override public void doAfterCompose(Component window) throws Exception { super.doAfterCompose(window); /** * 1. Set an 'alias' for this composer name to access it in the * zul-file.<br> * 2. Set the parameter 'recurse' to 'false' to avoid problems with * managing more than one zul-file in one page. Otherwise it would be * overridden and can ends in curious error messages. */ this.self.setAttribute("controller", this, false); } // +++++++++++++++++++++++++++++++++++++++++++++++++ // // +++++++++++++++ Component Events ++++++++++++++++ // // +++++++++++++++++++++++++++++++++++++++++++++++++ // /** * Automatically called method from zk. * * @param event * @throws Exception */ public void onCreate$windowBlog(Event event) throws Exception { doFitSize(); /** * Calls the long running method that loads the pdf and closes the echo * event message if ready. */ loadDocument(event); } /** * when the "refresh" button is clicked. <br> * <br> * * @param event * @throws InterruptedException */ public void onClick$btnRefresh(Event event) throws InterruptedException { doFitSize(); } // +++++++++++++++++++++++++++++++++++++++++++++++++ // // +++++++++++++++++ Business Logic ++++++++++++++++ // // +++++++++++++++++++++++++++++++++++++++++++++++++ // /** * Loads the document and startet an echo event message. * * @param event * @throws Exception */ public void loadDocument(Event event) { // we load the website in an Echo-event to show a message to the // user if this is a long running operation. Clients.showBusy(Labels.getLabel("message.Information.LongOperationIsRunning")); Events.echoEvent("onLoadDocument", BlogCtrl.this.windowBlog, null); } public void onLoadDocument() { try { iFrameBlog.setSrc("http://www.forsthaus.de/blog"); } finally { Clients.clearBusy(); // close the message } } // +++++++++++++++++++++++++++++++++++++++++++++++++ // // ++++++++++++++++++++ Helpers ++++++++++++++++++++ // // +++++++++++++++++++++++++++++++++++++++++++++++++ // /** * Recalculates the container size for this controller and resize them. * * Calculate how many rows have been place in the listbox. Get the * currentDesktopHeight from a hidden Intbox from the index.zul that are * filled by onClientInfo() in the indexCtroller. */ public void doFitSize() { // normally 0 ! Or we have a i.e. a toolBar on top of the listBox. final int specialSize = 26; final int menuOffset = UserWorkspace.getInstance().getMenuOffset(); int height = ((Intbox) Path.getComponent("/outerIndexWindow/currentDesktopHeight")).getValue().intValue(); height = height - menuOffset; final int maxListBoxHeight = height - specialSize - 88; this.borderLayout_blog.setHeight(String.valueOf(maxListBoxHeight) + "px"); borderLayout_blog.invalidate(); } }