Hi, I'm trying out the CanvasItem APIs:
In code:
1 DataSource created which is attached to a ValuesManager which holds a form and a grid.
Issues:
* When entering edit mode in the grid, the CanvasItem in the form suddenly disappears. I think I don't reuse the same instance, isn't that right?
* Showcase sample says to do ((CanvasItem) item).setCanvas(innerPane), but item appears to be a TextItem instead of a CanvasItem.
I tried to do the same myself (setCanvasWorkaround), but this gives a warning.
Standalone test case:
thanks,
SmartGWT EE 26-07-2011
In code:
1 DataSource created which is attached to a ValuesManager which holds a form and a grid.
Issues:
* When entering edit mode in the grid, the CanvasItem in the form suddenly disappears. I think I don't reuse the same instance, isn't that right?
* Showcase sample says to do ((CanvasItem) item).setCanvas(innerPane), but item appears to be a TextItem instead of a CanvasItem.
I tried to do the same myself (setCanvasWorkaround), but this gives a warning.
Standalone test case:
Code:
public class CanvsTst implements EntryPoint { public void onModuleLoad() { RootPanel.get().add(getViewPanel()); } private static final String FIELD1 = "field1"; private static final String FIELD2 = "field2"; public Canvas getViewPanel() { MyRecord record1 = new MyRecord(1); MyRecord record2 = new MyRecord(2); MyRecord record3 = new MyRecord(3); VLayout container = new VLayout(); container.setWidth("50%"); container.setHeight("50%"); DataSourceField field1 = new DataSourceField(); field1.setTitle(FIELD1); field1.setName(FIELD1); field1.setEditorType(new TextItem(FIELD1)); DataSourceField field2 = new DataSourceField(); field2.setName(FIELD2); field2.setTitle(FIELD2); field2.setEditorType(new ListGridItem(FIELD2)); DataSource dataSource = new DataSource(); dataSource.setClientOnly(true); dataSource.setFields(field1, field2); DynamicForm form = new DynamicForm(); form.setWidth(450); form.setHeight(100); form.setDataPath("/form"); ValuesManager vm = new ValuesManager(); vm.setDataSource(dataSource); vm.setDisableValidation(true); vm.addMember(form); vm.setValue("/form", record1); vm.setValue("/grid", new Record[] { record1, record2, record3 }); ListGrid grid = new ListGrid(); grid.setWidth100(); grid.setHeight(200); grid.setCanEdit(true); grid.setValuesManager(vm); grid.setDataPath("/grid"); container.addMember(form); container.addMember(grid); return container; } public class ListGridItem extends CanvasItem { ListGridItem(String name) { super(name); setShouldSaveValue(true); setHeight("22px"); addShowValueHandler(new ShowValueHandler() { public void onShowValue(ShowValueEvent event) { Object value = event.getDataValue(); if (value != null) { CanvasItem item = (CanvasItem) event.getSource(); HTMLPane innerPane = (HTMLPane) item.getCanvas(); innerPane.setContents("==> " + value); } } }); setInitHandler(new FormItemInitHandler() { public void onInit(FormItem item) { HTMLPane innerPane = new HTMLPane(); innerPane.setContents("HTMLPane from onInit"); // 1.___ // ((CanvasItem) item).setCanvas(innerPane); /* * Results in: java.lang.ClassCastException * com.smartgwt.client.widgets.form.fields.TextItem */ // 2.___ // CanvsTst.setCanvasWorkaround(item, innerPane); /* * Workaround: set canvas attribute anyways Result in: [ERROR] * WARN:CanvasItem:isc_CanvasItem_1:Observer: [CanvasItem ID:isc_CanvasItem_1 * name:field2] is already observing method '$lf' on object '[HTMLPane * ID:isc_HTMLPane_0]', ignoring * * + value is not shown in the form and is only shown on the second edit of a * grid row */ } }); HTMLPane innerPane = new HTMLPane(); innerPane.setBackgroundColor("green"); innerPane.setContents("HTMLPane from constructor"); setCanvas(innerPane); /* * In no setCanvas is performed in the constructor: [ERROR] * WARN:CanvasItem:isc_CanvasItem_0:CanvasItem: field2 defined with no canvas property - * creating a default canvas for this item. */ } }; public class MyRecord extends Record { public MyRecord(int number) { super(); setAttribute(FIELD1, FIELD1 + "_value_" + number); setAttribute(FIELD2, FIELD2 + "_value_" + number); } } public static void setCanvasWorkaround(FormItem item, Canvas canvas) { item.setAttribute("canvas", canvas == null ? null : canvas.getOrCreateJsObj()); } }
thanks,
SmartGWT EE 26-07-2011
Comment