BrightSide Workbench Full Report + Source Code
HTMLComponent.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.html;
19 
20 import java.io.IOException;
21 import java.io.PrintWriter;
22 import java.io.StringWriter;
23 import java.util.Date;
24 import org.turro.elephant.context.ElephantContext;
25 import org.turro.elephant.context.IElement;
26 import org.turro.elephant.impl.util.Localizer;
27 import org.turro.i18n.I_;
28 
33 public class HTMLComponent extends HTMLHelper implements IHTMLRenderable {
34  protected IElement iel;
35  protected boolean editable = false;
36  protected StringWriter sw = null;
37 
39  public HTMLComponent(IElement iel) throws IOException {
40  this(iel, false);
41  }
42 
44  public HTMLComponent(IElement iel, boolean toString) throws IOException {
45  super(iel.getConstructor());
46  this.iel = iel;
47  if(toString) {
48  sw = new StringWriter();
49  setOut(new PrintWriter(sw));
50  }
51  else {
53  }
54  }
55 
56  @Override
57  public void writeDate(Date date, String mode) {
58  Localizer localizer = iel.getConstructor().getLocalizer();
59  write(localizer.parseValue("date", mode, date));
60  }
61 
62  @Override
63  public void writeNumber(Number number, String mode) {
64  Localizer localizer = iel.getConstructor().getLocalizer();
65  write(localizer.parseValue("number", mode, number));
66  }
67 
68  @Override
69  public void writeBytes(long bytes) {
70  Localizer localizer = iel.getConstructor().getLocalizer();
71  write(localizer.parseValue("bytes", null, Long.valueOf(bytes)));
72  }
73 
74  @Override
75  public void writeBoolean(boolean value) {
76  write(I_.compatibility().get("fmt." + (value ? "true" : "false")));
77  }
78 
79  public void configureInPlaceEditor(IElement element, String ident, String component, String action, String params, int rows) {
81  write(
82  "new Ajax.InPlaceEditor(" +
83  "$('" + ident + "')," +
85  "/xpaction/" + component + "?action=" + action + "&context=" + element.getContext().getPath() + "&idel=" + element.getId() + params + "', {" +
86  "okText: '" + I_.get("Save") + "'," +
87  "cancelText: '" + I_.get("Cancel") + "'," +
88  "savingText: '" + I_.get("Saving") + "',"+
89  "clickToEditText: '" + I_.get("Click to edit") + "'," +
90  "rows: " + rows + "," +
91  "ajaxOptions: {method: 'get'}" +
92  "});"
93  );
94  endJavaScript();
95  }
96 
97  public void configureFeditor(IElement element, String ident, String component, String action, String params, int rows) {
99  write(
100  "$('" + ident + "').onclick = function() { openFeditor(this); }"
101  );
102  endJavaScript();
103  }
104 
105  @Override
106  public String toString() {
107  if(sw != null) {
108  return sw.toString();
109  }
110  return null;
111  }
112 
113  /* IRenderable */
114 
115  @Override
116  public void startElement(int mode) {}
117 
118  @Override
119  public void endElement(int mode) {}
120 
121  @Override
122  public void writeElement(int mode) {}
123 
124  @Override
125  public String strElement(int mode) {
126  StringWriter w = new StringWriter();
127  setOut(new PrintWriter(w));
128  writeElement(mode);
129  return w.toString();
130  }
131 
132  @Override
133  public void setEditable(boolean editable) {
134  this.editable = editable;
135  }
136 
137 }
String parseValue(String type, String outFormat, Object value)
Definition: Localizer.java:96
void writeBoolean(boolean value)
void configureInPlaceEditor(IElement element, String ident, String component, String action, String params, int rows)
HTMLComponent(IElement iel, boolean toString)
void writeDate(Date date, String mode)
void setEditable(boolean editable)
void writeNumber(Number number, String mode)
void configureFeditor(IElement element, String ident, String component, String action, String params, int rows)
HTMLGenerator write(String value)
Definition: HTMLHelper.java:69
static String get(String msg)
Definition: I_.java:41
static I18nCompatibilityWrapper compatibility()
Definition: I_.java:109