Hi Isomorphic,I was attempting to integrate ckeditor with smartgwt.
First,I bind ckeditor for the "animals" datasource as follows:
My detail implementation code is shown as follows:
BuiltInDS.java
CKEditor.java
CKEditorItem.java
I was wondering if my implementation method is appropriate. What's your suggestion about ckEditor integration.
. smartgwtee-4.0p、ie9.0、eclipse
First,I bind ckeditor for the "animals" datasource as follows:
Code:
DataSource ds = DataSource.get("animals"); DataSourceField information = ds.getField("information"); ckEditor = new CKEditorItem("information", "信息"); information.setEditorType(ckEditor); ckEditor.setValue(DEFAULT_HTML_CONTENT); ckEditor.setShowTitle(false); ckEditor.setWidth("100"); ckEditor.setHeight("500");
BuiltInDS.java
Code:
public void onModuleLoad() { try { DataSource ds = DataSource.get("animals"); DataSourceField information = ds.getField("information"); ckEditor = new CKEditorItem("information", "信息"); information.setEditorType(ckEditor); ckEditor.setValue(DEFAULT_HTML_CONTENT); ckEditor.setShowTitle(false); ckEditor.setWidth("100"); ckEditor.setHeight("500"); VLayout main = new VLayout(); main.setSize("100%", "80%"); final DynamicForm form = new DynamicForm(); form.setBorder("2px solid blue"); form.setNumCols(2); form.setAutoFocus(true); form.setDataSource(ds); IButton btnPrintHTML = new IButton("打印HTML"); btnPrintHTML.addClickHandler(btnPrintHTML_onClick); IButton save = new IButton("保存"); save.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { form.saveData(); } }); form.setSize( "50%", "80%" ); HLayout hMain = new HLayout(); /************************** start *************************/ final ListGrid countryGrid = new ListGrid(); countryGrid.setWidth(500); countryGrid.setHeight(224); countryGrid.setShowAllRecords(true); ListGridField countryCodeField = new ListGridField("countryCode", "代码", 40); ListGridField nameField = new ListGridField("countryName", "国家"); ListGridField independenceField = new ListGridField("independence", "独立日", 225); independenceField.setType(ListGridFieldType.DATE); ListGridField populationField = new ListGridField("population", "人口"); populationField.setType(ListGridFieldType.INTEGER); ListGridField gdpField = new ListGridField("gdp", "GDP"); gdpField.setType(ListGridFieldType.FLOAT); countryGrid.setFields(new ListGridField[] {countryCodeField, nameField, independenceField, populationField, gdpField}); countryGrid.setCanResizeFields(true); countryGrid.setData(CountrySampleData.getRecords()); /************************** end *************************/ hMain.setMembers(btnPrintHTML, save, countryGrid); main.setMembers(form, hMain ); main.draw(); } catch (Exception exc) { SC.warn("An exception has occured:<br>" + exc.toString()); } }
Code:
package com.smartgwt.sample.client; import com.smartgwt.client.widgets.form.fields.CanvasItem; public class CKEditorItem extends CanvasItem { private CKEditor ckeCanvas; public CKEditorItem(String name) { super(name); ckeCanvas = new CKEditor(name); this.setCanvas(ckeCanvas); setShouldSaveValue( true ); } public CKEditorItem(String name, String title) { super( name, title ); ckeCanvas = new CKEditor(name); this.setCanvas(ckeCanvas); setShouldSaveValue( true ); } @Override public void setWidth(String width) { super.setWidth(width); ckeCanvas.setWidth(width); } @Override public void setWidth(int width) { super.setWidth(width); ckeCanvas.setWidth(width); } @Override public void setHeight(String height) { super.setHeight(height); ckeCanvas.setHeight(height); } @Override public void setHeight(int height) { super.setHeight(height); ckeCanvas.setHeight(height); } @Override public Object getValue() { return getCKEditorValue(ckeCanvas.getID()+"_ta"); } @Override public void setValue(String value) { super.setValue(value); if(ckeCanvas.isLoaded()) setCKEditorValue(ckeCanvas.getID()+"_ta", value); else ckeCanvas.setContents(value); } }
Code:
package com.smartgwt.sample.client; import com.smartgwt.client.types.Overflow; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.events.DrawEvent; import com.smartgwt.client.widgets.events.DrawHandler; public class CKEditor extends Canvas{ { setOverflow(Overflow.VISIBLE); setCanDragResize(false); setRedrawOnResize(false); setZIndex(0); } private boolean loaded=false; public CKEditor(String id){ super(id); addDrawHandler(new DrawHandler() { @Override public void onDraw(DrawEvent event) { loadCKEditor(); } }); } @Override public String getInnerHTML() { if(this.getContents() != null){ return "<textarea style='width=100%;height=100%' id=" + this.getID() + "_ta>"+ getContents()+"</textarea>"; } return "<textarea style='width=100%;height=100%' id=" + this.getID() + "_ta></textarea>"; } public boolean isLoaded() { return loaded; } }
. smartgwtee-4.0p、ie9.0、eclipse
Comment