how to apply html to SuggestList popup - gwt

How can I apply html to SuggestList popup in Gwt?
I want to apply html table in suggest list popup.
eg:
private SuggestOracle getSuggest() {
oracle = new MultiWordSuggestOracle();
oracle.add("<table border=1><tr><td>hussain</td></tr><td>hussain1</td></table>");
oracle.add("<table border=1><tr><td>taher</td></tr><td>taher1</td></table>");
oracle.add("<table border=1><tr><td>hussain22</td></tr><td>hussain2</td></table>");
return oracle;
}
The popup should show table with 2 column but it is taking html as text
Thanks
Husein

Override MultiWordSuggestOracle#isDisplayStringHTML().
Should SuggestOracle.Suggestion display strings be treated as HTML? If true, this all suggestions' display strings will be interpreted as HTML, otherwise as text.
MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(){
#Override
public boolean isDisplayStringHTML(){
return true;
}
};
Note: Each suggestion has a display string and a replacement string.
For more info have a look at SuggestOracle.Suggestion
--EDIT--
For more info have a look at MultiWordSuggestOracle and HTML display
complete sample code:
MultiWordSuggestOracle oracle = new MultiWordSuggestOracle() {
#Override
public boolean isDisplayStringHTML() {
return true;
}
};
Collection<Suggestion> suggestionList = new ArrayList<Suggestion>();
suggestionList.add(new MultiWordSuggestOracle.MultiWordSuggestion("hussain",
"<table border='1'><tr><td>hussain</td></tr></table>"));
suggestionList.add(new MultiWordSuggestOracle.MultiWordSuggestion("taher1",
"<table border='1'><tr><td>taher1</td></tr></table>"));
suggestionList.add(new MultiWordSuggestOracle.MultiWordSuggestion("hussain2",
"<table border='1'><tr><td>hussain2</td></tr></table>"));
oracle.setDefaultSuggestions(suggestionList);

Related

Layout update GWT

I use RPC calls to connect to mySql and bring text data from there.
My page is defined as split Layout.
my problem is that I don't know how to update the main layout with different text.
if i use the clear() method it will remove all the layout !
"p" is the splitLayout.
RPC:
rpcService.getChapterTxt(selectedBook,bookChapters[selectedBook],
new AsyncCallback<List<BibleTxt>>(){
public void onFailure(Throwable caught)
{
Window.alert("Failed getting Chapter");
}
public void onSuccess(List<BibleTxt> result)
{
int i = 0 ;
String verseText ="";
//Label verseLabel = new Label();
PPanel chapterPar = new PPanel();
HTML page= new HTML(verseText);
for(i=0;i<result.size();i++)
{
verseText = result.get(i).getVerseText();
//verseLabel.setText(verseText);
page.setText(page.getText() + verseText);
}
chapterPar.add(page);
//p.clear();
p.add(chapterPar); // adds the main layout
}
});
Why you don't reuse the text component changing its content text instead of continuously detaching/attaching elements to the widget hierarchy. That way should perform better and cause less problems.

use cellTree with widget

I want to add customized widgets into the cell tree, something like below:
>Label1
customized-widget
>Label2
customized-widget
>Label3
customized-widget
Under each label, there is a customized widget(extends composite)
I tried to use
public void render(
com.google.gwt.cell.client.Cell.Context context, Customizedwidget value, SafeHtmlBuilder sb) {
if(value!=null) sb.appendEscaped(value.getElement().getInnerHTML());
}
but, sb.appendEscaped(value.getElement().getInnerHTML()) is not working, it shows me a bunch of html or maybe javascript code when I click label.
I would like to know how I can solve this problem?
You can use SafeHtmlCell to include your own html content inside of the cell table's cell,
SafeHtmlCell html = new SafeHtmlCell();
final Column<DTO, SafeHtml> htmlContent = new Column<DTO, SafeHtml>(html) {
#Override
public SafeHtml getValue(DTO object) {
// code goes here
return new SafeHtml;
}
};
dataGrid.addColumn(htmlContent, "");
or you can use ButtonCell(to insert buttons), check other cell's also.
check this: GWT - Make CellTable Cell use HTML?

Controlling the font of the content of an HTML Table in iTextSharp

I am using the most recent DLLs and trying to render HTML fragments into a PDF document using the following code:
Private Function ReadHtml(ByVal text As String) As Paragraph
Dim par = NewParagraph()
Try
Dim htmlText = Server.HtmlDecode(text)
If Not htmlText.StartsWith("<") Then
htmlText = "<span>" & htmlText & "</span>"
End If
Using reader As New IO.StringReader(htmlText)
Dim mh As New MyHandler()
XMLWorkerHelper.GetInstance().ParseXHtml(mh, reader)
'use mh.elements
For Each element In mh.Elements
Dim list = TryCast(element, List)
If list IsNot Nothing Then
element = Clone(list)
End If
par.Add(element)
Next
setFont(par, m_rowFont)
End Using
Catch ex As Exception
Throw New Exception("Exception in ReadHtml using: '" & text & "'")
End Try
Return par
End Function
When this function returns, I take the paragraph and insert it into the PDF. The problem I am having is that while I can set the font in an outer div, and the resulting PDF will render that correctly, if I include an HTML table inside of the div where I've set the font, everything inside of the table renders using the Page's default font.
How do I control the font of the table content?
Your Html in font-size and font-family remove.
public string ConvertPdfHtml(string html)
{
html = CleanStyleAttribute(html, "font-family");
html = CleanStyleAttribute(html, "font-size");
....
return html;
}
private string CleanStyleAttribute(string html, string styleAttributeName)
{
return Regex.Replace(html, styleAttributeName + "(?>:(.*?);)","");
}

CodeMirror-UI in smartGWT tab

I have a question regarding the integration of CodeMirror UI in a smartGWT tab.
Basically, I can't display the CodeMirror-UI editor inside the textarea element I attached to a smartGWT tab. Here's what I did:
I installed CodeMirror-UI as described on its page, correcting the paths to match my project's directory hierarchy
I wrote a js script in my project's main html (at head) :
<head>
...
<script>
function fireEditor()
{
var textarea = window.document.getElementById('tab_editor' );
var uiOptions = { path : 'codemirror-ui/js/', searchMode : 'inline' };
var codeMirrorOptions = { mode: 'javascript' };
var editor = new CodeMirrorUI(textarea,uiOptions,codeMirrorOptions);
}
</script>
</head>
I invoked the script while opening a (smartGWT) tab:
// create a smartGWT tab
Tab tab = new Tab("tab");
tab.setID("tab");
tab.setCanClose(true);
// put the CodeMirror UI inside the smartGWT tab
// create a smartGWT canvas
Canvas tabContent = new Canvas();
tabContent.setID("tabc");
tabContent.setWidth100();
tabContent.setHeight100();
// use a GWT HTMLPanel to attach new html elements to the smartGWT canvas
// and invoke the fireEditor() function to load the CodeMirror UI
HTMLPanel editorContainer = new HTMLPanel(
"<div id=\"editor_container\">"
+ "<textarea id=\"tab_editor\" style=\"width:100%;height:100%\" onload=\"fireEditor()\">"
+ "</textarea>"
+ "</div>");
editorContainer.setWidth("100%");
editorContainer.setHeight("100%");
running from a browser (I'm using firefox - iceweasel 10.0.10), this results in a smartGWT tab that shows an empty textarea element.
Checking with firebug, the area within the smartGWT tab contains the HTML I specified in the HTMLPanel, but no CodeMirror UI is shown.
What am I missing?
I'm using Eclipse Indigo, with gwt 2.4.0, smartgwt 3.0p, and codemirror ui 0.0.19 from its git repo (which itself uses CodeMirror 2.3).
Thank you
Found the solution.
First of all, there is no "onload" event for an html textarea element, so the code
HTMLPanel editorContainer = new HTMLPanel(
"<div id=\"editor_container\">"
+ "<textarea id=\"tab_editor\" style=\"width:100%;height:100%\" onload=\"fireEditor()\">"
+ "</textarea>"
+ "</div>");
will just place a textarea in the HTMLPanel, without calling "fireEditor()".
Replacing "onload" with "onclick" does the trick: once the textarea element shows up, click on it, and the CodeMirrorUI will show up as well.
Problem: I need to visualize the CodeMirrorUI interface automatically, ergo the "onclick" approach is useless.
To accomplish this task, I need to somehow modify the DOM of the smartGWT tab, replacing its inner html with CodeMirrorUI's html.
I found this documentation very helpful: http://www.smartclient.com/smartgwtee-latest/javadoc/com/smartgwt/client/docs/DomIntegration.html
this is the resulting code:
1) I kept the js script in my project's main html (at head) :
<head>
...
<script>
function fireEditor()
{
var textarea = window.document.getElementById('tab_editor' );
var uiOptions = { path : 'codemirror-ui/js/', searchMode : 'inline' };
var codeMirrorOptions = { mode: 'javascript' };
var editor = new CodeMirrorUI(textarea,uiOptions,codeMirrorOptions);
}
</script>
</head>
2) I created a new class -"MyEditor", following the example found in the documentation link I mentioned above :
public class MyEditor extends Canvas {
private String editor_id = null;
private static native void replace(String editor) /*-{
$wnd.fireEditor(editor);
}-*/;
public MyEditor(Integer num) {
editor_id = "editor_" + num;
setRedrawOnResize(false);
}
#Override
public String getInnerHTML() {
return "<textarea id=\"" + editor_id + "\"" + "style=\"width:100%;height:100%\"></textarea>";
}
#Override
protected void onDraw() {
MyEditor.replace(editor_id);
}
}
3) finally, I filled the smartGWT tab with an instance of MyEditor:
// create a smartGWT tab
Tab tab = new Tab("tab");
tab.setID("tab");
tab.setCanClose(true);
MyEditor editor = new MyEditor(tabNumber); // an integer number
tab.setPane(editor);
Tested. Working.

setting a default text to a GWT ListBox

I am trying to create a ListBox using GWT. I am using UiBinder to create the field.
I would like to set a default text on the list box and when a user clicks on the box, it should show me the list items. Once again, if user has not selected any option, it should show me the default text again.
Any way to do this either using Uibinder or some ListBox methods?
If I understand correctly you want a value to show but when the user clicks on the list it disappears and shows you the list items?
As far as I know there is no option to that natively.
What you can do is add the first item to hold your default value.
You can do this grammatically by using addItem in code or using:
<g:Listbox>
<g:item value="-1">Default text</g:item>
</g:Listbox>
works with gwt 2.1+
The value can still be selected.
You can choose to ignore it or add an attribute "disabled" with value "disabled" to the option element:
listbox.getElement().getFirstChildElement().setAttribute("disabled" ,"disabled" )
hope it helps a bit :)
You can also use a renderer to control what is shown if 'Null' is selected.
(Inspired by: How do I add items to GWT ListBox in Uibinder .ui.xml template ?)
private class SimpleRenderer implements Renderer<T>{
private String emptyValue = "Select a value";
#Override
public String render(T val) {
if(val == null) {
return emptyValue;
}
return val.toString();
}
#Override
public void render(T val, Appendable appendable) throws IOException {
appendable.append(render(val));
}
public void setEmptyValue(String emptyValue) {
this.emptyValue = emptyValue;
}
}