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 static final long serialVersionUID = 2045507176304630957L;
031            
032            private Element element;
033            
034            /**
035             * Creates a new server delay message.
036             * 
037             * @param message The message text.
038             */
039            public ServerDelayMessage(String message) {
040                    this(message, null);
041            }
042            
043            /**
044             * Creates a new server delay message.
045             * 
046             * @param message The message text.
047             * @param imageLocation A link to the image which is displayed above the text.
048             */
049            public ServerDelayMessage(String message, String imageLocation) {
050                    XmlDocument xmlDocument = new XmlDocument("div", null, null, HtmlDocument.XHTML_1_0_NAMESPACE_URI);
051                    Document document = xmlDocument.getDocument();
052                    Element divElement = document.getDocumentElement();
053                    divElement.setAttribute("id", ELEMENT_ID_MESSAGE);
054                    divElement.setAttribute("style",
055                                    "position:absolute;" +
056                                    "top:0px;" +
057                                    "left:0px;" +
058                                    "width:100%;" +
059                                    "height:100%;" +
060                                    "cursor:wait;" +
061                                    "margin:0px;" +
062                                    "padding:0px;" +
063                                    "visibility:hidden;" +
064                                    "z-index:10000;"
065                            );
066                    
067                    Element tableElement = document.createElement("table");
068                    tableElement.setAttribute("style",
069                                    "width:100%;" +
070                                    "height:100%;" +
071                                    "border:0px;" +
072                                    "padding:0px;"
073                    );
074                    divElement.appendChild(tableElement);
075                    
076                    Element tbodyElement = document.createElement("tbody");
077                    tableElement.appendChild(tbodyElement);
078                    
079                    Element trElement = document.createElement("tr");
080                    tbodyElement.appendChild(trElement);
081                    
082                    Element tdElement = document.createElement("td");
083                    trElement.appendChild(tdElement);
084                    
085                    Element messageElement = document.createElement("div");
086                    messageElement.setAttribute("id", ELEMENT_ID_LONG_MESSAGE);
087                    messageElement.setAttribute("style",
088                                    "margin-top:40px;" +
089                                    "margin-left:auto;" +
090                                    "margin-right:auto;" +
091                                    "background-color:#e6e6e6;" +
092                                    "color:#000000;" +
093                                    "padding:40px;" +
094                                    "width:200px;" +
095                                    "border:solid 2px #000000;" +
096                                    "font-family:verdana,arial,helvetica,sans-serif;" +
097                                    "font-size:10pt;" +
098                                    "text-align:left;"
099                            );
100                    
101                    if (imageLocation != null) {
102                            Element img = document.createElement("img");
103                            img.setAttribute("src", imageLocation);
104                            messageElement.appendChild(img);
105                    }
106                    
107                    messageElement.appendChild(document.createElement("br"));
108                    messageElement.appendChild(document.createElement("br"));
109                    
110                    messageElement.appendChild(document.createTextNode(message));
111                    
112                    tdElement.appendChild(messageElement);
113                    element = divElement;
114            }
115            
116            public Element getMessage() {
117                    return element;
118            }
119    
120    }