001    // This file is part of the Attempto Java Packages.
002    // Copyright 2008, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch).
003    //
004    // The Attempto Java Packages is free software: you can redistribute it and/or modify it under the
005    // terms of the GNU Lesser General Public License as published by the Free Software Foundation,
006    // either version 3 of the License, or (at your option) any later version.
007    //
008    // The Attempto Java Packages is distributed in the hope that it will be useful, but WITHOUT ANY
009    // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
010    // PURPOSE. See the GNU Lesser General Public License for more details.
011    //
012    // You should have received a copy of the GNU Lesser General Public License along with the Attempto
013    // Java Packages. If not, see http://www.gnu.org/licenses/.
014    
015    package ch.uzh.ifi.attempto.echocomp;
016    
017    import nextapp.echo2.webrender.output.HtmlDocument;
018    import nextapp.echo2.webrender.output.XmlDocument;
019    
020    import org.w3c.dom.Document;
021    import org.w3c.dom.Element;
022    
023    /**
024     * This class can be used to create user-defined messages in the case of server delay.
025     * 
026     * @author Tobias Kuhn
027     */
028    public class ServerDelayMessage extends nextapp.echo2.webrender.ServerDelayMessage {
029    
030            private Element element;
031            
032            /**
033             * Creates a new server delay message.
034             * 
035             * @param message The message text.
036             */
037            public ServerDelayMessage(String message) {
038                    this(message, null);
039            }
040            
041            /**
042             * Creates a new server delay message.
043             * 
044             * @param message The message text.
045             * @param imageLocation A link to the image which is displayed above the text.
046             */
047            public ServerDelayMessage(String message, String imageLocation) {
048                    XmlDocument xmlDocument = new XmlDocument("div", null, null, HtmlDocument.XHTML_1_0_NAMESPACE_URI);
049                    Document document = xmlDocument.getDocument();
050                    Element divElement = document.getDocumentElement();
051                    divElement.setAttribute("id", ELEMENT_ID_MESSAGE);
052                    divElement.setAttribute("style",
053                                    "position:absolute;" +
054                                    "top:0px;" +
055                                    "left:0px;" +
056                                    "width:100%;" +
057                                    "height:100%;" +
058                                    "cursor:wait;" +
059                                    "margin:0px;" +
060                                    "padding:0px;" +
061                                    "visibility:hidden;" +
062                                    "z-index:10000;"
063                            );
064                    
065                    Element tableElement = document.createElement("table");
066                    tableElement.setAttribute("style",
067                                    "width:100%;" +
068                                    "height:100%;" +
069                                    "border:0px;" +
070                                    "padding:0px;"
071                    );
072                    divElement.appendChild(tableElement);
073                    
074                    Element tbodyElement = document.createElement("tbody");
075                    tableElement.appendChild(tbodyElement);
076                    
077                    Element trElement = document.createElement("tr");
078                    tbodyElement.appendChild(trElement);
079                    
080                    Element tdElement = document.createElement("td");
081                    trElement.appendChild(tdElement);
082                    
083                    Element messageElement = document.createElement("div");
084                    messageElement.setAttribute("id", ELEMENT_ID_LONG_MESSAGE);
085                    messageElement.setAttribute("style",
086                                    "margin-top:40px;" +
087                                    "margin-left:auto;" +
088                                    "margin-right:auto;" +
089                                    "background-color:#e6e6e6;" +
090                                    "color:#000000;" +
091                                    "padding:40px;" +
092                                    "width:200px;" +
093                                    "border:solid 2px #000000;" +
094                                    "font-family:verdana,arial,helvetica,sans-serif;" +
095                                    "font-size:10pt;" +
096                                    "text-align:left;"
097                            );
098                    
099                    if (imageLocation != null) {
100                            Element img = document.createElement("img");
101                            img.setAttribute("src", imageLocation);
102                            messageElement.appendChild(img);
103                    }
104                    
105                    messageElement.appendChild(document.createElement("br"));
106                    messageElement.appendChild(document.createElement("br"));
107                    
108                    messageElement.appendChild(document.createTextNode(message));
109                    
110                    tdElement.appendChild(messageElement);
111                    element = divElement;
112            }
113            
114            public Element getMessage() {
115                    return element;
116            }
117    
118    }