/** * Initializes the cell with the information from the model. * * @param column the column * @param row the row */ public void init(IGridBindingColumnInformation column, IGridBindingRowInformation row) { setColumn(column); setRow(row); final IGridBinding grid = getGrid(); final IBindingContext context = grid.getContext(); final IGridModel model = grid.getModel(); final Object columnID = column.getId(); final Object rowID = row.getId(); // LogUtils.debug(this, "\ncolumn=" + columnID + "\nrow=" + rowID); IGridCell cell = null; try { if (Activator.getDefault().TRACE_SOURCE_MODEL) { LogUtils.debug( model, "Model[" + grid.getGrid().hashCode() + "]: getcell(" + columnID + ", " + rowID + ")"); } cell = model.getCell(columnID, rowID); if (Activator.getDefault().TRACE_SOURCE_MODEL) { LogUtils.debug(model, "Model: >>> " + cell); } } catch (final Exception ex) { LogUtils.throwException(this, "Cannot get cell", ex); } try { if (Activator.getDefault().TRACE_SOURCE_MODEL) { LogUtils.debug(model, "Model[" + grid.getGrid().hashCode() + "]: getValue"); } final IObservableValue value = cell.getValue(); if (Activator.getDefault().TRACE_SOURCE_MODEL) { LogUtils.debug(model, "Model: >>> " + value); } /* * Retrieve the wanted information */ setObjectValue(value); /* * If we didn't get a IOV, then just ignore it... */ if (value == null) return; // TODO: set the renderer: final item.s setDataType(IBindingDataType.Factory.create(value.getValue(), value.getValueType())); /* * We will use a UI binding to convert from myValue to myLabelUIAttribute... */ final AbstractUIAttribute attribute = new VirtualUIAttribute(String.class); setLabelUIAttribute(attribute); final IValueBinding lb = context.addBinding().model(value).ui(attribute); final Map<String, Object> args = cell.getArguments(); if (args != null) { lb.args(args); } lb.setCell(this); setLabelBinding(lb); /* * Set up the painter */ final Grid gridControl = grid.getGrid(); final UIAttributePainter p = new UIAttributePainter(gridControl, attribute); p.setDefaultBackground(gridControl.getBackground()); setPainter(p); /* * The column header sets the column width based on the arguments of the label binding */ if (rowID == IGridModel.HEADER1) { final GridColumn gridColumn = column.getGridColumn(); gridColumn.setWidth(lb.getArgument(Constants.ARG_WIDTH, Integer.class, 60)); // TODO: cell renderer // TODO: alignment } /* * We added a new binding so call finish as well... */ context.finish(FinishOption.IF_ALREADY_FINISHED); attribute.addChangeListener(myPropertyValueListener); // An immediate update updateCellValuesDelayed(); } catch (final Exception ex) { LogUtils.error(this, ex); } finally { cell.dispose(); } }