Changeset 5261
- Timestamp:
- 08/25/08 11:15:55 (3 months ago)
- Location:
- trunk
- Files:
-
- 3 added
- 2 modified
-
WebContent/ITMILL/themes/tests-tickets/layouts (added)
-
WebContent/ITMILL/themes/tests-tickets/layouts/Ticket1975.html (added)
-
src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java (modified) (4 diffs)
-
src/com/itmill/toolkit/tests/tickets/Ticket1975.java (added)
-
src/com/itmill/toolkit/ui/CustomLayout.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java
r5161 r5261 43 43 private final HashMap widgetToCaptionWrapper = new HashMap(); 44 44 45 /** Currently rendered style */46 String currentTemplate ;45 /** Name of the currently rendered style */ 46 String currentTemplateName; 47 47 48 48 /** Unexecuted scripts loaded from the template */ … … 53 53 54 54 private ApplicationConnection client; 55 56 /** Has the template been loaded from contents passed in UIDL **/ 57 private boolean hasTemplateContents = false; 55 58 56 59 public ICustomLayout() { … … 172 175 private void initializeHTML(UIDL uidl, ApplicationConnection client) { 173 176 177 final String newTemplateContents = uidl 178 .getStringAttribute("templateContents"); 174 179 final String newTemplate = uidl.getStringAttribute("template"); 175 180 176 // Get the HTML-template from client 177 String template = client 178 .getResource("layouts/" + newTemplate + ".html"); 179 if (template == null) { 180 template = "<em>Layout file layouts/" 181 + newTemplate 182 + ".html is missing. Components will be drawn for debug purposes.</em>"; 183 } else { 184 currentTemplate = newTemplate; 181 currentTemplateName = null; 182 hasTemplateContents = false; 183 184 String template = ""; 185 if (newTemplate != null) { 186 // Get the HTML-template from client 187 template = client.getResource("layouts/" + newTemplate + ".html"); 188 if (template == null) { 189 template = "<em>Layout file layouts/" 190 + newTemplate 191 + ".html is missing. Components will be drawn for debug purposes.</em>"; 192 } else { 193 currentTemplateName = newTemplate; 194 } 195 } else { 196 hasTemplateContents = true; 197 template = newTemplateContents; 185 198 } 186 199 … … 209 222 210 223 private boolean hasTemplate() { 211 if (currentTemplate == null) {224 if (currentTemplateName == null && !hasTemplateContents) { 212 225 return false; 213 226 } else { -
trunk/src/com/itmill/toolkit/ui/CustomLayout.java
r4747 r5261 5 5 package com.itmill.toolkit.ui; 6 6 7 import java.io.IOException; 8 import java.io.InputStream; 9 import java.io.InputStreamReader; 7 10 import java.util.HashMap; 8 11 import java.util.Iterator; … … 40 43 public class CustomLayout extends AbstractLayout { 41 44 45 private static final int BUFFER_SIZE = 10000; 46 42 47 /** 43 48 * Custom layout slots containing the components. … … 45 50 private final HashMap slots = new HashMap(); 46 51 47 private String templateName; 48 49 /** 50 * Constructor for custom layout with given template name. 52 private String templateContents = null; 53 54 private String templateName = null; 55 56 /** 57 * Constructs a custom layout with the template given in the stream. 58 * 59 * @param templateStream 60 * Stream containing template data. Must be using UTF-8 61 * encoding. To use a String as a template use for instance 62 * new ByteArrayInputStream("<template>".getBytes()). 63 * @param streamLength 64 * Length of the templateStream 65 * @throws IOException 66 */ 67 public CustomLayout(InputStream templateStream) throws IOException { 68 69 InputStreamReader reader = new InputStreamReader(templateStream); 70 StringBuffer b = new StringBuffer(BUFFER_SIZE); 71 72 char[] cbuf = new char[BUFFER_SIZE]; 73 int offset = 0; 74 75 while (true) { 76 int nrRead = reader.read(cbuf, offset, BUFFER_SIZE); 77 b.append(cbuf, 0, nrRead); 78 if (nrRead < BUFFER_SIZE) { 79 break; 80 } 81 } 82 83 templateContents = b.toString(); 84 } 85 86 /** 87 * Constructor for custom layout with given template name. Template file is 88 * fetched from "<theme>/layout/<templateName>". 51 89 */ 52 90 public CustomLayout(String template) { … … 154 192 super.paintContent(target); 155 193 156 target.addAttribute("template", templateName); 194 if (templateName != null) { 195 target.addAttribute("template", templateName); 196 } else { 197 target.addAttribute("templateContents", templateContents); 198 } 157 199 // Adds all items in all the locations 158 200 for (final Iterator i = slots.keySet().iterator(); i.hasNext();) { … … 226 268 public void setTemplateName(String templateName) { 227 269 this.templateName = templateName; 270 templateContents = null; 228 271 requestRepaint(); 229 272 }
